xref: /dpdk/app/test-eventdev/evt_options.c (revision 99f9d799ce21ab22e922ffec8aad51d56e24d04d)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Cavium, Inc
3  */
4 
5 #include <stdio.h>
6 #include <string.h>
7 #include <inttypes.h>
8 #include <getopt.h>
9 
10 #include <rte_string_fns.h>
11 #include <rte_common.h>
12 #include <rte_eventdev.h>
13 #include <rte_lcore.h>
14 
15 #include "evt_options.h"
16 #include "evt_test.h"
17 #include "parser.h"
18 
19 void
20 evt_options_default(struct evt_options *opt)
21 {
22 	memset(opt, 0, sizeof(*opt));
23 	opt->verbose_level = 1; /* Enable minimal prints */
24 	opt->dev_id = 0;
25 	strncpy(opt->test_name, "order_queue", EVT_TEST_NAME_MAX_LEN);
26 	opt->nb_flows = 1024;
27 	opt->socket_id = SOCKET_ID_ANY;
28 	opt->pool_sz = 16 * 1024;
29 	opt->wkr_deq_dep = 16;
30 	opt->nb_pkts = (1ULL << 26); /* do ~64M packets */
31 	opt->nb_timers = 1E8;
32 	opt->nb_timer_adptrs = 1;
33 	opt->timer_tick_nsec = 1E3; /* 1000ns ~ 1us */
34 	opt->max_tmo_nsec = 1E5;  /* 100000ns ~100us */
35 	opt->expiry_nsec = 1E4;   /* 10000ns ~10us */
36 	opt->prod_type = EVT_PROD_TYPE_SYNT;
37 	opt->eth_queues = 1;
38 	opt->vector_size = 64;
39 	opt->vector_tmo_nsec = 100E3;
40 }
41 
42 typedef int (*option_parser_t)(struct evt_options *opt,
43 		const char *arg);
44 
45 struct long_opt_parser {
46 	const char *lgopt_name;
47 	option_parser_t parser_fn;
48 };
49 
50 static int
51 evt_parse_nb_flows(struct evt_options *opt, const char *arg)
52 {
53 	int ret;
54 
55 	ret = parser_read_uint32(&(opt->nb_flows), arg);
56 
57 	return ret;
58 }
59 
60 static int
61 evt_parse_dev_id(struct evt_options *opt, const char *arg)
62 {
63 	int ret;
64 
65 	ret = parser_read_uint8(&(opt->dev_id), arg);
66 
67 	return ret;
68 }
69 
70 static int
71 evt_parse_verbose(struct evt_options *opt, const char *arg __rte_unused)
72 {
73 	opt->verbose_level = atoi(arg);
74 	return 0;
75 }
76 
77 static int
78 evt_parse_fwd_latency(struct evt_options *opt, const char *arg __rte_unused)
79 {
80 	opt->fwd_latency = 1;
81 	return 0;
82 }
83 
84 static int
85 evt_parse_queue_priority(struct evt_options *opt, const char *arg __rte_unused)
86 {
87 	opt->q_priority = 1;
88 	return 0;
89 }
90 
91 static int
92 evt_parse_deq_tmo_nsec(struct evt_options *opt, const char *arg)
93 {
94 	int ret;
95 
96 	ret = parser_read_uint32(&(opt->deq_tmo_nsec), arg);
97 
98 	return ret;
99 }
100 
101 static int
102 evt_parse_eth_prod_type(struct evt_options *opt, const char *arg __rte_unused)
103 {
104 	opt->prod_type = EVT_PROD_TYPE_ETH_RX_ADPTR;
105 	return 0;
106 }
107 
108 static int
109 evt_parse_timer_prod_type(struct evt_options *opt, const char *arg __rte_unused)
110 {
111 	opt->prod_type = EVT_PROD_TYPE_EVENT_TIMER_ADPTR;
112 	return 0;
113 }
114 
115 static int
116 evt_parse_timer_prod_type_burst(struct evt_options *opt,
117 		const char *arg __rte_unused)
118 {
119 	opt->prod_type = EVT_PROD_TYPE_EVENT_TIMER_ADPTR;
120 	opt->timdev_use_burst = 1;
121 	return 0;
122 }
123 
124 static int
125 evt_parse_test_name(struct evt_options *opt, const char *arg)
126 {
127 	strlcpy(opt->test_name, arg, EVT_TEST_NAME_MAX_LEN);
128 	return 0;
129 }
130 
131 static int
132 evt_parse_socket_id(struct evt_options *opt, const char *arg)
133 {
134 	opt->socket_id = atoi(arg);
135 	return 0;
136 }
137 
138 static int
139 evt_parse_wkr_deq_dep(struct evt_options *opt, const char *arg)
140 {
141 	int ret;
142 
143 	ret = parser_read_uint16(&(opt->wkr_deq_dep), arg);
144 	return ret;
145 }
146 
147 static int
148 evt_parse_nb_pkts(struct evt_options *opt, const char *arg)
149 {
150 	int ret;
151 
152 	ret = parser_read_uint64(&(opt->nb_pkts), arg);
153 
154 	return ret;
155 }
156 
157 static int
158 evt_parse_nb_timers(struct evt_options *opt, const char *arg)
159 {
160 	int ret;
161 
162 	ret = parser_read_uint64(&(opt->nb_timers), arg);
163 
164 	return ret;
165 }
166 
167 static int
168 evt_parse_timer_tick_nsec(struct evt_options *opt, const char *arg)
169 {
170 	int ret;
171 
172 	ret = parser_read_uint64(&(opt->timer_tick_nsec), arg);
173 
174 	return ret;
175 }
176 
177 static int
178 evt_parse_max_tmo_nsec(struct evt_options *opt, const char *arg)
179 {
180 	int ret;
181 
182 	ret = parser_read_uint64(&(opt->max_tmo_nsec), arg);
183 
184 	return ret;
185 }
186 
187 static int
188 evt_parse_expiry_nsec(struct evt_options *opt, const char *arg)
189 {
190 	int ret;
191 
192 	ret = parser_read_uint64(&(opt->expiry_nsec), arg);
193 
194 	return ret;
195 }
196 
197 static int
198 evt_parse_nb_timer_adptrs(struct evt_options *opt, const char *arg)
199 {
200 	int ret;
201 
202 	ret = parser_read_uint8(&(opt->nb_timer_adptrs), arg);
203 	if (opt->nb_timer_adptrs <= 0) {
204 		evt_err("Number of timer adapters cannot be <= 0");
205 		return -EINVAL;
206 	}
207 
208 	return ret;
209 }
210 
211 static int
212 evt_parse_pool_sz(struct evt_options *opt, const char *arg)
213 {
214 	opt->pool_sz = atoi(arg);
215 
216 	return 0;
217 }
218 
219 static int
220 evt_parse_plcores(struct evt_options *opt, const char *corelist)
221 {
222 	int ret;
223 
224 	ret = parse_lcores_list(opt->plcores, RTE_MAX_LCORE, corelist);
225 	if (ret == -E2BIG)
226 		evt_err("duplicate lcores in plcores");
227 
228 	return ret;
229 }
230 
231 static int
232 evt_parse_work_lcores(struct evt_options *opt, const char *corelist)
233 {
234 	int ret;
235 
236 	ret = parse_lcores_list(opt->wlcores, RTE_MAX_LCORE, corelist);
237 	if (ret == -E2BIG)
238 		evt_err("duplicate lcores in wlcores");
239 
240 	return ret;
241 }
242 
243 static int
244 evt_parse_mbuf_sz(struct evt_options *opt, const char *arg)
245 {
246 	int ret;
247 
248 	ret = parser_read_uint16(&(opt->mbuf_sz), arg);
249 
250 	return ret;
251 }
252 
253 static int
254 evt_parse_max_pkt_sz(struct evt_options *opt, const char *arg)
255 {
256 	int ret;
257 
258 	ret = parser_read_uint32(&(opt->max_pkt_sz), arg);
259 
260 	return ret;
261 }
262 
263 static int
264 evt_parse_ena_vector(struct evt_options *opt, const char *arg __rte_unused)
265 {
266 	opt->ena_vector = 1;
267 	return 0;
268 }
269 
270 static int
271 evt_parse_vector_size(struct evt_options *opt, const char *arg)
272 {
273 	int ret;
274 
275 	ret = parser_read_uint16(&(opt->vector_size), arg);
276 
277 	return ret;
278 }
279 
280 static int
281 evt_parse_vector_tmo_ns(struct evt_options *opt, const char *arg)
282 {
283 	int ret;
284 
285 	ret = parser_read_uint64(&(opt->vector_tmo_nsec), arg);
286 
287 	return ret;
288 }
289 
290 static int
291 evt_parse_eth_queues(struct evt_options *opt, const char *arg)
292 {
293 	int ret;
294 
295 	ret = parser_read_uint16(&(opt->eth_queues), arg);
296 
297 	return ret;
298 }
299 
300 static void
301 usage(char *program)
302 {
303 	printf("usage : %s [EAL options] -- [application options]\n", program);
304 	printf("application options:\n");
305 	printf("\t--verbose          : verbose level\n"
306 		"\t--dev              : device id of the event device\n"
307 		"\t--test             : name of the test application to run\n"
308 		"\t--socket_id        : socket_id of application resources\n"
309 		"\t--pool_sz          : pool size of the mempool\n"
310 		"\t--plcores          : list of lcore ids for producers\n"
311 		"\t--wlcores          : list of lcore ids for workers\n"
312 		"\t--stlist           : list of scheduled types of the stages\n"
313 		"\t--nb_flows         : number of flows to produce\n"
314 		"\t--nb_pkts          : number of packets to produce\n"
315 		"\t--worker_deq_depth : dequeue depth of the worker\n"
316 		"\t--fwd_latency      : perform fwd_latency measurement\n"
317 		"\t--queue_priority   : enable queue priority\n"
318 		"\t--deq_tmo_nsec     : global dequeue timeout\n"
319 		"\t--prod_type_ethdev : use ethernet device as producer.\n"
320 		"\t--prod_type_timerdev : use event timer device as producer.\n"
321 		"\t                     expity_nsec would be the timeout\n"
322 		"\t                     in ns.\n"
323 		"\t--prod_type_timerdev_burst : use timer device as producer\n"
324 		"\t                             burst mode.\n"
325 		"\t--nb_timers        : number of timers to arm.\n"
326 		"\t--nb_timer_adptrs  : number of timer adapters to use.\n"
327 		"\t--timer_tick_nsec  : timer tick interval in ns.\n"
328 		"\t--max_tmo_nsec     : max timeout interval in ns.\n"
329 		"\t--expiry_nsec      : event timer expiry ns.\n"
330 		"\t--mbuf_sz          : packet mbuf size.\n"
331 		"\t--max_pkt_sz       : max packet size.\n"
332 		"\t--nb_eth_queues    : number of ethernet Rx queues.\n"
333 		"\t--enable_vector    : enable event vectorization.\n"
334 		"\t--vector_size      : Max vector size.\n"
335 		"\t--vector_tmo_ns    : Max vector timeout in nanoseconds\n"
336 		);
337 	printf("available tests:\n");
338 	evt_test_dump_names();
339 }
340 
341 static int
342 evt_parse_sched_type_list(struct evt_options *opt, const char *arg)
343 {
344 	char c;
345 	int i = 0, j = -1;
346 
347 	for (i = 0; i < EVT_MAX_STAGES; i++)
348 		opt->sched_type_list[i] = (uint8_t)-1;
349 
350 	i = 0;
351 
352 	do {
353 		c = arg[++j];
354 
355 		switch (c) {
356 		case 'o':
357 		case 'O':
358 			opt->sched_type_list[i++] = RTE_SCHED_TYPE_ORDERED;
359 			break;
360 		case 'a':
361 		case 'A':
362 			opt->sched_type_list[i++] = RTE_SCHED_TYPE_ATOMIC;
363 			break;
364 		case 'p':
365 		case 'P':
366 			opt->sched_type_list[i++] = RTE_SCHED_TYPE_PARALLEL;
367 			break;
368 		case ',':
369 			break;
370 		default:
371 			if (c != '\0') {
372 				evt_err("invalid sched_type %c", c);
373 				return -EINVAL;
374 			}
375 		}
376 	} while (c != '\0');
377 
378 	opt->nb_stages = i;
379 	return 0;
380 }
381 
382 static struct option lgopts[] = {
383 	{ EVT_NB_FLOWS,            1, 0, 0 },
384 	{ EVT_DEVICE,              1, 0, 0 },
385 	{ EVT_VERBOSE,             1, 0, 0 },
386 	{ EVT_TEST,                1, 0, 0 },
387 	{ EVT_PROD_LCORES,         1, 0, 0 },
388 	{ EVT_WORK_LCORES,         1, 0, 0 },
389 	{ EVT_SOCKET_ID,           1, 0, 0 },
390 	{ EVT_POOL_SZ,             1, 0, 0 },
391 	{ EVT_NB_PKTS,             1, 0, 0 },
392 	{ EVT_WKR_DEQ_DEP,         1, 0, 0 },
393 	{ EVT_SCHED_TYPE_LIST,     1, 0, 0 },
394 	{ EVT_FWD_LATENCY,         0, 0, 0 },
395 	{ EVT_QUEUE_PRIORITY,      0, 0, 0 },
396 	{ EVT_DEQ_TMO_NSEC,        1, 0, 0 },
397 	{ EVT_PROD_ETHDEV,         0, 0, 0 },
398 	{ EVT_PROD_TIMERDEV,       0, 0, 0 },
399 	{ EVT_PROD_TIMERDEV_BURST, 0, 0, 0 },
400 	{ EVT_NB_TIMERS,           1, 0, 0 },
401 	{ EVT_NB_TIMER_ADPTRS,     1, 0, 0 },
402 	{ EVT_TIMER_TICK_NSEC,     1, 0, 0 },
403 	{ EVT_MAX_TMO_NSEC,        1, 0, 0 },
404 	{ EVT_EXPIRY_NSEC,         1, 0, 0 },
405 	{ EVT_MBUF_SZ,             1, 0, 0 },
406 	{ EVT_MAX_PKT_SZ,          1, 0, 0 },
407 	{ EVT_NB_ETH_QUEUES,       1, 0, 0 },
408 	{ EVT_ENA_VECTOR,          0, 0, 0 },
409 	{ EVT_VECTOR_SZ,           1, 0, 0 },
410 	{ EVT_VECTOR_TMO,          1, 0, 0 },
411 	{ EVT_HELP,                0, 0, 0 },
412 	{ NULL,                    0, 0, 0 }
413 };
414 
415 static int
416 evt_opts_parse_long(int opt_idx, struct evt_options *opt)
417 {
418 	unsigned int i;
419 
420 	struct long_opt_parser parsermap[] = {
421 		{ EVT_NB_FLOWS, evt_parse_nb_flows},
422 		{ EVT_DEVICE, evt_parse_dev_id},
423 		{ EVT_VERBOSE, evt_parse_verbose},
424 		{ EVT_TEST, evt_parse_test_name},
425 		{ EVT_PROD_LCORES, evt_parse_plcores},
426 		{ EVT_WORK_LCORES, evt_parse_work_lcores},
427 		{ EVT_SOCKET_ID, evt_parse_socket_id},
428 		{ EVT_POOL_SZ, evt_parse_pool_sz},
429 		{ EVT_NB_PKTS, evt_parse_nb_pkts},
430 		{ EVT_WKR_DEQ_DEP, evt_parse_wkr_deq_dep},
431 		{ EVT_SCHED_TYPE_LIST, evt_parse_sched_type_list},
432 		{ EVT_FWD_LATENCY, evt_parse_fwd_latency},
433 		{ EVT_QUEUE_PRIORITY, evt_parse_queue_priority},
434 		{ EVT_DEQ_TMO_NSEC, evt_parse_deq_tmo_nsec},
435 		{ EVT_PROD_ETHDEV, evt_parse_eth_prod_type},
436 		{ EVT_PROD_TIMERDEV, evt_parse_timer_prod_type},
437 		{ EVT_PROD_TIMERDEV_BURST, evt_parse_timer_prod_type_burst},
438 		{ EVT_NB_TIMERS, evt_parse_nb_timers},
439 		{ EVT_NB_TIMER_ADPTRS, evt_parse_nb_timer_adptrs},
440 		{ EVT_TIMER_TICK_NSEC, evt_parse_timer_tick_nsec},
441 		{ EVT_MAX_TMO_NSEC, evt_parse_max_tmo_nsec},
442 		{ EVT_EXPIRY_NSEC, evt_parse_expiry_nsec},
443 		{ EVT_MBUF_SZ, evt_parse_mbuf_sz},
444 		{ EVT_MAX_PKT_SZ, evt_parse_max_pkt_sz},
445 		{ EVT_NB_ETH_QUEUES, evt_parse_eth_queues},
446 		{ EVT_ENA_VECTOR, evt_parse_ena_vector},
447 		{ EVT_VECTOR_SZ, evt_parse_vector_size},
448 		{ EVT_VECTOR_TMO, evt_parse_vector_tmo_ns},
449 	};
450 
451 	for (i = 0; i < RTE_DIM(parsermap); i++) {
452 		if (strncmp(lgopts[opt_idx].name, parsermap[i].lgopt_name,
453 				strlen(lgopts[opt_idx].name)) == 0)
454 			return parsermap[i].parser_fn(opt, optarg);
455 	}
456 
457 	return -EINVAL;
458 }
459 
460 int
461 evt_options_parse(struct evt_options *opt, int argc, char **argv)
462 {
463 	int opts, retval, opt_idx;
464 
465 	while ((opts = getopt_long(argc, argv, "", lgopts, &opt_idx)) != EOF) {
466 		switch (opts) {
467 		case 0: /* long options */
468 			if (!strcmp(lgopts[opt_idx].name, "help")) {
469 				usage(argv[0]);
470 				exit(EXIT_SUCCESS);
471 			}
472 
473 			retval = evt_opts_parse_long(opt_idx, opt);
474 			if (retval != 0)
475 				return retval;
476 			break;
477 		default:
478 			return -EINVAL;
479 		}
480 	}
481 	return 0;
482 }
483 
484 void
485 evt_options_dump(struct evt_options *opt)
486 {
487 	int lcore_id;
488 	struct rte_event_dev_info dev_info;
489 
490 	rte_event_dev_info_get(opt->dev_id, &dev_info);
491 	evt_dump("driver", "%s", dev_info.driver_name);
492 	evt_dump("test", "%s", opt->test_name);
493 	evt_dump("dev", "%d", opt->dev_id);
494 	evt_dump("verbose_level", "%d", opt->verbose_level);
495 	evt_dump("socket_id", "%d", opt->socket_id);
496 	evt_dump("pool_sz", "%d", opt->pool_sz);
497 	evt_dump("main lcore", "%d", rte_get_main_lcore());
498 	evt_dump("nb_pkts", "%"PRIu64, opt->nb_pkts);
499 	evt_dump("nb_timers", "%"PRIu64, opt->nb_timers);
500 	evt_dump_begin("available lcores");
501 	RTE_LCORE_FOREACH(lcore_id)
502 		printf("%d ", lcore_id);
503 	evt_dump_end;
504 	evt_dump_nb_flows(opt);
505 	evt_dump_worker_dequeue_depth(opt);
506 }
507