1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2017 Cavium, Inc 3 */ 4 5 #ifndef _EVT_COMMON_ 6 #define _EVT_COMMON_ 7 8 #include <rte_common.h> 9 #include <rte_debug.h> 10 #include <rte_eventdev.h> 11 #include <rte_service.h> 12 13 #define CLNRM "\x1b[0m" 14 #define CLRED "\x1b[31m" 15 #define CLGRN "\x1b[32m" 16 #define CLYEL "\x1b[33m" 17 18 #define evt_err(fmt, args...) \ 19 fprintf(stderr, CLRED"error: %s() "fmt CLNRM "\n", __func__, ## args) 20 21 #define evt_info(fmt, args...) \ 22 fprintf(stdout, CLYEL""fmt CLNRM "\n", ## args) 23 24 #define EVT_STR_FMT 20 25 26 #define evt_dump(str, fmt, val...) \ 27 printf("\t%-*s : "fmt"\n", EVT_STR_FMT, str, ## val) 28 29 #define evt_dump_begin(str) printf("\t%-*s : {", EVT_STR_FMT, str) 30 31 #define evt_dump_end printf("\b}\n") 32 33 #define EVT_MAX_STAGES 64 34 #define EVT_MAX_PORTS 256 35 #define EVT_MAX_QUEUES 256 36 37 enum evt_prod_type { 38 EVT_PROD_TYPE_NONE, 39 EVT_PROD_TYPE_SYNT, /* Producer type Synthetic i.e. CPU. */ 40 EVT_PROD_TYPE_ETH_RX_ADPTR, /* Producer type Eth Rx Adapter. */ 41 EVT_PROD_TYPE_EVENT_TIMER_ADPTR, /* Producer type Timer Adapter. */ 42 EVT_PROD_TYPE_MAX, 43 }; 44 45 struct evt_options { 46 #define EVT_TEST_NAME_MAX_LEN 32 47 char test_name[EVT_TEST_NAME_MAX_LEN]; 48 bool plcores[RTE_MAX_LCORE]; 49 bool wlcores[RTE_MAX_LCORE]; 50 uint8_t sched_type_list[EVT_MAX_STAGES]; 51 uint32_t nb_flows; 52 int socket_id; 53 int pool_sz; 54 int nb_stages; 55 int verbose_level; 56 uint64_t nb_pkts; 57 uint8_t nb_timer_adptrs; 58 uint64_t nb_timers; 59 uint64_t timer_tick_nsec; 60 uint64_t optm_timer_tick_nsec; 61 uint64_t max_tmo_nsec; 62 uint64_t expiry_nsec; 63 uint16_t wkr_deq_dep; 64 uint8_t dev_id; 65 uint32_t tx_first; 66 uint32_t fwd_latency:1; 67 uint32_t q_priority:1; 68 uint32_t deq_tmo_nsec; 69 enum evt_prod_type prod_type; 70 uint8_t timdev_use_burst; 71 uint8_t timdev_cnt; 72 }; 73 74 static inline bool 75 evt_has_distributed_sched(uint8_t dev_id) 76 { 77 struct rte_event_dev_info dev_info; 78 79 rte_event_dev_info_get(dev_id, &dev_info); 80 return (dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED) ? 81 true : false; 82 } 83 84 static inline bool 85 evt_has_burst_mode(uint8_t dev_id) 86 { 87 struct rte_event_dev_info dev_info; 88 89 rte_event_dev_info_get(dev_id, &dev_info); 90 return (dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_BURST_MODE) ? 91 true : false; 92 } 93 94 95 static inline bool 96 evt_has_all_types_queue(uint8_t dev_id) 97 { 98 struct rte_event_dev_info dev_info; 99 100 rte_event_dev_info_get(dev_id, &dev_info); 101 return (dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_QUEUE_ALL_TYPES) ? 102 true : false; 103 } 104 105 static inline int 106 evt_service_setup(uint32_t service_id) 107 { 108 int32_t core_cnt; 109 unsigned int lcore = 0; 110 uint32_t core_array[RTE_MAX_LCORE]; 111 uint8_t cnt; 112 uint8_t min_cnt = UINT8_MAX; 113 114 if (!rte_service_lcore_count()) 115 return -ENOENT; 116 117 core_cnt = rte_service_lcore_list(core_array, 118 RTE_MAX_LCORE); 119 if (core_cnt < 0) 120 return -ENOENT; 121 /* Get the core which has least number of services running. */ 122 while (core_cnt--) { 123 /* Reset default mapping */ 124 rte_service_map_lcore_set(service_id, 125 core_array[core_cnt], 0); 126 cnt = rte_service_lcore_count_services( 127 core_array[core_cnt]); 128 if (cnt < min_cnt) { 129 lcore = core_array[core_cnt]; 130 min_cnt = cnt; 131 } 132 } 133 if (rte_service_map_lcore_set(service_id, lcore, 1)) 134 return -ENOENT; 135 136 return 0; 137 } 138 139 static inline int 140 evt_configure_eventdev(struct evt_options *opt, uint8_t nb_queues, 141 uint8_t nb_ports) 142 { 143 struct rte_event_dev_info info; 144 int ret; 145 146 memset(&info, 0, sizeof(struct rte_event_dev_info)); 147 ret = rte_event_dev_info_get(opt->dev_id, &info); 148 if (ret) { 149 evt_err("failed to get eventdev info %d", opt->dev_id); 150 return ret; 151 } 152 153 if (opt->deq_tmo_nsec) { 154 if (opt->deq_tmo_nsec < info.min_dequeue_timeout_ns) { 155 opt->deq_tmo_nsec = info.min_dequeue_timeout_ns; 156 evt_info("dequeue_timeout_ns too low, using %d", 157 opt->deq_tmo_nsec); 158 } 159 if (opt->deq_tmo_nsec > info.max_dequeue_timeout_ns) { 160 opt->deq_tmo_nsec = info.max_dequeue_timeout_ns; 161 evt_info("dequeue_timeout_ns too high, using %d", 162 opt->deq_tmo_nsec); 163 } 164 } 165 166 const struct rte_event_dev_config config = { 167 .dequeue_timeout_ns = opt->deq_tmo_nsec, 168 .nb_event_queues = nb_queues, 169 .nb_event_ports = nb_ports, 170 .nb_events_limit = info.max_num_events, 171 .nb_event_queue_flows = opt->nb_flows, 172 .nb_event_port_dequeue_depth = 173 info.max_event_port_dequeue_depth, 174 .nb_event_port_enqueue_depth = 175 info.max_event_port_enqueue_depth, 176 }; 177 178 return rte_event_dev_configure(opt->dev_id, &config); 179 } 180 181 #endif /* _EVT_COMMON_*/ 182