Chuck Lever | bcf3ffd | 2018-05-07 15:26:55 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 2 | /* |
Chuck Lever | b6e717cb | 2018-05-07 15:27:05 -0400 | [diff] [blame] | 3 | * Copyright (c) 2015-2018 Oracle. All rights reserved. |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 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 | */ |
Chuck Lever | ffe1f0d | 2015-06-04 11:21:42 -0400 | [diff] [blame] | 43 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 45 | #include <linux/fs.h> |
| 46 | #include <linux/sysctl.h> |
Tejun Heo | a25e758 | 2010-10-15 17:49:27 +0200 | [diff] [blame] | 47 | #include <linux/workqueue.h> |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 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 */ |
Chuck Lever | 97cc326 | 2018-03-20 17:05:15 -0400 | [diff] [blame] | 55 | unsigned int svcrdma_ord = 16; /* historical default */ |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 56 | static unsigned int min_ord = 1; |
Chuck Lever | 97cc326 | 2018-03-20 17:05:15 -0400 | [diff] [blame] | 57 | static unsigned int max_ord = 255; |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 58 | unsigned int svcrdma_max_requests = RPCRDMA_MAX_REQUESTS; |
Chuck Lever | 03fe993 | 2016-01-07 14:50:02 -0500 | [diff] [blame] | 59 | unsigned int svcrdma_max_bc_requests = RPCRDMA_MAX_BC_REQUESTS; |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 60 | static unsigned int min_max_requests = 4; |
| 61 | static unsigned int max_max_requests = 16384; |
Chuck Lever | ded8d19 | 2017-04-09 13:06:57 -0400 | [diff] [blame] | 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; |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 65 | |
| 66 | atomic_t rdma_stat_recv; |
| 67 | atomic_t rdma_stat_read; |
| 68 | atomic_t rdma_stat_write; |
| 69 | atomic_t rdma_stat_sq_starve; |
| 70 | atomic_t rdma_stat_rq_starve; |
| 71 | atomic_t rdma_stat_rq_poll; |
| 72 | atomic_t rdma_stat_rq_prod; |
| 73 | atomic_t rdma_stat_sq_poll; |
| 74 | atomic_t rdma_stat_sq_prod; |
| 75 | |
| 76 | /* |
| 77 | * This function implements reading and resetting an atomic_t stat |
| 78 | * variable through read/write to a proc file. Any write to the file |
| 79 | * resets the associated statistic to zero. Any read returns it's |
| 80 | * current value. |
| 81 | */ |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 82 | static int read_reset_stat(struct ctl_table *table, int write, |
Christoph Hellwig | 3292739 | 2020-04-24 08:43:38 +0200 | [diff] [blame] | 83 | void *buffer, size_t *lenp, loff_t *ppos) |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 84 | { |
| 85 | atomic_t *stat = (atomic_t *)table->data; |
| 86 | |
| 87 | if (!stat) |
| 88 | return -EINVAL; |
| 89 | |
| 90 | if (write) |
| 91 | atomic_set(stat, 0); |
| 92 | else { |
| 93 | char str_buf[32]; |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 94 | int len = snprintf(str_buf, 32, "%d\n", atomic_read(stat)); |
| 95 | if (len >= 32) |
| 96 | return -EFAULT; |
| 97 | len = strlen(str_buf); |
| 98 | if (*ppos > len) { |
| 99 | *lenp = 0; |
| 100 | return 0; |
| 101 | } |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 102 | len -= *ppos; |
| 103 | if (len > *lenp) |
| 104 | len = *lenp; |
Christoph Hellwig | 3292739 | 2020-04-24 08:43:38 +0200 | [diff] [blame] | 105 | if (len) |
| 106 | memcpy(buffer, str_buf, len); |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 107 | *lenp = len; |
| 108 | *ppos += len; |
| 109 | } |
| 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | static struct ctl_table_header *svcrdma_table_header; |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 114 | static struct ctl_table svcrdma_parm_table[] = { |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 115 | { |
| 116 | .procname = "max_requests", |
| 117 | .data = &svcrdma_max_requests, |
| 118 | .maxlen = sizeof(unsigned int), |
| 119 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 120 | .proc_handler = proc_dointvec_minmax, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 121 | .extra1 = &min_max_requests, |
| 122 | .extra2 = &max_max_requests |
| 123 | }, |
| 124 | { |
| 125 | .procname = "max_req_size", |
| 126 | .data = &svcrdma_max_req_size, |
| 127 | .maxlen = sizeof(unsigned int), |
| 128 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 129 | .proc_handler = proc_dointvec_minmax, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 130 | .extra1 = &min_max_inline, |
| 131 | .extra2 = &max_max_inline |
| 132 | }, |
| 133 | { |
| 134 | .procname = "max_outbound_read_requests", |
| 135 | .data = &svcrdma_ord, |
| 136 | .maxlen = sizeof(unsigned int), |
| 137 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 138 | .proc_handler = proc_dointvec_minmax, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 139 | .extra1 = &min_ord, |
| 140 | .extra2 = &max_ord, |
| 141 | }, |
| 142 | |
| 143 | { |
| 144 | .procname = "rdma_stat_read", |
| 145 | .data = &rdma_stat_read, |
| 146 | .maxlen = sizeof(atomic_t), |
| 147 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 148 | .proc_handler = read_reset_stat, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 149 | }, |
| 150 | { |
| 151 | .procname = "rdma_stat_recv", |
| 152 | .data = &rdma_stat_recv, |
| 153 | .maxlen = sizeof(atomic_t), |
| 154 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 155 | .proc_handler = read_reset_stat, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 156 | }, |
| 157 | { |
| 158 | .procname = "rdma_stat_write", |
| 159 | .data = &rdma_stat_write, |
| 160 | .maxlen = sizeof(atomic_t), |
| 161 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 162 | .proc_handler = read_reset_stat, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 163 | }, |
| 164 | { |
| 165 | .procname = "rdma_stat_sq_starve", |
| 166 | .data = &rdma_stat_sq_starve, |
| 167 | .maxlen = sizeof(atomic_t), |
| 168 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 169 | .proc_handler = read_reset_stat, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 170 | }, |
| 171 | { |
| 172 | .procname = "rdma_stat_rq_starve", |
| 173 | .data = &rdma_stat_rq_starve, |
| 174 | .maxlen = sizeof(atomic_t), |
| 175 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 176 | .proc_handler = read_reset_stat, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 177 | }, |
| 178 | { |
| 179 | .procname = "rdma_stat_rq_poll", |
| 180 | .data = &rdma_stat_rq_poll, |
| 181 | .maxlen = sizeof(atomic_t), |
| 182 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 183 | .proc_handler = read_reset_stat, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 184 | }, |
| 185 | { |
| 186 | .procname = "rdma_stat_rq_prod", |
| 187 | .data = &rdma_stat_rq_prod, |
| 188 | .maxlen = sizeof(atomic_t), |
| 189 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 190 | .proc_handler = read_reset_stat, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 191 | }, |
| 192 | { |
| 193 | .procname = "rdma_stat_sq_poll", |
| 194 | .data = &rdma_stat_sq_poll, |
| 195 | .maxlen = sizeof(atomic_t), |
| 196 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 197 | .proc_handler = read_reset_stat, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 198 | }, |
| 199 | { |
| 200 | .procname = "rdma_stat_sq_prod", |
| 201 | .data = &rdma_stat_sq_prod, |
| 202 | .maxlen = sizeof(atomic_t), |
| 203 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 204 | .proc_handler = read_reset_stat, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 205 | }, |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 206 | { }, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 207 | }; |
| 208 | |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 209 | static struct ctl_table svcrdma_table[] = { |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 210 | { |
| 211 | .procname = "svc_rdma", |
| 212 | .mode = 0555, |
| 213 | .child = svcrdma_parm_table |
| 214 | }, |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 215 | { }, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 216 | }; |
| 217 | |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 218 | static struct ctl_table svcrdma_root_table[] = { |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 219 | { |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 220 | .procname = "sunrpc", |
| 221 | .mode = 0555, |
| 222 | .child = svcrdma_table |
| 223 | }, |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 224 | { }, |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 225 | }; |
| 226 | |
| 227 | void svc_rdma_cleanup(void) |
| 228 | { |
| 229 | dprintk("SVCRDMA Module Removed, deregister RPC RDMA transport\n"); |
| 230 | if (svcrdma_table_header) { |
| 231 | unregister_sysctl_table(svcrdma_table_header); |
| 232 | svcrdma_table_header = NULL; |
| 233 | } |
| 234 | svc_unreg_xprt_class(&svc_rdma_class); |
| 235 | } |
| 236 | |
| 237 | int svc_rdma_init(void) |
| 238 | { |
| 239 | dprintk("SVCRDMA Module Init, register RPC RDMA transport\n"); |
| 240 | dprintk("\tsvcrdma_ord : %d\n", svcrdma_ord); |
Chuck Lever | 03fe993 | 2016-01-07 14:50:02 -0500 | [diff] [blame] | 241 | dprintk("\tmax_requests : %u\n", svcrdma_max_requests); |
Chuck Lever | 03fe993 | 2016-01-07 14:50:02 -0500 | [diff] [blame] | 242 | dprintk("\tmax_bc_requests : %u\n", svcrdma_max_bc_requests); |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 243 | dprintk("\tmax_inline : %d\n", svcrdma_max_req_size); |
Tejun Heo | a25e758 | 2010-10-15 17:49:27 +0200 | [diff] [blame] | 244 | |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 245 | if (!svcrdma_table_header) |
| 246 | svcrdma_table_header = |
| 247 | register_sysctl_table(svcrdma_root_table); |
| 248 | |
| 249 | /* Register RDMA with the SVC transport switch */ |
| 250 | svc_reg_xprt_class(&svc_rdma_class); |
| 251 | return 0; |
Tom Tucker | ef7fbf5 | 2007-12-12 16:13:19 -0600 | [diff] [blame] | 252 | } |