Commit | Line | Data |
---|---|---|
bcf3ffd4 | 1 | // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause |
ef7fbf59 | 2 | /* |
b6e717cb | 3 | * Copyright (c) 2015-2018 Oracle. All rights reserved. |
ef7fbf59 TT |
4 | * Copyright (c) 2005-2006 Network Appliance, Inc. All rights reserved. |
5 | * | |
6 | * This software is available to you under a choice of one of two | |
7 | * licenses. You may choose to be licensed under the terms of the GNU | |
8 | * General Public License (GPL) Version 2, available from the file | |
9 | * COPYING in the main directory of this source tree, or the BSD-type | |
10 | * license below: | |
11 | * | |
12 | * Redistribution and use in source and binary forms, with or without | |
13 | * modification, are permitted provided that the following conditions | |
14 | * are met: | |
15 | * | |
16 | * Redistributions of source code must retain the above copyright | |
17 | * notice, this list of conditions and the following disclaimer. | |
18 | * | |
19 | * Redistributions in binary form must reproduce the above | |
20 | * copyright notice, this list of conditions and the following | |
21 | * disclaimer in the documentation and/or other materials provided | |
22 | * with the distribution. | |
23 | * | |
24 | * Neither the name of the Network Appliance, Inc. nor the names of | |
25 | * its contributors may be used to endorse or promote products | |
26 | * derived from this software without specific prior written | |
27 | * permission. | |
28 | * | |
29 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
30 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
31 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
32 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
33 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
34 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
35 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
36 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
37 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
38 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
39 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
40 | * | |
41 | * Author: Tom Tucker <tom@opengridcomputing.com> | |
42 | */ | |
ffe1f0df | 43 | |
5a0e3ad6 | 44 | #include <linux/slab.h> |
ef7fbf59 TT |
45 | #include <linux/fs.h> |
46 | #include <linux/sysctl.h> | |
a25e758c | 47 | #include <linux/workqueue.h> |
ef7fbf59 TT |
48 | #include <linux/sunrpc/clnt.h> |
49 | #include <linux/sunrpc/sched.h> | |
50 | #include <linux/sunrpc/svc_rdma.h> | |
51 | ||
52 | #define RPCDBG_FACILITY RPCDBG_SVCXPRT | |
53 | ||
54 | /* RPC/RDMA parameters */ | |
97cc3264 | 55 | unsigned int svcrdma_ord = 16; /* historical default */ |
ef7fbf59 | 56 | static unsigned int min_ord = 1; |
97cc3264 | 57 | static unsigned int max_ord = 255; |
ef7fbf59 | 58 | unsigned int svcrdma_max_requests = RPCRDMA_MAX_REQUESTS; |
03fe9931 | 59 | unsigned int svcrdma_max_bc_requests = RPCRDMA_MAX_BC_REQUESTS; |
ef7fbf59 TT |
60 | static unsigned int min_max_requests = 4; |
61 | static unsigned int max_max_requests = 16384; | |
ded8d196 CL |
62 | unsigned int svcrdma_max_req_size = RPCRDMA_DEF_INLINE_THRESH; |
63 | static unsigned int min_max_inline = RPCRDMA_DEF_INLINE_THRESH; | |
64 | static unsigned int max_max_inline = RPCRDMA_MAX_INLINE_THRESH; | |
c6226ff9 CL |
65 | static unsigned int svcrdma_stat_unused; |
66 | static unsigned int zero; | |
ef7fbf59 | 67 | |
1e7e5573 | 68 | struct percpu_counter svcrdma_stat_read; |
df971cd8 | 69 | struct percpu_counter svcrdma_stat_recv; |
22df5a22 | 70 | struct percpu_counter svcrdma_stat_sq_starve; |
1e7e5573 | 71 | struct percpu_counter svcrdma_stat_write; |
ef7fbf59 | 72 | |
df971cd8 CL |
73 | enum { |
74 | SVCRDMA_COUNTER_BUFSIZ = sizeof(unsigned long long), | |
75 | }; | |
76 | ||
78eb4ea2 | 77 | static int svcrdma_counter_handler(const struct ctl_table *table, int write, |
df971cd8 CL |
78 | void *buffer, size_t *lenp, loff_t *ppos) |
79 | { | |
80 | struct percpu_counter *stat = (struct percpu_counter *)table->data; | |
81 | char tmp[SVCRDMA_COUNTER_BUFSIZ + 1]; | |
82 | int len; | |
83 | ||
84 | if (write) { | |
85 | percpu_counter_set(stat, 0); | |
86 | return 0; | |
87 | } | |
88 | ||
89 | len = snprintf(tmp, SVCRDMA_COUNTER_BUFSIZ, "%lld\n", | |
90 | percpu_counter_sum_positive(stat)); | |
91 | if (len >= SVCRDMA_COUNTER_BUFSIZ) | |
92 | return -EFAULT; | |
93 | len = strlen(tmp); | |
94 | if (*ppos > len) { | |
95 | *lenp = 0; | |
96 | return 0; | |
97 | } | |
98 | len -= *ppos; | |
99 | if (len > *lenp) | |
100 | len = *lenp; | |
101 | if (len) | |
102 | memcpy(buffer, tmp, len); | |
103 | *lenp = len; | |
104 | *ppos += len; | |
105 | ||
106 | return 0; | |
107 | } | |
108 | ||
ef7fbf59 | 109 | static struct ctl_table_header *svcrdma_table_header; |
fe2c6338 | 110 | static struct ctl_table svcrdma_parm_table[] = { |
ef7fbf59 TT |
111 | { |
112 | .procname = "max_requests", | |
113 | .data = &svcrdma_max_requests, | |
114 | .maxlen = sizeof(unsigned int), | |
115 | .mode = 0644, | |
6d456111 | 116 | .proc_handler = proc_dointvec_minmax, |
ef7fbf59 TT |
117 | .extra1 = &min_max_requests, |
118 | .extra2 = &max_max_requests | |
119 | }, | |
120 | { | |
121 | .procname = "max_req_size", | |
122 | .data = &svcrdma_max_req_size, | |
123 | .maxlen = sizeof(unsigned int), | |
124 | .mode = 0644, | |
6d456111 | 125 | .proc_handler = proc_dointvec_minmax, |
ef7fbf59 TT |
126 | .extra1 = &min_max_inline, |
127 | .extra2 = &max_max_inline | |
128 | }, | |
129 | { | |
130 | .procname = "max_outbound_read_requests", | |
131 | .data = &svcrdma_ord, | |
132 | .maxlen = sizeof(unsigned int), | |
133 | .mode = 0644, | |
6d456111 | 134 | .proc_handler = proc_dointvec_minmax, |
ef7fbf59 TT |
135 | .extra1 = &min_ord, |
136 | .extra2 = &max_ord, | |
137 | }, | |
138 | ||
139 | { | |
140 | .procname = "rdma_stat_read", | |
1e7e5573 CL |
141 | .data = &svcrdma_stat_read, |
142 | .maxlen = SVCRDMA_COUNTER_BUFSIZ, | |
ef7fbf59 | 143 | .mode = 0644, |
1e7e5573 | 144 | .proc_handler = svcrdma_counter_handler, |
ef7fbf59 TT |
145 | }, |
146 | { | |
147 | .procname = "rdma_stat_recv", | |
df971cd8 CL |
148 | .data = &svcrdma_stat_recv, |
149 | .maxlen = SVCRDMA_COUNTER_BUFSIZ, | |
ef7fbf59 | 150 | .mode = 0644, |
df971cd8 | 151 | .proc_handler = svcrdma_counter_handler, |
ef7fbf59 TT |
152 | }, |
153 | { | |
154 | .procname = "rdma_stat_write", | |
1e7e5573 CL |
155 | .data = &svcrdma_stat_write, |
156 | .maxlen = SVCRDMA_COUNTER_BUFSIZ, | |
ef7fbf59 | 157 | .mode = 0644, |
1e7e5573 | 158 | .proc_handler = svcrdma_counter_handler, |
ef7fbf59 TT |
159 | }, |
160 | { | |
161 | .procname = "rdma_stat_sq_starve", | |
22df5a22 CL |
162 | .data = &svcrdma_stat_sq_starve, |
163 | .maxlen = SVCRDMA_COUNTER_BUFSIZ, | |
ef7fbf59 | 164 | .mode = 0644, |
22df5a22 | 165 | .proc_handler = svcrdma_counter_handler, |
ef7fbf59 TT |
166 | }, |
167 | { | |
168 | .procname = "rdma_stat_rq_starve", | |
c6226ff9 CL |
169 | .data = &svcrdma_stat_unused, |
170 | .maxlen = sizeof(unsigned int), | |
ef7fbf59 | 171 | .mode = 0644, |
c6226ff9 CL |
172 | .proc_handler = proc_dointvec_minmax, |
173 | .extra1 = &zero, | |
174 | .extra2 = &zero, | |
ef7fbf59 TT |
175 | }, |
176 | { | |
177 | .procname = "rdma_stat_rq_poll", | |
c6226ff9 CL |
178 | .data = &svcrdma_stat_unused, |
179 | .maxlen = sizeof(unsigned int), | |
ef7fbf59 | 180 | .mode = 0644, |
c6226ff9 CL |
181 | .proc_handler = proc_dointvec_minmax, |
182 | .extra1 = &zero, | |
183 | .extra2 = &zero, | |
ef7fbf59 TT |
184 | }, |
185 | { | |
186 | .procname = "rdma_stat_rq_prod", | |
c6226ff9 CL |
187 | .data = &svcrdma_stat_unused, |
188 | .maxlen = sizeof(unsigned int), | |
ef7fbf59 | 189 | .mode = 0644, |
c6226ff9 CL |
190 | .proc_handler = proc_dointvec_minmax, |
191 | .extra1 = &zero, | |
192 | .extra2 = &zero, | |
ef7fbf59 TT |
193 | }, |
194 | { | |
195 | .procname = "rdma_stat_sq_poll", | |
c6226ff9 CL |
196 | .data = &svcrdma_stat_unused, |
197 | .maxlen = sizeof(unsigned int), | |
ef7fbf59 | 198 | .mode = 0644, |
c6226ff9 CL |
199 | .proc_handler = proc_dointvec_minmax, |
200 | .extra1 = &zero, | |
201 | .extra2 = &zero, | |
ef7fbf59 TT |
202 | }, |
203 | { | |
204 | .procname = "rdma_stat_sq_prod", | |
c6226ff9 CL |
205 | .data = &svcrdma_stat_unused, |
206 | .maxlen = sizeof(unsigned int), | |
ef7fbf59 | 207 | .mode = 0644, |
c6226ff9 CL |
208 | .proc_handler = proc_dointvec_minmax, |
209 | .extra1 = &zero, | |
210 | .extra2 = &zero, | |
ef7fbf59 | 211 | }, |
ef7fbf59 TT |
212 | }; |
213 | ||
59a00257 CL |
214 | static void svc_rdma_proc_cleanup(void) |
215 | { | |
216 | if (!svcrdma_table_header) | |
217 | return; | |
218 | unregister_sysctl_table(svcrdma_table_header); | |
219 | svcrdma_table_header = NULL; | |
df971cd8 | 220 | |
1e7e5573 | 221 | percpu_counter_destroy(&svcrdma_stat_write); |
22df5a22 | 222 | percpu_counter_destroy(&svcrdma_stat_sq_starve); |
df971cd8 | 223 | percpu_counter_destroy(&svcrdma_stat_recv); |
1e7e5573 | 224 | percpu_counter_destroy(&svcrdma_stat_read); |
59a00257 CL |
225 | } |
226 | ||
227 | static int svc_rdma_proc_init(void) | |
228 | { | |
df971cd8 CL |
229 | int rc; |
230 | ||
59a00257 CL |
231 | if (svcrdma_table_header) |
232 | return 0; | |
233 | ||
1e7e5573 CL |
234 | rc = percpu_counter_init(&svcrdma_stat_read, 0, GFP_KERNEL); |
235 | if (rc) | |
236 | goto out_err; | |
df971cd8 | 237 | rc = percpu_counter_init(&svcrdma_stat_recv, 0, GFP_KERNEL); |
22df5a22 CL |
238 | if (rc) |
239 | goto out_err; | |
240 | rc = percpu_counter_init(&svcrdma_stat_sq_starve, 0, GFP_KERNEL); | |
1e7e5573 CL |
241 | if (rc) |
242 | goto out_err; | |
243 | rc = percpu_counter_init(&svcrdma_stat_write, 0, GFP_KERNEL); | |
df971cd8 CL |
244 | if (rc) |
245 | goto out_err; | |
246 | ||
376bcd9b LC |
247 | svcrdma_table_header = register_sysctl("sunrpc/svc_rdma", |
248 | svcrdma_parm_table); | |
59a00257 | 249 | return 0; |
df971cd8 CL |
250 | |
251 | out_err: | |
1e7e5573 | 252 | percpu_counter_destroy(&svcrdma_stat_sq_starve); |
22df5a22 | 253 | percpu_counter_destroy(&svcrdma_stat_recv); |
1e7e5573 | 254 | percpu_counter_destroy(&svcrdma_stat_read); |
df971cd8 | 255 | return rc; |
59a00257 CL |
256 | } |
257 | ||
9c7e1a06 CL |
258 | struct workqueue_struct *svcrdma_wq; |
259 | ||
ef7fbf59 TT |
260 | void svc_rdma_cleanup(void) |
261 | { | |
ef7fbf59 | 262 | svc_unreg_xprt_class(&svc_rdma_class); |
59a00257 | 263 | svc_rdma_proc_cleanup(); |
9c7e1a06 CL |
264 | if (svcrdma_wq) { |
265 | struct workqueue_struct *wq = svcrdma_wq; | |
266 | ||
267 | svcrdma_wq = NULL; | |
268 | destroy_workqueue(wq); | |
269 | } | |
270 | ||
271 | dprintk("SVCRDMA Module Removed, deregister RPC RDMA transport\n"); | |
ef7fbf59 TT |
272 | } |
273 | ||
274 | int svc_rdma_init(void) | |
275 | { | |
9c7e1a06 | 276 | struct workqueue_struct *wq; |
59a00257 CL |
277 | int rc; |
278 | ||
9c7e1a06 CL |
279 | wq = alloc_workqueue("svcrdma", WQ_UNBOUND, 0); |
280 | if (!wq) | |
281 | return -ENOMEM; | |
a25e758c | 282 | |
59a00257 | 283 | rc = svc_rdma_proc_init(); |
9c7e1a06 CL |
284 | if (rc) { |
285 | destroy_workqueue(wq); | |
59a00257 | 286 | return rc; |
9c7e1a06 | 287 | } |
ef7fbf59 | 288 | |
9c7e1a06 | 289 | svcrdma_wq = wq; |
ef7fbf59 | 290 | svc_reg_xprt_class(&svc_rdma_class); |
9c7e1a06 CL |
291 | |
292 | dprintk("SVCRDMA Module Init, register RPC RDMA transport\n"); | |
293 | dprintk("\tsvcrdma_ord : %d\n", svcrdma_ord); | |
294 | dprintk("\tmax_requests : %u\n", svcrdma_max_requests); | |
295 | dprintk("\tmax_bc_requests : %u\n", svcrdma_max_bc_requests); | |
296 | dprintk("\tmax_inline : %d\n", svcrdma_max_req_size); | |
ef7fbf59 TT |
297 | return 0; |
298 | } |