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