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