1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42#include <linux/slab.h>
43#include <linux/fs.h>
44#include <linux/sysctl.h>
45#include <linux/workqueue.h>
46#include <linux/sunrpc/clnt.h>
47#include <linux/sunrpc/sched.h>
48#include <linux/sunrpc/svc_rdma.h>
49#include "xprt_rdma.h"
50
51#define RPCDBG_FACILITY RPCDBG_SVCXPRT
52
53
54unsigned int svcrdma_ord = RPCRDMA_ORD;
55static unsigned int min_ord = 1;
56static unsigned int max_ord = 4096;
57unsigned int svcrdma_max_requests = RPCRDMA_MAX_REQUESTS;
58unsigned int svcrdma_max_bc_requests = RPCRDMA_MAX_BC_REQUESTS;
59static unsigned int min_max_requests = 4;
60static unsigned int max_max_requests = 16384;
61unsigned int svcrdma_max_req_size = RPCRDMA_DEF_INLINE_THRESH;
62static unsigned int min_max_inline = RPCRDMA_DEF_INLINE_THRESH;
63static unsigned int max_max_inline = RPCRDMA_MAX_INLINE_THRESH;
64
65atomic_t rdma_stat_recv;
66atomic_t rdma_stat_read;
67atomic_t rdma_stat_write;
68atomic_t rdma_stat_sq_starve;
69atomic_t rdma_stat_rq_starve;
70atomic_t rdma_stat_rq_poll;
71atomic_t rdma_stat_rq_prod;
72atomic_t rdma_stat_sq_poll;
73atomic_t rdma_stat_sq_prod;
74
75struct workqueue_struct *svc_rdma_wq;
76
77
78
79
80
81
82
83static int read_reset_stat(struct ctl_table *table, int write,
84 void __user *buffer, size_t *lenp,
85 loff_t *ppos)
86{
87 atomic_t *stat = (atomic_t *)table->data;
88
89 if (!stat)
90 return -EINVAL;
91
92 if (write)
93 atomic_set(stat, 0);
94 else {
95 char str_buf[32];
96 char *data;
97 int len = snprintf(str_buf, 32, "%d\n", atomic_read(stat));
98 if (len >= 32)
99 return -EFAULT;
100 len = strlen(str_buf);
101 if (*ppos > len) {
102 *lenp = 0;
103 return 0;
104 }
105 data = &str_buf[*ppos];
106 len -= *ppos;
107 if (len > *lenp)
108 len = *lenp;
109 if (len && copy_to_user(buffer, str_buf, len))
110 return -EFAULT;
111 *lenp = len;
112 *ppos += len;
113 }
114 return 0;
115}
116
117static struct ctl_table_header *svcrdma_table_header;
118static struct ctl_table svcrdma_parm_table[] = {
119 {
120 .procname = "max_requests",
121 .data = &svcrdma_max_requests,
122 .maxlen = sizeof(unsigned int),
123 .mode = 0644,
124 .proc_handler = proc_dointvec_minmax,
125 .extra1 = &min_max_requests,
126 .extra2 = &max_max_requests
127 },
128 {
129 .procname = "max_req_size",
130 .data = &svcrdma_max_req_size,
131 .maxlen = sizeof(unsigned int),
132 .mode = 0644,
133 .proc_handler = proc_dointvec_minmax,
134 .extra1 = &min_max_inline,
135 .extra2 = &max_max_inline
136 },
137 {
138 .procname = "max_outbound_read_requests",
139 .data = &svcrdma_ord,
140 .maxlen = sizeof(unsigned int),
141 .mode = 0644,
142 .proc_handler = proc_dointvec_minmax,
143 .extra1 = &min_ord,
144 .extra2 = &max_ord,
145 },
146
147 {
148 .procname = "rdma_stat_read",
149 .data = &rdma_stat_read,
150 .maxlen = sizeof(atomic_t),
151 .mode = 0644,
152 .proc_handler = read_reset_stat,
153 },
154 {
155 .procname = "rdma_stat_recv",
156 .data = &rdma_stat_recv,
157 .maxlen = sizeof(atomic_t),
158 .mode = 0644,
159 .proc_handler = read_reset_stat,
160 },
161 {
162 .procname = "rdma_stat_write",
163 .data = &rdma_stat_write,
164 .maxlen = sizeof(atomic_t),
165 .mode = 0644,
166 .proc_handler = read_reset_stat,
167 },
168 {
169 .procname = "rdma_stat_sq_starve",
170 .data = &rdma_stat_sq_starve,
171 .maxlen = sizeof(atomic_t),
172 .mode = 0644,
173 .proc_handler = read_reset_stat,
174 },
175 {
176 .procname = "rdma_stat_rq_starve",
177 .data = &rdma_stat_rq_starve,
178 .maxlen = sizeof(atomic_t),
179 .mode = 0644,
180 .proc_handler = read_reset_stat,
181 },
182 {
183 .procname = "rdma_stat_rq_poll",
184 .data = &rdma_stat_rq_poll,
185 .maxlen = sizeof(atomic_t),
186 .mode = 0644,
187 .proc_handler = read_reset_stat,
188 },
189 {
190 .procname = "rdma_stat_rq_prod",
191 .data = &rdma_stat_rq_prod,
192 .maxlen = sizeof(atomic_t),
193 .mode = 0644,
194 .proc_handler = read_reset_stat,
195 },
196 {
197 .procname = "rdma_stat_sq_poll",
198 .data = &rdma_stat_sq_poll,
199 .maxlen = sizeof(atomic_t),
200 .mode = 0644,
201 .proc_handler = read_reset_stat,
202 },
203 {
204 .procname = "rdma_stat_sq_prod",
205 .data = &rdma_stat_sq_prod,
206 .maxlen = sizeof(atomic_t),
207 .mode = 0644,
208 .proc_handler = read_reset_stat,
209 },
210 { },
211};
212
213static struct ctl_table svcrdma_table[] = {
214 {
215 .procname = "svc_rdma",
216 .mode = 0555,
217 .child = svcrdma_parm_table
218 },
219 { },
220};
221
222static struct ctl_table svcrdma_root_table[] = {
223 {
224 .procname = "sunrpc",
225 .mode = 0555,
226 .child = svcrdma_table
227 },
228 { },
229};
230
231void svc_rdma_cleanup(void)
232{
233 dprintk("SVCRDMA Module Removed, deregister RPC RDMA transport\n");
234 destroy_workqueue(svc_rdma_wq);
235 if (svcrdma_table_header) {
236 unregister_sysctl_table(svcrdma_table_header);
237 svcrdma_table_header = NULL;
238 }
239#if defined(CONFIG_SUNRPC_BACKCHANNEL)
240 svc_unreg_xprt_class(&svc_rdma_bc_class);
241#endif
242 svc_unreg_xprt_class(&svc_rdma_class);
243}
244
245int svc_rdma_init(void)
246{
247 dprintk("SVCRDMA Module Init, register RPC RDMA transport\n");
248 dprintk("\tsvcrdma_ord : %d\n", svcrdma_ord);
249 dprintk("\tmax_requests : %u\n", svcrdma_max_requests);
250 dprintk("\tmax_bc_requests : %u\n", svcrdma_max_bc_requests);
251 dprintk("\tmax_inline : %d\n", svcrdma_max_req_size);
252
253 svc_rdma_wq = alloc_workqueue("svc_rdma", 0, 0);
254 if (!svc_rdma_wq)
255 return -ENOMEM;
256
257 if (!svcrdma_table_header)
258 svcrdma_table_header =
259 register_sysctl_table(svcrdma_root_table);
260
261
262 svc_reg_xprt_class(&svc_rdma_class);
263#if defined(CONFIG_SUNRPC_BACKCHANNEL)
264 svc_reg_xprt_class(&svc_rdma_bc_class);
265#endif
266 return 0;
267}
268