Whamcloud - gitweb
LU-6245 libcfs: replace CFS_MODULE_PARAM with linux kernel module api
[fs/lustre-release.git] / lnet / klnds / o2iblnd / o2iblnd_modparams.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lnet/klnds/o2iblnd/o2iblnd_modparams.c
37  *
38  * Author: Eric Barton <eric@bartonsoftware.com>
39  */
40
41 #include "o2iblnd.h"
42
43 static int service = 987;
44 module_param(service, int, 0444);
45 MODULE_PARM_DESC(service, "service number (within RDMA_PS_TCP)");
46
47 static int cksum = 0;
48 module_param(cksum, int, 0644);
49 MODULE_PARM_DESC(cksum, "set non-zero to enable message (not RDMA) checksums");
50
51 static int timeout = 50;
52 module_param(timeout, int, 0644);
53 MODULE_PARM_DESC(timeout, "timeout (seconds)");
54
55 /* Number of threads in each scheduler pool which is percpt,
56  * we will estimate reasonable value based on CPUs if it's set to zero. */
57 static int nscheds;
58 module_param(nscheds, int, 0444);
59 MODULE_PARM_DESC(nscheds, "number of threads in each scheduler pool");
60
61 /* NB: this value is shared by all CPTs, it can grow at runtime */
62 static int ntx = 512;
63 module_param(ntx, int, 0444);
64 MODULE_PARM_DESC(ntx, "# of message descriptors allocated for each pool");
65
66 /* NB: this value is shared by all CPTs */
67 static int credits = 256;
68 module_param(credits, int, 0444);
69 MODULE_PARM_DESC(credits, "# concurrent sends");
70
71 static int peer_credits = 8;
72 module_param(peer_credits, int, 0444);
73 MODULE_PARM_DESC(peer_credits, "# concurrent sends to 1 peer");
74
75 static int peer_credits_hiw = 0;
76 module_param(peer_credits_hiw, int, 0444);
77 MODULE_PARM_DESC(peer_credits_hiw, "when eagerly to return credits");
78
79 static int peer_buffer_credits = 0;
80 module_param(peer_buffer_credits, int, 0444);
81 MODULE_PARM_DESC(peer_buffer_credits, "# per-peer router buffer credits");
82
83 static int peer_timeout = 180;
84 module_param(peer_timeout, int, 0444);
85 MODULE_PARM_DESC(peer_timeout, "Seconds without aliveness news to declare peer dead (<=0 to disable)");
86
87 static char *ipif_name = "ib0";
88 module_param(ipif_name, charp, 0444);
89 MODULE_PARM_DESC(ipif_name, "IPoIB interface name");
90
91 static int retry_count = 5;
92 module_param(retry_count, int, 0644);
93 MODULE_PARM_DESC(retry_count, "Retransmissions when no ACK received");
94
95 static int rnr_retry_count = 6;
96 module_param(rnr_retry_count, int, 0644);
97 MODULE_PARM_DESC(rnr_retry_count, "RNR retransmissions");
98
99 static int keepalive = 100;
100 module_param(keepalive, int, 0644);
101 MODULE_PARM_DESC(keepalive, "Idle time in seconds before sending a keepalive");
102
103 static int ib_mtu;
104 module_param(ib_mtu, int, 0444);
105 MODULE_PARM_DESC(ib_mtu, "IB MTU 256/512/1024/2048/4096");
106
107 static int concurrent_sends;
108 module_param(concurrent_sends, int, 0444);
109 MODULE_PARM_DESC(concurrent_sends, "send work-queue sizing");
110
111 static int map_on_demand;
112 module_param(map_on_demand, int, 0444);
113 MODULE_PARM_DESC(map_on_demand, "map on demand");
114
115 /* NB: this value is shared by all CPTs, it can grow at runtime */
116 static int fmr_pool_size = 512;
117 module_param(fmr_pool_size, int, 0444);
118 MODULE_PARM_DESC(fmr_pool_size, "size of fmr pool on each CPT (>= ntx / 4)");
119
120 /* NB: this value is shared by all CPTs, it can grow at runtime */
121 static int fmr_flush_trigger = 384;
122 module_param(fmr_flush_trigger, int, 0444);
123 MODULE_PARM_DESC(fmr_flush_trigger, "# dirty FMRs that triggers pool flush");
124
125 static int fmr_cache = 1;
126 module_param(fmr_cache, int, 0444);
127 MODULE_PARM_DESC(fmr_cache, "non-zero to enable FMR caching");
128
129 /*
130  * 0: disable failover
131  * 1: enable failover if necessary
132  * 2: force to failover (for debug)
133  */
134 static int dev_failover = 0;
135 module_param(dev_failover, int, 0444);
136 MODULE_PARM_DESC(dev_failover, "HCA failover for bonding (0 off, 1 on, other values reserved)");
137
138 static int require_privileged_port;
139 module_param(require_privileged_port, int, 0644);
140 MODULE_PARM_DESC(require_privileged_port, "require privileged port when accepting connection");
141
142 static int use_privileged_port = 1;
143 module_param(use_privileged_port, int, 0644);
144 MODULE_PARM_DESC(use_privileged_port, "use privileged port when initiating connection");
145
146 kib_tunables_t kiblnd_tunables = {
147         .kib_dev_failover           = &dev_failover,
148         .kib_service                = &service,
149         .kib_cksum                  = &cksum,
150         .kib_timeout                = &timeout,
151         .kib_keepalive              = &keepalive,
152         .kib_ntx                    = &ntx,
153         .kib_default_ipif           = &ipif_name,
154         .kib_retry_count            = &retry_count,
155         .kib_rnr_retry_count        = &rnr_retry_count,
156         .kib_ib_mtu                 = &ib_mtu,
157         .kib_require_priv_port      = &require_privileged_port,
158         .kib_use_priv_port          = &use_privileged_port,
159         .kib_nscheds                = &nscheds
160 };
161
162 static struct lnet_ioctl_config_o2iblnd_tunables default_tunables;
163
164 #if defined(CONFIG_SYSCTL) && !CFS_SYSFS_MODULE_PARM
165
166 static char ipif_basename_space[32];
167
168 static struct ctl_table kiblnd_ctl_table[] = {
169         {
170                 INIT_CTL_NAME
171                 .procname       = "service",
172                 .data           = &service,
173                 .maxlen         = sizeof(int),
174                 .mode           = 0444,
175                 .proc_handler   = &proc_dointvec
176         },
177         {
178                 INIT_CTL_NAME
179                 .procname       = "cksum",
180                 .data           = &cksum,
181                 .maxlen         = sizeof(int),
182                 .mode           = 0644,
183                 .proc_handler   = &proc_dointvec
184         },
185         {
186                 INIT_CTL_NAME
187                 .procname       = "timeout",
188                 .data           = &timeout,
189                 .maxlen         = sizeof(int),
190                 .mode           = 0644,
191                 .proc_handler   = &proc_dointvec
192         },
193         {
194                 INIT_CTL_NAME
195                 .procname       = "ntx",
196                 .data           = &ntx,
197                 .maxlen         = sizeof(int),
198                 .mode           = 0444,
199                 .proc_handler   = &proc_dointvec
200         },
201         {
202                 INIT_CTL_NAME
203                 .procname       = "credits",
204                 .data           = &credits,
205                 .maxlen         = sizeof(int),
206                 .mode           = 0444,
207                 .proc_handler   = &proc_dointvec
208         },
209         {
210                 INIT_CTL_NAME
211                 .procname       = "peer_credits",
212                 .data           = &peer_credits,
213                 .maxlen         = sizeof(int),
214                 .mode           = 0444,
215                 .proc_handler   = &proc_dointvec
216         },
217         {
218                 INIT_CTL_NAME
219                 .procname       = "peer_credits_hiw",
220                 .data           = &peer_credits_hiw,
221                 .maxlen         = sizeof(int),
222                 .mode           = 0444,
223                 .proc_handler   = &proc_dointvec
224         },
225         {
226                 INIT_CTL_NAME
227                 .procname       = "peer_buffer_credits",
228                 .data           = &peer_buffer_credits,
229                 .maxlen         = sizeof(int),
230                 .mode           = 0444,
231                 .proc_handler   = &proc_dointvec
232         },
233         {
234                 INIT_CTL_NAME
235                 .procname       = "peer_timeout",
236                 .data           = &peer_timeout,
237                 .maxlen         = sizeof(int),
238                 .mode           = 0444,
239                 .proc_handler   = &proc_dointvec
240         },
241         {
242                 INIT_CTL_NAME
243                 .procname       = "ipif_name",
244                 .data           = ipif_basename_space,
245                 .maxlen         = sizeof(ipif_basename_space),
246                 .mode           = 0444,
247                 .proc_handler   = &proc_dostring
248         },
249         {
250                 INIT_CTL_NAME
251                 .procname       = "retry_count",
252                 .data           = &retry_count,
253                 .maxlen         = sizeof(int),
254                 .mode           = 0644,
255                 .proc_handler   = &proc_dointvec
256         },
257         {
258                 INIT_CTL_NAME
259                 .procname       = "rnr_retry_count",
260                 .data           = &rnr_retry_count,
261                 .maxlen         = sizeof(int),
262                 .mode           = 0644,
263                 .proc_handler   = &proc_dointvec
264         },
265         {
266                 INIT_CTL_NAME
267                 .procname       = "keepalive",
268                 .data           = &keepalive,
269                 .maxlen         = sizeof(int),
270                 .mode           = 0644,
271                 .proc_handler   = &proc_dointvec
272         },
273         {
274                 INIT_CTL_NAME
275                 .procname       = "concurrent_sends",
276                 .data           = &concurrent_sends,
277                 .maxlen         = sizeof(int),
278                 .mode           = 0444,
279                 .proc_handler   = &proc_dointvec
280         },
281         {
282                 INIT_CTL_NAME
283                 .procname       = "ib_mtu",
284                 .data           = &ib_mtu,
285                 .maxlen         = sizeof(int),
286                 .mode           = 0444,
287                 .proc_handler   = &proc_dointvec
288         },
289         {
290                 INIT_CTL_NAME
291                 .procname       = "map_on_demand",
292                 .data           = &map_on_demand,
293                 .maxlen         = sizeof(int),
294                 .mode           = 0444,
295                 .proc_handler   = &proc_dointvec
296         },
297         {
298                 INIT_CTL_NAME
299                 .procname       = "fmr_pool_size",
300                 .data           = &fmr_pool_size,
301                 .maxlen         = sizeof(int),
302                 .mode           = 0444,
303                 .proc_handler   = &proc_dointvec
304         },
305         {
306                 INIT_CTL_NAME
307                 .procname       = "fmr_flush_trigger",
308                 .data           = &fmr_flush_trigger,
309                 .maxlen         = sizeof(int),
310                 .mode           = 0444,
311                 .proc_handler   = &proc_dointvec
312         },
313         {
314                 INIT_CTL_NAME
315                 .procname       = "fmr_cache",
316                 .data           = &fmr_cache,
317                 .maxlen         = sizeof(int),
318                 .mode           = 0444,
319                 .proc_handler   = &proc_dointvec
320         },
321         {
322                 INIT_CTL_NAME
323                 .procname       = "dev_failover",
324                 .data           = &dev_failover,
325                 .maxlen         = sizeof(int),
326                 .mode           = 0444,
327                 .proc_handler   = &proc_dointvec
328         },
329         { 0 }
330 };
331
332 static struct ctl_table kiblnd_top_ctl_table[] = {
333         {
334                 INIT_CTL_NAME
335                 .procname       = "o2iblnd",
336                 .data           = NULL,
337                 .maxlen         = 0,
338                 .mode           = 0555,
339                 .child          = kiblnd_ctl_table
340         },
341         { 0 }
342 };
343
344 void
345 kiblnd_initstrtunable(char *space, char *str, int size)
346 {
347         strncpy(space, str, size);
348         space[size-1] = 0;
349 }
350
351 static void
352 kiblnd_sysctl_init (void)
353 {
354         kiblnd_initstrtunable(ipif_basename_space, ipif_name,
355                               sizeof(ipif_basename_space));
356
357         kiblnd_tunables.kib_sysctl =
358                 register_sysctl_table(kiblnd_top_ctl_table);
359
360         if (kiblnd_tunables.kib_sysctl == NULL)
361                 CWARN("Can't setup /proc tunables\n");
362 }
363
364 static void
365 kiblnd_sysctl_fini (void)
366 {
367         if (kiblnd_tunables.kib_sysctl != NULL)
368                 unregister_sysctl_table(kiblnd_tunables.kib_sysctl);
369 }
370
371 #else
372
373 static void
374 kiblnd_sysctl_init (void)
375 {
376 }
377
378 static void
379 kiblnd_sysctl_fini (void)
380 {
381 }
382 #endif
383
384 /* # messages/RDMAs in-flight */
385 int
386 kiblnd_msg_queue_size(int version, lnet_ni_t *ni)
387 {
388         if (version == IBLND_MSG_VERSION_1)
389                 return IBLND_MSG_QUEUE_SIZE_V1;
390         else if (ni)
391                 return ni->ni_peertxcredits;
392         else
393                 return peer_credits;
394 }
395
396 int
397 kiblnd_tunables_setup(lnet_ni_t *ni)
398 {
399         struct lnet_ioctl_config_o2iblnd_tunables *tunables;
400
401         /*
402          * if there was no tunables specified, setup the tunables to be
403          * defaulted
404          */
405         if (!ni->ni_lnd_tunables) {
406                 LIBCFS_ALLOC(ni->ni_lnd_tunables,
407                              sizeof(*ni->ni_lnd_tunables));
408                 if (!ni->ni_lnd_tunables)
409                         return -ENOMEM;
410
411                 memcpy(&ni->ni_lnd_tunables->lt_tun_u.lt_o2ib,
412                        &default_tunables, sizeof(*tunables));
413         }
414         tunables = &ni->ni_lnd_tunables->lt_tun_u.lt_o2ib;
415
416         /* Current API version */
417         tunables->lnd_version = 0;
418
419         if (kiblnd_translate_mtu(*kiblnd_tunables.kib_ib_mtu) < 0) {
420                 CERROR("Invalid ib_mtu %d, expected 256/512/1024/2048/4096\n",
421                        *kiblnd_tunables.kib_ib_mtu);
422                 return -EINVAL;
423         }
424
425         if (!ni->ni_peertimeout)
426                 ni->ni_peertimeout = peer_timeout;
427
428         if (!ni->ni_maxtxcredits)
429                 ni->ni_maxtxcredits = credits;
430
431         if (!ni->ni_peertxcredits)
432                 ni->ni_peertxcredits = peer_credits;
433
434         if (!ni->ni_peerrtrcredits)
435                 ni->ni_peerrtrcredits = peer_buffer_credits;
436
437         if (ni->ni_peertxcredits < IBLND_CREDITS_DEFAULT)
438                 ni->ni_peertxcredits = IBLND_CREDITS_DEFAULT;
439
440         if (ni->ni_peertxcredits > IBLND_CREDITS_MAX)
441                 ni->ni_peertxcredits = IBLND_CREDITS_MAX;
442
443         if (ni->ni_peertxcredits > credits)
444                 ni->ni_peertxcredits = credits;
445
446         if (!tunables->lnd_peercredits_hiw)
447                 tunables->lnd_peercredits_hiw = peer_credits_hiw;
448
449         if (tunables->lnd_peercredits_hiw < ni->ni_peertxcredits / 2)
450                 tunables->lnd_peercredits_hiw = ni->ni_peertxcredits / 2;
451
452         if (tunables->lnd_peercredits_hiw >= ni->ni_peertxcredits)
453                 tunables->lnd_peercredits_hiw = ni->ni_peertxcredits - 1;
454
455         if (tunables->lnd_map_on_demand < 0 ||
456             tunables->lnd_map_on_demand > IBLND_MAX_RDMA_FRAGS) {
457                 /* disable map-on-demand */
458                 tunables->lnd_map_on_demand = 0;
459         }
460
461         if (tunables->lnd_map_on_demand == 1) {
462                 /* don't make sense to create map if only one fragment */
463                 tunables->lnd_map_on_demand = 2;
464         }
465
466         if (tunables->lnd_concurrent_sends == 0) {
467                 if (tunables->lnd_map_on_demand > 0 &&
468                     tunables->lnd_map_on_demand <= IBLND_MAX_RDMA_FRAGS / 8) {
469                         tunables->lnd_concurrent_sends =
470                                                 ni->ni_peertxcredits * 2;
471                 } else {
472                         tunables->lnd_concurrent_sends = ni->ni_peertxcredits;
473                 }
474         }
475
476         if (tunables->lnd_concurrent_sends > ni->ni_peertxcredits * 2)
477                 tunables->lnd_concurrent_sends = ni->ni_peertxcredits * 2;
478
479         if (tunables->lnd_concurrent_sends < ni->ni_peertxcredits / 2)
480                 tunables->lnd_concurrent_sends = ni->ni_peertxcredits / 2;
481
482         if (tunables->lnd_concurrent_sends < ni->ni_peertxcredits) {
483                 CWARN("Concurrent sends %d is lower than message "
484                       "queue size: %d, performance may drop slightly.\n",
485                       tunables->lnd_concurrent_sends, ni->ni_peertxcredits);
486         }
487
488         if (!tunables->lnd_fmr_pool_size)
489                 tunables->lnd_fmr_pool_size = fmr_pool_size;
490         if (!tunables->lnd_fmr_flush_trigger)
491                 tunables->lnd_fmr_flush_trigger = fmr_flush_trigger;
492         if (!tunables->lnd_fmr_cache)
493                 tunables->lnd_fmr_cache = fmr_cache;
494
495         return 0;
496 }
497
498 int
499 kiblnd_tunables_init(void)
500 {
501         default_tunables.lnd_version = 0;
502         default_tunables.lnd_peercredits_hiw = peer_credits_hiw,
503         default_tunables.lnd_map_on_demand = map_on_demand;
504         default_tunables.lnd_concurrent_sends = concurrent_sends;
505         default_tunables.lnd_fmr_pool_size = fmr_pool_size;
506         default_tunables.lnd_fmr_flush_trigger = fmr_flush_trigger;
507         default_tunables.lnd_fmr_cache = fmr_cache;
508
509         kiblnd_sysctl_init();
510         return 0;
511 }
512
513 void
514 kiblnd_tunables_fini(void)
515 {
516         kiblnd_sysctl_fini();
517 }