Whamcloud - gitweb
LU-56 o2iblnd: CPT affinity o2iblnd
[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 /*
31  * This file is part of Lustre, http://www.lustre.org/
32  * Lustre is a trademark of Sun Microsystems, Inc.
33  *
34  * lnet/klnds/o2iblnd/o2iblnd_modparams.c
35  *
36  * Author: Eric Barton <eric@bartonsoftware.com>
37  */
38
39 #include "o2iblnd.h"
40
41 static int service = 987;
42 CFS_MODULE_PARM(service, "i", int, 0444,
43                 "service number (within RDMA_PS_TCP)");
44
45 static int cksum = 0;
46 CFS_MODULE_PARM(cksum, "i", int, 0644,
47                 "set non-zero to enable message (not RDMA) checksums");
48
49 static int timeout = 50;
50 CFS_MODULE_PARM(timeout, "i", int, 0644,
51                 "timeout (seconds)");
52
53 /* Number of threads in each scheduler pool which is percpt,
54  * we will estimate reasonable value based on CPUs if it's set to zero. */
55 static int nscheds;
56 CFS_MODULE_PARM(nscheds, "i", int, 0444,
57                 "number of threads in each scheduler pool");
58
59 /* NB: this value is shared by all CPTs, it can grow at runtime */
60 static int ntx = 512;
61 CFS_MODULE_PARM(ntx, "i", int, 0444,
62                 "# of message descriptors allocated for each pool");
63
64 /* NB: this value is shared by all CPTs */
65 static int credits = 256;
66 CFS_MODULE_PARM(credits, "i", int, 0444,
67                 "# concurrent sends");
68
69 static int peer_credits = 8;
70 CFS_MODULE_PARM(peer_credits, "i", int, 0444,
71                 "# concurrent sends to 1 peer");
72
73 static int peer_credits_hiw = 0;
74 CFS_MODULE_PARM(peer_credits_hiw, "i", int, 0444,
75                 "when eagerly to return credits");
76
77 static int peer_buffer_credits = 0;
78 CFS_MODULE_PARM(peer_buffer_credits, "i", int, 0444,
79                 "# per-peer router buffer credits");
80
81 static int peer_timeout = 180;
82 CFS_MODULE_PARM(peer_timeout, "i", int, 0444,
83                 "Seconds without aliveness news to declare peer dead (<=0 to disable)");
84
85 static char *ipif_name = "ib0";
86 CFS_MODULE_PARM(ipif_name, "s", charp, 0444,
87                 "IPoIB interface name");
88
89 static int retry_count = 5;
90 CFS_MODULE_PARM(retry_count, "i", int, 0644,
91                 "Retransmissions when no ACK received");
92
93 static int rnr_retry_count = 6;
94 CFS_MODULE_PARM(rnr_retry_count, "i", int, 0644,
95                 "RNR retransmissions");
96
97 static int keepalive = 100;
98 CFS_MODULE_PARM(keepalive, "i", int, 0644,
99                 "Idle time in seconds before sending a keepalive");
100
101 static int ib_mtu = 0;
102 CFS_MODULE_PARM(ib_mtu, "i", int, 0444,
103                 "IB MTU 256/512/1024/2048/4096");
104
105 static int concurrent_sends = 0;
106 CFS_MODULE_PARM(concurrent_sends, "i", int, 0444,
107                 "send work-queue sizing");
108
109 static int map_on_demand = 0;
110 CFS_MODULE_PARM(map_on_demand, "i", int, 0444,
111                 "map on demand");
112
113 /* NB: this value is shared by all CPTs, it can grow at runtime */
114 static int fmr_pool_size = 512;
115 CFS_MODULE_PARM(fmr_pool_size, "i", int, 0444,
116                 "size of fmr pool on each CPT (>= ntx / 4)");
117
118 /* NB: this value is shared by all CPTs, it can grow at runtime */
119 static int fmr_flush_trigger = 384;
120 CFS_MODULE_PARM(fmr_flush_trigger, "i", int, 0444,
121                 "# dirty FMRs that triggers pool flush");
122
123 static int fmr_cache = 1;
124 CFS_MODULE_PARM(fmr_cache, "i", int, 0444,
125                 "non-zero to enable FMR caching");
126
127 /* NB: this value is shared by all CPTs, it can grow at runtime */
128 static int pmr_pool_size = 512;
129 CFS_MODULE_PARM(pmr_pool_size, "i", int, 0444,
130                 "size of MR cache pmr pool on each CPT");
131
132 /*
133  * 0: disable failover
134  * 1: enable failover if necessary
135  * 2: force to failover (for debug)
136  */
137 static int dev_failover = 0;
138 CFS_MODULE_PARM(dev_failover, "i", int, 0444,
139                "HCA failover for bonding (0 off, 1 on, other values reserved)");
140
141
142 static int require_privileged_port = 0;
143 CFS_MODULE_PARM(require_privileged_port, "i", int, 0644,
144                 "require privileged port when accepting connection");
145
146 static int use_privileged_port = 1;
147 CFS_MODULE_PARM(use_privileged_port, "i", int, 0644,
148                 "use privileged port when initiating connection");
149
150 kib_tunables_t kiblnd_tunables = {
151         .kib_dev_failover           = &dev_failover,
152         .kib_service                = &service,
153         .kib_cksum                  = &cksum,
154         .kib_timeout                = &timeout,
155         .kib_keepalive              = &keepalive,
156         .kib_ntx                    = &ntx,
157         .kib_credits                = &credits,
158         .kib_peertxcredits          = &peer_credits,
159         .kib_peercredits_hiw        = &peer_credits_hiw,
160         .kib_peerrtrcredits         = &peer_buffer_credits,
161         .kib_peertimeout            = &peer_timeout,
162         .kib_default_ipif           = &ipif_name,
163         .kib_retry_count            = &retry_count,
164         .kib_rnr_retry_count        = &rnr_retry_count,
165         .kib_concurrent_sends       = &concurrent_sends,
166         .kib_ib_mtu                 = &ib_mtu,
167         .kib_map_on_demand          = &map_on_demand,
168         .kib_fmr_pool_size          = &fmr_pool_size,
169         .kib_fmr_flush_trigger      = &fmr_flush_trigger,
170         .kib_fmr_cache              = &fmr_cache,
171         .kib_pmr_pool_size          = &pmr_pool_size,
172         .kib_require_priv_port      = &require_privileged_port,
173         .kib_use_priv_port          = &use_privileged_port,
174         .kib_nscheds                = &nscheds
175 };
176
177 #if defined(CONFIG_SYSCTL) && !CFS_SYSFS_MODULE_PARM
178
179 static char ipif_basename_space[32];
180
181 #ifndef HAVE_SYSCTL_UNNUMBERED
182
183 enum {
184         O2IBLND_SERVICE  = 1,
185         O2IBLND_CKSUM,
186         O2IBLND_TIMEOUT,
187         O2IBLND_NTX,
188         O2IBLND_CREDITS,
189         O2IBLND_PEER_TXCREDITS,
190         O2IBLND_PEER_CREDITS_HIW,
191         O2IBLND_PEER_RTRCREDITS,
192         O2IBLND_PEER_TIMEOUT,
193         O2IBLND_IPIF_BASENAME,
194         O2IBLND_RETRY_COUNT,
195         O2IBLND_RNR_RETRY_COUNT,
196         O2IBLND_KEEPALIVE,
197         O2IBLND_CONCURRENT_SENDS,
198         O2IBLND_IB_MTU,
199         O2IBLND_MAP_ON_DEMAND,
200         O2IBLND_FMR_POOL_SIZE,
201         O2IBLND_FMR_FLUSH_TRIGGER,
202         O2IBLND_FMR_CACHE,
203         O2IBLND_PMR_POOL_SIZE,
204         O2IBLND_DEV_FAILOVER
205 };
206 #else
207
208 #define O2IBLND_SERVICE          CTL_UNNUMBERED
209 #define O2IBLND_CKSUM            CTL_UNNUMBERED
210 #define O2IBLND_TIMEOUT          CTL_UNNUMBERED
211 #define O2IBLND_NTX              CTL_UNNUMBERED
212 #define O2IBLND_CREDITS          CTL_UNNUMBERED
213 #define O2IBLND_PEER_TXCREDITS   CTL_UNNUMBERED
214 #define O2IBLND_PEER_CREDITS_HIW CTL_UNNUMBERED
215 #define O2IBLND_PEER_RTRCREDITS  CTL_UNNUMBERED
216 #define O2IBLND_PEER_TIMEOUT     CTL_UNNUMBERED
217 #define O2IBLND_IPIF_BASENAME    CTL_UNNUMBERED
218 #define O2IBLND_RETRY_COUNT      CTL_UNNUMBERED
219 #define O2IBLND_RNR_RETRY_COUNT  CTL_UNNUMBERED
220 #define O2IBLND_KEEPALIVE        CTL_UNNUMBERED
221 #define O2IBLND_CONCURRENT_SENDS CTL_UNNUMBERED
222 #define O2IBLND_IB_MTU           CTL_UNNUMBERED
223 #define O2IBLND_MAP_ON_DEMAND    CTL_UNNUMBERED
224 #define O2IBLND_FMR_POOL_SIZE    CTL_UNNUMBERED
225 #define O2IBLND_FMR_FLUSH_TRIGGER CTL_UNNUMBERED
226 #define O2IBLND_FMR_CACHE        CTL_UNNUMBERED
227 #define O2IBLND_PMR_POOL_SIZE    CTL_UNNUMBERED
228 #define O2IBLND_DEV_FAILOVER     CTL_UNNUMBERED
229
230 #endif
231
232 static cfs_sysctl_table_t kiblnd_ctl_table[] = {
233         {
234                 .ctl_name = O2IBLND_SERVICE,
235                 .procname = "service",
236                 .data     = &service,
237                 .maxlen   = sizeof(int),
238                 .mode     = 0444,
239                 .proc_handler = &proc_dointvec
240         },
241         {
242                 .ctl_name = O2IBLND_CKSUM,
243                 .procname = "cksum",
244                 .data     = &cksum,
245                 .maxlen   = sizeof(int),
246                 .mode     = 0644,
247                 .proc_handler = &proc_dointvec
248         },
249         {
250                 .ctl_name = O2IBLND_TIMEOUT,
251                 .procname = "timeout",
252                 .data     = &timeout,
253                 .maxlen   = sizeof(int),
254                 .mode     = 0644,
255                 .proc_handler = &proc_dointvec
256         },
257         {
258                 .ctl_name = O2IBLND_NTX,
259                 .procname = "ntx",
260                 .data     = &ntx,
261                 .maxlen   = sizeof(int),
262                 .mode     = 0444,
263                 .proc_handler = &proc_dointvec
264         },
265         {
266                 .ctl_name = O2IBLND_CREDITS,
267                 .procname = "credits",
268                 .data     = &credits,
269                 .maxlen   = sizeof(int),
270                 .mode     = 0444,
271                 .proc_handler = &proc_dointvec
272         },
273         {
274                 .ctl_name = O2IBLND_PEER_TXCREDITS,
275                 .procname = "peer_credits",
276                 .data     = &peer_credits,
277                 .maxlen   = sizeof(int),
278                 .mode     = 0444,
279                 .proc_handler = &proc_dointvec
280         },
281         {
282                 .ctl_name = O2IBLND_PEER_CREDITS_HIW,
283                 .procname = "peer_credits_hiw",
284                 .data     = &peer_credits_hiw,
285                 .maxlen   = sizeof(int),
286                 .mode     = 0444,
287                 .proc_handler = &proc_dointvec
288         },
289         {
290                 .ctl_name = O2IBLND_PEER_RTRCREDITS,
291                 .procname = "peer_buffer_credits",
292                 .data     = &peer_buffer_credits,
293                 .maxlen   = sizeof(int),
294                 .mode     = 0444,
295                 .proc_handler = &proc_dointvec
296         },
297         {
298                 .ctl_name = O2IBLND_PEER_TIMEOUT,
299                 .procname = "peer_timeout",
300                 .data     = &peer_timeout,
301                 .maxlen   = sizeof(int),
302                 .mode     = 0444,
303                 .proc_handler = &proc_dointvec
304         },
305         {
306                 .ctl_name = O2IBLND_IPIF_BASENAME,
307                 .procname = "ipif_name",
308                 .data     = ipif_basename_space,
309                 .maxlen   = sizeof(ipif_basename_space),
310                 .mode     = 0444,
311                 .proc_handler = &proc_dostring
312         },
313         {
314                 .ctl_name = O2IBLND_RETRY_COUNT,
315                 .procname = "retry_count",
316                 .data     = &retry_count,
317                 .maxlen   = sizeof(int),
318                 .mode     = 0644,
319                 .proc_handler = &proc_dointvec
320         },
321         {
322                 .ctl_name = O2IBLND_RNR_RETRY_COUNT,
323                 .procname = "rnr_retry_count",
324                 .data     = &rnr_retry_count,
325                 .maxlen   = sizeof(int),
326                 .mode     = 0644,
327                 .proc_handler = &proc_dointvec
328         },
329         {
330                 .ctl_name = O2IBLND_KEEPALIVE,
331                 .procname = "keepalive",
332                 .data     = &keepalive,
333                 .maxlen   = sizeof(int),
334                 .mode     = 0644,
335                 .proc_handler = &proc_dointvec
336         },
337         {
338                 .ctl_name = O2IBLND_CONCURRENT_SENDS,
339                 .procname = "concurrent_sends",
340                 .data     = &concurrent_sends,
341                 .maxlen   = sizeof(int),
342                 .mode     = 0444,
343                 .proc_handler = &proc_dointvec
344         },
345         {
346                 .ctl_name = O2IBLND_IB_MTU,
347                 .procname = "ib_mtu",
348                 .data     = &ib_mtu,
349                 .maxlen   = sizeof(int),
350                 .mode     = 0444,
351                 .proc_handler = &proc_dointvec
352         },
353         {
354                 .ctl_name = O2IBLND_MAP_ON_DEMAND,
355                 .procname = "map_on_demand",
356                 .data     = &map_on_demand,
357                 .maxlen   = sizeof(int),
358                 .mode     = 0444,
359                 .proc_handler = &proc_dointvec
360         },
361
362         {
363                 .ctl_name = O2IBLND_FMR_POOL_SIZE,
364                 .procname = "fmr_pool_size",
365                 .data     = &fmr_pool_size,
366                 .maxlen   = sizeof(int),
367                 .mode     = 0444,
368                 .proc_handler = &proc_dointvec
369         },
370         {
371                 .ctl_name = O2IBLND_FMR_FLUSH_TRIGGER,
372                 .procname = "fmr_flush_trigger",
373                 .data     = &fmr_flush_trigger,
374                 .maxlen   = sizeof(int),
375                 .mode     = 0444,
376                 .proc_handler = &proc_dointvec
377         },
378         {
379                 .ctl_name = O2IBLND_FMR_CACHE,
380                 .procname = "fmr_cache",
381                 .data     = &fmr_cache,
382                 .maxlen   = sizeof(int),
383                 .mode     = 0444,
384                 .proc_handler = &proc_dointvec
385         },
386         {
387                 .ctl_name = O2IBLND_PMR_POOL_SIZE,
388                 .procname = "pmr_pool_size",
389                 .data     = &pmr_pool_size,
390                 .maxlen   = sizeof(int),
391                 .mode     = 0444,
392                 .proc_handler = &proc_dointvec
393         },
394         {
395                 .ctl_name = O2IBLND_DEV_FAILOVER,
396                 .procname = "dev_failover",
397                 .data     = &dev_failover,
398                 .maxlen   = sizeof(int),
399                 .mode     = 0444,
400                 .proc_handler = &proc_dointvec
401         },
402         {0}
403 };
404
405 static cfs_sysctl_table_t kiblnd_top_ctl_table[] = {
406         {
407                 .ctl_name = CTL_O2IBLND,
408                 .procname = "o2iblnd",
409                 .data     = NULL,
410                 .maxlen   = 0,
411                 .mode     = 0555,
412                 .child    = kiblnd_ctl_table
413         },
414         {0}
415 };
416
417 void
418 kiblnd_initstrtunable(char *space, char *str, int size)
419 {
420         strncpy(space, str, size);
421         space[size-1] = 0;
422 }
423
424 void
425 kiblnd_sysctl_init (void)
426 {
427         kiblnd_initstrtunable(ipif_basename_space, ipif_name,
428                               sizeof(ipif_basename_space));
429
430         kiblnd_tunables.kib_sysctl =
431                 cfs_register_sysctl_table(kiblnd_top_ctl_table, 0);
432
433         if (kiblnd_tunables.kib_sysctl == NULL)
434                 CWARN("Can't setup /proc tunables\n");
435 }
436
437 void
438 kiblnd_sysctl_fini (void)
439 {
440         if (kiblnd_tunables.kib_sysctl != NULL)
441                 cfs_unregister_sysctl_table(kiblnd_tunables.kib_sysctl);
442 }
443
444 #else
445
446 void
447 kiblnd_sysctl_init (void)
448 {
449 }
450
451 void
452 kiblnd_sysctl_fini (void)
453 {
454 }
455
456 #endif
457
458 int
459 kiblnd_tunables_init (void)
460 {
461         if (kiblnd_translate_mtu(*kiblnd_tunables.kib_ib_mtu) < 0) {
462                 CERROR("Invalid ib_mtu %d, expected 256/512/1024/2048/4096\n",
463                        *kiblnd_tunables.kib_ib_mtu);
464                 return -EINVAL;
465         }
466
467         if (*kiblnd_tunables.kib_peertxcredits < IBLND_CREDITS_DEFAULT)
468                 *kiblnd_tunables.kib_peertxcredits = IBLND_CREDITS_DEFAULT;
469
470         if (*kiblnd_tunables.kib_peertxcredits > IBLND_CREDITS_MAX)
471                 *kiblnd_tunables.kib_peertxcredits = IBLND_CREDITS_MAX;
472
473         if (*kiblnd_tunables.kib_peertxcredits > *kiblnd_tunables.kib_credits)
474                 *kiblnd_tunables.kib_peertxcredits = *kiblnd_tunables.kib_credits;
475
476         if (*kiblnd_tunables.kib_peercredits_hiw < *kiblnd_tunables.kib_peertxcredits / 2)
477                 *kiblnd_tunables.kib_peercredits_hiw = *kiblnd_tunables.kib_peertxcredits / 2;
478
479         if (*kiblnd_tunables.kib_peercredits_hiw >= *kiblnd_tunables.kib_peertxcredits)
480                 *kiblnd_tunables.kib_peercredits_hiw = *kiblnd_tunables.kib_peertxcredits - 1;
481
482         if (*kiblnd_tunables.kib_map_on_demand < 0 ||
483             *kiblnd_tunables.kib_map_on_demand > IBLND_MAX_RDMA_FRAGS)
484                 *kiblnd_tunables.kib_map_on_demand = 0; /* disable map-on-demand */
485
486         if (*kiblnd_tunables.kib_map_on_demand == 1)
487                 *kiblnd_tunables.kib_map_on_demand = 2; /* don't make sense to create map if only one fragment */
488
489         if (*kiblnd_tunables.kib_concurrent_sends == 0) {
490                 if (*kiblnd_tunables.kib_map_on_demand > 0 &&
491                     *kiblnd_tunables.kib_map_on_demand <= IBLND_MAX_RDMA_FRAGS / 8)
492                         *kiblnd_tunables.kib_concurrent_sends = (*kiblnd_tunables.kib_peertxcredits) * 2;
493                 else
494                         *kiblnd_tunables.kib_concurrent_sends = (*kiblnd_tunables.kib_peertxcredits);
495         }
496
497         if (*kiblnd_tunables.kib_concurrent_sends > *kiblnd_tunables.kib_peertxcredits * 2)
498                 *kiblnd_tunables.kib_concurrent_sends = *kiblnd_tunables.kib_peertxcredits * 2;
499
500         if (*kiblnd_tunables.kib_concurrent_sends < *kiblnd_tunables.kib_peertxcredits / 2)
501                 *kiblnd_tunables.kib_concurrent_sends = *kiblnd_tunables.kib_peertxcredits / 2;
502
503         if (*kiblnd_tunables.kib_concurrent_sends < *kiblnd_tunables.kib_peertxcredits) {
504                 CWARN("Concurrent sends %d is lower than message queue size: %d, "
505                       "performance may drop slightly.\n",
506                       *kiblnd_tunables.kib_concurrent_sends, *kiblnd_tunables.kib_peertxcredits);
507         }
508
509         kiblnd_sysctl_init();
510         return 0;
511 }
512
513 void
514 kiblnd_tunables_fini (void)
515 {
516         kiblnd_sysctl_fini();
517 }