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