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