.. | .. |
---|
7 | 7 | #define _RDMA_RESTRACK_H_ |
---|
8 | 8 | |
---|
9 | 9 | #include <linux/typecheck.h> |
---|
10 | | -#include <linux/rwsem.h> |
---|
11 | 10 | #include <linux/sched.h> |
---|
12 | 11 | #include <linux/kref.h> |
---|
13 | 12 | #include <linux/completion.h> |
---|
14 | 13 | #include <linux/sched/task.h> |
---|
15 | 14 | #include <uapi/rdma/rdma_netlink.h> |
---|
| 15 | +#include <linux/xarray.h> |
---|
| 16 | + |
---|
| 17 | +struct ib_device; |
---|
| 18 | +struct sk_buff; |
---|
16 | 19 | |
---|
17 | 20 | /** |
---|
18 | 21 | * enum rdma_restrack_type - HW objects to track |
---|
.. | .. |
---|
39 | 42 | */ |
---|
40 | 43 | RDMA_RESTRACK_MR, |
---|
41 | 44 | /** |
---|
| 45 | + * @RDMA_RESTRACK_CTX: Verbs contexts (CTX) |
---|
| 46 | + */ |
---|
| 47 | + RDMA_RESTRACK_CTX, |
---|
| 48 | + /** |
---|
| 49 | + * @RDMA_RESTRACK_COUNTER: Statistic Counter |
---|
| 50 | + */ |
---|
| 51 | + RDMA_RESTRACK_COUNTER, |
---|
| 52 | + /** |
---|
42 | 53 | * @RDMA_RESTRACK_MAX: Last entry, used for array dclarations |
---|
43 | 54 | */ |
---|
44 | 55 | RDMA_RESTRACK_MAX |
---|
45 | | -}; |
---|
46 | | - |
---|
47 | | -#define RDMA_RESTRACK_HASH_BITS 8 |
---|
48 | | -struct rdma_restrack_entry; |
---|
49 | | - |
---|
50 | | -/** |
---|
51 | | - * struct rdma_restrack_root - main resource tracking management |
---|
52 | | - * entity, per-device |
---|
53 | | - */ |
---|
54 | | -struct rdma_restrack_root { |
---|
55 | | - /* |
---|
56 | | - * @rwsem: Read/write lock to protect lists |
---|
57 | | - */ |
---|
58 | | - struct rw_semaphore rwsem; |
---|
59 | | - /** |
---|
60 | | - * @hash: global database for all resources per-device |
---|
61 | | - */ |
---|
62 | | - DECLARE_HASHTABLE(hash, RDMA_RESTRACK_HASH_BITS); |
---|
63 | | - /** |
---|
64 | | - * @fill_res_entry: driver-specific fill function |
---|
65 | | - * |
---|
66 | | - * Allows rdma drivers to add their own restrack attributes. |
---|
67 | | - */ |
---|
68 | | - int (*fill_res_entry)(struct sk_buff *msg, |
---|
69 | | - struct rdma_restrack_entry *entry); |
---|
70 | 56 | }; |
---|
71 | 57 | |
---|
72 | 58 | /** |
---|
.. | .. |
---|
105 | 91 | */ |
---|
106 | 92 | const char *kern_name; |
---|
107 | 93 | /** |
---|
108 | | - * @node: hash table entry |
---|
109 | | - */ |
---|
110 | | - struct hlist_node node; |
---|
111 | | - /** |
---|
112 | 94 | * @type: various objects in restrack database |
---|
113 | 95 | */ |
---|
114 | 96 | enum rdma_restrack_type type; |
---|
| 97 | + /** |
---|
| 98 | + * @user: user resource |
---|
| 99 | + */ |
---|
| 100 | + bool user; |
---|
| 101 | + /** |
---|
| 102 | + * @id: ID to expose to users |
---|
| 103 | + */ |
---|
| 104 | + u32 id; |
---|
115 | 105 | }; |
---|
116 | 106 | |
---|
117 | | -/** |
---|
118 | | - * rdma_restrack_init() - initialize resource tracking |
---|
119 | | - * @res: resource tracking root |
---|
120 | | - */ |
---|
121 | | -void rdma_restrack_init(struct rdma_restrack_root *res); |
---|
122 | | - |
---|
123 | | -/** |
---|
124 | | - * rdma_restrack_clean() - clean resource tracking |
---|
125 | | - * @res: resource tracking root |
---|
126 | | - */ |
---|
127 | | -void rdma_restrack_clean(struct rdma_restrack_root *res); |
---|
128 | | - |
---|
129 | | -/** |
---|
130 | | - * rdma_restrack_count() - the current usage of specific object |
---|
131 | | - * @res: resource entry |
---|
132 | | - * @type: actual type of object to operate |
---|
133 | | - * @ns: PID namespace |
---|
134 | | - */ |
---|
135 | | -int rdma_restrack_count(struct rdma_restrack_root *res, |
---|
136 | | - enum rdma_restrack_type type, |
---|
137 | | - struct pid_namespace *ns); |
---|
138 | | - |
---|
139 | | -/** |
---|
140 | | - * rdma_restrack_add() - add object to the reource tracking database |
---|
141 | | - * @res: resource entry |
---|
142 | | - */ |
---|
143 | | -void rdma_restrack_add(struct rdma_restrack_entry *res); |
---|
144 | | - |
---|
145 | | -/** |
---|
146 | | - * rdma_restrack_del() - delete object from the reource tracking database |
---|
147 | | - * @res: resource entry |
---|
148 | | - * @type: actual type of object to operate |
---|
149 | | - */ |
---|
150 | | -void rdma_restrack_del(struct rdma_restrack_entry *res); |
---|
151 | | - |
---|
| 107 | +int rdma_restrack_count(struct ib_device *dev, |
---|
| 108 | + enum rdma_restrack_type type); |
---|
152 | 109 | /** |
---|
153 | 110 | * rdma_is_kernel_res() - check the owner of resource |
---|
154 | 111 | * @res: resource entry |
---|
155 | 112 | */ |
---|
156 | | -static inline bool rdma_is_kernel_res(struct rdma_restrack_entry *res) |
---|
| 113 | +static inline bool rdma_is_kernel_res(const struct rdma_restrack_entry *res) |
---|
157 | 114 | { |
---|
158 | | - return !res->task; |
---|
| 115 | + return !res->user; |
---|
159 | 116 | } |
---|
160 | 117 | |
---|
161 | 118 | /** |
---|
.. | .. |
---|
170 | 127 | */ |
---|
171 | 128 | int rdma_restrack_put(struct rdma_restrack_entry *res); |
---|
172 | 129 | |
---|
173 | | -/** |
---|
174 | | - * rdma_restrack_set_task() - set the task for this resource |
---|
175 | | - * @res: resource entry |
---|
176 | | - * @task: task struct |
---|
177 | | - */ |
---|
178 | | -static inline void rdma_restrack_set_task(struct rdma_restrack_entry *res, |
---|
179 | | - struct task_struct *task) |
---|
180 | | -{ |
---|
181 | | - if (res->task) |
---|
182 | | - put_task_struct(res->task); |
---|
183 | | - get_task_struct(task); |
---|
184 | | - res->task = task; |
---|
185 | | -} |
---|
186 | | - |
---|
187 | 130 | /* |
---|
188 | 131 | * Helper functions for rdma drivers when filling out |
---|
189 | 132 | * nldev driver attributes. |
---|
.. | .. |
---|
194 | 137 | int rdma_nl_put_driver_u64(struct sk_buff *msg, const char *name, u64 value); |
---|
195 | 138 | int rdma_nl_put_driver_u64_hex(struct sk_buff *msg, const char *name, |
---|
196 | 139 | u64 value); |
---|
| 140 | +int rdma_nl_put_driver_string(struct sk_buff *msg, const char *name, |
---|
| 141 | + const char *str); |
---|
| 142 | +int rdma_nl_stat_hwcounter_entry(struct sk_buff *msg, const char *name, |
---|
| 143 | + u64 value); |
---|
| 144 | + |
---|
| 145 | +struct rdma_restrack_entry *rdma_restrack_get_byid(struct ib_device *dev, |
---|
| 146 | + enum rdma_restrack_type type, |
---|
| 147 | + u32 id); |
---|
197 | 148 | #endif /* _RDMA_RESTRACK_H_ */ |
---|