svc_rdma.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. */
  41. #include <linux/slab.h>
  42. #include <linux/fs.h>
  43. #include <linux/sysctl.h>
  44. #include <linux/workqueue.h>
  45. #include <linux/sunrpc/clnt.h>
  46. #include <linux/sunrpc/sched.h>
  47. #include <linux/sunrpc/svc_rdma.h>
  48. #include "xprt_rdma.h"
  49. #define RPCDBG_FACILITY RPCDBG_SVCXPRT
  50. /* RPC/RDMA parameters */
  51. unsigned int svcrdma_ord = RPCRDMA_ORD;
  52. static unsigned int min_ord = 1;
  53. static unsigned int max_ord = 4096;
  54. unsigned int svcrdma_max_requests = RPCRDMA_MAX_REQUESTS;
  55. unsigned int svcrdma_max_bc_requests = RPCRDMA_MAX_BC_REQUESTS;
  56. static unsigned int min_max_requests = 4;
  57. static unsigned int max_max_requests = 16384;
  58. unsigned int svcrdma_max_req_size = RPCRDMA_DEF_INLINE_THRESH;
  59. static unsigned int min_max_inline = RPCRDMA_DEF_INLINE_THRESH;
  60. static unsigned int max_max_inline = RPCRDMA_MAX_INLINE_THRESH;
  61. atomic_t rdma_stat_recv;
  62. atomic_t rdma_stat_read;
  63. atomic_t rdma_stat_write;
  64. atomic_t rdma_stat_sq_starve;
  65. atomic_t rdma_stat_rq_starve;
  66. atomic_t rdma_stat_rq_poll;
  67. atomic_t rdma_stat_rq_prod;
  68. atomic_t rdma_stat_sq_poll;
  69. atomic_t rdma_stat_sq_prod;
  70. struct workqueue_struct *svc_rdma_wq;
  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 __user *buffer, size_t *lenp,
  79. loff_t *ppos)
  80. {
  81. atomic_t *stat = (atomic_t *)table->data;
  82. if (!stat)
  83. return -EINVAL;
  84. if (write)
  85. atomic_set(stat, 0);
  86. else {
  87. char str_buf[32];
  88. char *data;
  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. data = &str_buf[*ppos];
  98. len -= *ppos;
  99. if (len > *lenp)
  100. len = *lenp;
  101. if (len && copy_to_user(buffer, str_buf, len))
  102. return -EFAULT;
  103. *lenp = len;
  104. *ppos += len;
  105. }
  106. return 0;
  107. }
  108. static struct ctl_table_header *svcrdma_table_header;
  109. static struct ctl_table svcrdma_parm_table[] = {
  110. {
  111. .procname = "max_requests",
  112. .data = &svcrdma_max_requests,
  113. .maxlen = sizeof(unsigned int),
  114. .mode = 0644,
  115. .proc_handler = proc_dointvec_minmax,
  116. .extra1 = &min_max_requests,
  117. .extra2 = &max_max_requests
  118. },
  119. {
  120. .procname = "max_req_size",
  121. .data = &svcrdma_max_req_size,
  122. .maxlen = sizeof(unsigned int),
  123. .mode = 0644,
  124. .proc_handler = proc_dointvec_minmax,
  125. .extra1 = &min_max_inline,
  126. .extra2 = &max_max_inline
  127. },
  128. {
  129. .procname = "max_outbound_read_requests",
  130. .data = &svcrdma_ord,
  131. .maxlen = sizeof(unsigned int),
  132. .mode = 0644,
  133. .proc_handler = proc_dointvec_minmax,
  134. .extra1 = &min_ord,
  135. .extra2 = &max_ord,
  136. },
  137. {
  138. .procname = "rdma_stat_read",
  139. .data = &rdma_stat_read,
  140. .maxlen = sizeof(atomic_t),
  141. .mode = 0644,
  142. .proc_handler = read_reset_stat,
  143. },
  144. {
  145. .procname = "rdma_stat_recv",
  146. .data = &rdma_stat_recv,
  147. .maxlen = sizeof(atomic_t),
  148. .mode = 0644,
  149. .proc_handler = read_reset_stat,
  150. },
  151. {
  152. .procname = "rdma_stat_write",
  153. .data = &rdma_stat_write,
  154. .maxlen = sizeof(atomic_t),
  155. .mode = 0644,
  156. .proc_handler = read_reset_stat,
  157. },
  158. {
  159. .procname = "rdma_stat_sq_starve",
  160. .data = &rdma_stat_sq_starve,
  161. .maxlen = sizeof(atomic_t),
  162. .mode = 0644,
  163. .proc_handler = read_reset_stat,
  164. },
  165. {
  166. .procname = "rdma_stat_rq_starve",
  167. .data = &rdma_stat_rq_starve,
  168. .maxlen = sizeof(atomic_t),
  169. .mode = 0644,
  170. .proc_handler = read_reset_stat,
  171. },
  172. {
  173. .procname = "rdma_stat_rq_poll",
  174. .data = &rdma_stat_rq_poll,
  175. .maxlen = sizeof(atomic_t),
  176. .mode = 0644,
  177. .proc_handler = read_reset_stat,
  178. },
  179. {
  180. .procname = "rdma_stat_rq_prod",
  181. .data = &rdma_stat_rq_prod,
  182. .maxlen = sizeof(atomic_t),
  183. .mode = 0644,
  184. .proc_handler = read_reset_stat,
  185. },
  186. {
  187. .procname = "rdma_stat_sq_poll",
  188. .data = &rdma_stat_sq_poll,
  189. .maxlen = sizeof(atomic_t),
  190. .mode = 0644,
  191. .proc_handler = read_reset_stat,
  192. },
  193. {
  194. .procname = "rdma_stat_sq_prod",
  195. .data = &rdma_stat_sq_prod,
  196. .maxlen = sizeof(atomic_t),
  197. .mode = 0644,
  198. .proc_handler = read_reset_stat,
  199. },
  200. { },
  201. };
  202. static struct ctl_table svcrdma_table[] = {
  203. {
  204. .procname = "svc_rdma",
  205. .mode = 0555,
  206. .child = svcrdma_parm_table
  207. },
  208. { },
  209. };
  210. static struct ctl_table svcrdma_root_table[] = {
  211. {
  212. .procname = "sunrpc",
  213. .mode = 0555,
  214. .child = svcrdma_table
  215. },
  216. { },
  217. };
  218. void svc_rdma_cleanup(void)
  219. {
  220. dprintk("SVCRDMA Module Removed, deregister RPC RDMA transport\n");
  221. destroy_workqueue(svc_rdma_wq);
  222. if (svcrdma_table_header) {
  223. unregister_sysctl_table(svcrdma_table_header);
  224. svcrdma_table_header = NULL;
  225. }
  226. #if defined(CONFIG_SUNRPC_BACKCHANNEL)
  227. svc_unreg_xprt_class(&svc_rdma_bc_class);
  228. #endif
  229. svc_unreg_xprt_class(&svc_rdma_class);
  230. }
  231. int svc_rdma_init(void)
  232. {
  233. dprintk("SVCRDMA Module Init, register RPC RDMA transport\n");
  234. dprintk("\tsvcrdma_ord : %d\n", svcrdma_ord);
  235. dprintk("\tmax_requests : %u\n", svcrdma_max_requests);
  236. dprintk("\tmax_bc_requests : %u\n", svcrdma_max_bc_requests);
  237. dprintk("\tmax_inline : %d\n", svcrdma_max_req_size);
  238. svc_rdma_wq = alloc_workqueue("svc_rdma", 0, 0);
  239. if (!svc_rdma_wq)
  240. return -ENOMEM;
  241. if (!svcrdma_table_header)
  242. svcrdma_table_header =
  243. register_sysctl_table(svcrdma_root_table);
  244. /* Register RDMA with the SVC transport switch */
  245. svc_reg_xprt_class(&svc_rdma_class);
  246. #if defined(CONFIG_SUNRPC_BACKCHANNEL)
  247. svc_reg_xprt_class(&svc_rdma_bc_class);
  248. #endif
  249. return 0;
  250. }