Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2005-2006 Network Appliance, Inc. All rights reserved. |
| 3 | * |
| 4 | * This software is available to you under a choice of one of two |
| 5 | * licenses. You may choose to be licensed under the terms of the GNU |
| 6 | * General Public License (GPL) Version 2, available from the file |
| 7 | * COPYING in the main directory of this source tree, or the BSD-type |
| 8 | * license below: |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or without |
| 11 | * modification, are permitted provided that the following conditions |
| 12 | * are met: |
| 13 | * |
| 14 | * Redistributions of source code must retain the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer. |
| 16 | * |
| 17 | * Redistributions in binary form must reproduce the above |
| 18 | * copyright notice, this list of conditions and the following |
| 19 | * disclaimer in the documentation and/or other materials provided |
| 20 | * with the distribution. |
| 21 | * |
| 22 | * Neither the name of the Network Appliance, Inc. nor the names of |
| 23 | * its contributors may be used to endorse or promote products |
| 24 | * derived from this software without specific prior written |
| 25 | * permission. |
| 26 | * |
| 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 30 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 31 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 32 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 33 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 34 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 35 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 36 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 38 | * |
| 39 | * Author: Tom Tucker <tom@opengridcomputing.com> |
| 40 | */ |
Chuck Lever | ffe1f0d | 2015-06-04 11:21:42 -0400 | [diff] [blame] | 41 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 42 | #include <linux/slab.h> |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 43 | #include <linux/fs.h> |
| 44 | #include <linux/sysctl.h> |
Tejun Heo | a25e758 | 2010-10-15 17:49:27 +0200 | [diff] [blame] | 45 | #include <linux/workqueue.h> |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 46 | #include <linux/sunrpc/clnt.h> |
| 47 | #include <linux/sunrpc/sched.h> |
| 48 | #include <linux/sunrpc/svc_rdma.h> |
Tom Tucker | cec56c8 | 2012-02-15 11:30:00 -0600 | [diff] [blame] | 49 | #include "xprt_rdma.h" |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 50 | |
| 51 | #define RPCDBG_FACILITY RPCDBG_SVCXPRT |
| 52 | |
| 53 | /* RPC/RDMA parameters */ |
| 54 | unsigned int svcrdma_ord = RPCRDMA_ORD; |
| 55 | static unsigned int min_ord = 1; |
| 56 | static unsigned int max_ord = 4096; |
| 57 | unsigned int svcrdma_max_requests = RPCRDMA_MAX_REQUESTS; |
Chuck Lever | 03fe993 | 2016-01-07 14:50:02 -0500 | [diff] [blame] | 58 | unsigned int svcrdma_max_bc_requests = RPCRDMA_MAX_BC_REQUESTS; |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 59 | static unsigned int min_max_requests = 4; |
| 60 | static unsigned int max_max_requests = 16384; |
| 61 | unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE; |
| 62 | static unsigned int min_max_inline = 4096; |
| 63 | static unsigned int max_max_inline = 65536; |
| 64 | |
| 65 | atomic_t rdma_stat_recv; |
| 66 | atomic_t rdma_stat_read; |
| 67 | atomic_t rdma_stat_write; |
| 68 | atomic_t rdma_stat_sq_starve; |
| 69 | atomic_t rdma_stat_rq_starve; |
| 70 | atomic_t rdma_stat_rq_poll; |
| 71 | atomic_t rdma_stat_rq_prod; |
| 72 | atomic_t rdma_stat_sq_poll; |
| 73 | atomic_t rdma_stat_sq_prod; |
| 74 | |
Tejun Heo | a25e758 | 2010-10-15 17:49:27 +0200 | [diff] [blame] | 75 | struct workqueue_struct *svc_rdma_wq; |
| 76 | |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 77 | /* |
| 78 | * This function implements reading and resetting an atomic_t stat |
| 79 | * variable through read/write to a proc file. Any write to the file |
| 80 | * resets the associated statistic to zero. Any read returns it's |
| 81 | * current value. |
| 82 | */ |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 83 | static int read_reset_stat(struct ctl_table *table, int write, |
Alexey Dobriyan | 8d65af7 | 2009-09-23 15:57:19 -0700 | [diff] [blame] | 84 | void __user *buffer, size_t *lenp, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 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 | |
| 117 | static struct ctl_table_header *svcrdma_table_header; |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 118 | static struct ctl_table svcrdma_parm_table[] = { |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 119 | { |
| 120 | .procname = "max_requests", |
| 121 | .data = &svcrdma_max_requests, |
| 122 | .maxlen = sizeof(unsigned int), |
| 123 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 124 | .proc_handler = proc_dointvec_minmax, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 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, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 133 | .proc_handler = proc_dointvec_minmax, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 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, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 142 | .proc_handler = proc_dointvec_minmax, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 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, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 152 | .proc_handler = read_reset_stat, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 153 | }, |
| 154 | { |
| 155 | .procname = "rdma_stat_recv", |
| 156 | .data = &rdma_stat_recv, |
| 157 | .maxlen = sizeof(atomic_t), |
| 158 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 159 | .proc_handler = read_reset_stat, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 160 | }, |
| 161 | { |
| 162 | .procname = "rdma_stat_write", |
| 163 | .data = &rdma_stat_write, |
| 164 | .maxlen = sizeof(atomic_t), |
| 165 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 166 | .proc_handler = read_reset_stat, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 167 | }, |
| 168 | { |
| 169 | .procname = "rdma_stat_sq_starve", |
| 170 | .data = &rdma_stat_sq_starve, |
| 171 | .maxlen = sizeof(atomic_t), |
| 172 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 173 | .proc_handler = read_reset_stat, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 174 | }, |
| 175 | { |
| 176 | .procname = "rdma_stat_rq_starve", |
| 177 | .data = &rdma_stat_rq_starve, |
| 178 | .maxlen = sizeof(atomic_t), |
| 179 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 180 | .proc_handler = read_reset_stat, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 181 | }, |
| 182 | { |
| 183 | .procname = "rdma_stat_rq_poll", |
| 184 | .data = &rdma_stat_rq_poll, |
| 185 | .maxlen = sizeof(atomic_t), |
| 186 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 187 | .proc_handler = read_reset_stat, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 188 | }, |
| 189 | { |
| 190 | .procname = "rdma_stat_rq_prod", |
| 191 | .data = &rdma_stat_rq_prod, |
| 192 | .maxlen = sizeof(atomic_t), |
| 193 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 194 | .proc_handler = read_reset_stat, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 195 | }, |
| 196 | { |
| 197 | .procname = "rdma_stat_sq_poll", |
| 198 | .data = &rdma_stat_sq_poll, |
| 199 | .maxlen = sizeof(atomic_t), |
| 200 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 201 | .proc_handler = read_reset_stat, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 202 | }, |
| 203 | { |
| 204 | .procname = "rdma_stat_sq_prod", |
| 205 | .data = &rdma_stat_sq_prod, |
| 206 | .maxlen = sizeof(atomic_t), |
| 207 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 208 | .proc_handler = read_reset_stat, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 209 | }, |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 210 | { }, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 211 | }; |
| 212 | |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 213 | static struct ctl_table svcrdma_table[] = { |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 214 | { |
| 215 | .procname = "svc_rdma", |
| 216 | .mode = 0555, |
| 217 | .child = svcrdma_parm_table |
| 218 | }, |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 219 | { }, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 220 | }; |
| 221 | |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 222 | static struct ctl_table svcrdma_root_table[] = { |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 223 | { |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 224 | .procname = "sunrpc", |
| 225 | .mode = 0555, |
| 226 | .child = svcrdma_table |
| 227 | }, |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 228 | { }, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 229 | }; |
| 230 | |
| 231 | void svc_rdma_cleanup(void) |
| 232 | { |
| 233 | dprintk("SVCRDMA Module Removed, deregister RPC RDMA transport\n"); |
Tejun Heo | a25e758 | 2010-10-15 17:49:27 +0200 | [diff] [blame] | 234 | destroy_workqueue(svc_rdma_wq); |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 235 | if (svcrdma_table_header) { |
| 236 | unregister_sysctl_table(svcrdma_table_header); |
| 237 | svcrdma_table_header = NULL; |
| 238 | } |
Chuck Lever | 9468431 | 2015-10-24 17:28:16 -0400 | [diff] [blame] | 239 | #if defined(CONFIG_SUNRPC_BACKCHANNEL) |
| 240 | svc_unreg_xprt_class(&svc_rdma_bc_class); |
| 241 | #endif |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 242 | svc_unreg_xprt_class(&svc_rdma_class); |
| 243 | } |
| 244 | |
| 245 | int svc_rdma_init(void) |
| 246 | { |
| 247 | dprintk("SVCRDMA Module Init, register RPC RDMA transport\n"); |
| 248 | dprintk("\tsvcrdma_ord : %d\n", svcrdma_ord); |
Chuck Lever | 03fe993 | 2016-01-07 14:50:02 -0500 | [diff] [blame] | 249 | dprintk("\tmax_requests : %u\n", svcrdma_max_requests); |
| 250 | dprintk("\tsq_depth : %u\n", |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 251 | svcrdma_max_requests * RPCRDMA_SQ_DEPTH_MULT); |
Chuck Lever | 03fe993 | 2016-01-07 14:50:02 -0500 | [diff] [blame] | 252 | dprintk("\tmax_bc_requests : %u\n", svcrdma_max_bc_requests); |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 253 | dprintk("\tmax_inline : %d\n", svcrdma_max_req_size); |
Tejun Heo | a25e758 | 2010-10-15 17:49:27 +0200 | [diff] [blame] | 254 | |
| 255 | svc_rdma_wq = alloc_workqueue("svc_rdma", 0, 0); |
| 256 | if (!svc_rdma_wq) |
| 257 | return -ENOMEM; |
| 258 | |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 259 | if (!svcrdma_table_header) |
| 260 | svcrdma_table_header = |
| 261 | register_sysctl_table(svcrdma_root_table); |
| 262 | |
| 263 | /* Register RDMA with the SVC transport switch */ |
| 264 | svc_reg_xprt_class(&svc_rdma_class); |
Chuck Lever | 9468431 | 2015-10-24 17:28:16 -0400 | [diff] [blame] | 265 | #if defined(CONFIG_SUNRPC_BACKCHANNEL) |
| 266 | svc_reg_xprt_class(&svc_rdma_bc_class); |
| 267 | #endif |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 268 | return 0; |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 269 | } |