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