4 * Copyright (C) Cavium, Inc 2017.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Cavium, Inc nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <rte_common.h>
39 #include <rte_eventdev.h>
40 #include <rte_lcore.h>
42 #include "evt_options.h"
47 evt_options_default(struct evt_options *opt)
49 memset(opt, 0, sizeof(*opt));
50 opt->verbose_level = 1; /* Enable minimal prints */
52 strncpy(opt->test_name, "order_queue", EVT_TEST_NAME_MAX_LEN);
54 opt->socket_id = SOCKET_ID_ANY;
55 opt->pool_sz = 16 * 1024;
56 opt->wkr_deq_dep = 16;
57 opt->nb_pkts = (1ULL << 26); /* do ~64M packets */
60 typedef int (*option_parser_t)(struct evt_options *opt,
63 struct long_opt_parser {
64 const char *lgopt_name;
65 option_parser_t parser_fn;
69 evt_parse_nb_flows(struct evt_options *opt, const char *arg)
73 ret = parser_read_uint32(&(opt->nb_flows), arg);
79 evt_parse_dev_id(struct evt_options *opt, const char *arg)
83 ret = parser_read_uint8(&(opt->dev_id), arg);
89 evt_parse_verbose(struct evt_options *opt, const char *arg __rte_unused)
91 opt->verbose_level = atoi(arg);
96 evt_parse_fwd_latency(struct evt_options *opt, const char *arg __rte_unused)
103 evt_parse_queue_priority(struct evt_options *opt, const char *arg __rte_unused)
110 evt_parse_test_name(struct evt_options *opt, const char *arg)
112 snprintf(opt->test_name, EVT_TEST_NAME_MAX_LEN, "%s", arg);
117 evt_parse_socket_id(struct evt_options *opt, const char *arg)
119 opt->socket_id = atoi(arg);
124 evt_parse_wkr_deq_dep(struct evt_options *opt, const char *arg)
128 ret = parser_read_uint16(&(opt->wkr_deq_dep), arg);
133 evt_parse_nb_pkts(struct evt_options *opt, const char *arg)
137 ret = parser_read_uint64(&(opt->nb_pkts), arg);
143 evt_parse_pool_sz(struct evt_options *opt, const char *arg)
145 opt->pool_sz = atoi(arg);
151 evt_parse_plcores(struct evt_options *opt, const char *corelist)
155 ret = parse_lcores_list(opt->plcores, corelist);
157 evt_err("duplicate lcores in plcores");
163 evt_parse_work_lcores(struct evt_options *opt, const char *corelist)
167 ret = parse_lcores_list(opt->wlcores, corelist);
169 evt_err("duplicate lcores in wlcores");
177 printf("usage : %s [EAL options] -- [application options]\n", program);
178 printf("application options:\n");
179 printf("\t--verbose : verbose level\n"
180 "\t--dev : device id of the event device\n"
181 "\t--test : name of the test application to run\n"
182 "\t--socket_id : socket_id of application resources\n"
183 "\t--pool_sz : pool size of the mempool\n"
184 "\t--plcores : list of lcore ids for producers\n"
185 "\t--wlcores : list of lcore ids for workers\n"
186 "\t--stlist : list of scheduled types of the stages\n"
187 "\t--nb_flows : number of flows to produce\n"
188 "\t--nb_pkts : number of packets to produce\n"
189 "\t--worker_deq_depth : dequeue depth of the worker\n"
190 "\t--fwd_latency : perform fwd_latency measurement\n"
191 "\t--queue_priority : enable queue priority\n"
193 printf("available tests:\n");
194 evt_test_dump_names();
198 evt_parse_sched_type_list(struct evt_options *opt, const char *arg)
203 for (i = 0; i < EVT_MAX_STAGES; i++)
204 opt->sched_type_list[i] = (uint8_t)-1;
214 opt->sched_type_list[i++] = RTE_SCHED_TYPE_ORDERED;
218 opt->sched_type_list[i++] = RTE_SCHED_TYPE_ATOMIC;
222 opt->sched_type_list[i++] = RTE_SCHED_TYPE_PARALLEL;
228 evt_err("invalid sched_type %c", c);
238 static struct option lgopts[] = {
239 { EVT_NB_FLOWS, 1, 0, 0 },
240 { EVT_DEVICE, 1, 0, 0 },
241 { EVT_VERBOSE, 1, 0, 0 },
242 { EVT_TEST, 1, 0, 0 },
243 { EVT_PROD_LCORES, 1, 0, 0 },
244 { EVT_WORK_LCORES, 1, 0, 0 },
245 { EVT_SOCKET_ID, 1, 0, 0 },
246 { EVT_POOL_SZ, 1, 0, 0 },
247 { EVT_NB_PKTS, 1, 0, 0 },
248 { EVT_WKR_DEQ_DEP, 1, 0, 0 },
249 { EVT_SCHED_TYPE_LIST, 1, 0, 0 },
250 { EVT_FWD_LATENCY, 0, 0, 0 },
251 { EVT_QUEUE_PRIORITY, 0, 0, 0 },
252 { EVT_HELP, 0, 0, 0 },
257 evt_opts_parse_long(int opt_idx, struct evt_options *opt)
261 struct long_opt_parser parsermap[] = {
262 { EVT_NB_FLOWS, evt_parse_nb_flows},
263 { EVT_DEVICE, evt_parse_dev_id},
264 { EVT_VERBOSE, evt_parse_verbose},
265 { EVT_TEST, evt_parse_test_name},
266 { EVT_PROD_LCORES, evt_parse_plcores},
267 { EVT_WORK_LCORES, evt_parse_work_lcores},
268 { EVT_SOCKET_ID, evt_parse_socket_id},
269 { EVT_POOL_SZ, evt_parse_pool_sz},
270 { EVT_NB_PKTS, evt_parse_nb_pkts},
271 { EVT_WKR_DEQ_DEP, evt_parse_wkr_deq_dep},
272 { EVT_SCHED_TYPE_LIST, evt_parse_sched_type_list},
273 { EVT_FWD_LATENCY, evt_parse_fwd_latency},
274 { EVT_QUEUE_PRIORITY, evt_parse_queue_priority},
277 for (i = 0; i < RTE_DIM(parsermap); i++) {
278 if (strncmp(lgopts[opt_idx].name, parsermap[i].lgopt_name,
279 strlen(parsermap[i].lgopt_name)) == 0)
280 return parsermap[i].parser_fn(opt, optarg);
287 evt_options_parse(struct evt_options *opt, int argc, char **argv)
289 int opts, retval, opt_idx;
291 while ((opts = getopt_long(argc, argv, "", lgopts, &opt_idx)) != EOF) {
293 case 0: /* long options */
294 if (!strcmp(lgopts[opt_idx].name, "help")) {
299 retval = evt_opts_parse_long(opt_idx, opt);
311 evt_options_dump(struct evt_options *opt)
314 struct rte_event_dev_info dev_info;
316 rte_event_dev_info_get(opt->dev_id, &dev_info);
317 evt_dump("driver", "%s", dev_info.driver_name);
318 evt_dump("test", "%s", opt->test_name);
319 evt_dump("dev", "%d", opt->dev_id);
320 evt_dump("verbose_level", "%d", opt->verbose_level);
321 evt_dump("socket_id", "%d", opt->socket_id);
322 evt_dump("pool_sz", "%d", opt->pool_sz);
323 evt_dump("master lcore", "%d", rte_get_master_lcore());
324 evt_dump("nb_pkts", "%"PRIu64, opt->nb_pkts);
325 evt_dump_begin("available lcores");
326 RTE_LCORE_FOREACH(lcore_id)
327 printf("%d ", lcore_id);
329 evt_dump_nb_flows(opt);
330 evt_dump_worker_dequeue_depth(opt);