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