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