Motr  M0
m0lnetping_main.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2012-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #include <linux/module.h>
24 #include <linux/kernel.h>
25 #include <linux/inet.h> /* in_aton */
26 
27 #include "lib/memory.h"
28 #include "lib/misc.h" /* M0_SET0 */
29 #include "net/net.h"
30 #include "net/lnet/lnet.h"
31 #include "net/lnet/st/ping.h"
32 
38 /* Module parameters */
39 static bool quiet = false;
40 module_param(quiet, bool, S_IRUGO);
41 MODULE_PARM_DESC(quiet, "quiet mode");
42 
43 static int verbose = 0;
44 module_param(verbose, int, S_IRUGO);
45 MODULE_PARM_DESC(verbose, "verbosity level");
46 
47 static bool client_only = false;
48 module_param(client_only, bool, S_IRUGO);
49 MODULE_PARM_DESC(verbose, "run client only");
50 
51 static bool server_only = false;
52 module_param(server_only, bool, S_IRUGO);
53 MODULE_PARM_DESC(server_only, "run server only");
54 
55 static bool async_events = false;
56 module_param(async_events, bool, S_IRUGO);
57 MODULE_PARM_DESC(async_events, "async event processing (old style)");
58 
59 static uint nr_bufs = PING_DEF_BUFS;
60 module_param(nr_bufs, uint, S_IRUGO);
61 MODULE_PARM_DESC(nr_bufs, "total number of network buffers to allocate");
62 
63 static uint nr_recv_bufs = 0;
64 module_param(nr_recv_bufs, uint, S_IRUGO);
65 MODULE_PARM_DESC(nr_recv_bufs, "number of receive buffers (server only)");
66 
67 static char *bulk_size = NULL;
68 module_param(bulk_size, charp, S_IRUGO);
69 MODULE_PARM_DESC(bulk_size, "bulk data size");
70 
71 static int active_bulk_delay = 0;
72 module_param(active_bulk_delay, int, S_IRUGO);
73 MODULE_PARM_DESC(active_bulk_delay, "Delay before sending active receive");
74 
76 module_param(nr_clients, int, S_IRUGO);
77 MODULE_PARM_DESC(nr_clients, "number of client threads");
78 
79 static int loops = PING_DEF_LOOPS;
80 module_param(loops, int, S_IRUGO);
81 MODULE_PARM_DESC(loops, "loops to run");
82 
84 module_param(bulk_timeout, int, S_IRUGO);
85 MODULE_PARM_DESC(bulk_timeout, "bulk timeout");
86 
88 module_param(msg_timeout, int, S_IRUGO);
89 MODULE_PARM_DESC(msg_timeout, "message timeout");
90 
91 static char *client_network = NULL;
92 module_param(client_network, charp, S_IRUGO);
93 MODULE_PARM_DESC(client_network, "client network interface (ip@intf)");
94 
95 static int client_portal = -1;
96 module_param(client_portal, int, S_IRUGO);
97 MODULE_PARM_DESC(client_portal, "client portal (optional)");
98 
100 module_param(client_tmid, int, S_IRUGO);
101 MODULE_PARM_DESC(client_tmid, "client base TMID (optional)");
102 
103 static char *server_network = NULL;
104 module_param(server_network, charp, S_IRUGO);
105 MODULE_PARM_DESC(server_network, "server network interface (ip@intf)");
106 
107 static int server_portal = -1;
108 module_param(server_portal, int, S_IRUGO);
109 MODULE_PARM_DESC(server_portal, "server portal (optional)");
110 
111 static int server_tmid = -1;
112 module_param(server_tmid, int, S_IRUGO);
113 MODULE_PARM_DESC(server_tmid, "server TMID (optional)");
114 
115 static int server_min_recv_size = -1;
116 module_param(server_min_recv_size, int, S_IRUGO);
117 MODULE_PARM_DESC(server_min_recv_size, "server min receive size (optional)");
118 
119 static int server_max_recv_msgs = -1;
120 module_param(server_max_recv_msgs, int, S_IRUGO);
121 MODULE_PARM_DESC(server_max_recv_msgs, "server max receive msgs (optional)");
122 
123 static int send_msg_size = -1;
124 module_param(send_msg_size, int, S_IRUGO);
125 MODULE_PARM_DESC(send_msg_size, "client message size (optional)");
126 
127 static int server_debug = 0;
128 module_param(server_debug, int, S_IRUGO);
129 MODULE_PARM_DESC(server_debug, "server debug (optional)");
130 
131 static int client_debug = 0;
132 module_param(client_debug, int, S_IRUGO);
133 MODULE_PARM_DESC(client_debug, "client debug (optional)");
134 
135 static int quiet_printk(const char *fmt, ...)
136 {
137  return 0;
138 }
139 
140 static int verbose_printk(const char *fmt, ...)
141 {
142  va_list varargs;
143  char *fmtbuf;
144  int rc;
145 
146  va_start(varargs, fmt);
147  fmtbuf = m0_alloc(strlen(fmt) + sizeof KERN_INFO);
148  if (fmtbuf != NULL) {
149  sprintf(fmtbuf, "%s%s", KERN_INFO, fmt);
150  fmt = fmtbuf;
151  }
152  /* call vprintk(KERN_INFO ...) */
153  rc = vprintk(fmt, varargs);
154  va_end(varargs);
155  m0_free(fmtbuf);
156  return rc;
157 }
158 
159 static struct nlx_ping_ops verbose_ops = {
160  .pf = verbose_printk,
162 };
163 
164 static struct nlx_ping_ops quiet_ops = {
165  .pf = quiet_printk,
167 };
168 
169 static struct nlx_ping_ctx sctx = {
170  .pc_tm = {
172  }
173 };
174 
175 static struct m0_thread server_thread;
176 static struct m0_thread *client_thread;
178 
179 static int __init m0_netst_init_k(void)
180 {
181  int rc;
182  uint64_t buffer_size;
184 
185  /* parse module options */
186  if (nr_bufs < PING_MIN_BUFS) {
187  printk(KERN_WARNING "Minimum of %d buffers required\n",
188  PING_MIN_BUFS);
189  return -EINVAL;
190  }
191  buffer_size = nlx_ping_parse_uint64(bulk_size);
192  if (buffer_size > PING_MAX_BUFFER_SIZE) {
193  printk(KERN_WARNING "Max supported bulk data size: %d\n",
195  return -EINVAL;
196  }
198  printk(KERN_WARNING "Max of %d client threads supported\n",
200  return -EINVAL;
201  }
202  if (client_only && server_only)
203  client_only = server_only = false;
204  if (server_network == NULL) {
205  printk(KERN_WARNING "Server LNet interface address missing ("
206  "e.g. 10.1.2.3@tcp0, 1.2.3.4@o2ib1)\n");
207  return -EINVAL;
208  }
209  if (!server_only && client_network == NULL) {
210  printk(KERN_WARNING "Client LNet interface address missing ("
211  "e.g. 10.1.2.3@tcp0, 1.2.3.4@o2ib1)\n");
212  return -EINVAL;
213  }
214  if (server_portal < 0)
216  if (client_portal < 0)
218  if (server_tmid < 0)
220  if (client_tmid < 0)
222  if (verbose < 0)
223  verbose = 0;
224 
225  /* set up sys fs entries? */
226 
227  nlx_ping_init();
228 
229  if (!client_only) {
230  /* set up server context */
233  if (!quiet)
235  else
236  sctx.pc_ops = &quiet_ops;
237 
240  sctx.pc_bulk_size = buffer_size;
254 
255  printk(KERN_INFO "Motr LNet System Test"
256  " Server Initialized\n");
257  }
258 
259  if (!server_only) {
260  int i;
261  int32_t client_base_tmid = client_tmid;
264 
266  M0_ASSERT(params != NULL);
267 
268  /* start all the client threads */
269  for (i = 0; i < nr_clients; ++i) {
270  if (client_base_tmid != PING_CLIENT_DYNAMIC_TMID)
271  client_tmid = client_base_tmid + i;
272 #define CPARAM_SET(f) params[i].f = f
273  CPARAM_SET(loops);
285 #undef CPARAM_SET
286  params[i].bulk_size = buffer_size;
287  params[i].client_id = i + 1;
288  params[i].client_pid = M0_NET_LNET_PID;
289  params[i].server_pid = M0_NET_LNET_PID;
290  params[i].debug = client_debug;
291  if (!quiet)
292  params[i].ops = &verbose_ops;
293  else
294  params[i].ops = &quiet_ops;
295 
297  struct nlx_ping_client_params *,
299  "client_%d", params[i].client_id);
300  M0_ASSERT(rc == 0);
301  }
302  printk(KERN_INFO "Motr LNet System Test"
303  " %d Client(s) Initialized\n", nr_clients);
304  }
305 
306  return 0;
307 }
308 
309 static void __exit m0_netst_fini_k(void)
310 {
312  if (!server_only) {
313  int i;
314  for (i = 0; i < nr_clients; ++i) {
316  if (!quiet && verbose > 0) {
317  printk(KERN_INFO "Client %d: joined\n",
318  params[i].client_id);
319  }
320  }
321  if (!quiet)
322  nlx_ping_print_qstats_total("Client total",
323  &verbose_ops);
325  m0_free(params);
326  }
327 
328  if (!client_only) {
329  if (sctx.pc_ops->pqs != NULL)
330  (*sctx.pc_ops->pqs)(&sctx, false);
331 
336  }
337 
338  nlx_ping_fini();
339  printk(KERN_INFO "Motr Kernel Messaging System Test removed\n");
340 }
341 
344 
345 /*
346  * We are using Apache license for complete motr code but for MODULE_LICENSE
347  * marker there is no provision to mention Apache for this marker. But as this
348  * marker is necessary to remove the warnings, keeping this blank to make
349  * compiler happy.
350  */
352  /* LNetDFS */
354 
355 /*
356  * Local variables:
357  * c-indentation-style: "K&R"
358  * c-basic-offset: 8
359  * tab-width: 8
360  * fill-column: 80
361  * scroll-step: 1
362  * End:
363  */
#define M0_ALLOC_ARR(arr, nr)
Definition: memory.h:84
struct m0_cond pc_cond
Definition: ping.h:66
static int server_portal
int pc_server_bulk_delay
Definition: ping.h:72
static struct m0_thread server_thread
static int server_max_recv_msgs
#define NULL
Definition: misc.h:38
static int server_min_recv_size
int m0_thread_join(struct m0_thread *q)
Definition: kthread.c:169
static int server_debug
static char * client_network
int nlx_ping_print_qstats_total(const char *ident, const struct nlx_ping_ops *ops)
Definition: ping.c:151
enum m0_net_tm_state ntm_state
Definition: net.h:819
uint32_t pc_nr_bufs
Definition: ping.h:53
static int send_msg_size
int(* pf)(const char *format,...) __attribute__((format(printf
Definition: ping.h:32
const struct nlx_ping_ops * pc_ops
Definition: ping.h:41
static int quiet_printk(const char *fmt,...)
#define M0_THREAD_INIT(thread, TYPE, init, func, arg, namefmt,...)
Definition: thread.h:139
MODULE_PARM_DESC(quiet, "quiet mode")
M0_INTERNAL void m0_cond_init(struct m0_cond *cond, struct m0_mutex *mutex)
Definition: cond.c:40
void nlx_ping_server_spawn(struct m0_thread *server_thread, struct nlx_ping_ctx *sctx)
Definition: ping.c:1496
static void __exit m0_netst_fini_k(void)
uint32_t pc_portal
Definition: ping.h:46
static int active_bulk_delay
int pc_msg_timeout
Definition: ping.h:71
static int __init m0_netst_init_k(void)
int i
Definition: dir.c:1033
static struct nlx_ping_client_params * params
static int bulk_timeout
module_param(quiet, bool, S_IRUGO)
module_init(motr_init)
#define M0_ASSERT(cond)
struct m0_net_transfer_mc pc_tm
Definition: ping.h:64
M0_THREAD_ENTER
Definition: dir.c:336
M0_INTERNAL void m0_cond_fini(struct m0_cond *cond)
Definition: cond.c:46
const char * pc_network
Definition: ping.h:44
static char * server_network
char * fmt(const char *format,...) __attribute__((format(printf
void * m0_alloc(size_t size)
Definition: memory.c:126
bool pc_sync_events
Definition: ping.h:77
M0_INTERNAL void m0_mutex_init(struct m0_mutex *mutex)
Definition: mutex.c:35
void nlx_ping_init()
Definition: ping.c:1916
static bool quiet
void nlx_ping_fini()
Definition: ping.c:1921
static uint nr_recv_bufs
int pc_max_recv_msgs
Definition: ping.h:59
int32_t pc_tmid
Definition: ping.h:47
static struct nlx_ping_ops quiet_ops
module_exit(motr_exit)
int pc_bulk_timeout
Definition: ping.h:70
uint32_t pc_nr_recv_bufs
Definition: ping.h:54
void nlx_ping_server_should_stop(struct nlx_ping_ctx *ctx)
Definition: ping.c:1485
MODULE_LICENSE()
static int client_debug
static int nr_clients
static char * bulk_size
void nlx_ping_client(struct nlx_ping_client_params *params)
Definition: ping.c:1837
uint64_t nlx_ping_parse_uint64(const char *s)
Definition: ping.c:171
Definition: common.h:34
M0_INTERNAL void m0_mutex_fini(struct m0_mutex *mutex)
Definition: mutex.c:42
static struct m0_thread * client_thread
int pc_verbose
Definition: ping.h:88
static struct nlx_ping_ops verbose_ops
uint64_t pc_bulk_size
Definition: ping.h:60
int pc_tm_debug
Definition: ping.h:74
#define CPARAM_SET(f)
int(*) void(* pqs)(struct nlx_ping_ctx *ctx, bool reset)
Definition: ping.h:34
static bool server_only
static struct nlx_ping_ctx sctx
int pc_min_recv_size
Definition: ping.h:58
void m0_free(void *data)
Definition: memory.c:146
static int verbose
static int verbose_printk(const char *fmt,...)
static int client_portal
int32_t rc
Definition: trigger_fop.h:47
static int loops
static int client_tmid
static int msg_timeout
static int server_tmid
int pc_dom_debug
Definition: ping.h:73
struct m0_mutex pc_mutex
Definition: ping.h:65
void nlx_ping_print_qstats_tm(struct nlx_ping_ctx *ctx, bool reset)
Definition: ping.c:136
static bool async_events
static uint nr_bufs
static bool client_only