d8a9fdcc5272e69e61e57217446e6df53ccabbe0
[deb_dpdk.git] / app / test-eventdev / evt_options.h
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright (C) Cavium, Inc 2017.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above copyright
13  *       notice, this list of conditions and the following disclaimer in
14  *       the documentation and/or other materials provided with the
15  *       distribution.
16  *     * Neither the name of Cavium, Inc nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef _EVT_OPTIONS_
34 #define _EVT_OPTIONS_
35
36 #include <stdio.h>
37 #include <stdbool.h>
38
39 #include <rte_common.h>
40 #include <rte_eventdev.h>
41 #include <rte_lcore.h>
42
43 #include "evt_common.h"
44
45 #define EVT_BOOL_FMT(x)          ((x) ? "true" : "false")
46
47 #define EVT_VERBOSE              ("verbose")
48 #define EVT_DEVICE               ("dev")
49 #define EVT_TEST                 ("test")
50 #define EVT_SCHED_LCORE          ("slcore")
51 #define EVT_PROD_LCORES          ("plcores")
52 #define EVT_WORK_LCORES          ("wlcores")
53 #define EVT_NB_FLOWS             ("nb_flows")
54 #define EVT_SOCKET_ID            ("socket_id")
55 #define EVT_POOL_SZ              ("pool_sz")
56 #define EVT_WKR_DEQ_DEP          ("worker_deq_depth")
57 #define EVT_NB_PKTS              ("nb_pkts")
58 #define EVT_NB_STAGES            ("nb_stages")
59 #define EVT_SCHED_TYPE_LIST      ("stlist")
60 #define EVT_FWD_LATENCY          ("fwd_latency")
61 #define EVT_QUEUE_PRIORITY       ("queue_priority")
62 #define EVT_HELP                 ("help")
63
64 struct evt_options {
65 #define EVT_TEST_NAME_MAX_LEN     32
66         char test_name[EVT_TEST_NAME_MAX_LEN];
67         bool plcores[RTE_MAX_LCORE];
68         bool wlcores[RTE_MAX_LCORE];
69         uint8_t sched_type_list[EVT_MAX_STAGES];
70         int slcore;
71         uint32_t nb_flows;
72         int socket_id;
73         int pool_sz;
74         int nb_stages;
75         int verbose_level;
76         uint64_t nb_pkts;
77         uint16_t wkr_deq_dep;
78         uint8_t dev_id;
79         uint32_t fwd_latency:1;
80         uint32_t q_priority:1;
81 };
82
83 void evt_options_default(struct evt_options *opt);
84 int evt_options_parse(struct evt_options *opt, int argc, char **argv);
85 void evt_options_dump(struct evt_options *opt);
86
87 /* options check helpers */
88 static inline bool
89 evt_lcores_has_overlap(bool lcores[], int lcore)
90 {
91         if (lcores[lcore] == true) {
92                 evt_err("lcore overlaps at %d", lcore);
93                 return true;
94         }
95
96         return false;
97 }
98
99 static inline bool
100 evt_lcores_has_overlap_multi(bool lcoresx[], bool lcoresy[])
101 {
102         int i;
103
104         for (i = 0; i < RTE_MAX_LCORE; i++) {
105                 if (lcoresx[i] && lcoresy[i]) {
106                         evt_err("lcores overlaps at %d", i);
107                         return true;
108                 }
109         }
110         return false;
111 }
112
113 static inline bool
114 evt_has_active_lcore(bool lcores[])
115 {
116         int i;
117
118         for (i = 0; i < RTE_MAX_LCORE; i++)
119                 if (lcores[i])
120                         return true;
121         return false;
122 }
123
124 static inline int
125 evt_nr_active_lcores(bool lcores[])
126 {
127         int i;
128         int c = 0;
129
130         for (i = 0; i < RTE_MAX_LCORE; i++)
131                 if (lcores[i])
132                         c++;
133         return c;
134 }
135
136 static inline int
137 evt_get_first_active_lcore(bool lcores[])
138 {
139         int i;
140
141         for (i = 0; i < RTE_MAX_LCORE; i++)
142                 if (lcores[i])
143                         return i;
144         return -1;
145 }
146
147 static inline bool
148 evt_has_disabled_lcore(bool lcores[])
149 {
150         int i;
151
152         for (i = 0; i < RTE_MAX_LCORE; i++)
153                 if ((lcores[i] == true) && !(rte_lcore_is_enabled(i)))
154                         return true;
155         return false;
156 }
157
158 static inline bool
159 evt_has_invalid_stage(struct evt_options *opt)
160 {
161         if (!opt->nb_stages) {
162                 evt_err("need minimum one stage, check --stlist");
163                 return true;
164         }
165         if (opt->nb_stages > EVT_MAX_STAGES) {
166                 evt_err("requested changes are beyond EVT_MAX_STAGES=%d",
167                         EVT_MAX_STAGES);
168                 return true;
169         }
170         return false;
171 }
172
173 static inline bool
174 evt_has_invalid_sched_type(struct evt_options *opt)
175 {
176         int i;
177
178         for (i = 0; i < opt->nb_stages; i++) {
179                 if (opt->sched_type_list[i] > RTE_SCHED_TYPE_PARALLEL) {
180                         evt_err("invalid sched_type %d at %d",
181                                 opt->sched_type_list[i], i);
182                         return true;
183                 }
184         }
185         return false;
186 }
187
188 /* option dump helpers */
189 static inline void
190 evt_dump_worker_lcores(struct evt_options *opt)
191 {
192         int c;
193
194         evt_dump_begin("worker lcores");
195         for  (c = 0; c < RTE_MAX_LCORE; c++) {
196                 if (opt->wlcores[c])
197                         printf("%d ", c);
198         }
199         evt_dump_end;
200 }
201
202 static inline void
203 evt_dump_producer_lcores(struct evt_options *opt)
204 {
205         int c;
206
207         evt_dump_begin("producer lcores");
208         for  (c = 0; c < RTE_MAX_LCORE; c++) {
209                 if (opt->plcores[c])
210                         printf("%d ", c);
211         }
212         evt_dump_end;
213 }
214
215 static inline void
216 evt_dump_nb_flows(struct evt_options *opt)
217 {
218         evt_dump("nb_flows", "%d", opt->nb_flows);
219 }
220
221 static inline void
222 evt_dump_scheduler_lcore(struct evt_options *opt)
223 {
224         evt_dump("scheduler lcore", "%d", opt->slcore);
225 }
226
227 static inline void
228 evt_dump_worker_dequeue_depth(struct evt_options *opt)
229 {
230         evt_dump("worker deq depth", "%d", opt->wkr_deq_dep);
231 }
232
233 static inline void
234 evt_dump_nb_stages(struct evt_options *opt)
235 {
236         evt_dump("nb_stages", "%d", opt->nb_stages);
237 }
238
239 static inline void
240 evt_dump_fwd_latency(struct evt_options *opt)
241 {
242         evt_dump("fwd_latency", "%s", EVT_BOOL_FMT(opt->fwd_latency));
243 }
244
245 static inline void
246 evt_dump_queue_priority(struct evt_options *opt)
247 {
248         evt_dump("queue_priority", "%s", EVT_BOOL_FMT(opt->q_priority));
249 }
250
251 static inline const char*
252 evt_sched_type_2_str(uint8_t sched_type)
253 {
254
255         if (sched_type == RTE_SCHED_TYPE_ORDERED)
256                 return "O";
257         else if (sched_type == RTE_SCHED_TYPE_ATOMIC)
258                 return "A";
259         else if (sched_type == RTE_SCHED_TYPE_PARALLEL)
260                 return "P";
261         else
262                 return "I";
263 }
264
265 static inline void
266 evt_dump_sched_type_list(struct evt_options *opt)
267 {
268         int i;
269
270         evt_dump_begin("sched_type_list");
271         for (i = 0; i < opt->nb_stages; i++)
272                 printf("%s ", evt_sched_type_2_str(opt->sched_type_list[i]));
273
274         evt_dump_end;
275 }
276
277 #endif /* _EVT_OPTIONS_ */