153a3b7e8SJerin Jacob /* SPDX-License-Identifier: BSD-3-Clause 253a3b7e8SJerin Jacob * Copyright(c) 2017 Cavium, Inc 3ffbae86fSJerin Jacob */ 4ffbae86fSJerin Jacob 5ffbae86fSJerin Jacob #ifndef _TEST_PERF_COMMON_ 6ffbae86fSJerin Jacob #define _TEST_PERF_COMMON_ 7ffbae86fSJerin Jacob 8ffbae86fSJerin Jacob #include <stdio.h> 9ffbae86fSJerin Jacob #include <stdbool.h> 10ffbae86fSJerin Jacob #include <unistd.h> 11ffbae86fSJerin Jacob 12ffbae86fSJerin Jacob #include <rte_cycles.h> 1359f697e3SPavan Nikhilesh #include <rte_ethdev.h> 14ffbae86fSJerin Jacob #include <rte_eventdev.h> 153617aae5SPavan Nikhilesh #include <rte_event_eth_rx_adapter.h> 16d008f20bSPavan Nikhilesh #include <rte_event_timer_adapter.h> 17ffbae86fSJerin Jacob #include <rte_lcore.h> 18ffbae86fSJerin Jacob #include <rte_malloc.h> 19ffbae86fSJerin Jacob #include <rte_mempool.h> 20ffbae86fSJerin Jacob #include <rte_prefetch.h> 21ffbae86fSJerin Jacob 22ffbae86fSJerin Jacob #include "evt_common.h" 23ffbae86fSJerin Jacob #include "evt_options.h" 24ffbae86fSJerin Jacob #include "evt_test.h" 25ffbae86fSJerin Jacob 26ffbae86fSJerin Jacob struct test_perf; 27ffbae86fSJerin Jacob 28ffbae86fSJerin Jacob struct worker_data { 29ffbae86fSJerin Jacob uint64_t processed_pkts; 30ffbae86fSJerin Jacob uint64_t latency; 31ffbae86fSJerin Jacob uint8_t dev_id; 32ffbae86fSJerin Jacob uint8_t port_id; 33ffbae86fSJerin Jacob struct test_perf *t; 34ffbae86fSJerin Jacob } __rte_cache_aligned; 35ffbae86fSJerin Jacob 36ffbae86fSJerin Jacob struct prod_data { 37ffbae86fSJerin Jacob uint8_t dev_id; 38ffbae86fSJerin Jacob uint8_t port_id; 39ffbae86fSJerin Jacob uint8_t queue_id; 40ffbae86fSJerin Jacob struct test_perf *t; 41ffbae86fSJerin Jacob } __rte_cache_aligned; 42ffbae86fSJerin Jacob 43d008f20bSPavan Nikhilesh 44ffbae86fSJerin Jacob struct test_perf { 45ffbae86fSJerin Jacob /* Don't change the offset of "done". Signal handler use this memory 46ffbae86fSJerin Jacob * to terminate all lcores work. 47ffbae86fSJerin Jacob */ 48ffbae86fSJerin Jacob int done; 49ffbae86fSJerin Jacob uint64_t outstand_pkts; 50ffbae86fSJerin Jacob uint8_t nb_workers; 51ffbae86fSJerin Jacob enum evt_test_result result; 52ffbae86fSJerin Jacob uint32_t nb_flows; 53ffbae86fSJerin Jacob uint64_t nb_pkts; 54ffbae86fSJerin Jacob struct rte_mempool *pool; 55ffbae86fSJerin Jacob struct prod_data prod[EVT_MAX_PORTS]; 56ffbae86fSJerin Jacob struct worker_data worker[EVT_MAX_PORTS]; 57ffbae86fSJerin Jacob struct evt_options *opt; 58ffbae86fSJerin Jacob uint8_t sched_type_list[EVT_MAX_STAGES] __rte_cache_aligned; 59d008f20bSPavan Nikhilesh struct rte_event_timer_adapter *timer_adptr[ 60d008f20bSPavan Nikhilesh RTE_EVENT_TIMER_ADAPTER_NUM_MAX] __rte_cache_aligned; 61ffbae86fSJerin Jacob } __rte_cache_aligned; 62ffbae86fSJerin Jacob 6341c219e6SJerin Jacob struct perf_elt { 64d008f20bSPavan Nikhilesh union { 65d008f20bSPavan Nikhilesh struct rte_event_timer tim; 66d008f20bSPavan Nikhilesh struct { 67d008f20bSPavan Nikhilesh char pad[offsetof(struct rte_event_timer, user_meta)]; 6841c219e6SJerin Jacob uint64_t timestamp; 69d008f20bSPavan Nikhilesh }; 70d008f20bSPavan Nikhilesh }; 7141c219e6SJerin Jacob } __rte_cache_aligned; 7241c219e6SJerin Jacob 732369f733SJerin Jacob #define BURST_SIZE 16 742369f733SJerin Jacob 752369f733SJerin Jacob #define PERF_WORKER_INIT\ 762369f733SJerin Jacob struct worker_data *w = arg;\ 772369f733SJerin Jacob struct test_perf *t = w->t;\ 782369f733SJerin Jacob struct evt_options *opt = t->opt;\ 792369f733SJerin Jacob const uint8_t dev = w->dev_id;\ 802369f733SJerin Jacob const uint8_t port = w->port_id;\ 81d008f20bSPavan Nikhilesh const uint8_t prod_timer_type = \ 82d008f20bSPavan Nikhilesh opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR;\ 832369f733SJerin Jacob uint8_t *const sched_type_list = &t->sched_type_list[0];\ 842369f733SJerin Jacob struct rte_mempool *const pool = t->pool;\ 852369f733SJerin Jacob const uint8_t nb_stages = t->opt->nb_stages;\ 862369f733SJerin Jacob const uint8_t laststage = nb_stages - 1;\ 872369f733SJerin Jacob uint8_t cnt = 0;\ 882369f733SJerin Jacob void *bufs[16] __rte_cache_aligned;\ 892369f733SJerin Jacob int const sz = RTE_DIM(bufs);\ 902369f733SJerin Jacob if (opt->verbose_level > 1)\ 912369f733SJerin Jacob printf("%s(): lcore %d dev_id %d port=%d\n", __func__,\ 922369f733SJerin Jacob rte_lcore_id(), dev, port) 932369f733SJerin Jacob 9433011cb3SThomas Monjalon static __rte_always_inline int 952369f733SJerin Jacob perf_process_last_stage(struct rte_mempool *const pool, 962369f733SJerin Jacob struct rte_event *const ev, struct worker_data *const w, 972369f733SJerin Jacob void *bufs[], int const buf_sz, uint8_t count) 982369f733SJerin Jacob { 992369f733SJerin Jacob bufs[count++] = ev->event_ptr; 100c7c033d1SFeifei Wang 101*37f60fd6SFeifei Wang /* release fence here ensures event_prt is 102*37f60fd6SFeifei Wang * stored before updating the number of 103*37f60fd6SFeifei Wang * processed packets for worker lcores 104c7c033d1SFeifei Wang */ 105*37f60fd6SFeifei Wang rte_atomic_thread_fence(__ATOMIC_RELEASE); 106c7c033d1SFeifei Wang w->processed_pkts++; 1072369f733SJerin Jacob 1082369f733SJerin Jacob if (unlikely(count == buf_sz)) { 1092369f733SJerin Jacob count = 0; 1102369f733SJerin Jacob rte_mempool_put_bulk(pool, bufs, buf_sz); 1112369f733SJerin Jacob } 1122369f733SJerin Jacob return count; 1132369f733SJerin Jacob } 1142369f733SJerin Jacob 11533011cb3SThomas Monjalon static __rte_always_inline uint8_t 1162369f733SJerin Jacob perf_process_last_stage_latency(struct rte_mempool *const pool, 1172369f733SJerin Jacob struct rte_event *const ev, struct worker_data *const w, 1182369f733SJerin Jacob void *bufs[], int const buf_sz, uint8_t count) 1192369f733SJerin Jacob { 1202369f733SJerin Jacob uint64_t latency; 1212369f733SJerin Jacob struct perf_elt *const m = ev->event_ptr; 1222369f733SJerin Jacob 1232369f733SJerin Jacob bufs[count++] = ev->event_ptr; 124c7c033d1SFeifei Wang 125*37f60fd6SFeifei Wang /* release fence here ensures event_prt is 126*37f60fd6SFeifei Wang * stored before updating the number of 127*37f60fd6SFeifei Wang * processed packets for worker lcores 128c7c033d1SFeifei Wang */ 129*37f60fd6SFeifei Wang rte_atomic_thread_fence(__ATOMIC_RELEASE); 1302369f733SJerin Jacob w->processed_pkts++; 1312369f733SJerin Jacob 1322369f733SJerin Jacob if (unlikely(count == buf_sz)) { 1332369f733SJerin Jacob count = 0; 1342369f733SJerin Jacob latency = rte_get_timer_cycles() - m->timestamp; 1352369f733SJerin Jacob rte_mempool_put_bulk(pool, bufs, buf_sz); 1362369f733SJerin Jacob } else { 1372369f733SJerin Jacob latency = rte_get_timer_cycles() - m->timestamp; 1382369f733SJerin Jacob } 1392369f733SJerin Jacob 1402369f733SJerin Jacob w->latency += latency; 1412369f733SJerin Jacob return count; 1422369f733SJerin Jacob } 1432369f733SJerin Jacob 1442369f733SJerin Jacob 145272de067SJerin Jacob static inline int 146272de067SJerin Jacob perf_nb_event_ports(struct evt_options *opt) 147272de067SJerin Jacob { 148272de067SJerin Jacob return evt_nr_active_lcores(opt->wlcores) + 149272de067SJerin Jacob evt_nr_active_lcores(opt->plcores); 150272de067SJerin Jacob } 151272de067SJerin Jacob 15241c219e6SJerin Jacob int perf_test_result(struct evt_test *test, struct evt_options *opt); 153272de067SJerin Jacob int perf_opt_check(struct evt_options *opt, uint64_t nb_queues); 154ffbae86fSJerin Jacob int perf_test_setup(struct evt_test *test, struct evt_options *opt); 1553fc8de4fSPavan Nikhilesh int perf_ethdev_setup(struct evt_test *test, struct evt_options *opt); 15641c219e6SJerin Jacob int perf_mempool_setup(struct evt_test *test, struct evt_options *opt); 15784a7513dSJerin Jacob int perf_event_dev_port_setup(struct evt_test *test, struct evt_options *opt, 158535c630cSPavan Nikhilesh uint8_t stride, uint8_t nb_queues, 159535c630cSPavan Nikhilesh const struct rte_event_port_conf *port_conf); 16057305d79SPavan Nikhilesh int perf_event_dev_service_setup(uint8_t dev_id); 1619d3aeb18SJerin Jacob int perf_launch_lcores(struct evt_test *test, struct evt_options *opt, 1629d3aeb18SJerin Jacob int (*worker)(void *)); 163272de067SJerin Jacob void perf_opt_dump(struct evt_options *opt, uint8_t nb_queues); 164ffbae86fSJerin Jacob void perf_test_destroy(struct evt_test *test, struct evt_options *opt); 16541c219e6SJerin Jacob void perf_eventdev_destroy(struct evt_test *test, struct evt_options *opt); 1667f3daf34SPavan Nikhilesh void perf_ethdev_destroy(struct evt_test *test, struct evt_options *opt); 16741c219e6SJerin Jacob void perf_mempool_destroy(struct evt_test *test, struct evt_options *opt); 168ffbae86fSJerin Jacob 169ffbae86fSJerin Jacob #endif /* _TEST_PERF_COMMON_ */ 170