hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/include/rdma/restrack.h
....@@ -7,12 +7,15 @@
77 #define _RDMA_RESTRACK_H_
88
99 #include <linux/typecheck.h>
10
-#include <linux/rwsem.h>
1110 #include <linux/sched.h>
1211 #include <linux/kref.h>
1312 #include <linux/completion.h>
1413 #include <linux/sched/task.h>
1514 #include <uapi/rdma/rdma_netlink.h>
15
+#include <linux/xarray.h>
16
+
17
+struct ib_device;
18
+struct sk_buff;
1619
1720 /**
1821 * enum rdma_restrack_type - HW objects to track
....@@ -39,34 +42,17 @@
3942 */
4043 RDMA_RESTRACK_MR,
4144 /**
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
+ /**
4253 * @RDMA_RESTRACK_MAX: Last entry, used for array dclarations
4354 */
4455 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);
7056 };
7157
7258 /**
....@@ -105,57 +91,28 @@
10591 */
10692 const char *kern_name;
10793 /**
108
- * @node: hash table entry
109
- */
110
- struct hlist_node node;
111
- /**
11294 * @type: various objects in restrack database
11395 */
11496 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;
115105 };
116106
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);
152109 /**
153110 * rdma_is_kernel_res() - check the owner of resource
154111 * @res: resource entry
155112 */
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)
157114 {
158
- return !res->task;
115
+ return !res->user;
159116 }
160117
161118 /**
....@@ -170,20 +127,6 @@
170127 */
171128 int rdma_restrack_put(struct rdma_restrack_entry *res);
172129
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
-
187130 /*
188131 * Helper functions for rdma drivers when filling out
189132 * nldev driver attributes.
....@@ -194,4 +137,12 @@
194137 int rdma_nl_put_driver_u64(struct sk_buff *msg, const char *name, u64 value);
195138 int rdma_nl_put_driver_u64_hex(struct sk_buff *msg, const char *name,
196139 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);
197148 #endif /* _RDMA_RESTRACK_H_ */