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