153a3b7e8SJerin Jacob /* SPDX-License-Identifier: BSD-3-Clause 253a3b7e8SJerin Jacob * Copyright(c) 2017 Cavium, Inc 3ffbae86fSJerin Jacob */ 4ffbae86fSJerin Jacob 5ffbae86fSJerin Jacob #include "test_perf_common.h" 6ffbae86fSJerin Jacob 741c219e6SJerin Jacob int 841c219e6SJerin Jacob perf_test_result(struct evt_test *test, struct evt_options *opt) 941c219e6SJerin Jacob { 1041c219e6SJerin Jacob RTE_SET_USED(opt); 116b1a14a8SPavan Nikhilesh int i; 126b1a14a8SPavan Nikhilesh uint64_t total = 0; 1341c219e6SJerin Jacob struct test_perf *t = evt_test_priv(test); 1441c219e6SJerin Jacob 156b1a14a8SPavan Nikhilesh printf("Packet distribution across worker cores :\n"); 166b1a14a8SPavan Nikhilesh for (i = 0; i < t->nb_workers; i++) 176b1a14a8SPavan Nikhilesh total += t->worker[i].processed_pkts; 186b1a14a8SPavan Nikhilesh for (i = 0; i < t->nb_workers; i++) 196b1a14a8SPavan Nikhilesh printf("Worker %d packets: "CLGRN"%"PRIx64" "CLNRM"percentage:" 206b1a14a8SPavan Nikhilesh CLGRN" %3.2f\n"CLNRM, i, 216b1a14a8SPavan Nikhilesh t->worker[i].processed_pkts, 226b1a14a8SPavan Nikhilesh (((double)t->worker[i].processed_pkts)/total) 236b1a14a8SPavan Nikhilesh * 100); 246b1a14a8SPavan Nikhilesh 2541c219e6SJerin Jacob return t->result; 2641c219e6SJerin Jacob } 2741c219e6SJerin Jacob 289d3aeb18SJerin Jacob static inline int 299d3aeb18SJerin Jacob perf_producer(void *arg) 309d3aeb18SJerin Jacob { 319d3aeb18SJerin Jacob struct prod_data *p = arg; 329d3aeb18SJerin Jacob struct test_perf *t = p->t; 339d3aeb18SJerin Jacob struct evt_options *opt = t->opt; 349d3aeb18SJerin Jacob const uint8_t dev_id = p->dev_id; 359d3aeb18SJerin Jacob const uint8_t port = p->port_id; 369d3aeb18SJerin Jacob struct rte_mempool *pool = t->pool; 379d3aeb18SJerin Jacob const uint64_t nb_pkts = t->nb_pkts; 389d3aeb18SJerin Jacob const uint32_t nb_flows = t->nb_flows; 399d3aeb18SJerin Jacob uint32_t flow_counter = 0; 409d3aeb18SJerin Jacob uint64_t count = 0; 419d3aeb18SJerin Jacob struct perf_elt *m; 429d3aeb18SJerin Jacob struct rte_event ev; 439d3aeb18SJerin Jacob 449d3aeb18SJerin Jacob if (opt->verbose_level > 1) 459d3aeb18SJerin Jacob printf("%s(): lcore %d dev_id %d port=%d queue %d\n", __func__, 469d3aeb18SJerin Jacob rte_lcore_id(), dev_id, port, p->queue_id); 479d3aeb18SJerin Jacob 489d3aeb18SJerin Jacob ev.event = 0; 499d3aeb18SJerin Jacob ev.op = RTE_EVENT_OP_NEW; 509d3aeb18SJerin Jacob ev.queue_id = p->queue_id; 519d3aeb18SJerin Jacob ev.sched_type = t->opt->sched_type_list[0]; 529d3aeb18SJerin Jacob ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL; 539d3aeb18SJerin Jacob ev.event_type = RTE_EVENT_TYPE_CPU; 549d3aeb18SJerin Jacob ev.sub_event_type = 0; /* stage 0 */ 559d3aeb18SJerin Jacob 569d3aeb18SJerin Jacob while (count < nb_pkts && t->done == false) { 579d3aeb18SJerin Jacob if (rte_mempool_get(pool, (void **)&m) < 0) 589d3aeb18SJerin Jacob continue; 599d3aeb18SJerin Jacob 609d3aeb18SJerin Jacob ev.flow_id = flow_counter++ % nb_flows; 619d3aeb18SJerin Jacob ev.event_ptr = m; 629d3aeb18SJerin Jacob m->timestamp = rte_get_timer_cycles(); 639d3aeb18SJerin Jacob while (rte_event_enqueue_burst(dev_id, port, &ev, 1) != 1) { 649d3aeb18SJerin Jacob if (t->done) 659d3aeb18SJerin Jacob break; 669d3aeb18SJerin Jacob rte_pause(); 679d3aeb18SJerin Jacob m->timestamp = rte_get_timer_cycles(); 689d3aeb18SJerin Jacob } 699d3aeb18SJerin Jacob count++; 709d3aeb18SJerin Jacob } 719d3aeb18SJerin Jacob 729d3aeb18SJerin Jacob return 0; 739d3aeb18SJerin Jacob } 749d3aeb18SJerin Jacob 75d008f20bSPavan Nikhilesh static inline int 76d008f20bSPavan Nikhilesh perf_event_timer_producer(void *arg) 77d008f20bSPavan Nikhilesh { 78d008f20bSPavan Nikhilesh struct prod_data *p = arg; 79d008f20bSPavan Nikhilesh struct test_perf *t = p->t; 80d008f20bSPavan Nikhilesh struct evt_options *opt = t->opt; 81d008f20bSPavan Nikhilesh uint32_t flow_counter = 0; 82d008f20bSPavan Nikhilesh uint64_t count = 0; 83d008f20bSPavan Nikhilesh uint64_t arm_latency = 0; 84d008f20bSPavan Nikhilesh const uint8_t nb_timer_adptrs = opt->nb_timer_adptrs; 85d008f20bSPavan Nikhilesh const uint32_t nb_flows = t->nb_flows; 86d008f20bSPavan Nikhilesh const uint64_t nb_timers = opt->nb_timers; 87d008f20bSPavan Nikhilesh struct rte_mempool *pool = t->pool; 88d008f20bSPavan Nikhilesh struct perf_elt *m; 89d008f20bSPavan Nikhilesh struct rte_event_timer_adapter **adptr = t->timer_adptr; 9052553263SPavan Nikhilesh struct rte_event_timer tim; 91d008f20bSPavan Nikhilesh uint64_t timeout_ticks = opt->expiry_nsec / opt->timer_tick_nsec; 92d008f20bSPavan Nikhilesh 9352553263SPavan Nikhilesh memset(&tim, 0, sizeof(struct rte_event_timer)); 94d008f20bSPavan Nikhilesh timeout_ticks = opt->optm_timer_tick_nsec ? 95d008f20bSPavan Nikhilesh (timeout_ticks * opt->timer_tick_nsec) 96d008f20bSPavan Nikhilesh / opt->optm_timer_tick_nsec : timeout_ticks; 97d008f20bSPavan Nikhilesh timeout_ticks += timeout_ticks ? 0 : 1; 9852553263SPavan Nikhilesh tim.ev.event_type = RTE_EVENT_TYPE_TIMER; 9952553263SPavan Nikhilesh tim.ev.op = RTE_EVENT_OP_NEW; 10052553263SPavan Nikhilesh tim.ev.sched_type = t->opt->sched_type_list[0]; 10152553263SPavan Nikhilesh tim.ev.queue_id = p->queue_id; 10252553263SPavan Nikhilesh tim.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL; 10352553263SPavan Nikhilesh tim.state = RTE_EVENT_TIMER_NOT_ARMED; 10452553263SPavan Nikhilesh tim.timeout_ticks = timeout_ticks; 105d008f20bSPavan Nikhilesh 106d008f20bSPavan Nikhilesh if (opt->verbose_level > 1) 107d008f20bSPavan Nikhilesh printf("%s(): lcore %d\n", __func__, rte_lcore_id()); 108d008f20bSPavan Nikhilesh 109d008f20bSPavan Nikhilesh while (count < nb_timers && t->done == false) { 110d008f20bSPavan Nikhilesh if (rte_mempool_get(pool, (void **)&m) < 0) 111d008f20bSPavan Nikhilesh continue; 112d008f20bSPavan Nikhilesh 113d008f20bSPavan Nikhilesh m->tim = tim; 114d008f20bSPavan Nikhilesh m->tim.ev.flow_id = flow_counter++ % nb_flows; 115d008f20bSPavan Nikhilesh m->tim.ev.event_ptr = m; 116d008f20bSPavan Nikhilesh m->timestamp = rte_get_timer_cycles(); 117d008f20bSPavan Nikhilesh while (rte_event_timer_arm_burst( 118d008f20bSPavan Nikhilesh adptr[flow_counter % nb_timer_adptrs], 119d008f20bSPavan Nikhilesh (struct rte_event_timer **)&m, 1) != 1) { 120d008f20bSPavan Nikhilesh if (t->done) 121d008f20bSPavan Nikhilesh break; 122d008f20bSPavan Nikhilesh rte_pause(); 123d008f20bSPavan Nikhilesh m->timestamp = rte_get_timer_cycles(); 124d008f20bSPavan Nikhilesh } 125d008f20bSPavan Nikhilesh arm_latency += rte_get_timer_cycles() - m->timestamp; 126d008f20bSPavan Nikhilesh count++; 127d008f20bSPavan Nikhilesh } 128d008f20bSPavan Nikhilesh fflush(stdout); 129d008f20bSPavan Nikhilesh rte_delay_ms(1000); 130d008f20bSPavan Nikhilesh printf("%s(): lcore %d Average event timer arm latency = %.3f us\n", 131d008f20bSPavan Nikhilesh __func__, rte_lcore_id(), (float)(arm_latency / count) / 132d008f20bSPavan Nikhilesh (rte_get_timer_hz() / 1000000)); 133d008f20bSPavan Nikhilesh return 0; 134d008f20bSPavan Nikhilesh } 135d008f20bSPavan Nikhilesh 13617b22d0bSPavan Nikhilesh static inline int 13717b22d0bSPavan Nikhilesh perf_event_timer_producer_burst(void *arg) 13817b22d0bSPavan Nikhilesh { 13917b22d0bSPavan Nikhilesh int i; 14017b22d0bSPavan Nikhilesh struct prod_data *p = arg; 14117b22d0bSPavan Nikhilesh struct test_perf *t = p->t; 14217b22d0bSPavan Nikhilesh struct evt_options *opt = t->opt; 14317b22d0bSPavan Nikhilesh uint32_t flow_counter = 0; 14417b22d0bSPavan Nikhilesh uint64_t count = 0; 14517b22d0bSPavan Nikhilesh uint64_t arm_latency = 0; 14617b22d0bSPavan Nikhilesh const uint8_t nb_timer_adptrs = opt->nb_timer_adptrs; 14717b22d0bSPavan Nikhilesh const uint32_t nb_flows = t->nb_flows; 14817b22d0bSPavan Nikhilesh const uint64_t nb_timers = opt->nb_timers; 14917b22d0bSPavan Nikhilesh struct rte_mempool *pool = t->pool; 15017b22d0bSPavan Nikhilesh struct perf_elt *m[BURST_SIZE + 1] = {NULL}; 15117b22d0bSPavan Nikhilesh struct rte_event_timer_adapter **adptr = t->timer_adptr; 15252553263SPavan Nikhilesh struct rte_event_timer tim; 15317b22d0bSPavan Nikhilesh uint64_t timeout_ticks = opt->expiry_nsec / opt->timer_tick_nsec; 15417b22d0bSPavan Nikhilesh 15552553263SPavan Nikhilesh memset(&tim, 0, sizeof(struct rte_event_timer)); 15617b22d0bSPavan Nikhilesh timeout_ticks = opt->optm_timer_tick_nsec ? 15717b22d0bSPavan Nikhilesh (timeout_ticks * opt->timer_tick_nsec) 15817b22d0bSPavan Nikhilesh / opt->optm_timer_tick_nsec : timeout_ticks; 15917b22d0bSPavan Nikhilesh timeout_ticks += timeout_ticks ? 0 : 1; 16052553263SPavan Nikhilesh tim.ev.event_type = RTE_EVENT_TYPE_TIMER; 16152553263SPavan Nikhilesh tim.ev.op = RTE_EVENT_OP_NEW; 16252553263SPavan Nikhilesh tim.ev.sched_type = t->opt->sched_type_list[0]; 16352553263SPavan Nikhilesh tim.ev.queue_id = p->queue_id; 16452553263SPavan Nikhilesh tim.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL; 16552553263SPavan Nikhilesh tim.state = RTE_EVENT_TIMER_NOT_ARMED; 16652553263SPavan Nikhilesh tim.timeout_ticks = timeout_ticks; 16717b22d0bSPavan Nikhilesh 16817b22d0bSPavan Nikhilesh if (opt->verbose_level > 1) 16917b22d0bSPavan Nikhilesh printf("%s(): lcore %d\n", __func__, rte_lcore_id()); 17017b22d0bSPavan Nikhilesh 17117b22d0bSPavan Nikhilesh while (count < nb_timers && t->done == false) { 17217b22d0bSPavan Nikhilesh if (rte_mempool_get_bulk(pool, (void **)m, BURST_SIZE) < 0) 17317b22d0bSPavan Nikhilesh continue; 17417b22d0bSPavan Nikhilesh for (i = 0; i < BURST_SIZE; i++) { 17517b22d0bSPavan Nikhilesh rte_prefetch0(m[i + 1]); 17617b22d0bSPavan Nikhilesh m[i]->tim = tim; 17717b22d0bSPavan Nikhilesh m[i]->tim.ev.flow_id = flow_counter++ % nb_flows; 17817b22d0bSPavan Nikhilesh m[i]->tim.ev.event_ptr = m[i]; 17917b22d0bSPavan Nikhilesh m[i]->timestamp = rte_get_timer_cycles(); 18017b22d0bSPavan Nikhilesh } 18117b22d0bSPavan Nikhilesh rte_event_timer_arm_tmo_tick_burst( 18217b22d0bSPavan Nikhilesh adptr[flow_counter % nb_timer_adptrs], 18317b22d0bSPavan Nikhilesh (struct rte_event_timer **)m, 18417b22d0bSPavan Nikhilesh tim.timeout_ticks, 18517b22d0bSPavan Nikhilesh BURST_SIZE); 18617b22d0bSPavan Nikhilesh arm_latency += rte_get_timer_cycles() - m[i - 1]->timestamp; 18717b22d0bSPavan Nikhilesh count += BURST_SIZE; 18817b22d0bSPavan Nikhilesh } 18917b22d0bSPavan Nikhilesh fflush(stdout); 19017b22d0bSPavan Nikhilesh rte_delay_ms(1000); 19117b22d0bSPavan Nikhilesh printf("%s(): lcore %d Average event timer arm latency = %.3f us\n", 19217b22d0bSPavan Nikhilesh __func__, rte_lcore_id(), (float)(arm_latency / count) / 19317b22d0bSPavan Nikhilesh (rte_get_timer_hz() / 1000000)); 19417b22d0bSPavan Nikhilesh return 0; 19517b22d0bSPavan Nikhilesh } 19617b22d0bSPavan Nikhilesh 19759f697e3SPavan Nikhilesh static int 19859f697e3SPavan Nikhilesh perf_producer_wrapper(void *arg) 19959f697e3SPavan Nikhilesh { 20059f697e3SPavan Nikhilesh struct prod_data *p = arg; 20159f697e3SPavan Nikhilesh struct test_perf *t = p->t; 20259f697e3SPavan Nikhilesh /* Launch the producer function only in case of synthetic producer. */ 20359f697e3SPavan Nikhilesh if (t->opt->prod_type == EVT_PROD_TYPE_SYNT) 20459f697e3SPavan Nikhilesh return perf_producer(arg); 20517b22d0bSPavan Nikhilesh else if (t->opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR && 20617b22d0bSPavan Nikhilesh !t->opt->timdev_use_burst) 207d008f20bSPavan Nikhilesh return perf_event_timer_producer(arg); 20817b22d0bSPavan Nikhilesh else if (t->opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR && 20917b22d0bSPavan Nikhilesh t->opt->timdev_use_burst) 21017b22d0bSPavan Nikhilesh return perf_event_timer_producer_burst(arg); 21159f697e3SPavan Nikhilesh return 0; 21259f697e3SPavan Nikhilesh } 21359f697e3SPavan Nikhilesh 2149d3aeb18SJerin Jacob static inline uint64_t 2159d3aeb18SJerin Jacob processed_pkts(struct test_perf *t) 2169d3aeb18SJerin Jacob { 2179d3aeb18SJerin Jacob uint8_t i; 2189d3aeb18SJerin Jacob uint64_t total = 0; 2199d3aeb18SJerin Jacob 2209d3aeb18SJerin Jacob rte_smp_rmb(); 2219d3aeb18SJerin Jacob for (i = 0; i < t->nb_workers; i++) 2229d3aeb18SJerin Jacob total += t->worker[i].processed_pkts; 2239d3aeb18SJerin Jacob 2249d3aeb18SJerin Jacob return total; 2259d3aeb18SJerin Jacob } 2269d3aeb18SJerin Jacob 2279d3aeb18SJerin Jacob static inline uint64_t 2289d3aeb18SJerin Jacob total_latency(struct test_perf *t) 2299d3aeb18SJerin Jacob { 2309d3aeb18SJerin Jacob uint8_t i; 2319d3aeb18SJerin Jacob uint64_t total = 0; 2329d3aeb18SJerin Jacob 2339d3aeb18SJerin Jacob rte_smp_rmb(); 2349d3aeb18SJerin Jacob for (i = 0; i < t->nb_workers; i++) 2359d3aeb18SJerin Jacob total += t->worker[i].latency; 2369d3aeb18SJerin Jacob 2379d3aeb18SJerin Jacob return total; 2389d3aeb18SJerin Jacob } 2399d3aeb18SJerin Jacob 2409d3aeb18SJerin Jacob 2419d3aeb18SJerin Jacob int 2429d3aeb18SJerin Jacob perf_launch_lcores(struct evt_test *test, struct evt_options *opt, 2439d3aeb18SJerin Jacob int (*worker)(void *)) 2449d3aeb18SJerin Jacob { 2459d3aeb18SJerin Jacob int ret, lcore_id; 2469d3aeb18SJerin Jacob struct test_perf *t = evt_test_priv(test); 2479d3aeb18SJerin Jacob 2489d3aeb18SJerin Jacob int port_idx = 0; 2499d3aeb18SJerin Jacob /* launch workers */ 2509d3aeb18SJerin Jacob RTE_LCORE_FOREACH_SLAVE(lcore_id) { 2519d3aeb18SJerin Jacob if (!(opt->wlcores[lcore_id])) 2529d3aeb18SJerin Jacob continue; 2539d3aeb18SJerin Jacob 2549d3aeb18SJerin Jacob ret = rte_eal_remote_launch(worker, 2559d3aeb18SJerin Jacob &t->worker[port_idx], lcore_id); 2569d3aeb18SJerin Jacob if (ret) { 2579d3aeb18SJerin Jacob evt_err("failed to launch worker %d", lcore_id); 2589d3aeb18SJerin Jacob return ret; 2599d3aeb18SJerin Jacob } 2609d3aeb18SJerin Jacob port_idx++; 2619d3aeb18SJerin Jacob } 2629d3aeb18SJerin Jacob 2639d3aeb18SJerin Jacob /* launch producers */ 2649d3aeb18SJerin Jacob RTE_LCORE_FOREACH_SLAVE(lcore_id) { 2659d3aeb18SJerin Jacob if (!(opt->plcores[lcore_id])) 2669d3aeb18SJerin Jacob continue; 2679d3aeb18SJerin Jacob 26859f697e3SPavan Nikhilesh ret = rte_eal_remote_launch(perf_producer_wrapper, 26959f697e3SPavan Nikhilesh &t->prod[port_idx], lcore_id); 2709d3aeb18SJerin Jacob if (ret) { 2719d3aeb18SJerin Jacob evt_err("failed to launch perf_producer %d", lcore_id); 2729d3aeb18SJerin Jacob return ret; 2739d3aeb18SJerin Jacob } 2749d3aeb18SJerin Jacob port_idx++; 2759d3aeb18SJerin Jacob } 2769d3aeb18SJerin Jacob 277d008f20bSPavan Nikhilesh const uint64_t total_pkts = t->outstand_pkts; 2789d3aeb18SJerin Jacob 2799d3aeb18SJerin Jacob uint64_t dead_lock_cycles = rte_get_timer_cycles(); 2809d3aeb18SJerin Jacob int64_t dead_lock_remaining = total_pkts; 2819d3aeb18SJerin Jacob const uint64_t dead_lock_sample = rte_get_timer_hz() * 5; 2829d3aeb18SJerin Jacob 2839d3aeb18SJerin Jacob uint64_t perf_cycles = rte_get_timer_cycles(); 2849d3aeb18SJerin Jacob int64_t perf_remaining = total_pkts; 2859d3aeb18SJerin Jacob const uint64_t perf_sample = rte_get_timer_hz(); 2869d3aeb18SJerin Jacob 2879d3aeb18SJerin Jacob static float total_mpps; 2889d3aeb18SJerin Jacob static uint64_t samples; 2899d3aeb18SJerin Jacob 2909d3aeb18SJerin Jacob const uint64_t freq_mhz = rte_get_timer_hz() / 1000000; 2919d3aeb18SJerin Jacob int64_t remaining = t->outstand_pkts - processed_pkts(t); 2929d3aeb18SJerin Jacob 2939d3aeb18SJerin Jacob while (t->done == false) { 2949d3aeb18SJerin Jacob const uint64_t new_cycles = rte_get_timer_cycles(); 2959d3aeb18SJerin Jacob 2969d3aeb18SJerin Jacob if ((new_cycles - perf_cycles) > perf_sample) { 2979d3aeb18SJerin Jacob const uint64_t latency = total_latency(t); 2989d3aeb18SJerin Jacob const uint64_t pkts = processed_pkts(t); 2999d3aeb18SJerin Jacob 3009d3aeb18SJerin Jacob remaining = t->outstand_pkts - pkts; 3019d3aeb18SJerin Jacob float mpps = (float)(perf_remaining-remaining)/1000000; 3029d3aeb18SJerin Jacob 3039d3aeb18SJerin Jacob perf_remaining = remaining; 3049d3aeb18SJerin Jacob perf_cycles = new_cycles; 3059d3aeb18SJerin Jacob total_mpps += mpps; 3069d3aeb18SJerin Jacob ++samples; 30704716352SJerin Jacob if (opt->fwd_latency && pkts > 0) { 3089d3aeb18SJerin Jacob printf(CLGRN"\r%.3f mpps avg %.3f mpps [avg fwd latency %.3f us] "CLNRM, 3099d3aeb18SJerin Jacob mpps, total_mpps/samples, 3109d3aeb18SJerin Jacob (float)(latency/pkts)/freq_mhz); 3119d3aeb18SJerin Jacob } else { 3129d3aeb18SJerin Jacob printf(CLGRN"\r%.3f mpps avg %.3f mpps"CLNRM, 3139d3aeb18SJerin Jacob mpps, total_mpps/samples); 3149d3aeb18SJerin Jacob } 3159d3aeb18SJerin Jacob fflush(stdout); 3169d3aeb18SJerin Jacob 3179d3aeb18SJerin Jacob if (remaining <= 0) { 3189d3aeb18SJerin Jacob t->result = EVT_TEST_SUCCESS; 319d008f20bSPavan Nikhilesh if (opt->prod_type == EVT_PROD_TYPE_SYNT || 320d008f20bSPavan Nikhilesh opt->prod_type == 321d008f20bSPavan Nikhilesh EVT_PROD_TYPE_EVENT_TIMER_ADPTR) { 32259f697e3SPavan Nikhilesh t->done = true; 3239d3aeb18SJerin Jacob rte_smp_wmb(); 3249d3aeb18SJerin Jacob break; 3259d3aeb18SJerin Jacob } 3269d3aeb18SJerin Jacob } 32759f697e3SPavan Nikhilesh } 3289d3aeb18SJerin Jacob 32959f697e3SPavan Nikhilesh if (new_cycles - dead_lock_cycles > dead_lock_sample && 33047303784SErik Gabriel Carrillo (opt->prod_type == EVT_PROD_TYPE_SYNT || 33147303784SErik Gabriel Carrillo opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR)) { 3329d3aeb18SJerin Jacob remaining = t->outstand_pkts - processed_pkts(t); 3339d3aeb18SJerin Jacob if (dead_lock_remaining == remaining) { 3349d3aeb18SJerin Jacob rte_event_dev_dump(opt->dev_id, stdout); 3359d3aeb18SJerin Jacob evt_err("No schedules for seconds, deadlock"); 3369d3aeb18SJerin Jacob t->done = true; 3379d3aeb18SJerin Jacob rte_smp_wmb(); 3389d3aeb18SJerin Jacob break; 3399d3aeb18SJerin Jacob } 3409d3aeb18SJerin Jacob dead_lock_remaining = remaining; 3419d3aeb18SJerin Jacob dead_lock_cycles = new_cycles; 3429d3aeb18SJerin Jacob } 3439d3aeb18SJerin Jacob } 3449d3aeb18SJerin Jacob printf("\n"); 3459d3aeb18SJerin Jacob return 0; 3469d3aeb18SJerin Jacob } 3479d3aeb18SJerin Jacob 3483617aae5SPavan Nikhilesh static int 3493617aae5SPavan Nikhilesh perf_event_rx_adapter_setup(struct evt_options *opt, uint8_t stride, 3503617aae5SPavan Nikhilesh struct rte_event_port_conf prod_conf) 3513617aae5SPavan Nikhilesh { 3523617aae5SPavan Nikhilesh int ret = 0; 3533617aae5SPavan Nikhilesh uint16_t prod; 3543617aae5SPavan Nikhilesh struct rte_event_eth_rx_adapter_queue_conf queue_conf; 3553617aae5SPavan Nikhilesh 3563617aae5SPavan Nikhilesh memset(&queue_conf, 0, 3573617aae5SPavan Nikhilesh sizeof(struct rte_event_eth_rx_adapter_queue_conf)); 3583617aae5SPavan Nikhilesh queue_conf.ev.sched_type = opt->sched_type_list[0]; 3598728ccf3SThomas Monjalon RTE_ETH_FOREACH_DEV(prod) { 3603617aae5SPavan Nikhilesh uint32_t cap; 3613617aae5SPavan Nikhilesh 3623617aae5SPavan Nikhilesh ret = rte_event_eth_rx_adapter_caps_get(opt->dev_id, 3633617aae5SPavan Nikhilesh prod, &cap); 3643617aae5SPavan Nikhilesh if (ret) { 3653617aae5SPavan Nikhilesh evt_err("failed to get event rx adapter[%d]" 3663617aae5SPavan Nikhilesh " capabilities", 3673617aae5SPavan Nikhilesh opt->dev_id); 3683617aae5SPavan Nikhilesh return ret; 3693617aae5SPavan Nikhilesh } 3703617aae5SPavan Nikhilesh queue_conf.ev.queue_id = prod * stride; 3713617aae5SPavan Nikhilesh ret = rte_event_eth_rx_adapter_create(prod, opt->dev_id, 3723617aae5SPavan Nikhilesh &prod_conf); 3733617aae5SPavan Nikhilesh if (ret) { 3743617aae5SPavan Nikhilesh evt_err("failed to create rx adapter[%d]", prod); 3753617aae5SPavan Nikhilesh return ret; 3763617aae5SPavan Nikhilesh } 3773617aae5SPavan Nikhilesh ret = rte_event_eth_rx_adapter_queue_add(prod, prod, -1, 3783617aae5SPavan Nikhilesh &queue_conf); 3793617aae5SPavan Nikhilesh if (ret) { 3803617aae5SPavan Nikhilesh evt_err("failed to add rx queues to adapter[%d]", prod); 3813617aae5SPavan Nikhilesh return ret; 3823617aae5SPavan Nikhilesh } 3833617aae5SPavan Nikhilesh 384b0333c55SPavan Nikhilesh if (!(cap & RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT)) { 385b0333c55SPavan Nikhilesh uint32_t service_id; 386b0333c55SPavan Nikhilesh 387b0333c55SPavan Nikhilesh rte_event_eth_rx_adapter_service_id_get(prod, 388b0333c55SPavan Nikhilesh &service_id); 389b0333c55SPavan Nikhilesh ret = evt_service_setup(service_id); 390b0333c55SPavan Nikhilesh if (ret) { 391b0333c55SPavan Nikhilesh evt_err("Failed to setup service core" 392b0333c55SPavan Nikhilesh " for Rx adapter\n"); 393b0333c55SPavan Nikhilesh return ret; 394b0333c55SPavan Nikhilesh } 395b0333c55SPavan Nikhilesh } 396b0333c55SPavan Nikhilesh 3973617aae5SPavan Nikhilesh ret = rte_eth_dev_start(prod); 3983617aae5SPavan Nikhilesh if (ret) { 3993617aae5SPavan Nikhilesh evt_err("Ethernet dev [%d] failed to start." 4003617aae5SPavan Nikhilesh " Using synthetic producer", prod); 4013617aae5SPavan Nikhilesh return ret; 4023617aae5SPavan Nikhilesh } 4033617aae5SPavan Nikhilesh 4043617aae5SPavan Nikhilesh ret = rte_event_eth_rx_adapter_start(prod); 4053617aae5SPavan Nikhilesh if (ret) { 4063617aae5SPavan Nikhilesh evt_err("Rx adapter[%d] start failed", prod); 4073617aae5SPavan Nikhilesh return ret; 4083617aae5SPavan Nikhilesh } 4093617aae5SPavan Nikhilesh printf("%s: Port[%d] using Rx adapter[%d] started\n", __func__, 4103617aae5SPavan Nikhilesh prod, prod); 4113617aae5SPavan Nikhilesh } 4123617aae5SPavan Nikhilesh 4133617aae5SPavan Nikhilesh return ret; 4143617aae5SPavan Nikhilesh } 4153617aae5SPavan Nikhilesh 416d008f20bSPavan Nikhilesh static int 417d008f20bSPavan Nikhilesh perf_event_timer_adapter_setup(struct test_perf *t) 418d008f20bSPavan Nikhilesh { 419d008f20bSPavan Nikhilesh int i; 420d008f20bSPavan Nikhilesh int ret; 421d008f20bSPavan Nikhilesh struct rte_event_timer_adapter_info adapter_info; 422d008f20bSPavan Nikhilesh struct rte_event_timer_adapter *wl; 423d008f20bSPavan Nikhilesh uint8_t nb_producers = evt_nr_active_lcores(t->opt->plcores); 424d008f20bSPavan Nikhilesh uint8_t flags = RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES; 425d008f20bSPavan Nikhilesh 426d008f20bSPavan Nikhilesh if (nb_producers == 1) 427d008f20bSPavan Nikhilesh flags |= RTE_EVENT_TIMER_ADAPTER_F_SP_PUT; 428d008f20bSPavan Nikhilesh 429d008f20bSPavan Nikhilesh for (i = 0; i < t->opt->nb_timer_adptrs; i++) { 430d008f20bSPavan Nikhilesh struct rte_event_timer_adapter_conf config = { 431d008f20bSPavan Nikhilesh .event_dev_id = t->opt->dev_id, 432d008f20bSPavan Nikhilesh .timer_adapter_id = i, 433d008f20bSPavan Nikhilesh .timer_tick_ns = t->opt->timer_tick_nsec, 434d008f20bSPavan Nikhilesh .max_tmo_ns = t->opt->max_tmo_nsec, 435*c13b1ad7SPavan Nikhilesh .nb_timers = t->opt->pool_sz, 436d008f20bSPavan Nikhilesh .flags = flags, 437d008f20bSPavan Nikhilesh }; 438d008f20bSPavan Nikhilesh 439d008f20bSPavan Nikhilesh wl = rte_event_timer_adapter_create(&config); 440d008f20bSPavan Nikhilesh if (wl == NULL) { 441d008f20bSPavan Nikhilesh evt_err("failed to create event timer ring %d", i); 442d008f20bSPavan Nikhilesh return rte_errno; 443d008f20bSPavan Nikhilesh } 444d008f20bSPavan Nikhilesh 445d008f20bSPavan Nikhilesh memset(&adapter_info, 0, 446d008f20bSPavan Nikhilesh sizeof(struct rte_event_timer_adapter_info)); 447d008f20bSPavan Nikhilesh rte_event_timer_adapter_get_info(wl, &adapter_info); 448d008f20bSPavan Nikhilesh t->opt->optm_timer_tick_nsec = adapter_info.min_resolution_ns; 449d008f20bSPavan Nikhilesh 450d008f20bSPavan Nikhilesh if (!(adapter_info.caps & 451d008f20bSPavan Nikhilesh RTE_EVENT_TIMER_ADAPTER_CAP_INTERNAL_PORT)) { 452d008f20bSPavan Nikhilesh uint32_t service_id; 453d008f20bSPavan Nikhilesh 454d008f20bSPavan Nikhilesh rte_event_timer_adapter_service_id_get(wl, 455d008f20bSPavan Nikhilesh &service_id); 456d008f20bSPavan Nikhilesh ret = evt_service_setup(service_id); 457d008f20bSPavan Nikhilesh if (ret) { 458d008f20bSPavan Nikhilesh evt_err("Failed to setup service core" 459d008f20bSPavan Nikhilesh " for timer adapter\n"); 460d008f20bSPavan Nikhilesh return ret; 461d008f20bSPavan Nikhilesh } 462d008f20bSPavan Nikhilesh rte_service_runstate_set(service_id, 1); 463d008f20bSPavan Nikhilesh } 464d008f20bSPavan Nikhilesh 465d008f20bSPavan Nikhilesh ret = rte_event_timer_adapter_start(wl); 466d008f20bSPavan Nikhilesh if (ret) { 467d008f20bSPavan Nikhilesh evt_err("failed to Start event timer adapter %d", i); 468d008f20bSPavan Nikhilesh return ret; 469d008f20bSPavan Nikhilesh } 470d008f20bSPavan Nikhilesh t->timer_adptr[i] = wl; 471d008f20bSPavan Nikhilesh } 472d008f20bSPavan Nikhilesh return 0; 473d008f20bSPavan Nikhilesh } 474d008f20bSPavan Nikhilesh 475272de067SJerin Jacob int 47684a7513dSJerin Jacob perf_event_dev_port_setup(struct evt_test *test, struct evt_options *opt, 477535c630cSPavan Nikhilesh uint8_t stride, uint8_t nb_queues, 478535c630cSPavan Nikhilesh const struct rte_event_port_conf *port_conf) 47984a7513dSJerin Jacob { 48084a7513dSJerin Jacob struct test_perf *t = evt_test_priv(test); 4813617aae5SPavan Nikhilesh uint16_t port, prod; 48284a7513dSJerin Jacob int ret = -1; 48384a7513dSJerin Jacob 48484a7513dSJerin Jacob /* setup one port per worker, linking to all queues */ 48584a7513dSJerin Jacob for (port = 0; port < evt_nr_active_lcores(opt->wlcores); 48684a7513dSJerin Jacob port++) { 48784a7513dSJerin Jacob struct worker_data *w = &t->worker[port]; 48884a7513dSJerin Jacob 48984a7513dSJerin Jacob w->dev_id = opt->dev_id; 49084a7513dSJerin Jacob w->port_id = port; 49184a7513dSJerin Jacob w->t = t; 49284a7513dSJerin Jacob w->processed_pkts = 0; 49384a7513dSJerin Jacob w->latency = 0; 49484a7513dSJerin Jacob 495535c630cSPavan Nikhilesh ret = rte_event_port_setup(opt->dev_id, port, port_conf); 49684a7513dSJerin Jacob if (ret) { 49784a7513dSJerin Jacob evt_err("failed to setup port %d", port); 49884a7513dSJerin Jacob return ret; 49984a7513dSJerin Jacob } 50084a7513dSJerin Jacob 50184a7513dSJerin Jacob ret = rte_event_port_link(opt->dev_id, port, NULL, NULL, 0); 50284a7513dSJerin Jacob if (ret != nb_queues) { 50384a7513dSJerin Jacob evt_err("failed to link all queues to port %d", port); 50484a7513dSJerin Jacob return -EINVAL; 50584a7513dSJerin Jacob } 50684a7513dSJerin Jacob } 50784a7513dSJerin Jacob 50884a7513dSJerin Jacob /* port for producers, no links */ 5093617aae5SPavan Nikhilesh if (opt->prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR) { 5103617aae5SPavan Nikhilesh for ( ; port < perf_nb_event_ports(opt); port++) { 5113617aae5SPavan Nikhilesh struct prod_data *p = &t->prod[port]; 5123617aae5SPavan Nikhilesh p->t = t; 5133617aae5SPavan Nikhilesh } 5143617aae5SPavan Nikhilesh 515535c630cSPavan Nikhilesh ret = perf_event_rx_adapter_setup(opt, stride, *port_conf); 5163617aae5SPavan Nikhilesh if (ret) 5173617aae5SPavan Nikhilesh return ret; 518d008f20bSPavan Nikhilesh } else if (opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) { 519d008f20bSPavan Nikhilesh prod = 0; 520d008f20bSPavan Nikhilesh for ( ; port < perf_nb_event_ports(opt); port++) { 521d008f20bSPavan Nikhilesh struct prod_data *p = &t->prod[port]; 522d008f20bSPavan Nikhilesh p->queue_id = prod * stride; 523d008f20bSPavan Nikhilesh p->t = t; 524d008f20bSPavan Nikhilesh prod++; 525d008f20bSPavan Nikhilesh } 526d008f20bSPavan Nikhilesh 527d008f20bSPavan Nikhilesh ret = perf_event_timer_adapter_setup(t); 528d008f20bSPavan Nikhilesh if (ret) 529d008f20bSPavan Nikhilesh return ret; 5303617aae5SPavan Nikhilesh } else { 53184a7513dSJerin Jacob prod = 0; 53284a7513dSJerin Jacob for ( ; port < perf_nb_event_ports(opt); port++) { 53384a7513dSJerin Jacob struct prod_data *p = &t->prod[port]; 53484a7513dSJerin Jacob 53584a7513dSJerin Jacob p->dev_id = opt->dev_id; 53684a7513dSJerin Jacob p->port_id = port; 53784a7513dSJerin Jacob p->queue_id = prod * stride; 53884a7513dSJerin Jacob p->t = t; 53984a7513dSJerin Jacob 5403617aae5SPavan Nikhilesh ret = rte_event_port_setup(opt->dev_id, port, 541535c630cSPavan Nikhilesh port_conf); 54284a7513dSJerin Jacob if (ret) { 54384a7513dSJerin Jacob evt_err("failed to setup port %d", port); 54484a7513dSJerin Jacob return ret; 54584a7513dSJerin Jacob } 54684a7513dSJerin Jacob prod++; 54784a7513dSJerin Jacob } 5483617aae5SPavan Nikhilesh } 54984a7513dSJerin Jacob 55084a7513dSJerin Jacob return ret; 55184a7513dSJerin Jacob } 55284a7513dSJerin Jacob 55384a7513dSJerin Jacob int 554272de067SJerin Jacob perf_opt_check(struct evt_options *opt, uint64_t nb_queues) 555272de067SJerin Jacob { 556272de067SJerin Jacob unsigned int lcores; 557272de067SJerin Jacob 558b01974daSPavan Nikhilesh /* N producer + N worker + 1 master when producer cores are used 559b01974daSPavan Nikhilesh * Else N worker + 1 master when Rx adapter is used 560b01974daSPavan Nikhilesh */ 561b01974daSPavan Nikhilesh lcores = opt->prod_type == EVT_PROD_TYPE_SYNT ? 3 : 2; 562272de067SJerin Jacob 563272de067SJerin Jacob if (rte_lcore_count() < lcores) { 564272de067SJerin Jacob evt_err("test need minimum %d lcores", lcores); 565272de067SJerin Jacob return -1; 566272de067SJerin Jacob } 567272de067SJerin Jacob 568272de067SJerin Jacob /* Validate worker lcores */ 569272de067SJerin Jacob if (evt_lcores_has_overlap(opt->wlcores, rte_get_master_lcore())) { 570272de067SJerin Jacob evt_err("worker lcores overlaps with master lcore"); 571272de067SJerin Jacob return -1; 572272de067SJerin Jacob } 573272de067SJerin Jacob if (evt_lcores_has_overlap_multi(opt->wlcores, opt->plcores)) { 574272de067SJerin Jacob evt_err("worker lcores overlaps producer lcores"); 575272de067SJerin Jacob return -1; 576272de067SJerin Jacob } 577272de067SJerin Jacob if (evt_has_disabled_lcore(opt->wlcores)) { 578272de067SJerin Jacob evt_err("one or more workers lcores are not enabled"); 579272de067SJerin Jacob return -1; 580272de067SJerin Jacob } 581272de067SJerin Jacob if (!evt_has_active_lcore(opt->wlcores)) { 582272de067SJerin Jacob evt_err("minimum one worker is required"); 583272de067SJerin Jacob return -1; 584272de067SJerin Jacob } 585272de067SJerin Jacob 586b01974daSPavan Nikhilesh if (opt->prod_type == EVT_PROD_TYPE_SYNT) { 587272de067SJerin Jacob /* Validate producer lcores */ 588b01974daSPavan Nikhilesh if (evt_lcores_has_overlap(opt->plcores, 589b01974daSPavan Nikhilesh rte_get_master_lcore())) { 590272de067SJerin Jacob evt_err("producer lcores overlaps with master lcore"); 591272de067SJerin Jacob return -1; 592272de067SJerin Jacob } 593272de067SJerin Jacob if (evt_has_disabled_lcore(opt->plcores)) { 594272de067SJerin Jacob evt_err("one or more producer lcores are not enabled"); 595272de067SJerin Jacob return -1; 596272de067SJerin Jacob } 597272de067SJerin Jacob if (!evt_has_active_lcore(opt->plcores)) { 598272de067SJerin Jacob evt_err("minimum one producer is required"); 599272de067SJerin Jacob return -1; 600272de067SJerin Jacob } 601b01974daSPavan Nikhilesh } 602272de067SJerin Jacob 603272de067SJerin Jacob if (evt_has_invalid_stage(opt)) 604272de067SJerin Jacob return -1; 605272de067SJerin Jacob 606272de067SJerin Jacob if (evt_has_invalid_sched_type(opt)) 607272de067SJerin Jacob return -1; 608272de067SJerin Jacob 609272de067SJerin Jacob if (nb_queues > EVT_MAX_QUEUES) { 610272de067SJerin Jacob evt_err("number of queues exceeds %d", EVT_MAX_QUEUES); 611272de067SJerin Jacob return -1; 612272de067SJerin Jacob } 613272de067SJerin Jacob if (perf_nb_event_ports(opt) > EVT_MAX_PORTS) { 614272de067SJerin Jacob evt_err("number of ports exceeds %d", EVT_MAX_PORTS); 615272de067SJerin Jacob return -1; 616272de067SJerin Jacob } 617272de067SJerin Jacob 618272de067SJerin Jacob /* Fixups */ 619d008f20bSPavan Nikhilesh if ((opt->nb_stages == 1 && 620d008f20bSPavan Nikhilesh opt->prod_type != EVT_PROD_TYPE_EVENT_TIMER_ADPTR) && 621d008f20bSPavan Nikhilesh opt->fwd_latency) { 622272de067SJerin Jacob evt_info("fwd_latency is valid when nb_stages > 1, disabling"); 623272de067SJerin Jacob opt->fwd_latency = 0; 624272de067SJerin Jacob } 625d008f20bSPavan Nikhilesh 626272de067SJerin Jacob if (opt->fwd_latency && !opt->q_priority) { 627272de067SJerin Jacob evt_info("enabled queue priority for latency measurement"); 628272de067SJerin Jacob opt->q_priority = 1; 629272de067SJerin Jacob } 6309d3aeb18SJerin Jacob if (opt->nb_pkts == 0) 6319d3aeb18SJerin Jacob opt->nb_pkts = INT64_MAX/evt_nr_active_lcores(opt->plcores); 632272de067SJerin Jacob 633272de067SJerin Jacob return 0; 634272de067SJerin Jacob } 635272de067SJerin Jacob 636272de067SJerin Jacob void 637272de067SJerin Jacob perf_opt_dump(struct evt_options *opt, uint8_t nb_queues) 638272de067SJerin Jacob { 639272de067SJerin Jacob evt_dump("nb_prod_lcores", "%d", evt_nr_active_lcores(opt->plcores)); 640272de067SJerin Jacob evt_dump_producer_lcores(opt); 641272de067SJerin Jacob evt_dump("nb_worker_lcores", "%d", evt_nr_active_lcores(opt->wlcores)); 642272de067SJerin Jacob evt_dump_worker_lcores(opt); 643272de067SJerin Jacob evt_dump_nb_stages(opt); 644272de067SJerin Jacob evt_dump("nb_evdev_ports", "%d", perf_nb_event_ports(opt)); 645272de067SJerin Jacob evt_dump("nb_evdev_queues", "%d", nb_queues); 646272de067SJerin Jacob evt_dump_queue_priority(opt); 647272de067SJerin Jacob evt_dump_sched_type_list(opt); 648b01974daSPavan Nikhilesh evt_dump_producer_type(opt); 649272de067SJerin Jacob } 650272de067SJerin Jacob 65141c219e6SJerin Jacob void 65241c219e6SJerin Jacob perf_eventdev_destroy(struct evt_test *test, struct evt_options *opt) 65341c219e6SJerin Jacob { 654d008f20bSPavan Nikhilesh int i; 655d008f20bSPavan Nikhilesh struct test_perf *t = evt_test_priv(test); 65641c219e6SJerin Jacob 657d008f20bSPavan Nikhilesh if (opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) { 658d008f20bSPavan Nikhilesh for (i = 0; i < opt->nb_timer_adptrs; i++) 659d008f20bSPavan Nikhilesh rte_event_timer_adapter_stop(t->timer_adptr[i]); 660d008f20bSPavan Nikhilesh } 66141c219e6SJerin Jacob rte_event_dev_stop(opt->dev_id); 66241c219e6SJerin Jacob rte_event_dev_close(opt->dev_id); 66341c219e6SJerin Jacob } 66441c219e6SJerin Jacob 66541c219e6SJerin Jacob static inline void 66641c219e6SJerin Jacob perf_elt_init(struct rte_mempool *mp, void *arg __rte_unused, 66741c219e6SJerin Jacob void *obj, unsigned i __rte_unused) 66841c219e6SJerin Jacob { 66941c219e6SJerin Jacob memset(obj, 0, mp->elt_size); 67041c219e6SJerin Jacob } 67141c219e6SJerin Jacob 6723fc8de4fSPavan Nikhilesh #define NB_RX_DESC 128 6733fc8de4fSPavan Nikhilesh #define NB_TX_DESC 512 6743fc8de4fSPavan Nikhilesh int 6753fc8de4fSPavan Nikhilesh perf_ethdev_setup(struct evt_test *test, struct evt_options *opt) 6763fc8de4fSPavan Nikhilesh { 6778728ccf3SThomas Monjalon uint16_t i; 6783fc8de4fSPavan Nikhilesh struct test_perf *t = evt_test_priv(test); 6793fc8de4fSPavan Nikhilesh struct rte_eth_conf port_conf = { 6803fc8de4fSPavan Nikhilesh .rxmode = { 6813fc8de4fSPavan Nikhilesh .mq_mode = ETH_MQ_RX_RSS, 6823fc8de4fSPavan Nikhilesh .max_rx_pkt_len = ETHER_MAX_LEN, 6833fc8de4fSPavan Nikhilesh .split_hdr_size = 0, 6843fc8de4fSPavan Nikhilesh }, 6853fc8de4fSPavan Nikhilesh .rx_adv_conf = { 6863fc8de4fSPavan Nikhilesh .rss_conf = { 6873fc8de4fSPavan Nikhilesh .rss_key = NULL, 6883fc8de4fSPavan Nikhilesh .rss_hf = ETH_RSS_IP, 6893fc8de4fSPavan Nikhilesh }, 6903fc8de4fSPavan Nikhilesh }, 6913fc8de4fSPavan Nikhilesh }; 6923fc8de4fSPavan Nikhilesh 693d008f20bSPavan Nikhilesh if (opt->prod_type == EVT_PROD_TYPE_SYNT || 694d008f20bSPavan Nikhilesh opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) 6953fc8de4fSPavan Nikhilesh return 0; 6963fc8de4fSPavan Nikhilesh 697d9a42a69SThomas Monjalon if (!rte_eth_dev_count_avail()) { 6983fc8de4fSPavan Nikhilesh evt_err("No ethernet ports found."); 6993fc8de4fSPavan Nikhilesh return -ENODEV; 7003fc8de4fSPavan Nikhilesh } 7013fc8de4fSPavan Nikhilesh 7028728ccf3SThomas Monjalon RTE_ETH_FOREACH_DEV(i) { 7034f5701f2SFerruh Yigit struct rte_eth_dev_info dev_info; 7044f5701f2SFerruh Yigit struct rte_eth_conf local_port_conf = port_conf; 7053fc8de4fSPavan Nikhilesh 7064f5701f2SFerruh Yigit rte_eth_dev_info_get(i, &dev_info); 7074f5701f2SFerruh Yigit 7084f5701f2SFerruh Yigit local_port_conf.rx_adv_conf.rss_conf.rss_hf &= 7094f5701f2SFerruh Yigit dev_info.flow_type_rss_offloads; 7104f5701f2SFerruh Yigit if (local_port_conf.rx_adv_conf.rss_conf.rss_hf != 7114f5701f2SFerruh Yigit port_conf.rx_adv_conf.rss_conf.rss_hf) { 7124f5701f2SFerruh Yigit evt_info("Port %u modified RSS hash function based on hardware support," 7134f5701f2SFerruh Yigit "requested:%#"PRIx64" configured:%#"PRIx64"\n", 7144f5701f2SFerruh Yigit i, 7154f5701f2SFerruh Yigit port_conf.rx_adv_conf.rss_conf.rss_hf, 7164f5701f2SFerruh Yigit local_port_conf.rx_adv_conf.rss_conf.rss_hf); 7174f5701f2SFerruh Yigit } 7184f5701f2SFerruh Yigit 7194f5701f2SFerruh Yigit if (rte_eth_dev_configure(i, 1, 1, &local_port_conf) < 0) { 7203fc8de4fSPavan Nikhilesh evt_err("Failed to configure eth port [%d]", i); 7213fc8de4fSPavan Nikhilesh return -EINVAL; 7223fc8de4fSPavan Nikhilesh } 7233fc8de4fSPavan Nikhilesh 7243fc8de4fSPavan Nikhilesh if (rte_eth_rx_queue_setup(i, 0, NB_RX_DESC, 7253fc8de4fSPavan Nikhilesh rte_socket_id(), NULL, t->pool) < 0) { 7263fc8de4fSPavan Nikhilesh evt_err("Failed to setup eth port [%d] rx_queue: %d.", 7273fc8de4fSPavan Nikhilesh i, 0); 7283fc8de4fSPavan Nikhilesh return -EINVAL; 7293fc8de4fSPavan Nikhilesh } 7303fc8de4fSPavan Nikhilesh 7313fc8de4fSPavan Nikhilesh if (rte_eth_tx_queue_setup(i, 0, NB_TX_DESC, 7323fc8de4fSPavan Nikhilesh rte_socket_id(), NULL) < 0) { 7333fc8de4fSPavan Nikhilesh evt_err("Failed to setup eth port [%d] tx_queue: %d.", 7343fc8de4fSPavan Nikhilesh i, 0); 7353fc8de4fSPavan Nikhilesh return -EINVAL; 7363fc8de4fSPavan Nikhilesh } 7373fc8de4fSPavan Nikhilesh 7383fc8de4fSPavan Nikhilesh rte_eth_promiscuous_enable(i); 7393fc8de4fSPavan Nikhilesh } 7403fc8de4fSPavan Nikhilesh 7413fc8de4fSPavan Nikhilesh return 0; 7423fc8de4fSPavan Nikhilesh } 7433fc8de4fSPavan Nikhilesh 7447f3daf34SPavan Nikhilesh void perf_ethdev_destroy(struct evt_test *test, struct evt_options *opt) 7457f3daf34SPavan Nikhilesh { 7468728ccf3SThomas Monjalon uint16_t i; 7477f3daf34SPavan Nikhilesh RTE_SET_USED(test); 7487f3daf34SPavan Nikhilesh 7497f3daf34SPavan Nikhilesh if (opt->prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR) { 7508728ccf3SThomas Monjalon RTE_ETH_FOREACH_DEV(i) { 7513617aae5SPavan Nikhilesh rte_event_eth_rx_adapter_stop(i); 7527f3daf34SPavan Nikhilesh rte_eth_dev_stop(i); 7537f3daf34SPavan Nikhilesh } 7547f3daf34SPavan Nikhilesh } 7557f3daf34SPavan Nikhilesh } 7567f3daf34SPavan Nikhilesh 75741c219e6SJerin Jacob int 75841c219e6SJerin Jacob perf_mempool_setup(struct evt_test *test, struct evt_options *opt) 75941c219e6SJerin Jacob { 76041c219e6SJerin Jacob struct test_perf *t = evt_test_priv(test); 76141c219e6SJerin Jacob 762d008f20bSPavan Nikhilesh if (opt->prod_type == EVT_PROD_TYPE_SYNT || 763d008f20bSPavan Nikhilesh opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) { 76441c219e6SJerin Jacob t->pool = rte_mempool_create(test->name, /* mempool name */ 76541c219e6SJerin Jacob opt->pool_sz, /* number of elements*/ 76641c219e6SJerin Jacob sizeof(struct perf_elt), /* element size*/ 76741c219e6SJerin Jacob 512, /* cache size*/ 76841c219e6SJerin Jacob 0, NULL, NULL, 76941c219e6SJerin Jacob perf_elt_init, /* obj constructor */ 77041c219e6SJerin Jacob NULL, opt->socket_id, 0); /* flags */ 7718577cc1aSPavan Nikhilesh } else { 7728577cc1aSPavan Nikhilesh t->pool = rte_pktmbuf_pool_create(test->name, /* mempool name */ 7738577cc1aSPavan Nikhilesh opt->pool_sz, /* number of elements*/ 7748577cc1aSPavan Nikhilesh 512, /* cache size*/ 7758577cc1aSPavan Nikhilesh 0, 7768577cc1aSPavan Nikhilesh RTE_MBUF_DEFAULT_BUF_SIZE, 7778577cc1aSPavan Nikhilesh opt->socket_id); /* flags */ 7788577cc1aSPavan Nikhilesh 7798577cc1aSPavan Nikhilesh } 7808577cc1aSPavan Nikhilesh 78141c219e6SJerin Jacob if (t->pool == NULL) { 78241c219e6SJerin Jacob evt_err("failed to create mempool"); 78341c219e6SJerin Jacob return -ENOMEM; 78441c219e6SJerin Jacob } 78541c219e6SJerin Jacob 78641c219e6SJerin Jacob return 0; 78741c219e6SJerin Jacob } 78841c219e6SJerin Jacob 78941c219e6SJerin Jacob void 79041c219e6SJerin Jacob perf_mempool_destroy(struct evt_test *test, struct evt_options *opt) 79141c219e6SJerin Jacob { 79241c219e6SJerin Jacob RTE_SET_USED(opt); 79341c219e6SJerin Jacob struct test_perf *t = evt_test_priv(test); 79441c219e6SJerin Jacob 79541c219e6SJerin Jacob rte_mempool_free(t->pool); 79641c219e6SJerin Jacob } 797ffbae86fSJerin Jacob 798ffbae86fSJerin Jacob int 799ffbae86fSJerin Jacob perf_test_setup(struct evt_test *test, struct evt_options *opt) 800ffbae86fSJerin Jacob { 801ffbae86fSJerin Jacob void *test_perf; 802ffbae86fSJerin Jacob 803ffbae86fSJerin Jacob test_perf = rte_zmalloc_socket(test->name, sizeof(struct test_perf), 804ffbae86fSJerin Jacob RTE_CACHE_LINE_SIZE, opt->socket_id); 805ffbae86fSJerin Jacob if (test_perf == NULL) { 806ffbae86fSJerin Jacob evt_err("failed to allocate test_perf memory"); 807ffbae86fSJerin Jacob goto nomem; 808ffbae86fSJerin Jacob } 809ffbae86fSJerin Jacob test->test_priv = test_perf; 810ffbae86fSJerin Jacob 811ffbae86fSJerin Jacob struct test_perf *t = evt_test_priv(test); 812ffbae86fSJerin Jacob 813d008f20bSPavan Nikhilesh if (opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) { 814d008f20bSPavan Nikhilesh t->outstand_pkts = opt->nb_timers * 815d008f20bSPavan Nikhilesh evt_nr_active_lcores(opt->plcores); 816d008f20bSPavan Nikhilesh t->nb_pkts = opt->nb_timers; 817d008f20bSPavan Nikhilesh } else { 818d008f20bSPavan Nikhilesh t->outstand_pkts = opt->nb_pkts * 819d008f20bSPavan Nikhilesh evt_nr_active_lcores(opt->plcores); 820d008f20bSPavan Nikhilesh t->nb_pkts = opt->nb_pkts; 821d008f20bSPavan Nikhilesh } 822d008f20bSPavan Nikhilesh 823ffbae86fSJerin Jacob t->nb_workers = evt_nr_active_lcores(opt->wlcores); 824ffbae86fSJerin Jacob t->done = false; 825ffbae86fSJerin Jacob t->nb_flows = opt->nb_flows; 826ffbae86fSJerin Jacob t->result = EVT_TEST_FAILED; 827ffbae86fSJerin Jacob t->opt = opt; 828ffbae86fSJerin Jacob memcpy(t->sched_type_list, opt->sched_type_list, 829ffbae86fSJerin Jacob sizeof(opt->sched_type_list)); 830ffbae86fSJerin Jacob return 0; 831ffbae86fSJerin Jacob nomem: 832ffbae86fSJerin Jacob return -ENOMEM; 833ffbae86fSJerin Jacob } 834ffbae86fSJerin Jacob 835ffbae86fSJerin Jacob void 836ffbae86fSJerin Jacob perf_test_destroy(struct evt_test *test, struct evt_options *opt) 837ffbae86fSJerin Jacob { 838ffbae86fSJerin Jacob RTE_SET_USED(opt); 839ffbae86fSJerin Jacob 840ffbae86fSJerin Jacob rte_free(test->test_priv); 841ffbae86fSJerin Jacob } 842