xref: /dpdk/app/test-eventdev/evt_options.h (revision 7a7a04d3ce8eab9b53d23b673dfdc71b50fd523d)
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_DMADEV          ("prod_type_dmadev")
39 #define EVT_PROD_TIMERDEV        ("prod_type_timerdev")
40 #define EVT_PROD_TIMERDEV_BURST  ("prod_type_timerdev_burst")
41 #define EVT_DMA_ADPTR_MODE       ("dma_adptr_mode")
42 #define EVT_CRYPTO_ADPTR_MODE	 ("crypto_adptr_mode")
43 #define EVT_CRYPTO_OP_TYPE	 ("crypto_op_type")
44 #define EVT_CRYPTO_CIPHER_ALG	 ("crypto_cipher_alg")
45 #define EVT_CRYPTO_CIPHER_KEY	 ("crypto_cipher_key")
46 #define EVT_CRYPTO_CIPHER_IV_SZ  ("crypto_cipher_iv_sz")
47 #define EVT_NB_TIMERS            ("nb_timers")
48 #define EVT_NB_TIMER_ADPTRS      ("nb_timer_adptrs")
49 #define EVT_TIMER_TICK_NSEC      ("timer_tick_nsec")
50 #define EVT_MAX_TMO_NSEC         ("max_tmo_nsec")
51 #define EVT_EXPIRY_NSEC          ("expiry_nsec")
52 #define EVT_MBUF_SZ              ("mbuf_sz")
53 #define EVT_MAX_PKT_SZ           ("max_pkt_sz")
54 #define EVT_PROD_ENQ_BURST_SZ    ("prod_enq_burst_sz")
55 #define EVT_NB_ETH_QUEUES        ("nb_eth_queues")
56 #define EVT_ENA_VECTOR           ("enable_vector")
57 #define EVT_VECTOR_SZ            ("vector_size")
58 #define EVT_VECTOR_TMO           ("vector_tmo_ns")
59 #define EVT_PER_PORT_POOL	 ("per_port_pool")
60 #define EVT_TX_FIRST		 ("tx_first")
61 #define EVT_TX_PKT_SZ		 ("tx_pkt_sz")
62 #define EVT_PRESCHEDULE          ("preschedule")
63 #define EVT_HELP                 ("help")
64 
65 void evt_options_default(struct evt_options *opt);
66 int evt_options_parse(struct evt_options *opt, int argc, char **argv);
67 void evt_options_dump(struct evt_options *opt);
68 
69 /* options check helpers */
70 static inline bool
71 evt_lcores_has_overlap(bool lcores[], int lcore)
72 {
73 	if (lcores[lcore] == true) {
74 		evt_err("lcore overlaps at %d", lcore);
75 		return true;
76 	}
77 
78 	return false;
79 }
80 
81 static inline bool
82 evt_lcores_has_overlap_multi(bool lcoresx[], bool lcoresy[])
83 {
84 	int i;
85 
86 	for (i = 0; i < RTE_MAX_LCORE; i++) {
87 		if (lcoresx[i] && lcoresy[i]) {
88 			evt_err("lcores overlaps at %d", i);
89 			return true;
90 		}
91 	}
92 	return false;
93 }
94 
95 static inline bool
96 evt_has_active_lcore(bool lcores[])
97 {
98 	int i;
99 
100 	for (i = 0; i < RTE_MAX_LCORE; i++)
101 		if (lcores[i])
102 			return true;
103 	return false;
104 }
105 
106 static inline int
107 evt_nr_active_lcores(bool lcores[])
108 {
109 	int i;
110 	int c = 0;
111 
112 	for (i = 0; i < RTE_MAX_LCORE; i++)
113 		if (lcores[i])
114 			c++;
115 	return c;
116 }
117 
118 static inline int
119 evt_get_first_active_lcore(bool lcores[])
120 {
121 	int i;
122 
123 	for (i = 0; i < RTE_MAX_LCORE; i++)
124 		if (lcores[i])
125 			return i;
126 	return -1;
127 }
128 
129 static inline bool
130 evt_has_disabled_lcore(bool lcores[])
131 {
132 	int i;
133 
134 	for (i = 0; i < RTE_MAX_LCORE; i++)
135 		if ((lcores[i] == true) && !(rte_lcore_is_enabled(i)))
136 			return true;
137 	return false;
138 }
139 
140 static inline bool
141 evt_has_invalid_stage(struct evt_options *opt)
142 {
143 	if (!opt->nb_stages) {
144 		evt_err("need minimum one stage, check --stlist");
145 		return true;
146 	}
147 	if (opt->nb_stages > EVT_MAX_STAGES) {
148 		evt_err("requested changes are beyond EVT_MAX_STAGES=%d",
149 			EVT_MAX_STAGES);
150 		return true;
151 	}
152 	return false;
153 }
154 
155 static inline bool
156 evt_has_invalid_sched_type(struct evt_options *opt)
157 {
158 	int i;
159 
160 	for (i = 0; i < opt->nb_stages; i++) {
161 		if (opt->sched_type_list[i] > RTE_SCHED_TYPE_PARALLEL) {
162 			evt_err("invalid sched_type %d at %d",
163 				opt->sched_type_list[i], i);
164 			return true;
165 		}
166 	}
167 	return false;
168 }
169 
170 /* option dump helpers */
171 static inline void
172 evt_dump_worker_lcores(struct evt_options *opt)
173 {
174 	int c;
175 
176 	evt_dump_begin("worker lcores");
177 	for  (c = 0; c < RTE_MAX_LCORE; c++) {
178 		if (opt->wlcores[c])
179 			printf("%d ", c);
180 	}
181 	evt_dump_end;
182 }
183 
184 static inline void
185 evt_dump_producer_lcores(struct evt_options *opt)
186 {
187 	int c;
188 
189 	evt_dump_begin("producer lcores");
190 	for  (c = 0; c < RTE_MAX_LCORE; c++) {
191 		if (opt->plcores[c])
192 			printf("%d ", c);
193 	}
194 	evt_dump_end;
195 }
196 
197 static inline void
198 evt_dump_nb_flows(struct evt_options *opt)
199 {
200 	evt_dump("nb_flows", "%d", opt->nb_flows);
201 }
202 
203 static inline void
204 evt_dump_worker_dequeue_depth(struct evt_options *opt)
205 {
206 	evt_dump("worker deq depth", "%d", opt->wkr_deq_dep);
207 }
208 
209 static inline void
210 evt_dump_nb_stages(struct evt_options *opt)
211 {
212 	evt_dump("nb_stages", "%d", opt->nb_stages);
213 }
214 
215 static inline void
216 evt_dump_fwd_latency(struct evt_options *opt)
217 {
218 	evt_dump("fwd_latency", "%s", EVT_BOOL_FMT(opt->fwd_latency));
219 }
220 
221 static inline void
222 evt_dump_queue_priority(struct evt_options *opt)
223 {
224 	evt_dump("queue_priority", "%s", EVT_BOOL_FMT(opt->q_priority));
225 }
226 
227 static inline const char*
228 evt_sched_type_2_str(uint8_t sched_type)
229 {
230 
231 	if (sched_type == RTE_SCHED_TYPE_ORDERED)
232 		return "O";
233 	else if (sched_type == RTE_SCHED_TYPE_ATOMIC)
234 		return "A";
235 	else if (sched_type == RTE_SCHED_TYPE_PARALLEL)
236 		return "P";
237 	else
238 		return "I";
239 }
240 
241 static inline void
242 evt_dump_sched_type_list(struct evt_options *opt)
243 {
244 	int i;
245 
246 	evt_dump_begin("sched_type_list");
247 	for (i = 0; i < opt->nb_stages; i++)
248 		printf("%s ", evt_sched_type_2_str(opt->sched_type_list[i]));
249 
250 	evt_dump_end;
251 }
252 
253 static inline const char *
254 evt_prod_id_to_name(enum evt_prod_type prod_type)
255 {
256 	switch (prod_type) {
257 	default:
258 	case EVT_PROD_TYPE_SYNT:
259 		return "Synthetic producer lcores";
260 	case EVT_PROD_TYPE_ETH_RX_ADPTR:
261 		return "Ethdev Rx Adapter";
262 	case EVT_PROD_TYPE_EVENT_TIMER_ADPTR:
263 		return "Event timer adapter";
264 	case EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR:
265 		return "Event crypto adapter";
266 	case EVT_PROD_TYPE_EVENT_DMA_ADPTR:
267 		return "Event dma adapter";
268 	}
269 
270 	return "";
271 }
272 
273 #define EVT_PROD_MAX_NAME_LEN 50
274 static inline void
275 evt_dump_producer_type(struct evt_options *opt)
276 {
277 	char name[EVT_PROD_MAX_NAME_LEN];
278 
279 	switch (opt->prod_type) {
280 	default:
281 	case EVT_PROD_TYPE_SYNT:
282 		snprintf(name, EVT_PROD_MAX_NAME_LEN,
283 				"Synthetic producer lcores");
284 		break;
285 	case EVT_PROD_TYPE_ETH_RX_ADPTR:
286 		snprintf(name, EVT_PROD_MAX_NAME_LEN,
287 				"Ethdev Rx Adapter producers");
288 		evt_dump("nb_ethdev", "%d", rte_eth_dev_count_avail());
289 		break;
290 	case EVT_PROD_TYPE_EVENT_TIMER_ADPTR:
291 		if (opt->timdev_use_burst)
292 			snprintf(name, EVT_PROD_MAX_NAME_LEN,
293 				"Event timer adapter burst mode producer");
294 		else
295 			snprintf(name, EVT_PROD_MAX_NAME_LEN,
296 				"Event timer adapter producer");
297 		evt_dump("nb_timer_adapters", "%d", opt->nb_timer_adptrs);
298 		evt_dump("max_tmo_nsec", "%"PRIu64"", opt->max_tmo_nsec);
299 		evt_dump("expiry_nsec", "%"PRIu64"", opt->expiry_nsec);
300 		if (opt->optm_timer_tick_nsec)
301 			evt_dump("optm_timer_tick_nsec", "%"PRIu64"",
302 					opt->optm_timer_tick_nsec);
303 		else
304 			evt_dump("timer_tick_nsec", "%"PRIu64"",
305 					opt->timer_tick_nsec);
306 		break;
307 	case EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR:
308 		snprintf(name, EVT_PROD_MAX_NAME_LEN,
309 			 "Event crypto adapter producers");
310 		evt_dump("crypto adapter mode", "%s",
311 			 opt->crypto_adptr_mode ? "OP_FORWARD" : "OP_NEW");
312 		evt_dump("crypto op type", "%s",
313 			 (opt->crypto_op_type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) ?
314 			 "SYMMETRIC" : "ASYMMETRIC");
315 		evt_dump("nb_cryptodev", "%u", rte_cryptodev_count());
316 		if (opt->crypto_op_type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
317 			evt_dump("cipher algo", "%s",
318 				 rte_cryptodev_get_cipher_algo_string(opt->crypto_cipher_alg));
319 			evt_dump("cipher key sz", "%u",
320 				 opt->crypto_cipher_key_sz);
321 			evt_dump("cipher iv sz", "%u", opt->crypto_cipher_iv_sz);
322 		}
323 		break;
324 	case EVT_PROD_TYPE_EVENT_DMA_ADPTR:
325 		snprintf(name, EVT_PROD_MAX_NAME_LEN,
326 			 "Event dma adapter producers");
327 		evt_dump("dma adapter mode", "%s",
328 			 opt->dma_adptr_mode ? "OP_FORWARD" : "OP_NEW");
329 		evt_dump("nb_dmadev", "%u", rte_dma_count_avail());
330 		break;
331 
332 	}
333 	evt_dump("prod_type", "%s", name);
334 }
335 
336 #endif /* _EVT_OPTIONS_ */
337