Whamcloud - gitweb
LU-8943 lnd: Enable Multiple OPA Endpoints between Nodes
[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.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, 2016, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  *
32  * lnet/klnds/o2iblnd/o2iblnd_modparams.c
33  *
34  * Author: Eric Barton <eric@bartonsoftware.com>
35  */
36
37 #include "o2iblnd.h"
38
39 #define CURRENT_LND_VERSION 1
40
41 static int service = 987;
42 module_param(service, int, 0444);
43 MODULE_PARM_DESC(service, "service number (within RDMA_PS_TCP)");
44
45 static int cksum = 0;
46 module_param(cksum, int, 0644);
47 MODULE_PARM_DESC(cksum, "set non-zero to enable message (not RDMA) checksums");
48
49 static int timeout = 50;
50 module_param(timeout, int, 0644);
51 MODULE_PARM_DESC(timeout, "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 module_param(nscheds, int, 0444);
57 MODULE_PARM_DESC(nscheds, "number of threads in each scheduler pool");
58
59 static unsigned int conns_per_peer = 1;
60 module_param(conns_per_peer, uint, 0444);
61 MODULE_PARM_DESC(conns_per_peer, "number of connections per peer");
62
63 /* NB: this value is shared by all CPTs, it can grow at runtime */
64 static int ntx = 512;
65 module_param(ntx, int, 0444);
66 MODULE_PARM_DESC(ntx, "# of message descriptors allocated for each pool");
67
68 /* NB: this value is shared by all CPTs */
69 static int credits = 256;
70 module_param(credits, int, 0444);
71 MODULE_PARM_DESC(credits, "# concurrent sends");
72
73 static int peer_credits = 8;
74 module_param(peer_credits, int, 0444);
75 MODULE_PARM_DESC(peer_credits, "# concurrent sends to 1 peer");
76
77 static int peer_credits_hiw = 0;
78 module_param(peer_credits_hiw, int, 0444);
79 MODULE_PARM_DESC(peer_credits_hiw, "when eagerly to return credits");
80
81 static int peer_buffer_credits = 0;
82 module_param(peer_buffer_credits, int, 0444);
83 MODULE_PARM_DESC(peer_buffer_credits, "# per-peer router buffer credits");
84
85 static int peer_timeout = 180;
86 module_param(peer_timeout, int, 0444);
87 MODULE_PARM_DESC(peer_timeout, "Seconds without aliveness news to declare peer dead (<=0 to disable)");
88
89 static char *ipif_name = "ib0";
90 module_param(ipif_name, charp, 0444);
91 MODULE_PARM_DESC(ipif_name, "IPoIB interface name");
92
93 static int retry_count = 5;
94 module_param(retry_count, int, 0644);
95 MODULE_PARM_DESC(retry_count, "Retransmissions when no ACK received");
96
97 static int rnr_retry_count = 6;
98 module_param(rnr_retry_count, int, 0644);
99 MODULE_PARM_DESC(rnr_retry_count, "RNR retransmissions");
100
101 static int keepalive = 100;
102 module_param(keepalive, int, 0644);
103 MODULE_PARM_DESC(keepalive, "Idle time in seconds before sending a keepalive");
104
105 static int ib_mtu;
106 module_param(ib_mtu, int, 0444);
107 MODULE_PARM_DESC(ib_mtu, "IB MTU 256/512/1024/2048/4096");
108
109 static int concurrent_sends;
110 module_param(concurrent_sends, int, 0444);
111 MODULE_PARM_DESC(concurrent_sends, "send work-queue sizing");
112
113 #ifdef HAVE_IB_GET_DMA_MR
114 #define IBLND_DEFAULT_MAP_ON_DEMAND 0
115 #define IBLND_MIN_MAP_ON_DEMAND 0
116 #else
117 #define IBLND_DEFAULT_MAP_ON_DEMAND IBLND_MAX_RDMA_FRAGS
118 #define IBLND_MIN_MAP_ON_DEMAND 1
119 #endif
120 static int map_on_demand = IBLND_DEFAULT_MAP_ON_DEMAND;
121 module_param(map_on_demand, int, 0444);
122 MODULE_PARM_DESC(map_on_demand, "map on demand");
123
124 /* NB: this value is shared by all CPTs, it can grow at runtime */
125 static int fmr_pool_size = 512;
126 module_param(fmr_pool_size, int, 0444);
127 MODULE_PARM_DESC(fmr_pool_size, "size of fmr pool on each CPT (>= ntx / 4)");
128
129 /* NB: this value is shared by all CPTs, it can grow at runtime */
130 static int fmr_flush_trigger = 384;
131 module_param(fmr_flush_trigger, int, 0444);
132 MODULE_PARM_DESC(fmr_flush_trigger, "# dirty FMRs that triggers pool flush");
133
134 static int fmr_cache = 1;
135 module_param(fmr_cache, int, 0444);
136 MODULE_PARM_DESC(fmr_cache, "non-zero to enable FMR caching");
137
138 /*
139  * 0: disable failover
140  * 1: enable failover if necessary
141  * 2: force to failover (for debug)
142  */
143 static int dev_failover = 0;
144 module_param(dev_failover, int, 0444);
145 MODULE_PARM_DESC(dev_failover, "HCA failover for bonding (0 off, 1 on, other values reserved)");
146
147 static int require_privileged_port;
148 module_param(require_privileged_port, int, 0644);
149 MODULE_PARM_DESC(require_privileged_port, "require privileged port when accepting connection");
150
151 static int use_privileged_port = 1;
152 module_param(use_privileged_port, int, 0644);
153 MODULE_PARM_DESC(use_privileged_port, "use privileged port when initiating connection");
154
155 static unsigned int wrq_sge = 1;
156 module_param(wrq_sge, uint, 0444);
157 MODULE_PARM_DESC(wrq_sge, "# scatter/gather element per work request");
158
159 kib_tunables_t kiblnd_tunables = {
160         .kib_dev_failover           = &dev_failover,
161         .kib_service                = &service,
162         .kib_cksum                  = &cksum,
163         .kib_timeout                = &timeout,
164         .kib_keepalive              = &keepalive,
165         .kib_ntx                    = &ntx,
166         .kib_default_ipif           = &ipif_name,
167         .kib_retry_count            = &retry_count,
168         .kib_rnr_retry_count        = &rnr_retry_count,
169         .kib_ib_mtu                 = &ib_mtu,
170         .kib_require_priv_port      = &require_privileged_port,
171         .kib_use_priv_port          = &use_privileged_port,
172         .kib_nscheds                = &nscheds,
173         .kib_wrq_sge                = &wrq_sge,
174 };
175
176 static struct lnet_ioctl_config_o2iblnd_tunables default_tunables;
177
178 /* # messages/RDMAs in-flight */
179 int
180 kiblnd_msg_queue_size(int version, struct lnet_ni *ni)
181 {
182         if (version == IBLND_MSG_VERSION_1)
183                 return IBLND_MSG_QUEUE_SIZE_V1;
184         else if (ni)
185                 return ni->ni_net->net_tunables.lct_peer_tx_credits;
186         else
187                 return peer_credits;
188 }
189
190 int
191 kiblnd_tunables_setup(struct lnet_ni *ni)
192 {
193         struct lnet_ioctl_config_o2iblnd_tunables *tunables;
194         struct lnet_ioctl_config_lnd_cmn_tunables *net_tunables;
195
196         /*
197          * if there was no tunables specified, setup the tunables to be
198          * defaulted
199          */
200         if (!ni->ni_lnd_tunables_set)
201                 memcpy(&ni->ni_lnd_tunables.lnd_tun_u.lnd_o2ib,
202                        &default_tunables, sizeof(*tunables));
203
204         tunables = &ni->ni_lnd_tunables.lnd_tun_u.lnd_o2ib;
205
206         /* Current API version */
207         tunables->lnd_version = CURRENT_LND_VERSION;
208
209         if (kiblnd_translate_mtu(*kiblnd_tunables.kib_ib_mtu) < 0) {
210                 CERROR("Invalid ib_mtu %d, expected 256/512/1024/2048/4096\n",
211                        *kiblnd_tunables.kib_ib_mtu);
212                 return -EINVAL;
213         }
214
215         net_tunables = &ni->ni_net->net_tunables;
216
217         if (net_tunables->lct_peer_timeout == -1)
218                 net_tunables->lct_peer_timeout = peer_timeout;
219
220         if (net_tunables->lct_max_tx_credits == -1)
221                 net_tunables->lct_max_tx_credits = credits;
222
223         if (net_tunables->lct_peer_tx_credits == -1)
224                 net_tunables->lct_peer_tx_credits = peer_credits;
225
226         if (net_tunables->lct_peer_rtr_credits == -1)
227                 net_tunables->lct_peer_rtr_credits = peer_buffer_credits;
228
229         if (net_tunables->lct_peer_tx_credits < IBLND_CREDITS_DEFAULT)
230                 net_tunables->lct_peer_tx_credits = IBLND_CREDITS_DEFAULT;
231
232         if (net_tunables->lct_peer_tx_credits > IBLND_CREDITS_MAX)
233                 net_tunables->lct_peer_tx_credits = IBLND_CREDITS_MAX;
234
235         if (net_tunables->lct_peer_tx_credits >
236             net_tunables->lct_max_tx_credits)
237                 net_tunables->lct_peer_tx_credits =
238                         net_tunables->lct_max_tx_credits;
239
240         if (!tunables->lnd_peercredits_hiw)
241                 tunables->lnd_peercredits_hiw = peer_credits_hiw;
242
243         if (tunables->lnd_peercredits_hiw < net_tunables->lct_peer_tx_credits / 2)
244                 tunables->lnd_peercredits_hiw = net_tunables->lct_peer_tx_credits / 2;
245
246         if (tunables->lnd_peercredits_hiw >= net_tunables->lct_peer_tx_credits)
247                 tunables->lnd_peercredits_hiw = net_tunables->lct_peer_tx_credits - 1;
248
249         if (tunables->lnd_map_on_demand < IBLND_MIN_MAP_ON_DEMAND ||
250             tunables->lnd_map_on_demand > IBLND_MAX_RDMA_FRAGS) {
251                 /* Use the default */
252                 CWARN("Invalid map_on_demand (%d), expects %d - %d. Using default of %d\n",
253                       tunables->lnd_map_on_demand, IBLND_MIN_MAP_ON_DEMAND,
254                       IBLND_MAX_RDMA_FRAGS, IBLND_DEFAULT_MAP_ON_DEMAND);
255                 tunables->lnd_map_on_demand = IBLND_DEFAULT_MAP_ON_DEMAND;
256         }
257
258         if (tunables->lnd_map_on_demand == 1) {
259                 /* don't make sense to create map if only one fragment */
260                 tunables->lnd_map_on_demand = 2;
261         }
262
263         if (tunables->lnd_concurrent_sends == 0) {
264                 if (tunables->lnd_map_on_demand > 0 &&
265                     tunables->lnd_map_on_demand <= IBLND_MAX_RDMA_FRAGS / 8) {
266                         tunables->lnd_concurrent_sends =
267                                         net_tunables->lct_peer_tx_credits * 2;
268                 } else {
269                         tunables->lnd_concurrent_sends =
270                                 net_tunables->lct_peer_tx_credits;
271                 }
272         }
273
274         if (tunables->lnd_concurrent_sends > net_tunables->lct_peer_tx_credits * 2)
275                 tunables->lnd_concurrent_sends = net_tunables->lct_peer_tx_credits * 2;
276
277         if (tunables->lnd_concurrent_sends < net_tunables->lct_peer_tx_credits / 2)
278                 tunables->lnd_concurrent_sends = net_tunables->lct_peer_tx_credits / 2;
279
280         if (tunables->lnd_concurrent_sends < net_tunables->lct_peer_tx_credits) {
281                 CWARN("Concurrent sends %d is lower than message "
282                       "queue size: %d, performance may drop slightly.\n",
283                       tunables->lnd_concurrent_sends,
284                       net_tunables->lct_peer_tx_credits);
285         }
286
287         if (!tunables->lnd_fmr_pool_size)
288                 tunables->lnd_fmr_pool_size = fmr_pool_size;
289         if (!tunables->lnd_fmr_flush_trigger)
290                 tunables->lnd_fmr_flush_trigger = fmr_flush_trigger;
291         if (!tunables->lnd_fmr_cache)
292                 tunables->lnd_fmr_cache = fmr_cache;
293         if (!tunables->lnd_conns_per_peer) {
294                 tunables->lnd_conns_per_peer = (conns_per_peer) ?
295                         conns_per_peer : 1;
296         }
297
298         return 0;
299 }
300
301 int
302 kiblnd_tunables_init(void)
303 {
304         default_tunables.lnd_version = CURRENT_LND_VERSION;
305         default_tunables.lnd_peercredits_hiw = peer_credits_hiw,
306         default_tunables.lnd_map_on_demand = map_on_demand;
307         default_tunables.lnd_concurrent_sends = concurrent_sends;
308         default_tunables.lnd_fmr_pool_size = fmr_pool_size;
309         default_tunables.lnd_fmr_flush_trigger = fmr_flush_trigger;
310         default_tunables.lnd_fmr_cache = fmr_cache;
311         default_tunables.lnd_conns_per_peer = conns_per_peer;
312         return 0;
313 }