svc_rdma.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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 <tom@opengridcomputing.com>
  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. atomic_t rdma_stat_recv;
  63. atomic_t rdma_stat_read;
  64. atomic_t rdma_stat_write;
  65. atomic_t rdma_stat_sq_starve;
  66. atomic_t rdma_stat_rq_starve;
  67. atomic_t rdma_stat_rq_poll;
  68. atomic_t rdma_stat_rq_prod;
  69. atomic_t rdma_stat_sq_poll;
  70. atomic_t rdma_stat_sq_prod;
  71. struct workqueue_struct *svc_rdma_wq;
  72. /*
  73. * This function implements reading and resetting an atomic_t stat
  74. * variable through read/write to a proc file. Any write to the file
  75. * resets the associated statistic to zero. Any read returns it's
  76. * current value.
  77. */
  78. static int read_reset_stat(struct ctl_table *table, int write,
  79. void __user *buffer, size_t *lenp,
  80. loff_t *ppos)
  81. {
  82. atomic_t *stat = (atomic_t *)table->data;
  83. if (!stat)
  84. return -EINVAL;
  85. if (write)
  86. atomic_set(stat, 0);
  87. else {
  88. char str_buf[32];
  89. int len = snprintf(str_buf, 32, "%d\n", atomic_read(stat));
  90. if (len >= 32)
  91. return -EFAULT;
  92. len = strlen(str_buf);
  93. if (*ppos > len) {
  94. *lenp = 0;
  95. return 0;
  96. }
  97. len -= *ppos;
  98. if (len > *lenp)
  99. len = *lenp;
  100. if (len && copy_to_user(buffer, str_buf, len))
  101. return -EFAULT;
  102. *lenp = len;
  103. *ppos += len;
  104. }
  105. return 0;
  106. }
  107. static struct ctl_table_header *svcrdma_table_header;
  108. static struct ctl_table svcrdma_parm_table[] = {
  109. {
  110. .procname = "max_requests",
  111. .data = &svcrdma_max_requests,
  112. .maxlen = sizeof(unsigned int),
  113. .mode = 0644,
  114. .proc_handler = proc_dointvec_minmax,
  115. .extra1 = &min_max_requests,
  116. .extra2 = &max_max_requests
  117. },
  118. {
  119. .procname = "max_req_size",
  120. .data = &svcrdma_max_req_size,
  121. .maxlen = sizeof(unsigned int),
  122. .mode = 0644,
  123. .proc_handler = proc_dointvec_minmax,
  124. .extra1 = &min_max_inline,
  125. .extra2 = &max_max_inline
  126. },
  127. {
  128. .procname = "max_outbound_read_requests",
  129. .data = &svcrdma_ord,
  130. .maxlen = sizeof(unsigned int),
  131. .mode = 0644,
  132. .proc_handler = proc_dointvec_minmax,
  133. .extra1 = &min_ord,
  134. .extra2 = &max_ord,
  135. },
  136. {
  137. .procname = "rdma_stat_read",
  138. .data = &rdma_stat_read,
  139. .maxlen = sizeof(atomic_t),
  140. .mode = 0644,
  141. .proc_handler = read_reset_stat,
  142. },
  143. {
  144. .procname = "rdma_stat_recv",
  145. .data = &rdma_stat_recv,
  146. .maxlen = sizeof(atomic_t),
  147. .mode = 0644,
  148. .proc_handler = read_reset_stat,
  149. },
  150. {
  151. .procname = "rdma_stat_write",
  152. .data = &rdma_stat_write,
  153. .maxlen = sizeof(atomic_t),
  154. .mode = 0644,
  155. .proc_handler = read_reset_stat,
  156. },
  157. {
  158. .procname = "rdma_stat_sq_starve",
  159. .data = &rdma_stat_sq_starve,
  160. .maxlen = sizeof(atomic_t),
  161. .mode = 0644,
  162. .proc_handler = read_reset_stat,
  163. },
  164. {
  165. .procname = "rdma_stat_rq_starve",
  166. .data = &rdma_stat_rq_starve,
  167. .maxlen = sizeof(atomic_t),
  168. .mode = 0644,
  169. .proc_handler = read_reset_stat,
  170. },
  171. {
  172. .procname = "rdma_stat_rq_poll",
  173. .data = &rdma_stat_rq_poll,
  174. .maxlen = sizeof(atomic_t),
  175. .mode = 0644,
  176. .proc_handler = read_reset_stat,
  177. },
  178. {
  179. .procname = "rdma_stat_rq_prod",
  180. .data = &rdma_stat_rq_prod,
  181. .maxlen = sizeof(atomic_t),
  182. .mode = 0644,
  183. .proc_handler = read_reset_stat,
  184. },
  185. {
  186. .procname = "rdma_stat_sq_poll",
  187. .data = &rdma_stat_sq_poll,
  188. .maxlen = sizeof(atomic_t),
  189. .mode = 0644,
  190. .proc_handler = read_reset_stat,
  191. },
  192. {
  193. .procname = "rdma_stat_sq_prod",
  194. .data = &rdma_stat_sq_prod,
  195. .maxlen = sizeof(atomic_t),
  196. .mode = 0644,
  197. .proc_handler = read_reset_stat,
  198. },
  199. { },
  200. };
  201. static struct ctl_table svcrdma_table[] = {
  202. {
  203. .procname = "svc_rdma",
  204. .mode = 0555,
  205. .child = svcrdma_parm_table
  206. },
  207. { },
  208. };
  209. static struct ctl_table svcrdma_root_table[] = {
  210. {
  211. .procname = "sunrpc",
  212. .mode = 0555,
  213. .child = svcrdma_table
  214. },
  215. { },
  216. };
  217. void svc_rdma_cleanup(void)
  218. {
  219. dprintk("SVCRDMA Module Removed, deregister RPC RDMA transport\n");
  220. destroy_workqueue(svc_rdma_wq);
  221. if (svcrdma_table_header) {
  222. unregister_sysctl_table(svcrdma_table_header);
  223. svcrdma_table_header = NULL;
  224. }
  225. #if defined(CONFIG_SUNRPC_BACKCHANNEL)
  226. svc_unreg_xprt_class(&svc_rdma_bc_class);
  227. #endif
  228. svc_unreg_xprt_class(&svc_rdma_class);
  229. }
  230. int svc_rdma_init(void)
  231. {
  232. dprintk("SVCRDMA Module Init, register RPC RDMA transport\n");
  233. dprintk("\tsvcrdma_ord : %d\n", svcrdma_ord);
  234. dprintk("\tmax_requests : %u\n", svcrdma_max_requests);
  235. dprintk("\tmax_bc_requests : %u\n", svcrdma_max_bc_requests);
  236. dprintk("\tmax_inline : %d\n", svcrdma_max_req_size);
  237. svc_rdma_wq = alloc_workqueue("svc_rdma", 0, 0);
  238. if (!svc_rdma_wq)
  239. return -ENOMEM;
  240. if (!svcrdma_table_header)
  241. svcrdma_table_header =
  242. register_sysctl_table(svcrdma_root_table);
  243. /* Register RDMA with the SVC transport switch */
  244. svc_reg_xprt_class(&svc_rdma_class);
  245. #if defined(CONFIG_SUNRPC_BACKCHANNEL)
  246. svc_reg_xprt_class(&svc_rdma_bc_class);
  247. #endif
  248. return 0;
  249. }