xref: /dpdk/app/test-eventdev/evt_options.h (revision 42a8fc7daa46256d150278fc9a7a846e27945a0c)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Cavium, Inc
3  */
4 
5 #ifndef _EVT_OPTIONS_
6 #define _EVT_OPTIONS_
7 
8 #include <stdio.h>
9 #include <stdbool.h>
10 
11 #include <rte_common.h>
12 #include <rte_cryptodev.h>
13 #include <rte_ethdev.h>
14 #include <rte_eventdev.h>
15 #include <rte_lcore.h>
16 
17 #include "evt_common.h"
18 
19 #define EVT_BOOL_FMT(x)          ((x) ? "true" : "false")
20 
21 #define EVT_VERBOSE              ("verbose")
22 #define EVT_DEVICE               ("dev")
23 #define EVT_TEST                 ("test")
24 #define EVT_PROD_LCORES          ("plcores")
25 #define EVT_WORK_LCORES          ("wlcores")
26 #define EVT_NB_FLOWS             ("nb_flows")
27 #define EVT_SOCKET_ID            ("socket_id")
28 #define EVT_POOL_SZ              ("pool_sz")
29 #define EVT_WKR_DEQ_DEP          ("worker_deq_depth")
30 #define EVT_NB_PKTS              ("nb_pkts")
31 #define EVT_NB_STAGES            ("nb_stages")
32 #define EVT_SCHED_TYPE_LIST      ("stlist")
33 #define EVT_FWD_LATENCY          ("fwd_latency")
34 #define EVT_QUEUE_PRIORITY       ("queue_priority")
35 #define EVT_DEQ_TMO_NSEC         ("deq_tmo_nsec")
36 #define EVT_PROD_ETHDEV          ("prod_type_ethdev")
37 #define EVT_PROD_CRYPTODEV	 ("prod_type_cryptodev")
38 #define EVT_PROD_TIMERDEV        ("prod_type_timerdev")
39 #define EVT_PROD_TIMERDEV_BURST  ("prod_type_timerdev_burst")
40 #define EVT_CRYPTO_ADPTR_MODE	 ("crypto_adptr_mode")
41 #define EVT_CRYPTO_OP_TYPE	 ("crypto_op_type")
42 #define EVT_NB_TIMERS            ("nb_timers")
43 #define EVT_NB_TIMER_ADPTRS      ("nb_timer_adptrs")
44 #define EVT_TIMER_TICK_NSEC      ("timer_tick_nsec")
45 #define EVT_MAX_TMO_NSEC         ("max_tmo_nsec")
46 #define EVT_EXPIRY_NSEC          ("expiry_nsec")
47 #define EVT_MBUF_SZ              ("mbuf_sz")
48 #define EVT_MAX_PKT_SZ           ("max_pkt_sz")
49 #define EVT_PROD_ENQ_BURST_SZ    ("prod_enq_burst_sz")
50 #define EVT_NB_ETH_QUEUES        ("nb_eth_queues")
51 #define EVT_ENA_VECTOR           ("enable_vector")
52 #define EVT_VECTOR_SZ            ("vector_size")
53 #define EVT_VECTOR_TMO           ("vector_tmo_ns")
54 #define EVT_PER_PORT_POOL	 ("per_port_pool")
55 #define EVT_TX_FIRST		 ("tx_first")
56 #define EVT_TX_PKT_SZ		 ("tx_pkt_sz")
57 #define EVT_HELP                 ("help")
58 
59 void evt_options_default(struct evt_options *opt);
60 int evt_options_parse(struct evt_options *opt, int argc, char **argv);
61 void evt_options_dump(struct evt_options *opt);
62 
63 /* options check helpers */
64 static inline bool
65 evt_lcores_has_overlap(bool lcores[], int lcore)
66 {
67 	if (lcores[lcore] == true) {
68 		evt_err("lcore overlaps at %d", lcore);
69 		return true;
70 	}
71 
72 	return false;
73 }
74 
75 static inline bool
76 evt_lcores_has_overlap_multi(bool lcoresx[], bool lcoresy[])
77 {
78 	int i;
79 
80 	for (i = 0; i < RTE_MAX_LCORE; i++) {
81 		if (lcoresx[i] && lcoresy[i]) {
82 			evt_err("lcores overlaps at %d", i);
83 			return true;
84 		}
85 	}
86 	return false;
87 }
88 
89 static inline bool
90 evt_has_active_lcore(bool lcores[])
91 {
92 	int i;
93 
94 	for (i = 0; i < RTE_MAX_LCORE; i++)
95 		if (lcores[i])
96 			return true;
97 	return false;
98 }
99 
100 static inline int
101 evt_nr_active_lcores(bool lcores[])
102 {
103 	int i;
104 	int c = 0;
105 
106 	for (i = 0; i < RTE_MAX_LCORE; i++)
107 		if (lcores[i])
108 			c++;
109 	return c;
110 }
111 
112 static inline int
113 evt_get_first_active_lcore(bool lcores[])
114 {
115 	int i;
116 
117 	for (i = 0; i < RTE_MAX_LCORE; i++)
118 		if (lcores[i])
119 			return i;
120 	return -1;
121 }
122 
123 static inline bool
124 evt_has_disabled_lcore(bool lcores[])
125 {
126 	int i;
127 
128 	for (i = 0; i < RTE_MAX_LCORE; i++)
129 		if ((lcores[i] == true) && !(rte_lcore_is_enabled(i)))
130 			return true;
131 	return false;
132 }
133 
134 static inline bool
135 evt_has_invalid_stage(struct evt_options *opt)
136 {
137 	if (!opt->nb_stages) {
138 		evt_err("need minimum one stage, check --stlist");
139 		return true;
140 	}
141 	if (opt->nb_stages > EVT_MAX_STAGES) {
142 		evt_err("requested changes are beyond EVT_MAX_STAGES=%d",
143 			EVT_MAX_STAGES);
144 		return true;
145 	}
146 	return false;
147 }
148 
149 static inline bool
150 evt_has_invalid_sched_type(struct evt_options *opt)
151 {
152 	int i;
153 
154 	for (i = 0; i < opt->nb_stages; i++) {
155 		if (opt->sched_type_list[i] > RTE_SCHED_TYPE_PARALLEL) {
156 			evt_err("invalid sched_type %d at %d",
157 				opt->sched_type_list[i], i);
158 			return true;
159 		}
160 	}
161 	return false;
162 }
163 
164 /* option dump helpers */
165 static inline void
166 evt_dump_worker_lcores(struct evt_options *opt)
167 {
168 	int c;
169 
170 	evt_dump_begin("worker lcores");
171 	for  (c = 0; c < RTE_MAX_LCORE; c++) {
172 		if (opt->wlcores[c])
173 			printf("%d ", c);
174 	}
175 	evt_dump_end;
176 }
177 
178 static inline void
179 evt_dump_producer_lcores(struct evt_options *opt)
180 {
181 	int c;
182 
183 	evt_dump_begin("producer lcores");
184 	for  (c = 0; c < RTE_MAX_LCORE; c++) {
185 		if (opt->plcores[c])
186 			printf("%d ", c);
187 	}
188 	evt_dump_end;
189 }
190 
191 static inline void
192 evt_dump_nb_flows(struct evt_options *opt)
193 {
194 	evt_dump("nb_flows", "%d", opt->nb_flows);
195 }
196 
197 static inline void
198 evt_dump_worker_dequeue_depth(struct evt_options *opt)
199 {
200 	evt_dump("worker deq depth", "%d", opt->wkr_deq_dep);
201 }
202 
203 static inline void
204 evt_dump_nb_stages(struct evt_options *opt)
205 {
206 	evt_dump("nb_stages", "%d", opt->nb_stages);
207 }
208 
209 static inline void
210 evt_dump_fwd_latency(struct evt_options *opt)
211 {
212 	evt_dump("fwd_latency", "%s", EVT_BOOL_FMT(opt->fwd_latency));
213 }
214 
215 static inline void
216 evt_dump_queue_priority(struct evt_options *opt)
217 {
218 	evt_dump("queue_priority", "%s", EVT_BOOL_FMT(opt->q_priority));
219 }
220 
221 static inline const char*
222 evt_sched_type_2_str(uint8_t sched_type)
223 {
224 
225 	if (sched_type == RTE_SCHED_TYPE_ORDERED)
226 		return "O";
227 	else if (sched_type == RTE_SCHED_TYPE_ATOMIC)
228 		return "A";
229 	else if (sched_type == RTE_SCHED_TYPE_PARALLEL)
230 		return "P";
231 	else
232 		return "I";
233 }
234 
235 static inline void
236 evt_dump_sched_type_list(struct evt_options *opt)
237 {
238 	int i;
239 
240 	evt_dump_begin("sched_type_list");
241 	for (i = 0; i < opt->nb_stages; i++)
242 		printf("%s ", evt_sched_type_2_str(opt->sched_type_list[i]));
243 
244 	evt_dump_end;
245 }
246 
247 static inline const char *
248 evt_prod_id_to_name(enum evt_prod_type prod_type)
249 {
250 	switch (prod_type) {
251 	default:
252 	case EVT_PROD_TYPE_SYNT:
253 		return "Synthetic producer lcores";
254 	case EVT_PROD_TYPE_ETH_RX_ADPTR:
255 		return "Ethdev Rx Adapter";
256 	case EVT_PROD_TYPE_EVENT_TIMER_ADPTR:
257 		return "Event timer adapter";
258 	case EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR:
259 		return "Event crypto adapter";
260 	}
261 
262 	return "";
263 }
264 
265 #define EVT_PROD_MAX_NAME_LEN 50
266 static inline void
267 evt_dump_producer_type(struct evt_options *opt)
268 {
269 	char name[EVT_PROD_MAX_NAME_LEN];
270 
271 	switch (opt->prod_type) {
272 	default:
273 	case EVT_PROD_TYPE_SYNT:
274 		snprintf(name, EVT_PROD_MAX_NAME_LEN,
275 				"Synthetic producer lcores");
276 		break;
277 	case EVT_PROD_TYPE_ETH_RX_ADPTR:
278 		snprintf(name, EVT_PROD_MAX_NAME_LEN,
279 				"Ethdev Rx Adapter producers");
280 		evt_dump("nb_ethdev", "%d", rte_eth_dev_count_avail());
281 		break;
282 	case EVT_PROD_TYPE_EVENT_TIMER_ADPTR:
283 		if (opt->timdev_use_burst)
284 			snprintf(name, EVT_PROD_MAX_NAME_LEN,
285 				"Event timer adapter burst mode producer");
286 		else
287 			snprintf(name, EVT_PROD_MAX_NAME_LEN,
288 				"Event timer adapter producer");
289 		evt_dump("nb_timer_adapters", "%d", opt->nb_timer_adptrs);
290 		evt_dump("max_tmo_nsec", "%"PRIu64"", opt->max_tmo_nsec);
291 		evt_dump("expiry_nsec", "%"PRIu64"", opt->expiry_nsec);
292 		if (opt->optm_timer_tick_nsec)
293 			evt_dump("optm_timer_tick_nsec", "%"PRIu64"",
294 					opt->optm_timer_tick_nsec);
295 		else
296 			evt_dump("timer_tick_nsec", "%"PRIu64"",
297 					opt->timer_tick_nsec);
298 		break;
299 	case EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR:
300 		snprintf(name, EVT_PROD_MAX_NAME_LEN,
301 			 "Event crypto adapter producers");
302 		evt_dump("crypto adapter mode", "%s",
303 			 opt->crypto_adptr_mode ? "OP_FORWARD" : "OP_NEW");
304 		evt_dump("crypto op type", "%s",
305 			 (opt->crypto_op_type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) ?
306 			 "SYMMETRIC" : "ASYMMETRIC");
307 		evt_dump("nb_cryptodev", "%u", rte_cryptodev_count());
308 		break;
309 	}
310 	evt_dump("prod_type", "%s", name);
311 }
312 
313 #endif /* _EVT_OPTIONS_ */
314