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