Motr  M0
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 <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26 
27 #include "motr/init.h"
28 #include "lib/assert.h"
29 #include "lib/errno.h"
30 #include "lib/getopts.h"
31 #include "lib/memory.h"
32 #include "lib/thread.h"
33 #include "net/net.h"
34 #include "net/lnet/lnet.h"
35 #include "net/lnet/st/ping.h"
36 
37 static struct nlx_ping_ctx sctx = {
38  .pc_tm = {
40  }
41 };
42 
43 static int quiet_printf(const char *fmt, ...)
44 {
45  return 0;
46 }
47 
48 static struct nlx_ping_ops verbose_ops = {
49  .pf = printf,
51 };
52 
53 static struct nlx_ping_ops quiet_ops = {
54  .pf = quiet_printf,
56 };
57 
58 int main(int argc, char *argv[])
59 {
60  int rc;
61  bool client_only = false;
62  bool server_only = false;
63  bool quiet = false;
64  int verbose = 0;
65  bool async_events = false;
66  int loops = PING_DEF_LOOPS;
68  int nr_bufs = PING_DEF_BUFS;
69  unsigned nr_recv_bufs = 0;
70  uint64_t bulk_size = 0;
73  int active_bulk_delay = 0;
74  const char *client_network = NULL;
75  int32_t client_portal = -1;
77  const char *server_network = NULL;
78  int32_t server_portal = -1;
79  int32_t server_tmid = -1;
80  int client_debug = 0;
81  int server_debug = 0;
82  int server_min_recv_size = -1;
83  int server_max_recv_msgs = -1;
84  int send_msg_size = -1;
85  struct m0_thread server_thread;
86 
87  rc = m0_init(NULL);
88  M0_ASSERT(rc == 0);
89 
90  rc = M0_GETOPTS("m0lnetping", argc, argv,
91  M0_FLAGARG('s', "run server only", &server_only),
92  M0_FLAGARG('c', "run client only", &client_only),
93  M0_FORMATARG('b', "number of buffers", "%i", &nr_bufs),
94  M0_FORMATARG('B', "number of receive buffers "
95  "(server only)",
96  "%u", &nr_recv_bufs),
97  M0_FORMATARG('l', "loops to run", "%i", &loops),
98  M0_STRINGARG('d', "bulk data size",
99  LAMBDA(void, (const char *str) {
100  bulk_size =
102  })),
103  M0_FORMATARG('n', "number of client threads", "%i",
104  &nr_clients),
105  M0_FORMATARG('D', "server active bulk delay",
106  "%i", &active_bulk_delay),
107  M0_STRINGARG('i', "client network interface (ip@intf)",
108  LAMBDA(void, (const char *str) {
109  client_network = str; })),
110  M0_FORMATARG('p', "client portal (optional)",
111  "%i", &client_portal),
112  M0_FORMATARG('t', "client base TMID (optional)",
113  "%i", &client_tmid),
114  M0_STRINGARG('I', "server network interface (ip@intf)",
115  LAMBDA(void, (const char *str) {
116  server_network = str; })),
117  M0_FORMATARG('P', "server portal (optional)",
118  "%i", &server_portal),
119  M0_FORMATARG('T', "server TMID (optional)",
120  "%i", &server_tmid),
121  M0_FORMATARG('o', "message timeout in seconds",
122  "%i", &msg_timeout),
123  M0_FORMATARG('O', "bulk timeout in seconds",
124  "%i", &bulk_timeout),
125  M0_FORMATARG('x', "client debug",
126  "%i", &client_debug),
127  M0_FORMATARG('X', "server debug",
128  "%i", &server_debug),
129  M0_FLAGARG('A', "async event processing (old style)",
130  &async_events),
131  M0_FORMATARG('R', "receive message max size "
132  "(server only)",
133  "%i", &server_min_recv_size),
134  M0_FORMATARG('M', "max receive messages in a single "
135  "buffer (server only)",
136  "%i", &server_max_recv_msgs),
137  M0_FORMATARG('m', "message size (client only)",
138  "%i", &send_msg_size),
139  M0_FORMATARG('v', "verbosity level",
140  "%i", &verbose),
141  M0_FLAGARG('q', "quiet", &quiet));
142  if (rc != 0)
143  return rc;
144 
146  fprintf(stderr, "Max of %d client threads supported\n",
148  return 1;
149  }
150  if (nr_bufs < PING_MIN_BUFS) {
151  fprintf(stderr, "Minimum of %d buffers required\n",
152  PING_MIN_BUFS);
153  return 1;
154  }
156  fprintf(stderr, "Max supported bulk data size: %d\n",
158  return 1;
159  }
160  if (client_only && server_only)
161  client_only = server_only = false;
162  if (!server_only && client_only && server_network == NULL) {
163  fprintf(stderr, "Server LNet interface address missing ("
164  "e.g. 10.1.2.3@tcp0, 1.2.3.4@o2ib1)\n");
165  return 1;
166  }
167  if (server_portal < 0)
169  if (client_portal < 0)
171  if (server_tmid < 0)
173  if (client_tmid < 0)
175  if (verbose < 0)
176  verbose = 0;
177 
178  nlx_ping_init();
179 
180  if (!client_only) {
181  /* start server in background thread */
184  if (!quiet)
186  else
187  sctx.pc_ops = &quiet_ops;
189  sctx.pc_nr_recv_bufs = nr_recv_bufs;
190  sctx.pc_bulk_size = bulk_size;
191  sctx.pc_bulk_timeout = bulk_timeout;
192  sctx.pc_msg_timeout = msg_timeout;
194  sctx.pc_network = server_network;
195  sctx.pc_pid = M0_NET_LNET_PID;
196  sctx.pc_portal = server_portal;
197  sctx.pc_tmid = server_tmid;
198  sctx.pc_dom_debug = server_debug;
199  sctx.pc_tm_debug = server_debug;
200  sctx.pc_sync_events = !async_events;
201  sctx.pc_min_recv_size = server_min_recv_size;
202  sctx.pc_max_recv_msgs = server_max_recv_msgs;
203  sctx.pc_verbose = verbose;
205 
206  if (!quiet)
207  printf("Motr LNet System Test Server Initialized\n");
208  }
209 
210  if (server_only) {
211  char readbuf[BUFSIZ];
212 
213  printf("Type \"quit\" or ^D to cause server to terminate\n");
214  while (fgets(readbuf, BUFSIZ, stdin)) {
215  if (strcmp(readbuf, "quit\n") == 0)
216  break;
217  if (strcmp(readbuf, "\n") == 0)
219  if (strcmp(readbuf, "reset_stats\n") == 0)
221  }
222  } else {
223  int i;
224  struct m0_thread *client_thread;
226  int32_t client_base_tmid = client_tmid;
229 
230  /* start all the client threads */
231  for (i = 0; i < nr_clients; ++i) {
232  if (client_base_tmid != PING_CLIENT_DYNAMIC_TMID)
233  client_tmid = client_base_tmid + i;
234 #define CPARAM_SET(f) params[i].f = f
235  CPARAM_SET(loops);
248 #undef CPARAM_SET
249  params[i].client_id = i + 1;
250  params[i].client_pid = M0_NET_LNET_PID;
251  params[i].server_pid = M0_NET_LNET_PID;
252  params[i].debug = client_debug;
253  if (!quiet)
254  params[i].ops = &verbose_ops;
255  else
256  params[i].ops = &quiet_ops;
257 
259  struct nlx_ping_client_params *,
261  "client_%d", params[i].client_id);
262  M0_ASSERT(rc == 0);
263  }
264  if (!quiet)
265  printf("Motr LNet System Test %d Client(s)"
266  " Initialized\n", nr_clients);
267 
268  /* ...and wait for them */
269  for (i = 0; i < nr_clients; ++i) {
271  if (!quiet && verbose > 0) {
272  printf("Client %d: joined\n",
273  params[i].client_id);
274  }
275  }
276  if (!quiet)
277  nlx_ping_print_qstats_total("Client total",
278  &verbose_ops);
280  m0_free(params);
281  }
282 
283  if (!client_only) {
284  if (!quiet)
290  }
291 
292  nlx_ping_fini();
293  m0_fini();
294  return 0;
295 }
296 
297 /*
298  * Local variables:
299  * c-indentation-style: "K&R"
300  * c-basic-offset: 8
301  * tab-width: 8
302  * fill-column: 80
303  * scroll-step: 1
304  * End:
305  */
#define M0_GETOPTS(progname, argc, argv,...)
Definition: getopts.h:169
int(* pf)(const char *format,...) __attribute__((format(printf
Definition: ping.h:33
#define M0_ALLOC_ARR(arr, nr)
Definition: memory.h:84
static int server_portal
static struct m0_thread server_thread
static int server_max_recv_msgs
#define M0_FLAGARG(ch, desc, ptr)
Definition: getopts.h:232
struct ping_ops quiet_ops
Definition: main.c:215
#define NULL
Definition: misc.h:38
static int server_min_recv_size
const struct ping_ops * pc_ops
Definition: ping.h:42
void m0_fini(void)
Definition: init.c:318
int m0_thread_join(struct m0_thread *q)
Definition: kthread.c:169
static int server_debug
static char * client_network
uint32_t pc_nr_bufs
Definition: ping.h:52
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
static int send_msg_size
struct ping_ctx sctx
Definition: main.c:80
static bool verbose
Definition: fdmi_echo.c:80
static int server_tmid
Definition: fdmi_echo.c:84
#define M0_THREAD_INIT(thread, TYPE, init, func, arg, namefmt,...)
Definition: thread.h:139
int m0_init(struct m0 *instance)
Definition: init.c:310
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 int active_bulk_delay
#define M0_STRINGARG(ch, desc, func)
Definition: getopts.h:207
int i
Definition: dir.c:1033
static struct nlx_ping_client_params * params
static int bulk_timeout
#define LAMBDA(T,...)
Definition: thread.h:153
int quiet_printf(const char *fmt,...)
Definition: main.c:205
#define M0_FORMATARG(ch, desc, fmt, ptr)
Definition: getopts.h:218
#define M0_ASSERT(cond)
M0_INTERNAL void m0_cond_fini(struct m0_cond *cond)
Definition: cond.c:46
struct m0_net_transfer_mc pc_tm
Definition: ping.h:59
static char * server_network
char * fmt(const char *format,...) __attribute__((format(printf
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_server_bulk_delay
Definition: ping.h:66
void nlx_ping_server_should_stop(struct nlx_ping_ctx *ctx)
Definition: ping.c:1485
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
struct m0_cond pc_cond
Definition: ping.h:61
struct m0_mutex pc_mutex
Definition: ping.h:60
int main(int argc, char *argv[])
Definition: main.c:245
static bool server_only
void m0_free(void *data)
Definition: memory.c:146
#define CPARAM_SET(f)
struct ping_ops verbose_ops
Definition: main.c:210
static int client_portal
int32_t rc
Definition: trigger_fop.h:47
static int loops
static int client_tmid
static int msg_timeout
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