common/mlx5: fix user mode register access command
[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_ethdev.h>
13 #include <rte_eventdev.h>
14 #include <rte_lcore.h>
15
16 #include "evt_common.h"
17
18 #define EVT_BOOL_FMT(x)          ((x) ? "true" : "false")
19
20 #define EVT_VERBOSE              ("verbose")
21 #define EVT_DEVICE               ("dev")
22 #define EVT_TEST                 ("test")
23 #define EVT_PROD_LCORES          ("plcores")
24 #define EVT_WORK_LCORES          ("wlcores")
25 #define EVT_NB_FLOWS             ("nb_flows")
26 #define EVT_SOCKET_ID            ("socket_id")
27 #define EVT_POOL_SZ              ("pool_sz")
28 #define EVT_WKR_DEQ_DEP          ("worker_deq_depth")
29 #define EVT_NB_PKTS              ("nb_pkts")
30 #define EVT_NB_STAGES            ("nb_stages")
31 #define EVT_SCHED_TYPE_LIST      ("stlist")
32 #define EVT_FWD_LATENCY          ("fwd_latency")
33 #define EVT_QUEUE_PRIORITY       ("queue_priority")
34 #define EVT_DEQ_TMO_NSEC         ("deq_tmo_nsec")
35 #define EVT_PROD_ETHDEV          ("prod_type_ethdev")
36 #define EVT_PROD_TIMERDEV        ("prod_type_timerdev")
37 #define EVT_PROD_TIMERDEV_BURST  ("prod_type_timerdev_burst")
38 #define EVT_NB_TIMERS            ("nb_timers")
39 #define EVT_NB_TIMER_ADPTRS      ("nb_timer_adptrs")
40 #define EVT_TIMER_TICK_NSEC      ("timer_tick_nsec")
41 #define EVT_MAX_TMO_NSEC         ("max_tmo_nsec")
42 #define EVT_EXPIRY_NSEC          ("expiry_nsec")
43 #define EVT_MBUF_SZ              ("mbuf_sz")
44 #define EVT_MAX_PKT_SZ           ("max_pkt_sz")
45 #define EVT_HELP                 ("help")
46
47 void evt_options_default(struct evt_options *opt);
48 int evt_options_parse(struct evt_options *opt, int argc, char **argv);
49 void evt_options_dump(struct evt_options *opt);
50
51 /* options check helpers */
52 static inline bool
53 evt_lcores_has_overlap(bool lcores[], int lcore)
54 {
55         if (lcores[lcore] == true) {
56                 evt_err("lcore overlaps at %d", lcore);
57                 return true;
58         }
59
60         return false;
61 }
62
63 static inline bool
64 evt_lcores_has_overlap_multi(bool lcoresx[], bool lcoresy[])
65 {
66         int i;
67
68         for (i = 0; i < RTE_MAX_LCORE; i++) {
69                 if (lcoresx[i] && lcoresy[i]) {
70                         evt_err("lcores overlaps at %d", i);
71                         return true;
72                 }
73         }
74         return false;
75 }
76
77 static inline bool
78 evt_has_active_lcore(bool lcores[])
79 {
80         int i;
81
82         for (i = 0; i < RTE_MAX_LCORE; i++)
83                 if (lcores[i])
84                         return true;
85         return false;
86 }
87
88 static inline int
89 evt_nr_active_lcores(bool lcores[])
90 {
91         int i;
92         int c = 0;
93
94         for (i = 0; i < RTE_MAX_LCORE; i++)
95                 if (lcores[i])
96                         c++;
97         return c;
98 }
99
100 static inline int
101 evt_get_first_active_lcore(bool lcores[])
102 {
103         int i;
104
105         for (i = 0; i < RTE_MAX_LCORE; i++)
106                 if (lcores[i])
107                         return i;
108         return -1;
109 }
110
111 static inline bool
112 evt_has_disabled_lcore(bool lcores[])
113 {
114         int i;
115
116         for (i = 0; i < RTE_MAX_LCORE; i++)
117                 if ((lcores[i] == true) && !(rte_lcore_is_enabled(i)))
118                         return true;
119         return false;
120 }
121
122 static inline bool
123 evt_has_invalid_stage(struct evt_options *opt)
124 {
125         if (!opt->nb_stages) {
126                 evt_err("need minimum one stage, check --stlist");
127                 return true;
128         }
129         if (opt->nb_stages > EVT_MAX_STAGES) {
130                 evt_err("requested changes are beyond EVT_MAX_STAGES=%d",
131                         EVT_MAX_STAGES);
132                 return true;
133         }
134         return false;
135 }
136
137 static inline bool
138 evt_has_invalid_sched_type(struct evt_options *opt)
139 {
140         int i;
141
142         for (i = 0; i < opt->nb_stages; i++) {
143                 if (opt->sched_type_list[i] > RTE_SCHED_TYPE_PARALLEL) {
144                         evt_err("invalid sched_type %d at %d",
145                                 opt->sched_type_list[i], i);
146                         return true;
147                 }
148         }
149         return false;
150 }
151
152 /* option dump helpers */
153 static inline void
154 evt_dump_worker_lcores(struct evt_options *opt)
155 {
156         int c;
157
158         evt_dump_begin("worker lcores");
159         for  (c = 0; c < RTE_MAX_LCORE; c++) {
160                 if (opt->wlcores[c])
161                         printf("%d ", c);
162         }
163         evt_dump_end;
164 }
165
166 static inline void
167 evt_dump_producer_lcores(struct evt_options *opt)
168 {
169         int c;
170
171         evt_dump_begin("producer lcores");
172         for  (c = 0; c < RTE_MAX_LCORE; c++) {
173                 if (opt->plcores[c])
174                         printf("%d ", c);
175         }
176         evt_dump_end;
177 }
178
179 static inline void
180 evt_dump_nb_flows(struct evt_options *opt)
181 {
182         evt_dump("nb_flows", "%d", opt->nb_flows);
183 }
184
185 static inline void
186 evt_dump_worker_dequeue_depth(struct evt_options *opt)
187 {
188         evt_dump("worker deq depth", "%d", opt->wkr_deq_dep);
189 }
190
191 static inline void
192 evt_dump_nb_stages(struct evt_options *opt)
193 {
194         evt_dump("nb_stages", "%d", opt->nb_stages);
195 }
196
197 static inline void
198 evt_dump_fwd_latency(struct evt_options *opt)
199 {
200         evt_dump("fwd_latency", "%s", EVT_BOOL_FMT(opt->fwd_latency));
201 }
202
203 static inline void
204 evt_dump_queue_priority(struct evt_options *opt)
205 {
206         evt_dump("queue_priority", "%s", EVT_BOOL_FMT(opt->q_priority));
207 }
208
209 static inline const char*
210 evt_sched_type_2_str(uint8_t sched_type)
211 {
212
213         if (sched_type == RTE_SCHED_TYPE_ORDERED)
214                 return "O";
215         else if (sched_type == RTE_SCHED_TYPE_ATOMIC)
216                 return "A";
217         else if (sched_type == RTE_SCHED_TYPE_PARALLEL)
218                 return "P";
219         else
220                 return "I";
221 }
222
223 static inline void
224 evt_dump_sched_type_list(struct evt_options *opt)
225 {
226         int i;
227
228         evt_dump_begin("sched_type_list");
229         for (i = 0; i < opt->nb_stages; i++)
230                 printf("%s ", evt_sched_type_2_str(opt->sched_type_list[i]));
231
232         evt_dump_end;
233 }
234
235 static inline const char *
236 evt_prod_id_to_name(enum evt_prod_type prod_type)
237 {
238         switch (prod_type) {
239         default:
240         case EVT_PROD_TYPE_SYNT:
241                 return "Synthetic producer lcores";
242         case EVT_PROD_TYPE_ETH_RX_ADPTR:
243                 return "Ethdev Rx Adapter";
244         case EVT_PROD_TYPE_EVENT_TIMER_ADPTR:
245                 return "Event timer adapter";
246         }
247
248         return "";
249 }
250
251 #define EVT_PROD_MAX_NAME_LEN 50
252 static inline void
253 evt_dump_producer_type(struct evt_options *opt)
254 {
255         char name[EVT_PROD_MAX_NAME_LEN];
256
257         switch (opt->prod_type) {
258         default:
259         case EVT_PROD_TYPE_SYNT:
260                 snprintf(name, EVT_PROD_MAX_NAME_LEN,
261                                 "Synthetic producer lcores");
262                 break;
263         case EVT_PROD_TYPE_ETH_RX_ADPTR:
264                 snprintf(name, EVT_PROD_MAX_NAME_LEN,
265                                 "Ethdev Rx Adapter producers");
266                 evt_dump("nb_ethdev", "%d", rte_eth_dev_count_avail());
267                 break;
268         case EVT_PROD_TYPE_EVENT_TIMER_ADPTR:
269                 if (opt->timdev_use_burst)
270                         snprintf(name, EVT_PROD_MAX_NAME_LEN,
271                                 "Event timer adapter burst mode producer");
272                 else
273                         snprintf(name, EVT_PROD_MAX_NAME_LEN,
274                                 "Event timer adapter producer");
275                 evt_dump("nb_timer_adapters", "%d", opt->nb_timer_adptrs);
276                 evt_dump("max_tmo_nsec", "%"PRIu64"", opt->max_tmo_nsec);
277                 evt_dump("expiry_nsec", "%"PRIu64"", opt->expiry_nsec);
278                 if (opt->optm_timer_tick_nsec)
279                         evt_dump("optm_timer_tick_nsec", "%"PRIu64"",
280                                         opt->optm_timer_tick_nsec);
281                 else
282                         evt_dump("timer_tick_nsec", "%"PRIu64"",
283                                         opt->timer_tick_nsec);
284                 break;
285         }
286         evt_dump("prod_type", "%s", name);
287 }
288
289 #endif /* _EVT_OPTIONS_ */