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