svc_rdma.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
  2. /*
  3. * Copyright (c) 2015-2018 Oracle. All rights reserved.
  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 <[email protected]>
  42. */
  43. #include <linux/slab.h>
  44. #include <linux/fs.h>
  45. #include <linux/sysctl.h>
  46. #include <linux/workqueue.h>
  47. #include <linux/sunrpc/clnt.h>
  48. #include <linux/sunrpc/sched.h>
  49. #include <linux/sunrpc/svc_rdma.h>
  50. #define RPCDBG_FACILITY RPCDBG_SVCXPRT
  51. /* RPC/RDMA parameters */
  52. unsigned int svcrdma_ord = 16; /* historical default */
  53. static unsigned int min_ord = 1;
  54. static unsigned int max_ord = 255;
  55. unsigned int svcrdma_max_requests = RPCRDMA_MAX_REQUESTS;
  56. unsigned int svcrdma_max_bc_requests = RPCRDMA_MAX_BC_REQUESTS;
  57. static unsigned int min_max_requests = 4;
  58. static unsigned int max_max_requests = 16384;
  59. unsigned int svcrdma_max_req_size = RPCRDMA_DEF_INLINE_THRESH;
  60. static unsigned int min_max_inline = RPCRDMA_DEF_INLINE_THRESH;
  61. static unsigned int max_max_inline = RPCRDMA_MAX_INLINE_THRESH;
  62. static unsigned int svcrdma_stat_unused;
  63. static unsigned int zero;
  64. struct percpu_counter svcrdma_stat_read;
  65. struct percpu_counter svcrdma_stat_recv;
  66. struct percpu_counter svcrdma_stat_sq_starve;
  67. struct percpu_counter svcrdma_stat_write;
  68. enum {
  69. SVCRDMA_COUNTER_BUFSIZ = sizeof(unsigned long long),
  70. };
  71. static int svcrdma_counter_handler(struct ctl_table *table, int write,
  72. void *buffer, size_t *lenp, loff_t *ppos)
  73. {
  74. struct percpu_counter *stat = (struct percpu_counter *)table->data;
  75. char tmp[SVCRDMA_COUNTER_BUFSIZ + 1];
  76. int len;
  77. if (write) {
  78. percpu_counter_set(stat, 0);
  79. return 0;
  80. }
  81. len = snprintf(tmp, SVCRDMA_COUNTER_BUFSIZ, "%lld\n",
  82. percpu_counter_sum_positive(stat));
  83. if (len >= SVCRDMA_COUNTER_BUFSIZ)
  84. return -EFAULT;
  85. len = strlen(tmp);
  86. if (*ppos > len) {
  87. *lenp = 0;
  88. return 0;
  89. }
  90. len -= *ppos;
  91. if (len > *lenp)
  92. len = *lenp;
  93. if (len)
  94. memcpy(buffer, tmp, len);
  95. *lenp = len;
  96. *ppos += len;
  97. return 0;
  98. }
  99. static struct ctl_table_header *svcrdma_table_header;
  100. static struct ctl_table svcrdma_parm_table[] = {
  101. {
  102. .procname = "max_requests",
  103. .data = &svcrdma_max_requests,
  104. .maxlen = sizeof(unsigned int),
  105. .mode = 0644,
  106. .proc_handler = proc_dointvec_minmax,
  107. .extra1 = &min_max_requests,
  108. .extra2 = &max_max_requests
  109. },
  110. {
  111. .procname = "max_req_size",
  112. .data = &svcrdma_max_req_size,
  113. .maxlen = sizeof(unsigned int),
  114. .mode = 0644,
  115. .proc_handler = proc_dointvec_minmax,
  116. .extra1 = &min_max_inline,
  117. .extra2 = &max_max_inline
  118. },
  119. {
  120. .procname = "max_outbound_read_requests",
  121. .data = &svcrdma_ord,
  122. .maxlen = sizeof(unsigned int),
  123. .mode = 0644,
  124. .proc_handler = proc_dointvec_minmax,
  125. .extra1 = &min_ord,
  126. .extra2 = &max_ord,
  127. },
  128. {
  129. .procname = "rdma_stat_read",
  130. .data = &svcrdma_stat_read,
  131. .maxlen = SVCRDMA_COUNTER_BUFSIZ,
  132. .mode = 0644,
  133. .proc_handler = svcrdma_counter_handler,
  134. },
  135. {
  136. .procname = "rdma_stat_recv",
  137. .data = &svcrdma_stat_recv,
  138. .maxlen = SVCRDMA_COUNTER_BUFSIZ,
  139. .mode = 0644,
  140. .proc_handler = svcrdma_counter_handler,
  141. },
  142. {
  143. .procname = "rdma_stat_write",
  144. .data = &svcrdma_stat_write,
  145. .maxlen = SVCRDMA_COUNTER_BUFSIZ,
  146. .mode = 0644,
  147. .proc_handler = svcrdma_counter_handler,
  148. },
  149. {
  150. .procname = "rdma_stat_sq_starve",
  151. .data = &svcrdma_stat_sq_starve,
  152. .maxlen = SVCRDMA_COUNTER_BUFSIZ,
  153. .mode = 0644,
  154. .proc_handler = svcrdma_counter_handler,
  155. },
  156. {
  157. .procname = "rdma_stat_rq_starve",
  158. .data = &svcrdma_stat_unused,
  159. .maxlen = sizeof(unsigned int),
  160. .mode = 0644,
  161. .proc_handler = proc_dointvec_minmax,
  162. .extra1 = &zero,
  163. .extra2 = &zero,
  164. },
  165. {
  166. .procname = "rdma_stat_rq_poll",
  167. .data = &svcrdma_stat_unused,
  168. .maxlen = sizeof(unsigned int),
  169. .mode = 0644,
  170. .proc_handler = proc_dointvec_minmax,
  171. .extra1 = &zero,
  172. .extra2 = &zero,
  173. },
  174. {
  175. .procname = "rdma_stat_rq_prod",
  176. .data = &svcrdma_stat_unused,
  177. .maxlen = sizeof(unsigned int),
  178. .mode = 0644,
  179. .proc_handler = proc_dointvec_minmax,
  180. .extra1 = &zero,
  181. .extra2 = &zero,
  182. },
  183. {
  184. .procname = "rdma_stat_sq_poll",
  185. .data = &svcrdma_stat_unused,
  186. .maxlen = sizeof(unsigned int),
  187. .mode = 0644,
  188. .proc_handler = proc_dointvec_minmax,
  189. .extra1 = &zero,
  190. .extra2 = &zero,
  191. },
  192. {
  193. .procname = "rdma_stat_sq_prod",
  194. .data = &svcrdma_stat_unused,
  195. .maxlen = sizeof(unsigned int),
  196. .mode = 0644,
  197. .proc_handler = proc_dointvec_minmax,
  198. .extra1 = &zero,
  199. .extra2 = &zero,
  200. },
  201. { },
  202. };
  203. static struct ctl_table svcrdma_table[] = {
  204. {
  205. .procname = "svc_rdma",
  206. .mode = 0555,
  207. .child = svcrdma_parm_table
  208. },
  209. { },
  210. };
  211. static struct ctl_table svcrdma_root_table[] = {
  212. {
  213. .procname = "sunrpc",
  214. .mode = 0555,
  215. .child = svcrdma_table
  216. },
  217. { },
  218. };
  219. static void svc_rdma_proc_cleanup(void)
  220. {
  221. if (!svcrdma_table_header)
  222. return;
  223. unregister_sysctl_table(svcrdma_table_header);
  224. svcrdma_table_header = NULL;
  225. percpu_counter_destroy(&svcrdma_stat_write);
  226. percpu_counter_destroy(&svcrdma_stat_sq_starve);
  227. percpu_counter_destroy(&svcrdma_stat_recv);
  228. percpu_counter_destroy(&svcrdma_stat_read);
  229. }
  230. static int svc_rdma_proc_init(void)
  231. {
  232. int rc;
  233. if (svcrdma_table_header)
  234. return 0;
  235. rc = percpu_counter_init(&svcrdma_stat_read, 0, GFP_KERNEL);
  236. if (rc)
  237. goto out_err;
  238. rc = percpu_counter_init(&svcrdma_stat_recv, 0, GFP_KERNEL);
  239. if (rc)
  240. goto out_err;
  241. rc = percpu_counter_init(&svcrdma_stat_sq_starve, 0, GFP_KERNEL);
  242. if (rc)
  243. goto out_err;
  244. rc = percpu_counter_init(&svcrdma_stat_write, 0, GFP_KERNEL);
  245. if (rc)
  246. goto out_err;
  247. svcrdma_table_header = register_sysctl_table(svcrdma_root_table);
  248. return 0;
  249. out_err:
  250. percpu_counter_destroy(&svcrdma_stat_sq_starve);
  251. percpu_counter_destroy(&svcrdma_stat_recv);
  252. percpu_counter_destroy(&svcrdma_stat_read);
  253. return rc;
  254. }
  255. void svc_rdma_cleanup(void)
  256. {
  257. dprintk("SVCRDMA Module Removed, deregister RPC RDMA transport\n");
  258. svc_unreg_xprt_class(&svc_rdma_class);
  259. svc_rdma_proc_cleanup();
  260. }
  261. int svc_rdma_init(void)
  262. {
  263. int rc;
  264. dprintk("SVCRDMA Module Init, register RPC RDMA transport\n");
  265. dprintk("\tsvcrdma_ord : %d\n", svcrdma_ord);
  266. dprintk("\tmax_requests : %u\n", svcrdma_max_requests);
  267. dprintk("\tmax_bc_requests : %u\n", svcrdma_max_bc_requests);
  268. dprintk("\tmax_inline : %d\n", svcrdma_max_req_size);
  269. rc = svc_rdma_proc_init();
  270. if (rc)
  271. return rc;
  272. /* Register RDMA with the SVC transport switch */
  273. svc_reg_xprt_class(&svc_rdma_class);
  274. return 0;
  275. }