svc_rdma.c 7.0 KB

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