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