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