svc_rdma.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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/module.h>
  42. #include <linux/init.h>
  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 = RPCRDMA_ORD;
  53. static unsigned int min_ord = 1;
  54. static unsigned int max_ord = 4096;
  55. unsigned int svcrdma_max_requests = RPCRDMA_MAX_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_MAX_REQ_SIZE;
  59. static unsigned int min_max_inline = 4096;
  60. static unsigned int max_max_inline = 65536;
  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. /* Temporary NFS request map and context caches */
  71. struct kmem_cache *svc_rdma_map_cachep;
  72. struct kmem_cache *svc_rdma_ctxt_cachep;
  73. struct workqueue_struct *svc_rdma_wq;
  74. /*
  75. * This function implements reading and resetting an atomic_t stat
  76. * variable through read/write to a proc file. Any write to the file
  77. * resets the associated statistic to zero. Any read returns it's
  78. * current value.
  79. */
  80. static int read_reset_stat(ctl_table *table, int write,
  81. void __user *buffer, size_t *lenp,
  82. loff_t *ppos)
  83. {
  84. atomic_t *stat = (atomic_t *)table->data;
  85. if (!stat)
  86. return -EINVAL;
  87. if (write)
  88. atomic_set(stat, 0);
  89. else {
  90. char str_buf[32];
  91. char *data;
  92. int len = snprintf(str_buf, 32, "%d\n", atomic_read(stat));
  93. if (len >= 32)
  94. return -EFAULT;
  95. len = strlen(str_buf);
  96. if (*ppos > len) {
  97. *lenp = 0;
  98. return 0;
  99. }
  100. data = &str_buf[*ppos];
  101. len -= *ppos;
  102. if (len > *lenp)
  103. len = *lenp;
  104. if (len && copy_to_user(buffer, str_buf, len))
  105. return -EFAULT;
  106. *lenp = len;
  107. *ppos += len;
  108. }
  109. return 0;
  110. }
  111. static struct ctl_table_header *svcrdma_table_header;
  112. static ctl_table svcrdma_parm_table[] = {
  113. {
  114. .procname = "max_requests",
  115. .data = &svcrdma_max_requests,
  116. .maxlen = sizeof(unsigned int),
  117. .mode = 0644,
  118. .proc_handler = proc_dointvec_minmax,
  119. .extra1 = &min_max_requests,
  120. .extra2 = &max_max_requests
  121. },
  122. {
  123. .procname = "max_req_size",
  124. .data = &svcrdma_max_req_size,
  125. .maxlen = sizeof(unsigned int),
  126. .mode = 0644,
  127. .proc_handler = proc_dointvec_minmax,
  128. .extra1 = &min_max_inline,
  129. .extra2 = &max_max_inline
  130. },
  131. {
  132. .procname = "max_outbound_read_requests",
  133. .data = &svcrdma_ord,
  134. .maxlen = sizeof(unsigned int),
  135. .mode = 0644,
  136. .proc_handler = proc_dointvec_minmax,
  137. .extra1 = &min_ord,
  138. .extra2 = &max_ord,
  139. },
  140. {
  141. .procname = "rdma_stat_read",
  142. .data = &rdma_stat_read,
  143. .maxlen = sizeof(atomic_t),
  144. .mode = 0644,
  145. .proc_handler = read_reset_stat,
  146. },
  147. {
  148. .procname = "rdma_stat_recv",
  149. .data = &rdma_stat_recv,
  150. .maxlen = sizeof(atomic_t),
  151. .mode = 0644,
  152. .proc_handler = read_reset_stat,
  153. },
  154. {
  155. .procname = "rdma_stat_write",
  156. .data = &rdma_stat_write,
  157. .maxlen = sizeof(atomic_t),
  158. .mode = 0644,
  159. .proc_handler = read_reset_stat,
  160. },
  161. {
  162. .procname = "rdma_stat_sq_starve",
  163. .data = &rdma_stat_sq_starve,
  164. .maxlen = sizeof(atomic_t),
  165. .mode = 0644,
  166. .proc_handler = read_reset_stat,
  167. },
  168. {
  169. .procname = "rdma_stat_rq_starve",
  170. .data = &rdma_stat_rq_starve,
  171. .maxlen = sizeof(atomic_t),
  172. .mode = 0644,
  173. .proc_handler = read_reset_stat,
  174. },
  175. {
  176. .procname = "rdma_stat_rq_poll",
  177. .data = &rdma_stat_rq_poll,
  178. .maxlen = sizeof(atomic_t),
  179. .mode = 0644,
  180. .proc_handler = read_reset_stat,
  181. },
  182. {
  183. .procname = "rdma_stat_rq_prod",
  184. .data = &rdma_stat_rq_prod,
  185. .maxlen = sizeof(atomic_t),
  186. .mode = 0644,
  187. .proc_handler = read_reset_stat,
  188. },
  189. {
  190. .procname = "rdma_stat_sq_poll",
  191. .data = &rdma_stat_sq_poll,
  192. .maxlen = sizeof(atomic_t),
  193. .mode = 0644,
  194. .proc_handler = read_reset_stat,
  195. },
  196. {
  197. .procname = "rdma_stat_sq_prod",
  198. .data = &rdma_stat_sq_prod,
  199. .maxlen = sizeof(atomic_t),
  200. .mode = 0644,
  201. .proc_handler = read_reset_stat,
  202. },
  203. { },
  204. };
  205. static ctl_table svcrdma_table[] = {
  206. {
  207. .procname = "svc_rdma",
  208. .mode = 0555,
  209. .child = svcrdma_parm_table
  210. },
  211. { },
  212. };
  213. static ctl_table svcrdma_root_table[] = {
  214. {
  215. .procname = "sunrpc",
  216. .mode = 0555,
  217. .child = svcrdma_table
  218. },
  219. { },
  220. };
  221. void svc_rdma_cleanup(void)
  222. {
  223. dprintk("SVCRDMA Module Removed, deregister RPC RDMA transport\n");
  224. destroy_workqueue(svc_rdma_wq);
  225. if (svcrdma_table_header) {
  226. unregister_sysctl_table(svcrdma_table_header);
  227. svcrdma_table_header = NULL;
  228. }
  229. svc_unreg_xprt_class(&svc_rdma_class);
  230. kmem_cache_destroy(svc_rdma_map_cachep);
  231. kmem_cache_destroy(svc_rdma_ctxt_cachep);
  232. }
  233. int svc_rdma_init(void)
  234. {
  235. dprintk("SVCRDMA Module Init, register RPC RDMA transport\n");
  236. dprintk("\tsvcrdma_ord : %d\n", svcrdma_ord);
  237. dprintk("\tmax_requests : %d\n", svcrdma_max_requests);
  238. dprintk("\tsq_depth : %d\n",
  239. svcrdma_max_requests * RPCRDMA_SQ_DEPTH_MULT);
  240. dprintk("\tmax_inline : %d\n", svcrdma_max_req_size);
  241. svc_rdma_wq = alloc_workqueue("svc_rdma", 0, 0);
  242. if (!svc_rdma_wq)
  243. return -ENOMEM;
  244. if (!svcrdma_table_header)
  245. svcrdma_table_header =
  246. register_sysctl_table(svcrdma_root_table);
  247. /* Create the temporary map cache */
  248. svc_rdma_map_cachep = kmem_cache_create("svc_rdma_map_cache",
  249. sizeof(struct svc_rdma_req_map),
  250. 0,
  251. SLAB_HWCACHE_ALIGN,
  252. NULL);
  253. if (!svc_rdma_map_cachep) {
  254. printk(KERN_INFO "Could not allocate map cache.\n");
  255. goto err0;
  256. }
  257. /* Create the temporary context cache */
  258. svc_rdma_ctxt_cachep =
  259. kmem_cache_create("svc_rdma_ctxt_cache",
  260. sizeof(struct svc_rdma_op_ctxt),
  261. 0,
  262. SLAB_HWCACHE_ALIGN,
  263. NULL);
  264. if (!svc_rdma_ctxt_cachep) {
  265. printk(KERN_INFO "Could not allocate WR ctxt cache.\n");
  266. goto err1;
  267. }
  268. /* Register RDMA with the SVC transport switch */
  269. svc_reg_xprt_class(&svc_rdma_class);
  270. return 0;
  271. err1:
  272. kmem_cache_destroy(svc_rdma_map_cachep);
  273. err0:
  274. unregister_sysctl_table(svcrdma_table_header);
  275. destroy_workqueue(svc_rdma_wq);
  276. return -ENOMEM;
  277. }
  278. MODULE_AUTHOR("Tom Tucker <tom@opengridcomputing.com>");
  279. MODULE_DESCRIPTION("SVC RDMA Transport");
  280. MODULE_LICENSE("Dual BSD/GPL");
  281. module_init(svc_rdma_init);
  282. module_exit(svc_rdma_cleanup);