Whamcloud - gitweb
6af4e85c51be884f8c8273301e02431893e1c45d
[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  2008 Sun Microsystems, Inc. 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 char *ipif_name = "ib0";
68 CFS_MODULE_PARM(ipif_name, "s", charp, 0444,
69                 "IPoIB interface name");
70
71 static int retry_count = 5;
72 CFS_MODULE_PARM(retry_count, "i", int, 0644,
73                 "Retransmissions when no ACK received");
74
75 static int rnr_retry_count = 6;
76 CFS_MODULE_PARM(rnr_retry_count, "i", int, 0644,
77                 "RNR retransmissions");
78
79 static int keepalive = 100;
80 CFS_MODULE_PARM(keepalive, "i", int, 0644,
81                 "Idle time in seconds before sending a keepalive");
82
83 static int ib_mtu = 0;
84 CFS_MODULE_PARM(ib_mtu, "i", int, 0444,
85                 "IB MTU 256/512/1024/2048/4096");
86
87 #if IBLND_MAP_ON_DEMAND
88 static int concurrent_sends = IBLND_RX_MSGS;
89 #else
90 static int concurrent_sends = IBLND_MSG_QUEUE_SIZE;
91 #endif
92 CFS_MODULE_PARM(concurrent_sends, "i", int, 0444,
93                 "send work-queue sizing");
94
95 #if IBLND_MAP_ON_DEMAND
96 static int fmr_pool_size = 512;
97 CFS_MODULE_PARM(fmr_pool_size, "i", int, 0444,
98                 "size of the fmr pool (>= ntx)");
99
100 static int fmr_flush_trigger = 384;
101 CFS_MODULE_PARM(fmr_flush_trigger, "i", int, 0444,
102                 "# dirty FMRs that triggers pool flush");
103
104 static int fmr_cache = 1;
105 CFS_MODULE_PARM(fmr_cache, "i", int, 0444,
106                 "non-zero to enable FMR caching");
107 #endif
108
109 kib_tunables_t kiblnd_tunables = {
110         .kib_service                = &service,
111         .kib_cksum                  = &cksum,
112         .kib_timeout                = &timeout,
113         .kib_keepalive              = &keepalive,
114         .kib_ntx                    = &ntx,
115         .kib_credits                = &credits,
116         .kib_peercredits            = &peer_credits,
117         .kib_default_ipif           = &ipif_name,
118         .kib_retry_count            = &retry_count,
119         .kib_rnr_retry_count        = &rnr_retry_count,
120         .kib_concurrent_sends       = &concurrent_sends,
121         .kib_ib_mtu                 = &ib_mtu,
122 #if IBLND_MAP_ON_DEMAND
123         .kib_fmr_pool_size          = &fmr_pool_size,
124         .kib_fmr_flush_trigger      = &fmr_flush_trigger,
125         .kib_fmr_cache              = &fmr_cache,
126 #endif
127 };
128
129 #if defined(CONFIG_SYSCTL) && !CFS_SYSFS_MODULE_PARM
130
131 static char ipif_basename_space[32];
132
133 #ifndef HAVE_SYSCTL_UNNUMBERED
134
135 enum {
136         O2IBLND_SERVICE  = 1,
137         O2IBLND_CKSUM,
138         O2IBLND_TIMEOUT,
139         O2IBLND_NTX,
140         O2IBLND_CREDITS,
141         O2IBLND_PEER_CREDITS,
142         O2IBLND_IPIF_BASENAME,
143         O2IBLND_RETRY_COUNT,
144         O2IBLND_RNR_RETRY_COUNT,
145         O2IBLND_KEEPALIVE,
146         O2IBLND_CONCURRENT_SENDS,
147         O2IBLND_IB_MTU,
148         O2IBLND_FMR_POOL_SIZE,
149         O2IBLND_FMR_FLUSH_TRIGGER,
150         O2IBLND_FMR_CACHE
151 };
152 #else
153
154 #define O2IBLND_SERVICE          CTL_UNNUMBERED
155 #define O2IBLND_CKSUM            CTL_UNNUMBERED
156 #define O2IBLND_TIMEOUT          CTL_UNNUMBERED
157 #define O2IBLND_NTX              CTL_UNNUMBERED
158 #define O2IBLND_CREDITS          CTL_UNNUMBERED
159 #define O2IBLND_PEER_CREDITS     CTL_UNNUMBERED
160 #define O2IBLND_IPIF_BASENAME    CTL_UNNUMBERED
161 #define O2IBLND_RETRY_COUNT      CTL_UNNUMBERED
162 #define O2IBLND_RNR_RETRY_COUNT  CTL_UNNUMBERED
163 #define O2IBLND_KEEPALIVE        CTL_UNNUMBERED
164 #define O2IBLND_CONCURRENT_SENDS CTL_UNNUMBERED
165 #define O2IBLND_IB_MTU           CTL_UNNUMBERED
166 #define O2IBLND_FMR_POOL_SIZE    CTL_UNNUMBERED
167 #define O2IBLND_FMR_FLUSH_TRIGGER CTL_UNNUMBERED
168 #define O2IBLND_FMR_CACHE        CTL_UNNUMBERED
169
170 #endif
171
172 static cfs_sysctl_table_t kiblnd_ctl_table[] = {
173         {
174                 .ctl_name = O2IBLND_SERVICE,
175                 .procname = "service",
176                 .data     = &service,
177                 .maxlen   = sizeof(int),
178                 .mode     = 0444,
179                 .proc_handler = &proc_dointvec
180         },
181         {
182                 .ctl_name = O2IBLND_CKSUM,
183                 .procname = "cksum",
184                 .data     = &cksum,
185                 .maxlen   = sizeof(int),
186                 .mode     = 0644,
187                 .proc_handler = &proc_dointvec
188         },
189         {
190                 .ctl_name = O2IBLND_TIMEOUT,
191                 .procname = "timeout",
192                 .data     = &timeout,
193                 .maxlen   = sizeof(int),
194                 .mode     = 0644,
195                 .proc_handler = &proc_dointvec
196         },
197         {
198                 .ctl_name = O2IBLND_NTX,
199                 .procname = "ntx",
200                 .data     = &ntx,
201                 .maxlen   = sizeof(int),
202                 .mode     = 0444,
203                 .proc_handler = &proc_dointvec
204         },
205         {
206                 .ctl_name = O2IBLND_CREDITS,
207                 .procname = "credits",
208                 .data     = &credits,
209                 .maxlen   = sizeof(int),
210                 .mode     = 0444,
211                 .proc_handler = &proc_dointvec
212         },
213         {
214                 .ctl_name = O2IBLND_PEER_CREDITS,
215                 .procname = "peer_credits",
216                 .data     = &peer_credits,
217                 .maxlen   = sizeof(int),
218                 .mode     = 0444,
219                 .proc_handler = &proc_dointvec
220         },
221         {
222                 .ctl_name = O2IBLND_IPIF_BASENAME,
223                 .procname = "ipif_name",
224                 .data     = ipif_basename_space,
225                 .maxlen   = sizeof(ipif_basename_space),
226                 .mode     = 0444,
227                 .proc_handler = &proc_dostring
228         },
229         {
230                 .ctl_name = O2IBLND_RETRY_COUNT,
231                 .procname = "retry_count",
232                 .data     = &retry_count,
233                 .maxlen   = sizeof(int),
234                 .mode     = 0644,
235                 .proc_handler = &proc_dointvec
236         },
237         {
238                 .ctl_name = O2IBLND_RNR_RETRY_COUNT,
239                 .procname = "rnr_retry_count",
240                 .data     = &rnr_retry_count,
241                 .maxlen   = sizeof(int),
242                 .mode     = 0644,
243                 .proc_handler = &proc_dointvec
244         },
245         {
246                 .ctl_name = O2IBLND_KEEPALIVE,
247                 .procname = "keepalive",
248                 .data     = &keepalive,
249                 .maxlen   = sizeof(int),
250                 .mode     = 0644,
251                 .proc_handler = &proc_dointvec
252         },
253         {
254                 .ctl_name = O2IBLND_CONCURRENT_SENDS,
255                 .procname = "concurrent_sends",
256                 .data     = &concurrent_sends,
257                 .maxlen   = sizeof(int),
258                 .mode     = 0444,
259                 .proc_handler = &proc_dointvec
260         },
261         {
262                 .ctl_name = O2IBLND_IB_MTU,
263                 .procname = "ib_mtu",
264                 .data     = &ib_mtu,
265                 .maxlen   = sizeof(int),
266                 .mode     = 0444,
267                 .proc_handler = &proc_dointvec
268         },
269 #if IBLND_MAP_ON_DEMAND
270         {
271                 .ctl_name = O2IBLND_FMR_POOL_SIZE,
272                 .procname = "fmr_pool_size",
273                 .data     = &fmr_pool_size,
274                 .maxlen   = sizeof(int),
275                 .mode     = 0444,
276                 .proc_handler = &proc_dointvec
277         },
278         {
279                 .ctl_name = O2IBLND_FMR_FLUSH_TRIGGER,
280                 .procname = "fmr_flush_trigger",
281                 .data     = &fmr_flush_trigger,
282                 .maxlen   = sizeof(int),
283                 .mode     = 0444,
284                 .proc_handler = &proc_dointvec
285         },
286         {
287                 .ctl_name = O2IBLND_FMR_CACHE,
288                 .procname = "fmr_cache",
289                 .data     = &fmr_cache,
290                 .maxlen   = sizeof(int),
291                 .mode     = 0444,
292                 .proc_handler = &proc_dointvec
293         },
294 #endif
295         {0}
296 };
297
298 static cfs_sysctl_table_t kiblnd_top_ctl_table[] = {
299         {
300                 .ctl_name = CTL_O2IBLND,
301                 .procname = "o2iblnd",
302                 .data     = NULL,
303                 .maxlen   = 0,
304                 .mode     = 0555,
305                 .child    = kiblnd_ctl_table
306         },
307         {0}
308 };
309
310 void
311 kiblnd_initstrtunable(char *space, char *str, int size)
312 {
313         strncpy(space, str, size);
314         space[size-1] = 0;
315 }
316
317 void
318 kiblnd_sysctl_init (void)
319 {
320         kiblnd_initstrtunable(ipif_basename_space, ipif_name,
321                               sizeof(ipif_basename_space));
322
323         kiblnd_tunables.kib_sysctl =
324                 cfs_register_sysctl_table(kiblnd_top_ctl_table, 0);
325
326         if (kiblnd_tunables.kib_sysctl == NULL)
327                 CWARN("Can't setup /proc tunables\n");
328 }
329
330 void
331 kiblnd_sysctl_fini (void)
332 {
333         if (kiblnd_tunables.kib_sysctl != NULL)
334                 cfs_unregister_sysctl_table(kiblnd_tunables.kib_sysctl);
335 }
336
337 #else
338
339 void
340 kiblnd_sysctl_init (void)
341 {
342 }
343
344 void
345 kiblnd_sysctl_fini (void)
346 {
347 }
348
349 #endif
350
351 int
352 kiblnd_tunables_init (void)
353 {
354         if (*kiblnd_tunables.kib_credits > *kiblnd_tunables.kib_ntx) {
355                 CERROR("Can't set credits(%d) > ntx(%d)\n",
356                        *kiblnd_tunables.kib_credits,
357                        *kiblnd_tunables.kib_ntx);
358                 return -EINVAL;
359         }
360
361         if (*kiblnd_tunables.kib_ib_mtu != 0 &&
362             *kiblnd_tunables.kib_ib_mtu != 256 &&
363             *kiblnd_tunables.kib_ib_mtu != 512 &&
364             *kiblnd_tunables.kib_ib_mtu != 1024 &&
365             *kiblnd_tunables.kib_ib_mtu != 2048 &&
366             *kiblnd_tunables.kib_ib_mtu != 4096) {
367                 CERROR("Invalid ib_mtu %d, expected 256/512/1024/2048/4096\n",
368                        *kiblnd_tunables.kib_ib_mtu);
369                 return -EINVAL;
370         }
371
372         if (*kiblnd_tunables.kib_concurrent_sends > IBLND_RX_MSGS)
373                 *kiblnd_tunables.kib_concurrent_sends = IBLND_RX_MSGS;
374         if (*kiblnd_tunables.kib_concurrent_sends < IBLND_MSG_QUEUE_SIZE / 2)
375                 *kiblnd_tunables.kib_concurrent_sends = IBLND_MSG_QUEUE_SIZE / 2;
376
377         if (*kiblnd_tunables.kib_concurrent_sends < IBLND_MSG_QUEUE_SIZE) {
378                 CWARN("Concurrent sends %d is lower than message queue size: %d, "
379                       "performance may drop slightly.\n",
380                       *kiblnd_tunables.kib_concurrent_sends, IBLND_MSG_QUEUE_SIZE);
381         }
382
383         kiblnd_sysctl_init();
384         return 0;
385 }
386
387 void
388 kiblnd_tunables_fini (void)
389 {
390         kiblnd_sysctl_fini();
391 }