153a3b7e8SJerin Jacob /* SPDX-License-Identifier: BSD-3-Clause 253a3b7e8SJerin Jacob * Copyright(c) 2017 Cavium, Inc 3ffbae86fSJerin Jacob */ 4ffbae86fSJerin Jacob 5626b12a8SPavan Nikhilesh #include <math.h> 6626b12a8SPavan Nikhilesh 7ffbae86fSJerin Jacob #include "test_perf_common.h" 8ffbae86fSJerin Jacob 9*de2bc16eSShijith Thotton #define NB_CRYPTODEV_DESCRIPTORS 128 10*de2bc16eSShijith Thotton 1141c219e6SJerin Jacob int 1241c219e6SJerin Jacob perf_test_result(struct evt_test *test, struct evt_options *opt) 1341c219e6SJerin Jacob { 1441c219e6SJerin Jacob RTE_SET_USED(opt); 156b1a14a8SPavan Nikhilesh int i; 166b1a14a8SPavan Nikhilesh uint64_t total = 0; 1741c219e6SJerin Jacob struct test_perf *t = evt_test_priv(test); 1841c219e6SJerin Jacob 196b1a14a8SPavan Nikhilesh printf("Packet distribution across worker cores :\n"); 206b1a14a8SPavan Nikhilesh for (i = 0; i < t->nb_workers; i++) 216b1a14a8SPavan Nikhilesh total += t->worker[i].processed_pkts; 226b1a14a8SPavan Nikhilesh for (i = 0; i < t->nb_workers; i++) 236b1a14a8SPavan Nikhilesh printf("Worker %d packets: "CLGRN"%"PRIx64" "CLNRM"percentage:" 24c0900d33SHarry van Haaren CLGRN" %3.2f"CLNRM"\n", i, 256b1a14a8SPavan Nikhilesh t->worker[i].processed_pkts, 266b1a14a8SPavan Nikhilesh (((double)t->worker[i].processed_pkts)/total) 276b1a14a8SPavan Nikhilesh * 100); 286b1a14a8SPavan Nikhilesh 2941c219e6SJerin Jacob return t->result; 3041c219e6SJerin Jacob } 3141c219e6SJerin Jacob 329d3aeb18SJerin Jacob static inline int 339d3aeb18SJerin Jacob perf_producer(void *arg) 349d3aeb18SJerin Jacob { 359a618803SPavan Nikhilesh int i; 369d3aeb18SJerin Jacob struct prod_data *p = arg; 379d3aeb18SJerin Jacob struct test_perf *t = p->t; 389d3aeb18SJerin Jacob struct evt_options *opt = t->opt; 399d3aeb18SJerin Jacob const uint8_t dev_id = p->dev_id; 409d3aeb18SJerin Jacob const uint8_t port = p->port_id; 419d3aeb18SJerin Jacob struct rte_mempool *pool = t->pool; 429d3aeb18SJerin Jacob const uint64_t nb_pkts = t->nb_pkts; 439d3aeb18SJerin Jacob const uint32_t nb_flows = t->nb_flows; 449d3aeb18SJerin Jacob uint32_t flow_counter = 0; 459d3aeb18SJerin Jacob uint64_t count = 0; 469a618803SPavan Nikhilesh struct perf_elt *m[BURST_SIZE + 1] = {NULL}; 479d3aeb18SJerin Jacob struct rte_event ev; 489d3aeb18SJerin Jacob 499d3aeb18SJerin Jacob if (opt->verbose_level > 1) 509d3aeb18SJerin Jacob printf("%s(): lcore %d dev_id %d port=%d queue %d\n", __func__, 519d3aeb18SJerin Jacob rte_lcore_id(), dev_id, port, p->queue_id); 529d3aeb18SJerin Jacob 539d3aeb18SJerin Jacob ev.event = 0; 549d3aeb18SJerin Jacob ev.op = RTE_EVENT_OP_NEW; 559d3aeb18SJerin Jacob ev.queue_id = p->queue_id; 569d3aeb18SJerin Jacob ev.sched_type = t->opt->sched_type_list[0]; 579d3aeb18SJerin Jacob ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL; 589d3aeb18SJerin Jacob ev.event_type = RTE_EVENT_TYPE_CPU; 599d3aeb18SJerin Jacob ev.sub_event_type = 0; /* stage 0 */ 609d3aeb18SJerin Jacob 619d3aeb18SJerin Jacob while (count < nb_pkts && t->done == false) { 629a618803SPavan Nikhilesh if (rte_mempool_get_bulk(pool, (void **)m, BURST_SIZE) < 0) 639d3aeb18SJerin Jacob continue; 649a618803SPavan Nikhilesh for (i = 0; i < BURST_SIZE; i++) { 659d3aeb18SJerin Jacob ev.flow_id = flow_counter++ % nb_flows; 669a618803SPavan Nikhilesh ev.event_ptr = m[i]; 679a618803SPavan Nikhilesh m[i]->timestamp = rte_get_timer_cycles(); 689a618803SPavan Nikhilesh while (rte_event_enqueue_burst(dev_id, 699a618803SPavan Nikhilesh port, &ev, 1) != 1) { 709d3aeb18SJerin Jacob if (t->done) 719d3aeb18SJerin Jacob break; 729d3aeb18SJerin Jacob rte_pause(); 739a618803SPavan Nikhilesh m[i]->timestamp = rte_get_timer_cycles(); 749d3aeb18SJerin Jacob } 759a618803SPavan Nikhilesh } 769a618803SPavan Nikhilesh count += BURST_SIZE; 779d3aeb18SJerin Jacob } 789d3aeb18SJerin Jacob 799d3aeb18SJerin Jacob return 0; 809d3aeb18SJerin Jacob } 819d3aeb18SJerin Jacob 82d008f20bSPavan Nikhilesh static inline int 8320841a25SRashmi Shetty perf_producer_burst(void *arg) 8420841a25SRashmi Shetty { 8520841a25SRashmi Shetty uint32_t i; 8620841a25SRashmi Shetty uint64_t timestamp; 8720841a25SRashmi Shetty struct rte_event_dev_info dev_info; 8820841a25SRashmi Shetty struct prod_data *p = arg; 8920841a25SRashmi Shetty struct test_perf *t = p->t; 9020841a25SRashmi Shetty struct evt_options *opt = t->opt; 9120841a25SRashmi Shetty const uint8_t dev_id = p->dev_id; 9220841a25SRashmi Shetty const uint8_t port = p->port_id; 9320841a25SRashmi Shetty struct rte_mempool *pool = t->pool; 9420841a25SRashmi Shetty const uint64_t nb_pkts = t->nb_pkts; 9520841a25SRashmi Shetty const uint32_t nb_flows = t->nb_flows; 9620841a25SRashmi Shetty uint32_t flow_counter = 0; 9720841a25SRashmi Shetty uint16_t enq = 0; 9820841a25SRashmi Shetty uint64_t count = 0; 9920841a25SRashmi Shetty struct perf_elt *m[MAX_PROD_ENQ_BURST_SIZE + 1]; 10020841a25SRashmi Shetty struct rte_event ev[MAX_PROD_ENQ_BURST_SIZE + 1]; 10120841a25SRashmi Shetty uint32_t burst_size = opt->prod_enq_burst_sz; 10220841a25SRashmi Shetty 10320841a25SRashmi Shetty memset(m, 0, sizeof(*m) * (MAX_PROD_ENQ_BURST_SIZE + 1)); 10420841a25SRashmi Shetty rte_event_dev_info_get(dev_id, &dev_info); 10520841a25SRashmi Shetty if (dev_info.max_event_port_enqueue_depth < burst_size) 10620841a25SRashmi Shetty burst_size = dev_info.max_event_port_enqueue_depth; 10720841a25SRashmi Shetty 10820841a25SRashmi Shetty if (opt->verbose_level > 1) 10920841a25SRashmi Shetty printf("%s(): lcore %d dev_id %d port=%d queue %d\n", __func__, 11020841a25SRashmi Shetty rte_lcore_id(), dev_id, port, p->queue_id); 11120841a25SRashmi Shetty 11220841a25SRashmi Shetty for (i = 0; i < burst_size; i++) { 11320841a25SRashmi Shetty ev[i].op = RTE_EVENT_OP_NEW; 11420841a25SRashmi Shetty ev[i].queue_id = p->queue_id; 11520841a25SRashmi Shetty ev[i].sched_type = t->opt->sched_type_list[0]; 11620841a25SRashmi Shetty ev[i].priority = RTE_EVENT_DEV_PRIORITY_NORMAL; 11720841a25SRashmi Shetty ev[i].event_type = RTE_EVENT_TYPE_CPU; 11820841a25SRashmi Shetty ev[i].sub_event_type = 0; /* stage 0 */ 11920841a25SRashmi Shetty } 12020841a25SRashmi Shetty 12120841a25SRashmi Shetty while (count < nb_pkts && t->done == false) { 12220841a25SRashmi Shetty if (rte_mempool_get_bulk(pool, (void **)m, burst_size) < 0) 12320841a25SRashmi Shetty continue; 12420841a25SRashmi Shetty timestamp = rte_get_timer_cycles(); 12520841a25SRashmi Shetty for (i = 0; i < burst_size; i++) { 12620841a25SRashmi Shetty ev[i].flow_id = flow_counter++ % nb_flows; 12720841a25SRashmi Shetty ev[i].event_ptr = m[i]; 12820841a25SRashmi Shetty m[i]->timestamp = timestamp; 12920841a25SRashmi Shetty } 13020841a25SRashmi Shetty enq = rte_event_enqueue_burst(dev_id, port, ev, burst_size); 13120841a25SRashmi Shetty while (enq < burst_size) { 13220841a25SRashmi Shetty enq += rte_event_enqueue_burst(dev_id, port, 13320841a25SRashmi Shetty ev + enq, 13420841a25SRashmi Shetty burst_size - enq); 13520841a25SRashmi Shetty if (t->done) 13620841a25SRashmi Shetty break; 13720841a25SRashmi Shetty rte_pause(); 13820841a25SRashmi Shetty timestamp = rte_get_timer_cycles(); 13920841a25SRashmi Shetty for (i = enq; i < burst_size; i++) 14020841a25SRashmi Shetty m[i]->timestamp = timestamp; 14120841a25SRashmi Shetty } 14220841a25SRashmi Shetty count += burst_size; 14320841a25SRashmi Shetty } 14420841a25SRashmi Shetty return 0; 14520841a25SRashmi Shetty } 14620841a25SRashmi Shetty 14720841a25SRashmi Shetty static inline int 148d008f20bSPavan Nikhilesh perf_event_timer_producer(void *arg) 149d008f20bSPavan Nikhilesh { 1509a618803SPavan Nikhilesh int i; 151d008f20bSPavan Nikhilesh struct prod_data *p = arg; 152d008f20bSPavan Nikhilesh struct test_perf *t = p->t; 153d008f20bSPavan Nikhilesh struct evt_options *opt = t->opt; 154d008f20bSPavan Nikhilesh uint32_t flow_counter = 0; 155d008f20bSPavan Nikhilesh uint64_t count = 0; 156d008f20bSPavan Nikhilesh uint64_t arm_latency = 0; 157d008f20bSPavan Nikhilesh const uint8_t nb_timer_adptrs = opt->nb_timer_adptrs; 158d008f20bSPavan Nikhilesh const uint32_t nb_flows = t->nb_flows; 159d008f20bSPavan Nikhilesh const uint64_t nb_timers = opt->nb_timers; 160d008f20bSPavan Nikhilesh struct rte_mempool *pool = t->pool; 1619a618803SPavan Nikhilesh struct perf_elt *m[BURST_SIZE + 1] = {NULL}; 162d008f20bSPavan Nikhilesh struct rte_event_timer_adapter **adptr = t->timer_adptr; 16352553263SPavan Nikhilesh struct rte_event_timer tim; 164d008f20bSPavan Nikhilesh uint64_t timeout_ticks = opt->expiry_nsec / opt->timer_tick_nsec; 165d008f20bSPavan Nikhilesh 16652553263SPavan Nikhilesh memset(&tim, 0, sizeof(struct rte_event_timer)); 167626b12a8SPavan Nikhilesh timeout_ticks = 168626b12a8SPavan Nikhilesh opt->optm_timer_tick_nsec 169626b12a8SPavan Nikhilesh ? ceil((double)(timeout_ticks * opt->timer_tick_nsec) / 170626b12a8SPavan Nikhilesh opt->optm_timer_tick_nsec) 171626b12a8SPavan Nikhilesh : timeout_ticks; 172d008f20bSPavan Nikhilesh timeout_ticks += timeout_ticks ? 0 : 1; 17352553263SPavan Nikhilesh tim.ev.event_type = RTE_EVENT_TYPE_TIMER; 17452553263SPavan Nikhilesh tim.ev.op = RTE_EVENT_OP_NEW; 17552553263SPavan Nikhilesh tim.ev.sched_type = t->opt->sched_type_list[0]; 17652553263SPavan Nikhilesh tim.ev.queue_id = p->queue_id; 17752553263SPavan Nikhilesh tim.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL; 17852553263SPavan Nikhilesh tim.state = RTE_EVENT_TIMER_NOT_ARMED; 17952553263SPavan Nikhilesh tim.timeout_ticks = timeout_ticks; 180d008f20bSPavan Nikhilesh 181d008f20bSPavan Nikhilesh if (opt->verbose_level > 1) 182d008f20bSPavan Nikhilesh printf("%s(): lcore %d\n", __func__, rte_lcore_id()); 183d008f20bSPavan Nikhilesh 184d008f20bSPavan Nikhilesh while (count < nb_timers && t->done == false) { 1859a618803SPavan Nikhilesh if (rte_mempool_get_bulk(pool, (void **)m, BURST_SIZE) < 0) 186d008f20bSPavan Nikhilesh continue; 1879a618803SPavan Nikhilesh for (i = 0; i < BURST_SIZE; i++) { 1889a618803SPavan Nikhilesh rte_prefetch0(m[i + 1]); 1899a618803SPavan Nikhilesh m[i]->tim = tim; 1909a618803SPavan Nikhilesh m[i]->tim.ev.flow_id = flow_counter++ % nb_flows; 1919a618803SPavan Nikhilesh m[i]->tim.ev.event_ptr = m[i]; 1929a618803SPavan Nikhilesh m[i]->timestamp = rte_get_timer_cycles(); 193d008f20bSPavan Nikhilesh while (rte_event_timer_arm_burst( 194d008f20bSPavan Nikhilesh adptr[flow_counter % nb_timer_adptrs], 1959a618803SPavan Nikhilesh (struct rte_event_timer **)&m[i], 1) != 1) { 196d008f20bSPavan Nikhilesh if (t->done) 197d008f20bSPavan Nikhilesh break; 1989a618803SPavan Nikhilesh m[i]->timestamp = rte_get_timer_cycles(); 199d008f20bSPavan Nikhilesh } 2009a618803SPavan Nikhilesh arm_latency += rte_get_timer_cycles() - m[i]->timestamp; 2019a618803SPavan Nikhilesh } 2029a618803SPavan Nikhilesh count += BURST_SIZE; 203d008f20bSPavan Nikhilesh } 204d008f20bSPavan Nikhilesh fflush(stdout); 205d008f20bSPavan Nikhilesh rte_delay_ms(1000); 206d008f20bSPavan Nikhilesh printf("%s(): lcore %d Average event timer arm latency = %.3f us\n", 20793b7794bSPavan Nikhilesh __func__, rte_lcore_id(), 20893b7794bSPavan Nikhilesh count ? (float)(arm_latency / count) / 20993b7794bSPavan Nikhilesh (rte_get_timer_hz() / 1000000) : 0); 210d008f20bSPavan Nikhilesh return 0; 211d008f20bSPavan Nikhilesh } 212d008f20bSPavan Nikhilesh 21317b22d0bSPavan Nikhilesh static inline int 21417b22d0bSPavan Nikhilesh perf_event_timer_producer_burst(void *arg) 21517b22d0bSPavan Nikhilesh { 21617b22d0bSPavan Nikhilesh int i; 21717b22d0bSPavan Nikhilesh struct prod_data *p = arg; 21817b22d0bSPavan Nikhilesh struct test_perf *t = p->t; 21917b22d0bSPavan Nikhilesh struct evt_options *opt = t->opt; 22017b22d0bSPavan Nikhilesh uint32_t flow_counter = 0; 22117b22d0bSPavan Nikhilesh uint64_t count = 0; 22217b22d0bSPavan Nikhilesh uint64_t arm_latency = 0; 22317b22d0bSPavan Nikhilesh const uint8_t nb_timer_adptrs = opt->nb_timer_adptrs; 22417b22d0bSPavan Nikhilesh const uint32_t nb_flows = t->nb_flows; 22517b22d0bSPavan Nikhilesh const uint64_t nb_timers = opt->nb_timers; 22617b22d0bSPavan Nikhilesh struct rte_mempool *pool = t->pool; 22717b22d0bSPavan Nikhilesh struct perf_elt *m[BURST_SIZE + 1] = {NULL}; 22817b22d0bSPavan Nikhilesh struct rte_event_timer_adapter **adptr = t->timer_adptr; 22952553263SPavan Nikhilesh struct rte_event_timer tim; 23017b22d0bSPavan Nikhilesh uint64_t timeout_ticks = opt->expiry_nsec / opt->timer_tick_nsec; 23117b22d0bSPavan Nikhilesh 23252553263SPavan Nikhilesh memset(&tim, 0, sizeof(struct rte_event_timer)); 233626b12a8SPavan Nikhilesh timeout_ticks = 234626b12a8SPavan Nikhilesh opt->optm_timer_tick_nsec 235626b12a8SPavan Nikhilesh ? ceil((double)(timeout_ticks * opt->timer_tick_nsec) / 236626b12a8SPavan Nikhilesh opt->optm_timer_tick_nsec) 237626b12a8SPavan Nikhilesh : timeout_ticks; 23817b22d0bSPavan Nikhilesh timeout_ticks += timeout_ticks ? 0 : 1; 23952553263SPavan Nikhilesh tim.ev.event_type = RTE_EVENT_TYPE_TIMER; 24052553263SPavan Nikhilesh tim.ev.op = RTE_EVENT_OP_NEW; 24152553263SPavan Nikhilesh tim.ev.sched_type = t->opt->sched_type_list[0]; 24252553263SPavan Nikhilesh tim.ev.queue_id = p->queue_id; 24352553263SPavan Nikhilesh tim.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL; 24452553263SPavan Nikhilesh tim.state = RTE_EVENT_TIMER_NOT_ARMED; 24552553263SPavan Nikhilesh tim.timeout_ticks = timeout_ticks; 24617b22d0bSPavan Nikhilesh 24717b22d0bSPavan Nikhilesh if (opt->verbose_level > 1) 24817b22d0bSPavan Nikhilesh printf("%s(): lcore %d\n", __func__, rte_lcore_id()); 24917b22d0bSPavan Nikhilesh 25017b22d0bSPavan Nikhilesh while (count < nb_timers && t->done == false) { 25117b22d0bSPavan Nikhilesh if (rte_mempool_get_bulk(pool, (void **)m, BURST_SIZE) < 0) 25217b22d0bSPavan Nikhilesh continue; 25317b22d0bSPavan Nikhilesh for (i = 0; i < BURST_SIZE; i++) { 25417b22d0bSPavan Nikhilesh rte_prefetch0(m[i + 1]); 25517b22d0bSPavan Nikhilesh m[i]->tim = tim; 25617b22d0bSPavan Nikhilesh m[i]->tim.ev.flow_id = flow_counter++ % nb_flows; 25717b22d0bSPavan Nikhilesh m[i]->tim.ev.event_ptr = m[i]; 25817b22d0bSPavan Nikhilesh m[i]->timestamp = rte_get_timer_cycles(); 25917b22d0bSPavan Nikhilesh } 26017b22d0bSPavan Nikhilesh rte_event_timer_arm_tmo_tick_burst( 26117b22d0bSPavan Nikhilesh adptr[flow_counter % nb_timer_adptrs], 26217b22d0bSPavan Nikhilesh (struct rte_event_timer **)m, 26317b22d0bSPavan Nikhilesh tim.timeout_ticks, 26417b22d0bSPavan Nikhilesh BURST_SIZE); 26517b22d0bSPavan Nikhilesh arm_latency += rte_get_timer_cycles() - m[i - 1]->timestamp; 26617b22d0bSPavan Nikhilesh count += BURST_SIZE; 26717b22d0bSPavan Nikhilesh } 26817b22d0bSPavan Nikhilesh fflush(stdout); 26917b22d0bSPavan Nikhilesh rte_delay_ms(1000); 27017b22d0bSPavan Nikhilesh printf("%s(): lcore %d Average event timer arm latency = %.3f us\n", 27193b7794bSPavan Nikhilesh __func__, rte_lcore_id(), 27293b7794bSPavan Nikhilesh count ? (float)(arm_latency / count) / 27393b7794bSPavan Nikhilesh (rte_get_timer_hz() / 1000000) : 0); 27417b22d0bSPavan Nikhilesh return 0; 27517b22d0bSPavan Nikhilesh } 27617b22d0bSPavan Nikhilesh 277*de2bc16eSShijith Thotton static inline void 278*de2bc16eSShijith Thotton crypto_adapter_enq_op_new(struct prod_data *p) 279*de2bc16eSShijith Thotton { 280*de2bc16eSShijith Thotton struct rte_cryptodev_sym_session **crypto_sess = p->ca.crypto_sess; 281*de2bc16eSShijith Thotton struct test_perf *t = p->t; 282*de2bc16eSShijith Thotton const uint32_t nb_flows = t->nb_flows; 283*de2bc16eSShijith Thotton const uint64_t nb_pkts = t->nb_pkts; 284*de2bc16eSShijith Thotton struct rte_mempool *pool = t->pool; 285*de2bc16eSShijith Thotton struct rte_crypto_sym_op *sym_op; 286*de2bc16eSShijith Thotton struct evt_options *opt = t->opt; 287*de2bc16eSShijith Thotton uint16_t qp_id = p->ca.cdev_qp_id; 288*de2bc16eSShijith Thotton uint8_t cdev_id = p->ca.cdev_id; 289*de2bc16eSShijith Thotton uint32_t flow_counter = 0; 290*de2bc16eSShijith Thotton struct rte_crypto_op *op; 291*de2bc16eSShijith Thotton struct rte_mbuf *m; 292*de2bc16eSShijith Thotton uint64_t count = 0; 293*de2bc16eSShijith Thotton uint16_t len; 294*de2bc16eSShijith Thotton 295*de2bc16eSShijith Thotton if (opt->verbose_level > 1) 296*de2bc16eSShijith Thotton printf("%s(): lcore %d queue %d cdev_id %u cdev_qp_id %u\n", 297*de2bc16eSShijith Thotton __func__, rte_lcore_id(), p->queue_id, p->ca.cdev_id, 298*de2bc16eSShijith Thotton p->ca.cdev_qp_id); 299*de2bc16eSShijith Thotton 300*de2bc16eSShijith Thotton len = opt->mbuf_sz ? opt->mbuf_sz : RTE_ETHER_MIN_LEN; 301*de2bc16eSShijith Thotton 302*de2bc16eSShijith Thotton while (count < nb_pkts && t->done == false) { 303*de2bc16eSShijith Thotton m = rte_pktmbuf_alloc(pool); 304*de2bc16eSShijith Thotton if (m == NULL) 305*de2bc16eSShijith Thotton continue; 306*de2bc16eSShijith Thotton 307*de2bc16eSShijith Thotton rte_pktmbuf_append(m, len); 308*de2bc16eSShijith Thotton op = rte_crypto_op_alloc(t->ca_op_pool, 309*de2bc16eSShijith Thotton RTE_CRYPTO_OP_TYPE_SYMMETRIC); 310*de2bc16eSShijith Thotton sym_op = op->sym; 311*de2bc16eSShijith Thotton sym_op->m_src = m; 312*de2bc16eSShijith Thotton sym_op->cipher.data.offset = 0; 313*de2bc16eSShijith Thotton sym_op->cipher.data.length = len; 314*de2bc16eSShijith Thotton rte_crypto_op_attach_sym_session( 315*de2bc16eSShijith Thotton op, crypto_sess[flow_counter++ % nb_flows]); 316*de2bc16eSShijith Thotton 317*de2bc16eSShijith Thotton while (rte_cryptodev_enqueue_burst(cdev_id, qp_id, &op, 1) != 1 && 318*de2bc16eSShijith Thotton t->done == false) 319*de2bc16eSShijith Thotton rte_pause(); 320*de2bc16eSShijith Thotton 321*de2bc16eSShijith Thotton count++; 322*de2bc16eSShijith Thotton } 323*de2bc16eSShijith Thotton } 324*de2bc16eSShijith Thotton 325*de2bc16eSShijith Thotton static inline void 326*de2bc16eSShijith Thotton crypto_adapter_enq_op_fwd(struct prod_data *p) 327*de2bc16eSShijith Thotton { 328*de2bc16eSShijith Thotton struct rte_cryptodev_sym_session **crypto_sess = p->ca.crypto_sess; 329*de2bc16eSShijith Thotton const uint8_t dev_id = p->dev_id; 330*de2bc16eSShijith Thotton const uint8_t port = p->port_id; 331*de2bc16eSShijith Thotton struct test_perf *t = p->t; 332*de2bc16eSShijith Thotton const uint32_t nb_flows = t->nb_flows; 333*de2bc16eSShijith Thotton const uint64_t nb_pkts = t->nb_pkts; 334*de2bc16eSShijith Thotton struct rte_mempool *pool = t->pool; 335*de2bc16eSShijith Thotton struct evt_options *opt = t->opt; 336*de2bc16eSShijith Thotton struct rte_crypto_sym_op *sym_op; 337*de2bc16eSShijith Thotton uint32_t flow_counter = 0; 338*de2bc16eSShijith Thotton struct rte_crypto_op *op; 339*de2bc16eSShijith Thotton struct rte_event ev; 340*de2bc16eSShijith Thotton struct rte_mbuf *m; 341*de2bc16eSShijith Thotton uint64_t count = 0; 342*de2bc16eSShijith Thotton uint16_t len; 343*de2bc16eSShijith Thotton 344*de2bc16eSShijith Thotton if (opt->verbose_level > 1) 345*de2bc16eSShijith Thotton printf("%s(): lcore %d port %d queue %d cdev_id %u cdev_qp_id %u\n", 346*de2bc16eSShijith Thotton __func__, rte_lcore_id(), port, p->queue_id, 347*de2bc16eSShijith Thotton p->ca.cdev_id, p->ca.cdev_qp_id); 348*de2bc16eSShijith Thotton 349*de2bc16eSShijith Thotton ev.event = 0; 350*de2bc16eSShijith Thotton ev.op = RTE_EVENT_OP_NEW; 351*de2bc16eSShijith Thotton ev.queue_id = p->queue_id; 352*de2bc16eSShijith Thotton ev.sched_type = RTE_SCHED_TYPE_ATOMIC; 353*de2bc16eSShijith Thotton ev.event_type = RTE_EVENT_TYPE_CPU; 354*de2bc16eSShijith Thotton len = opt->mbuf_sz ? opt->mbuf_sz : RTE_ETHER_MIN_LEN; 355*de2bc16eSShijith Thotton 356*de2bc16eSShijith Thotton while (count < nb_pkts && t->done == false) { 357*de2bc16eSShijith Thotton m = rte_pktmbuf_alloc(pool); 358*de2bc16eSShijith Thotton if (m == NULL) 359*de2bc16eSShijith Thotton continue; 360*de2bc16eSShijith Thotton 361*de2bc16eSShijith Thotton rte_pktmbuf_append(m, len); 362*de2bc16eSShijith Thotton op = rte_crypto_op_alloc(t->ca_op_pool, 363*de2bc16eSShijith Thotton RTE_CRYPTO_OP_TYPE_SYMMETRIC); 364*de2bc16eSShijith Thotton sym_op = op->sym; 365*de2bc16eSShijith Thotton sym_op->m_src = m; 366*de2bc16eSShijith Thotton sym_op->cipher.data.offset = 0; 367*de2bc16eSShijith Thotton sym_op->cipher.data.length = len; 368*de2bc16eSShijith Thotton rte_crypto_op_attach_sym_session( 369*de2bc16eSShijith Thotton op, crypto_sess[flow_counter++ % nb_flows]); 370*de2bc16eSShijith Thotton ev.event_ptr = op; 371*de2bc16eSShijith Thotton 372*de2bc16eSShijith Thotton while (rte_event_crypto_adapter_enqueue(dev_id, port, &ev, 1) != 1 && 373*de2bc16eSShijith Thotton t->done == false) 374*de2bc16eSShijith Thotton rte_pause(); 375*de2bc16eSShijith Thotton 376*de2bc16eSShijith Thotton count++; 377*de2bc16eSShijith Thotton } 378*de2bc16eSShijith Thotton } 379*de2bc16eSShijith Thotton 380*de2bc16eSShijith Thotton static inline int 381*de2bc16eSShijith Thotton perf_event_crypto_producer(void *arg) 382*de2bc16eSShijith Thotton { 383*de2bc16eSShijith Thotton struct prod_data *p = arg; 384*de2bc16eSShijith Thotton struct evt_options *opt = p->t->opt; 385*de2bc16eSShijith Thotton 386*de2bc16eSShijith Thotton if (opt->crypto_adptr_mode == RTE_EVENT_CRYPTO_ADAPTER_OP_NEW) 387*de2bc16eSShijith Thotton crypto_adapter_enq_op_new(p); 388*de2bc16eSShijith Thotton else 389*de2bc16eSShijith Thotton crypto_adapter_enq_op_fwd(p); 390*de2bc16eSShijith Thotton 391*de2bc16eSShijith Thotton return 0; 392*de2bc16eSShijith Thotton } 393*de2bc16eSShijith Thotton 39459f697e3SPavan Nikhilesh static int 39559f697e3SPavan Nikhilesh perf_producer_wrapper(void *arg) 39659f697e3SPavan Nikhilesh { 39759f697e3SPavan Nikhilesh struct prod_data *p = arg; 39859f697e3SPavan Nikhilesh struct test_perf *t = p->t; 39920841a25SRashmi Shetty bool burst = evt_has_burst_mode(p->dev_id); 40020841a25SRashmi Shetty 40120841a25SRashmi Shetty /* In case of synthetic producer, launch perf_producer or 40220841a25SRashmi Shetty * perf_producer_burst depending on producer enqueue burst size 40320841a25SRashmi Shetty */ 40420841a25SRashmi Shetty if (t->opt->prod_type == EVT_PROD_TYPE_SYNT && 40520841a25SRashmi Shetty t->opt->prod_enq_burst_sz == 1) 40659f697e3SPavan Nikhilesh return perf_producer(arg); 40720841a25SRashmi Shetty else if (t->opt->prod_type == EVT_PROD_TYPE_SYNT && 40820841a25SRashmi Shetty t->opt->prod_enq_burst_sz > 1) { 40920841a25SRashmi Shetty if (!burst) 41020841a25SRashmi Shetty evt_err("This event device does not support burst mode"); 41120841a25SRashmi Shetty else 41220841a25SRashmi Shetty return perf_producer_burst(arg); 41320841a25SRashmi Shetty } 41417b22d0bSPavan Nikhilesh else if (t->opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR && 41517b22d0bSPavan Nikhilesh !t->opt->timdev_use_burst) 416d008f20bSPavan Nikhilesh return perf_event_timer_producer(arg); 41717b22d0bSPavan Nikhilesh else if (t->opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR && 41817b22d0bSPavan Nikhilesh t->opt->timdev_use_burst) 41917b22d0bSPavan Nikhilesh return perf_event_timer_producer_burst(arg); 420*de2bc16eSShijith Thotton else if (t->opt->prod_type == EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR) 421*de2bc16eSShijith Thotton return perf_event_crypto_producer(arg); 42259f697e3SPavan Nikhilesh return 0; 42359f697e3SPavan Nikhilesh } 42459f697e3SPavan Nikhilesh 4259d3aeb18SJerin Jacob static inline uint64_t 4269d3aeb18SJerin Jacob processed_pkts(struct test_perf *t) 4279d3aeb18SJerin Jacob { 4289d3aeb18SJerin Jacob uint8_t i; 4299d3aeb18SJerin Jacob uint64_t total = 0; 4309d3aeb18SJerin Jacob 4319d3aeb18SJerin Jacob for (i = 0; i < t->nb_workers; i++) 4329d3aeb18SJerin Jacob total += t->worker[i].processed_pkts; 4339d3aeb18SJerin Jacob 4349d3aeb18SJerin Jacob return total; 4359d3aeb18SJerin Jacob } 4369d3aeb18SJerin Jacob 4379d3aeb18SJerin Jacob static inline uint64_t 4389d3aeb18SJerin Jacob total_latency(struct test_perf *t) 4399d3aeb18SJerin Jacob { 4409d3aeb18SJerin Jacob uint8_t i; 4419d3aeb18SJerin Jacob uint64_t total = 0; 4429d3aeb18SJerin Jacob 4439d3aeb18SJerin Jacob for (i = 0; i < t->nb_workers; i++) 4449d3aeb18SJerin Jacob total += t->worker[i].latency; 4459d3aeb18SJerin Jacob 4469d3aeb18SJerin Jacob return total; 4479d3aeb18SJerin Jacob } 4489d3aeb18SJerin Jacob 4499d3aeb18SJerin Jacob 4509d3aeb18SJerin Jacob int 4519d3aeb18SJerin Jacob perf_launch_lcores(struct evt_test *test, struct evt_options *opt, 4529d3aeb18SJerin Jacob int (*worker)(void *)) 4539d3aeb18SJerin Jacob { 4549d3aeb18SJerin Jacob int ret, lcore_id; 4559d3aeb18SJerin Jacob struct test_perf *t = evt_test_priv(test); 4569d3aeb18SJerin Jacob 4579d3aeb18SJerin Jacob int port_idx = 0; 4589d3aeb18SJerin Jacob /* launch workers */ 459cb056611SStephen Hemminger RTE_LCORE_FOREACH_WORKER(lcore_id) { 4609d3aeb18SJerin Jacob if (!(opt->wlcores[lcore_id])) 4619d3aeb18SJerin Jacob continue; 4629d3aeb18SJerin Jacob 4639d3aeb18SJerin Jacob ret = rte_eal_remote_launch(worker, 4649d3aeb18SJerin Jacob &t->worker[port_idx], lcore_id); 4659d3aeb18SJerin Jacob if (ret) { 4669d3aeb18SJerin Jacob evt_err("failed to launch worker %d", lcore_id); 4679d3aeb18SJerin Jacob return ret; 4689d3aeb18SJerin Jacob } 4699d3aeb18SJerin Jacob port_idx++; 4709d3aeb18SJerin Jacob } 4719d3aeb18SJerin Jacob 4729d3aeb18SJerin Jacob /* launch producers */ 473cb056611SStephen Hemminger RTE_LCORE_FOREACH_WORKER(lcore_id) { 4749d3aeb18SJerin Jacob if (!(opt->plcores[lcore_id])) 4759d3aeb18SJerin Jacob continue; 4769d3aeb18SJerin Jacob 47759f697e3SPavan Nikhilesh ret = rte_eal_remote_launch(perf_producer_wrapper, 47859f697e3SPavan Nikhilesh &t->prod[port_idx], lcore_id); 4799d3aeb18SJerin Jacob if (ret) { 4809d3aeb18SJerin Jacob evt_err("failed to launch perf_producer %d", lcore_id); 4819d3aeb18SJerin Jacob return ret; 4829d3aeb18SJerin Jacob } 4839d3aeb18SJerin Jacob port_idx++; 4849d3aeb18SJerin Jacob } 4859d3aeb18SJerin Jacob 486d008f20bSPavan Nikhilesh const uint64_t total_pkts = t->outstand_pkts; 4879d3aeb18SJerin Jacob 4889d3aeb18SJerin Jacob uint64_t dead_lock_cycles = rte_get_timer_cycles(); 4899d3aeb18SJerin Jacob int64_t dead_lock_remaining = total_pkts; 4909d3aeb18SJerin Jacob const uint64_t dead_lock_sample = rte_get_timer_hz() * 5; 4919d3aeb18SJerin Jacob 4929d3aeb18SJerin Jacob uint64_t perf_cycles = rte_get_timer_cycles(); 4939d3aeb18SJerin Jacob int64_t perf_remaining = total_pkts; 4949d3aeb18SJerin Jacob const uint64_t perf_sample = rte_get_timer_hz(); 4959d3aeb18SJerin Jacob 4969d3aeb18SJerin Jacob static float total_mpps; 4979d3aeb18SJerin Jacob static uint64_t samples; 4989d3aeb18SJerin Jacob 4999d3aeb18SJerin Jacob const uint64_t freq_mhz = rte_get_timer_hz() / 1000000; 5009d3aeb18SJerin Jacob int64_t remaining = t->outstand_pkts - processed_pkts(t); 5019d3aeb18SJerin Jacob 5029d3aeb18SJerin Jacob while (t->done == false) { 5039d3aeb18SJerin Jacob const uint64_t new_cycles = rte_get_timer_cycles(); 5049d3aeb18SJerin Jacob 5059d3aeb18SJerin Jacob if ((new_cycles - perf_cycles) > perf_sample) { 5069d3aeb18SJerin Jacob const uint64_t latency = total_latency(t); 5079d3aeb18SJerin Jacob const uint64_t pkts = processed_pkts(t); 5089d3aeb18SJerin Jacob 5099d3aeb18SJerin Jacob remaining = t->outstand_pkts - pkts; 5109d3aeb18SJerin Jacob float mpps = (float)(perf_remaining-remaining)/1000000; 5119d3aeb18SJerin Jacob 5129d3aeb18SJerin Jacob perf_remaining = remaining; 5139d3aeb18SJerin Jacob perf_cycles = new_cycles; 5149d3aeb18SJerin Jacob total_mpps += mpps; 5159d3aeb18SJerin Jacob ++samples; 51604716352SJerin Jacob if (opt->fwd_latency && pkts > 0) { 5179d3aeb18SJerin Jacob printf(CLGRN"\r%.3f mpps avg %.3f mpps [avg fwd latency %.3f us] "CLNRM, 5189d3aeb18SJerin Jacob mpps, total_mpps/samples, 5199d3aeb18SJerin Jacob (float)(latency/pkts)/freq_mhz); 5209d3aeb18SJerin Jacob } else { 5219d3aeb18SJerin Jacob printf(CLGRN"\r%.3f mpps avg %.3f mpps"CLNRM, 5229d3aeb18SJerin Jacob mpps, total_mpps/samples); 5239d3aeb18SJerin Jacob } 5249d3aeb18SJerin Jacob fflush(stdout); 5259d3aeb18SJerin Jacob 5269d3aeb18SJerin Jacob if (remaining <= 0) { 5279d3aeb18SJerin Jacob t->result = EVT_TEST_SUCCESS; 528d008f20bSPavan Nikhilesh if (opt->prod_type == EVT_PROD_TYPE_SYNT || 529d008f20bSPavan Nikhilesh opt->prod_type == 530*de2bc16eSShijith Thotton EVT_PROD_TYPE_EVENT_TIMER_ADPTR || 531*de2bc16eSShijith Thotton opt->prod_type == 532*de2bc16eSShijith Thotton EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR) { 53359f697e3SPavan Nikhilesh t->done = true; 5349d3aeb18SJerin Jacob break; 5359d3aeb18SJerin Jacob } 5369d3aeb18SJerin Jacob } 53759f697e3SPavan Nikhilesh } 5389d3aeb18SJerin Jacob 53959f697e3SPavan Nikhilesh if (new_cycles - dead_lock_cycles > dead_lock_sample && 54047303784SErik Gabriel Carrillo (opt->prod_type == EVT_PROD_TYPE_SYNT || 541*de2bc16eSShijith Thotton opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR || 542*de2bc16eSShijith Thotton opt->prod_type == EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR)) { 5439d3aeb18SJerin Jacob remaining = t->outstand_pkts - processed_pkts(t); 5449d3aeb18SJerin Jacob if (dead_lock_remaining == remaining) { 5459d3aeb18SJerin Jacob rte_event_dev_dump(opt->dev_id, stdout); 5469d3aeb18SJerin Jacob evt_err("No schedules for seconds, deadlock"); 5479d3aeb18SJerin Jacob t->done = true; 5489d3aeb18SJerin Jacob break; 5499d3aeb18SJerin Jacob } 5509d3aeb18SJerin Jacob dead_lock_remaining = remaining; 5519d3aeb18SJerin Jacob dead_lock_cycles = new_cycles; 5529d3aeb18SJerin Jacob } 5539d3aeb18SJerin Jacob } 5549d3aeb18SJerin Jacob printf("\n"); 5559d3aeb18SJerin Jacob return 0; 5569d3aeb18SJerin Jacob } 5579d3aeb18SJerin Jacob 5583617aae5SPavan Nikhilesh static int 5593617aae5SPavan Nikhilesh perf_event_rx_adapter_setup(struct evt_options *opt, uint8_t stride, 5603617aae5SPavan Nikhilesh struct rte_event_port_conf prod_conf) 5613617aae5SPavan Nikhilesh { 5623617aae5SPavan Nikhilesh int ret = 0; 5633617aae5SPavan Nikhilesh uint16_t prod; 5643617aae5SPavan Nikhilesh struct rte_event_eth_rx_adapter_queue_conf queue_conf; 5653617aae5SPavan Nikhilesh 5663617aae5SPavan Nikhilesh memset(&queue_conf, 0, 5673617aae5SPavan Nikhilesh sizeof(struct rte_event_eth_rx_adapter_queue_conf)); 5683617aae5SPavan Nikhilesh queue_conf.ev.sched_type = opt->sched_type_list[0]; 5698728ccf3SThomas Monjalon RTE_ETH_FOREACH_DEV(prod) { 5703617aae5SPavan Nikhilesh uint32_t cap; 5713617aae5SPavan Nikhilesh 5723617aae5SPavan Nikhilesh ret = rte_event_eth_rx_adapter_caps_get(opt->dev_id, 5733617aae5SPavan Nikhilesh prod, &cap); 5743617aae5SPavan Nikhilesh if (ret) { 5753617aae5SPavan Nikhilesh evt_err("failed to get event rx adapter[%d]" 5763617aae5SPavan Nikhilesh " capabilities", 5773617aae5SPavan Nikhilesh opt->dev_id); 5783617aae5SPavan Nikhilesh return ret; 5793617aae5SPavan Nikhilesh } 5803617aae5SPavan Nikhilesh queue_conf.ev.queue_id = prod * stride; 5813617aae5SPavan Nikhilesh ret = rte_event_eth_rx_adapter_create(prod, opt->dev_id, 5823617aae5SPavan Nikhilesh &prod_conf); 5833617aae5SPavan Nikhilesh if (ret) { 5843617aae5SPavan Nikhilesh evt_err("failed to create rx adapter[%d]", prod); 5853617aae5SPavan Nikhilesh return ret; 5863617aae5SPavan Nikhilesh } 5873617aae5SPavan Nikhilesh ret = rte_event_eth_rx_adapter_queue_add(prod, prod, -1, 5883617aae5SPavan Nikhilesh &queue_conf); 5893617aae5SPavan Nikhilesh if (ret) { 5903617aae5SPavan Nikhilesh evt_err("failed to add rx queues to adapter[%d]", prod); 5913617aae5SPavan Nikhilesh return ret; 5923617aae5SPavan Nikhilesh } 5933617aae5SPavan Nikhilesh 594b0333c55SPavan Nikhilesh if (!(cap & RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT)) { 595b0333c55SPavan Nikhilesh uint32_t service_id; 596b0333c55SPavan Nikhilesh 597b0333c55SPavan Nikhilesh rte_event_eth_rx_adapter_service_id_get(prod, 598b0333c55SPavan Nikhilesh &service_id); 599b0333c55SPavan Nikhilesh ret = evt_service_setup(service_id); 600b0333c55SPavan Nikhilesh if (ret) { 601b0333c55SPavan Nikhilesh evt_err("Failed to setup service core" 602b0333c55SPavan Nikhilesh " for Rx adapter\n"); 603b0333c55SPavan Nikhilesh return ret; 604b0333c55SPavan Nikhilesh } 605b0333c55SPavan Nikhilesh } 6063617aae5SPavan Nikhilesh } 6073617aae5SPavan Nikhilesh 6083617aae5SPavan Nikhilesh return ret; 6093617aae5SPavan Nikhilesh } 6103617aae5SPavan Nikhilesh 611d008f20bSPavan Nikhilesh static int 612d008f20bSPavan Nikhilesh perf_event_timer_adapter_setup(struct test_perf *t) 613d008f20bSPavan Nikhilesh { 614d008f20bSPavan Nikhilesh int i; 615d008f20bSPavan Nikhilesh int ret; 616d008f20bSPavan Nikhilesh struct rte_event_timer_adapter_info adapter_info; 617d008f20bSPavan Nikhilesh struct rte_event_timer_adapter *wl; 618d008f20bSPavan Nikhilesh uint8_t nb_producers = evt_nr_active_lcores(t->opt->plcores); 619d008f20bSPavan Nikhilesh uint8_t flags = RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES; 620d008f20bSPavan Nikhilesh 621d008f20bSPavan Nikhilesh if (nb_producers == 1) 622d008f20bSPavan Nikhilesh flags |= RTE_EVENT_TIMER_ADAPTER_F_SP_PUT; 623d008f20bSPavan Nikhilesh 624d008f20bSPavan Nikhilesh for (i = 0; i < t->opt->nb_timer_adptrs; i++) { 625d008f20bSPavan Nikhilesh struct rte_event_timer_adapter_conf config = { 626d008f20bSPavan Nikhilesh .event_dev_id = t->opt->dev_id, 627d008f20bSPavan Nikhilesh .timer_adapter_id = i, 628d008f20bSPavan Nikhilesh .timer_tick_ns = t->opt->timer_tick_nsec, 629d008f20bSPavan Nikhilesh .max_tmo_ns = t->opt->max_tmo_nsec, 630c13b1ad7SPavan Nikhilesh .nb_timers = t->opt->pool_sz, 631d008f20bSPavan Nikhilesh .flags = flags, 632d008f20bSPavan Nikhilesh }; 633d008f20bSPavan Nikhilesh 634d008f20bSPavan Nikhilesh wl = rte_event_timer_adapter_create(&config); 635d008f20bSPavan Nikhilesh if (wl == NULL) { 636d008f20bSPavan Nikhilesh evt_err("failed to create event timer ring %d", i); 637d008f20bSPavan Nikhilesh return rte_errno; 638d008f20bSPavan Nikhilesh } 639d008f20bSPavan Nikhilesh 640d008f20bSPavan Nikhilesh memset(&adapter_info, 0, 641d008f20bSPavan Nikhilesh sizeof(struct rte_event_timer_adapter_info)); 642d008f20bSPavan Nikhilesh rte_event_timer_adapter_get_info(wl, &adapter_info); 643d008f20bSPavan Nikhilesh t->opt->optm_timer_tick_nsec = adapter_info.min_resolution_ns; 644d008f20bSPavan Nikhilesh 645d008f20bSPavan Nikhilesh if (!(adapter_info.caps & 646d008f20bSPavan Nikhilesh RTE_EVENT_TIMER_ADAPTER_CAP_INTERNAL_PORT)) { 64799c25664SAndrzej Ostruszka uint32_t service_id = -1U; 648d008f20bSPavan Nikhilesh 649d008f20bSPavan Nikhilesh rte_event_timer_adapter_service_id_get(wl, 650d008f20bSPavan Nikhilesh &service_id); 651d008f20bSPavan Nikhilesh ret = evt_service_setup(service_id); 652d008f20bSPavan Nikhilesh if (ret) { 653d008f20bSPavan Nikhilesh evt_err("Failed to setup service core" 654d008f20bSPavan Nikhilesh " for timer adapter\n"); 655d008f20bSPavan Nikhilesh return ret; 656d008f20bSPavan Nikhilesh } 657d008f20bSPavan Nikhilesh rte_service_runstate_set(service_id, 1); 658d008f20bSPavan Nikhilesh } 659d008f20bSPavan Nikhilesh t->timer_adptr[i] = wl; 660d008f20bSPavan Nikhilesh } 661d008f20bSPavan Nikhilesh return 0; 662d008f20bSPavan Nikhilesh } 663d008f20bSPavan Nikhilesh 664*de2bc16eSShijith Thotton static int 665*de2bc16eSShijith Thotton perf_event_crypto_adapter_setup(struct test_perf *t, struct prod_data *p) 666*de2bc16eSShijith Thotton { 667*de2bc16eSShijith Thotton struct evt_options *opt = t->opt; 668*de2bc16eSShijith Thotton uint32_t cap; 669*de2bc16eSShijith Thotton int ret; 670*de2bc16eSShijith Thotton 671*de2bc16eSShijith Thotton ret = rte_event_crypto_adapter_caps_get(p->dev_id, p->ca.cdev_id, &cap); 672*de2bc16eSShijith Thotton if (ret) { 673*de2bc16eSShijith Thotton evt_err("Failed to get crypto adapter capabilities"); 674*de2bc16eSShijith Thotton return ret; 675*de2bc16eSShijith Thotton } 676*de2bc16eSShijith Thotton 677*de2bc16eSShijith Thotton if (((opt->crypto_adptr_mode == RTE_EVENT_CRYPTO_ADAPTER_OP_NEW) && 678*de2bc16eSShijith Thotton !(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW)) || 679*de2bc16eSShijith Thotton ((opt->crypto_adptr_mode == RTE_EVENT_CRYPTO_ADAPTER_OP_FORWARD) && 680*de2bc16eSShijith Thotton !(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD))) { 681*de2bc16eSShijith Thotton evt_err("crypto adapter %s mode unsupported\n", 682*de2bc16eSShijith Thotton opt->crypto_adptr_mode ? "OP_FORWARD" : "OP_NEW"); 683*de2bc16eSShijith Thotton return -ENOTSUP; 684*de2bc16eSShijith Thotton } else if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_SESSION_PRIVATE_DATA)) { 685*de2bc16eSShijith Thotton evt_err("Storing crypto session not supported"); 686*de2bc16eSShijith Thotton return -ENOTSUP; 687*de2bc16eSShijith Thotton } 688*de2bc16eSShijith Thotton 689*de2bc16eSShijith Thotton if (cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_QP_EV_BIND) { 690*de2bc16eSShijith Thotton struct rte_event response_info; 691*de2bc16eSShijith Thotton 692*de2bc16eSShijith Thotton response_info.event = 0; 693*de2bc16eSShijith Thotton response_info.sched_type = RTE_SCHED_TYPE_ATOMIC; 694*de2bc16eSShijith Thotton response_info.queue_id = p->queue_id; 695*de2bc16eSShijith Thotton ret = rte_event_crypto_adapter_queue_pair_add( 696*de2bc16eSShijith Thotton TEST_PERF_CA_ID, p->ca.cdev_id, p->ca.cdev_qp_id, 697*de2bc16eSShijith Thotton &response_info); 698*de2bc16eSShijith Thotton } else { 699*de2bc16eSShijith Thotton ret = rte_event_crypto_adapter_queue_pair_add( 700*de2bc16eSShijith Thotton TEST_PERF_CA_ID, p->ca.cdev_id, p->ca.cdev_qp_id, NULL); 701*de2bc16eSShijith Thotton } 702*de2bc16eSShijith Thotton 703*de2bc16eSShijith Thotton return ret; 704*de2bc16eSShijith Thotton } 705*de2bc16eSShijith Thotton 706*de2bc16eSShijith Thotton static struct rte_cryptodev_sym_session * 707*de2bc16eSShijith Thotton cryptodev_sym_sess_create(struct prod_data *p, struct test_perf *t) 708*de2bc16eSShijith Thotton { 709*de2bc16eSShijith Thotton struct rte_crypto_sym_xform cipher_xform; 710*de2bc16eSShijith Thotton struct rte_cryptodev_sym_session *sess; 711*de2bc16eSShijith Thotton 712*de2bc16eSShijith Thotton cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 713*de2bc16eSShijith Thotton cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 714*de2bc16eSShijith Thotton cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 715*de2bc16eSShijith Thotton cipher_xform.next = NULL; 716*de2bc16eSShijith Thotton 717*de2bc16eSShijith Thotton sess = rte_cryptodev_sym_session_create(t->ca_sess_pool); 718*de2bc16eSShijith Thotton if (sess == NULL) { 719*de2bc16eSShijith Thotton evt_err("Failed to create sym session"); 720*de2bc16eSShijith Thotton return NULL; 721*de2bc16eSShijith Thotton } 722*de2bc16eSShijith Thotton 723*de2bc16eSShijith Thotton if (rte_cryptodev_sym_session_init(p->ca.cdev_id, sess, &cipher_xform, 724*de2bc16eSShijith Thotton t->ca_sess_priv_pool)) { 725*de2bc16eSShijith Thotton evt_err("Failed to init session"); 726*de2bc16eSShijith Thotton return NULL; 727*de2bc16eSShijith Thotton } 728*de2bc16eSShijith Thotton 729*de2bc16eSShijith Thotton return sess; 730*de2bc16eSShijith Thotton } 731*de2bc16eSShijith Thotton 732272de067SJerin Jacob int 73384a7513dSJerin Jacob perf_event_dev_port_setup(struct evt_test *test, struct evt_options *opt, 734535c630cSPavan Nikhilesh uint8_t stride, uint8_t nb_queues, 735535c630cSPavan Nikhilesh const struct rte_event_port_conf *port_conf) 73684a7513dSJerin Jacob { 73784a7513dSJerin Jacob struct test_perf *t = evt_test_priv(test); 7383617aae5SPavan Nikhilesh uint16_t port, prod; 73984a7513dSJerin Jacob int ret = -1; 74084a7513dSJerin Jacob 74184a7513dSJerin Jacob /* setup one port per worker, linking to all queues */ 74284a7513dSJerin Jacob for (port = 0; port < evt_nr_active_lcores(opt->wlcores); 74384a7513dSJerin Jacob port++) { 74484a7513dSJerin Jacob struct worker_data *w = &t->worker[port]; 74584a7513dSJerin Jacob 74684a7513dSJerin Jacob w->dev_id = opt->dev_id; 74784a7513dSJerin Jacob w->port_id = port; 74884a7513dSJerin Jacob w->t = t; 74984a7513dSJerin Jacob w->processed_pkts = 0; 75084a7513dSJerin Jacob w->latency = 0; 75184a7513dSJerin Jacob 7525f94d108SHarry van Haaren struct rte_event_port_conf conf = *port_conf; 7535f94d108SHarry van Haaren conf.event_port_cfg |= RTE_EVENT_PORT_CFG_HINT_WORKER; 7545f94d108SHarry van Haaren 7555f94d108SHarry van Haaren ret = rte_event_port_setup(opt->dev_id, port, &conf); 75684a7513dSJerin Jacob if (ret) { 75784a7513dSJerin Jacob evt_err("failed to setup port %d", port); 75884a7513dSJerin Jacob return ret; 75984a7513dSJerin Jacob } 76084a7513dSJerin Jacob 76184a7513dSJerin Jacob ret = rte_event_port_link(opt->dev_id, port, NULL, NULL, 0); 76284a7513dSJerin Jacob if (ret != nb_queues) { 76384a7513dSJerin Jacob evt_err("failed to link all queues to port %d", port); 76484a7513dSJerin Jacob return -EINVAL; 76584a7513dSJerin Jacob } 76684a7513dSJerin Jacob } 76784a7513dSJerin Jacob 76884a7513dSJerin Jacob /* port for producers, no links */ 7693617aae5SPavan Nikhilesh if (opt->prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR) { 7703617aae5SPavan Nikhilesh for ( ; port < perf_nb_event_ports(opt); port++) { 7713617aae5SPavan Nikhilesh struct prod_data *p = &t->prod[port]; 7723617aae5SPavan Nikhilesh p->t = t; 7733617aae5SPavan Nikhilesh } 7743617aae5SPavan Nikhilesh 7755f94d108SHarry van Haaren struct rte_event_port_conf conf = *port_conf; 7765f94d108SHarry van Haaren conf.event_port_cfg |= RTE_EVENT_PORT_CFG_HINT_PRODUCER; 7775f94d108SHarry van Haaren 7785f94d108SHarry van Haaren ret = perf_event_rx_adapter_setup(opt, stride, conf); 7793617aae5SPavan Nikhilesh if (ret) 7803617aae5SPavan Nikhilesh return ret; 781d008f20bSPavan Nikhilesh } else if (opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) { 782d008f20bSPavan Nikhilesh prod = 0; 783d008f20bSPavan Nikhilesh for ( ; port < perf_nb_event_ports(opt); port++) { 784d008f20bSPavan Nikhilesh struct prod_data *p = &t->prod[port]; 785d008f20bSPavan Nikhilesh p->queue_id = prod * stride; 786d008f20bSPavan Nikhilesh p->t = t; 787d008f20bSPavan Nikhilesh prod++; 788d008f20bSPavan Nikhilesh } 789d008f20bSPavan Nikhilesh 790d008f20bSPavan Nikhilesh ret = perf_event_timer_adapter_setup(t); 791d008f20bSPavan Nikhilesh if (ret) 792d008f20bSPavan Nikhilesh return ret; 793*de2bc16eSShijith Thotton } else if (opt->prod_type == EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR) { 794*de2bc16eSShijith Thotton struct rte_event_port_conf conf = *port_conf; 795*de2bc16eSShijith Thotton uint8_t cdev_id = 0; 796*de2bc16eSShijith Thotton uint16_t qp_id = 0; 797*de2bc16eSShijith Thotton 798*de2bc16eSShijith Thotton ret = rte_event_crypto_adapter_create(TEST_PERF_CA_ID, 799*de2bc16eSShijith Thotton opt->dev_id, &conf, 0); 800*de2bc16eSShijith Thotton if (ret) { 801*de2bc16eSShijith Thotton evt_err("Failed to create crypto adapter"); 802*de2bc16eSShijith Thotton return ret; 803*de2bc16eSShijith Thotton } 804*de2bc16eSShijith Thotton 805*de2bc16eSShijith Thotton prod = 0; 806*de2bc16eSShijith Thotton for (; port < perf_nb_event_ports(opt); port++) { 807*de2bc16eSShijith Thotton struct rte_cryptodev_sym_session *crypto_sess; 808*de2bc16eSShijith Thotton union rte_event_crypto_metadata m_data; 809*de2bc16eSShijith Thotton struct prod_data *p = &t->prod[port]; 810*de2bc16eSShijith Thotton uint32_t flow_id; 811*de2bc16eSShijith Thotton 812*de2bc16eSShijith Thotton if (qp_id == rte_cryptodev_queue_pair_count(cdev_id)) { 813*de2bc16eSShijith Thotton cdev_id++; 814*de2bc16eSShijith Thotton qp_id = 0; 815*de2bc16eSShijith Thotton } 816*de2bc16eSShijith Thotton 817*de2bc16eSShijith Thotton p->dev_id = opt->dev_id; 818*de2bc16eSShijith Thotton p->port_id = port; 819*de2bc16eSShijith Thotton p->queue_id = prod * stride; 820*de2bc16eSShijith Thotton p->ca.cdev_id = cdev_id; 821*de2bc16eSShijith Thotton p->ca.cdev_qp_id = qp_id; 822*de2bc16eSShijith Thotton p->ca.crypto_sess = rte_zmalloc_socket( 823*de2bc16eSShijith Thotton NULL, sizeof(crypto_sess) * t->nb_flows, 824*de2bc16eSShijith Thotton RTE_CACHE_LINE_SIZE, opt->socket_id); 825*de2bc16eSShijith Thotton p->t = t; 826*de2bc16eSShijith Thotton 827*de2bc16eSShijith Thotton m_data.request_info.cdev_id = p->ca.cdev_id; 828*de2bc16eSShijith Thotton m_data.request_info.queue_pair_id = p->ca.cdev_qp_id; 829*de2bc16eSShijith Thotton m_data.response_info.sched_type = RTE_SCHED_TYPE_ATOMIC; 830*de2bc16eSShijith Thotton m_data.response_info.queue_id = p->queue_id; 831*de2bc16eSShijith Thotton 832*de2bc16eSShijith Thotton for (flow_id = 0; flow_id < t->nb_flows; flow_id++) { 833*de2bc16eSShijith Thotton crypto_sess = cryptodev_sym_sess_create(p, t); 834*de2bc16eSShijith Thotton if (crypto_sess == NULL) 835*de2bc16eSShijith Thotton return -ENOMEM; 836*de2bc16eSShijith Thotton 837*de2bc16eSShijith Thotton m_data.response_info.flow_id = flow_id; 838*de2bc16eSShijith Thotton rte_cryptodev_sym_session_set_user_data( 839*de2bc16eSShijith Thotton crypto_sess, &m_data, sizeof(m_data)); 840*de2bc16eSShijith Thotton p->ca.crypto_sess[flow_id] = crypto_sess; 841*de2bc16eSShijith Thotton } 842*de2bc16eSShijith Thotton 843*de2bc16eSShijith Thotton conf.event_port_cfg |= 844*de2bc16eSShijith Thotton RTE_EVENT_PORT_CFG_HINT_PRODUCER | 845*de2bc16eSShijith Thotton RTE_EVENT_PORT_CFG_HINT_CONSUMER; 846*de2bc16eSShijith Thotton 847*de2bc16eSShijith Thotton ret = rte_event_port_setup(opt->dev_id, port, &conf); 848*de2bc16eSShijith Thotton if (ret) { 849*de2bc16eSShijith Thotton evt_err("failed to setup port %d", port); 850*de2bc16eSShijith Thotton return ret; 851*de2bc16eSShijith Thotton } 852*de2bc16eSShijith Thotton 853*de2bc16eSShijith Thotton ret = perf_event_crypto_adapter_setup(t, p); 854*de2bc16eSShijith Thotton if (ret) 855*de2bc16eSShijith Thotton return ret; 856*de2bc16eSShijith Thotton 857*de2bc16eSShijith Thotton qp_id++; 858*de2bc16eSShijith Thotton prod++; 859*de2bc16eSShijith Thotton } 8603617aae5SPavan Nikhilesh } else { 86184a7513dSJerin Jacob prod = 0; 86284a7513dSJerin Jacob for ( ; port < perf_nb_event_ports(opt); port++) { 86384a7513dSJerin Jacob struct prod_data *p = &t->prod[port]; 86484a7513dSJerin Jacob 86584a7513dSJerin Jacob p->dev_id = opt->dev_id; 86684a7513dSJerin Jacob p->port_id = port; 86784a7513dSJerin Jacob p->queue_id = prod * stride; 86884a7513dSJerin Jacob p->t = t; 86984a7513dSJerin Jacob 8705f94d108SHarry van Haaren struct rte_event_port_conf conf = *port_conf; 8715f94d108SHarry van Haaren conf.event_port_cfg |= 8725f94d108SHarry van Haaren RTE_EVENT_PORT_CFG_HINT_PRODUCER | 8735f94d108SHarry van Haaren RTE_EVENT_PORT_CFG_HINT_CONSUMER; 8745f94d108SHarry van Haaren 8755f94d108SHarry van Haaren ret = rte_event_port_setup(opt->dev_id, port, &conf); 87684a7513dSJerin Jacob if (ret) { 87784a7513dSJerin Jacob evt_err("failed to setup port %d", port); 87884a7513dSJerin Jacob return ret; 87984a7513dSJerin Jacob } 88084a7513dSJerin Jacob prod++; 88184a7513dSJerin Jacob } 8823617aae5SPavan Nikhilesh } 88384a7513dSJerin Jacob 88484a7513dSJerin Jacob return ret; 88584a7513dSJerin Jacob } 88684a7513dSJerin Jacob 88784a7513dSJerin Jacob int 888272de067SJerin Jacob perf_opt_check(struct evt_options *opt, uint64_t nb_queues) 889272de067SJerin Jacob { 890272de067SJerin Jacob unsigned int lcores; 891272de067SJerin Jacob 892cb056611SStephen Hemminger /* N producer + N worker + main when producer cores are used 893cb056611SStephen Hemminger * Else N worker + main when Rx adapter is used 894b01974daSPavan Nikhilesh */ 895b01974daSPavan Nikhilesh lcores = opt->prod_type == EVT_PROD_TYPE_SYNT ? 3 : 2; 896272de067SJerin Jacob 897272de067SJerin Jacob if (rte_lcore_count() < lcores) { 898272de067SJerin Jacob evt_err("test need minimum %d lcores", lcores); 899272de067SJerin Jacob return -1; 900272de067SJerin Jacob } 901272de067SJerin Jacob 902272de067SJerin Jacob /* Validate worker lcores */ 903cb056611SStephen Hemminger if (evt_lcores_has_overlap(opt->wlcores, rte_get_main_lcore())) { 904cb056611SStephen Hemminger evt_err("worker lcores overlaps with main lcore"); 905272de067SJerin Jacob return -1; 906272de067SJerin Jacob } 907272de067SJerin Jacob if (evt_lcores_has_overlap_multi(opt->wlcores, opt->plcores)) { 908272de067SJerin Jacob evt_err("worker lcores overlaps producer lcores"); 909272de067SJerin Jacob return -1; 910272de067SJerin Jacob } 911272de067SJerin Jacob if (evt_has_disabled_lcore(opt->wlcores)) { 912272de067SJerin Jacob evt_err("one or more workers lcores are not enabled"); 913272de067SJerin Jacob return -1; 914272de067SJerin Jacob } 915272de067SJerin Jacob if (!evt_has_active_lcore(opt->wlcores)) { 916272de067SJerin Jacob evt_err("minimum one worker is required"); 917272de067SJerin Jacob return -1; 918272de067SJerin Jacob } 919272de067SJerin Jacob 920902387eaSPavan Nikhilesh if (opt->prod_type == EVT_PROD_TYPE_SYNT || 921*de2bc16eSShijith Thotton opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR || 922*de2bc16eSShijith Thotton opt->prod_type == EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR) { 923272de067SJerin Jacob /* Validate producer lcores */ 924b01974daSPavan Nikhilesh if (evt_lcores_has_overlap(opt->plcores, 925cb056611SStephen Hemminger rte_get_main_lcore())) { 926cb056611SStephen Hemminger evt_err("producer lcores overlaps with main lcore"); 927272de067SJerin Jacob return -1; 928272de067SJerin Jacob } 929272de067SJerin Jacob if (evt_has_disabled_lcore(opt->plcores)) { 930272de067SJerin Jacob evt_err("one or more producer lcores are not enabled"); 931272de067SJerin Jacob return -1; 932272de067SJerin Jacob } 933272de067SJerin Jacob if (!evt_has_active_lcore(opt->plcores)) { 934272de067SJerin Jacob evt_err("minimum one producer is required"); 935272de067SJerin Jacob return -1; 936272de067SJerin Jacob } 937b01974daSPavan Nikhilesh } 938272de067SJerin Jacob 939272de067SJerin Jacob if (evt_has_invalid_stage(opt)) 940272de067SJerin Jacob return -1; 941272de067SJerin Jacob 942272de067SJerin Jacob if (evt_has_invalid_sched_type(opt)) 943272de067SJerin Jacob return -1; 944272de067SJerin Jacob 945272de067SJerin Jacob if (nb_queues > EVT_MAX_QUEUES) { 946272de067SJerin Jacob evt_err("number of queues exceeds %d", EVT_MAX_QUEUES); 947272de067SJerin Jacob return -1; 948272de067SJerin Jacob } 949272de067SJerin Jacob if (perf_nb_event_ports(opt) > EVT_MAX_PORTS) { 950272de067SJerin Jacob evt_err("number of ports exceeds %d", EVT_MAX_PORTS); 951272de067SJerin Jacob return -1; 952272de067SJerin Jacob } 953272de067SJerin Jacob 954272de067SJerin Jacob /* Fixups */ 955d008f20bSPavan Nikhilesh if ((opt->nb_stages == 1 && 956d008f20bSPavan Nikhilesh opt->prod_type != EVT_PROD_TYPE_EVENT_TIMER_ADPTR) && 957d008f20bSPavan Nikhilesh opt->fwd_latency) { 958272de067SJerin Jacob evt_info("fwd_latency is valid when nb_stages > 1, disabling"); 959272de067SJerin Jacob opt->fwd_latency = 0; 960272de067SJerin Jacob } 961d008f20bSPavan Nikhilesh 962272de067SJerin Jacob if (opt->fwd_latency && !opt->q_priority) { 963272de067SJerin Jacob evt_info("enabled queue priority for latency measurement"); 964272de067SJerin Jacob opt->q_priority = 1; 965272de067SJerin Jacob } 9669d3aeb18SJerin Jacob if (opt->nb_pkts == 0) 9679d3aeb18SJerin Jacob opt->nb_pkts = INT64_MAX/evt_nr_active_lcores(opt->plcores); 968272de067SJerin Jacob 969272de067SJerin Jacob return 0; 970272de067SJerin Jacob } 971272de067SJerin Jacob 972272de067SJerin Jacob void 973272de067SJerin Jacob perf_opt_dump(struct evt_options *opt, uint8_t nb_queues) 974272de067SJerin Jacob { 975272de067SJerin Jacob evt_dump("nb_prod_lcores", "%d", evt_nr_active_lcores(opt->plcores)); 976272de067SJerin Jacob evt_dump_producer_lcores(opt); 977272de067SJerin Jacob evt_dump("nb_worker_lcores", "%d", evt_nr_active_lcores(opt->wlcores)); 978272de067SJerin Jacob evt_dump_worker_lcores(opt); 979272de067SJerin Jacob evt_dump_nb_stages(opt); 980272de067SJerin Jacob evt_dump("nb_evdev_ports", "%d", perf_nb_event_ports(opt)); 981272de067SJerin Jacob evt_dump("nb_evdev_queues", "%d", nb_queues); 982272de067SJerin Jacob evt_dump_queue_priority(opt); 983272de067SJerin Jacob evt_dump_sched_type_list(opt); 984b01974daSPavan Nikhilesh evt_dump_producer_type(opt); 98520841a25SRashmi Shetty evt_dump("prod_enq_burst_sz", "%d", opt->prod_enq_burst_sz); 986272de067SJerin Jacob } 987272de067SJerin Jacob 98841c219e6SJerin Jacob void 98941c219e6SJerin Jacob perf_eventdev_destroy(struct evt_test *test, struct evt_options *opt) 99041c219e6SJerin Jacob { 991d008f20bSPavan Nikhilesh int i; 992d008f20bSPavan Nikhilesh struct test_perf *t = evt_test_priv(test); 99341c219e6SJerin Jacob 994d008f20bSPavan Nikhilesh if (opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) { 995d008f20bSPavan Nikhilesh for (i = 0; i < opt->nb_timer_adptrs; i++) 996d008f20bSPavan Nikhilesh rte_event_timer_adapter_stop(t->timer_adptr[i]); 997d008f20bSPavan Nikhilesh } 99841c219e6SJerin Jacob rte_event_dev_stop(opt->dev_id); 99941c219e6SJerin Jacob rte_event_dev_close(opt->dev_id); 100041c219e6SJerin Jacob } 100141c219e6SJerin Jacob 100241c219e6SJerin Jacob static inline void 100341c219e6SJerin Jacob perf_elt_init(struct rte_mempool *mp, void *arg __rte_unused, 100441c219e6SJerin Jacob void *obj, unsigned i __rte_unused) 100541c219e6SJerin Jacob { 100641c219e6SJerin Jacob memset(obj, 0, mp->elt_size); 100741c219e6SJerin Jacob } 100841c219e6SJerin Jacob 10093fc8de4fSPavan Nikhilesh #define NB_RX_DESC 128 10103fc8de4fSPavan Nikhilesh #define NB_TX_DESC 512 10113fc8de4fSPavan Nikhilesh int 10123fc8de4fSPavan Nikhilesh perf_ethdev_setup(struct evt_test *test, struct evt_options *opt) 10133fc8de4fSPavan Nikhilesh { 10148728ccf3SThomas Monjalon uint16_t i; 101577339255SIvan Ilchenko int ret; 10163fc8de4fSPavan Nikhilesh struct test_perf *t = evt_test_priv(test); 10173fc8de4fSPavan Nikhilesh struct rte_eth_conf port_conf = { 10183fc8de4fSPavan Nikhilesh .rxmode = { 1019295968d1SFerruh Yigit .mq_mode = RTE_ETH_MQ_RX_RSS, 10203fc8de4fSPavan Nikhilesh .split_hdr_size = 0, 10213fc8de4fSPavan Nikhilesh }, 10223fc8de4fSPavan Nikhilesh .rx_adv_conf = { 10233fc8de4fSPavan Nikhilesh .rss_conf = { 10243fc8de4fSPavan Nikhilesh .rss_key = NULL, 1025295968d1SFerruh Yigit .rss_hf = RTE_ETH_RSS_IP, 10263fc8de4fSPavan Nikhilesh }, 10273fc8de4fSPavan Nikhilesh }, 10283fc8de4fSPavan Nikhilesh }; 10293fc8de4fSPavan Nikhilesh 1030*de2bc16eSShijith Thotton if (opt->prod_type != EVT_PROD_TYPE_ETH_RX_ADPTR) 10313fc8de4fSPavan Nikhilesh return 0; 10323fc8de4fSPavan Nikhilesh 1033d9a42a69SThomas Monjalon if (!rte_eth_dev_count_avail()) { 10343fc8de4fSPavan Nikhilesh evt_err("No ethernet ports found."); 10353fc8de4fSPavan Nikhilesh return -ENODEV; 10363fc8de4fSPavan Nikhilesh } 10373fc8de4fSPavan Nikhilesh 10388728ccf3SThomas Monjalon RTE_ETH_FOREACH_DEV(i) { 10394f5701f2SFerruh Yigit struct rte_eth_dev_info dev_info; 10404f5701f2SFerruh Yigit struct rte_eth_conf local_port_conf = port_conf; 10413fc8de4fSPavan Nikhilesh 104277339255SIvan Ilchenko ret = rte_eth_dev_info_get(i, &dev_info); 104377339255SIvan Ilchenko if (ret != 0) { 104477339255SIvan Ilchenko evt_err("Error during getting device (port %u) info: %s\n", 104577339255SIvan Ilchenko i, strerror(-ret)); 104677339255SIvan Ilchenko return ret; 104777339255SIvan Ilchenko } 10484f5701f2SFerruh Yigit 10494f5701f2SFerruh Yigit local_port_conf.rx_adv_conf.rss_conf.rss_hf &= 10504f5701f2SFerruh Yigit dev_info.flow_type_rss_offloads; 10514f5701f2SFerruh Yigit if (local_port_conf.rx_adv_conf.rss_conf.rss_hf != 10524f5701f2SFerruh Yigit port_conf.rx_adv_conf.rss_conf.rss_hf) { 10534f5701f2SFerruh Yigit evt_info("Port %u modified RSS hash function based on hardware support," 10544f5701f2SFerruh Yigit "requested:%#"PRIx64" configured:%#"PRIx64"\n", 10554f5701f2SFerruh Yigit i, 10564f5701f2SFerruh Yigit port_conf.rx_adv_conf.rss_conf.rss_hf, 10574f5701f2SFerruh Yigit local_port_conf.rx_adv_conf.rss_conf.rss_hf); 10584f5701f2SFerruh Yigit } 10594f5701f2SFerruh Yigit 10604f5701f2SFerruh Yigit if (rte_eth_dev_configure(i, 1, 1, &local_port_conf) < 0) { 10613fc8de4fSPavan Nikhilesh evt_err("Failed to configure eth port [%d]", i); 10623fc8de4fSPavan Nikhilesh return -EINVAL; 10633fc8de4fSPavan Nikhilesh } 10643fc8de4fSPavan Nikhilesh 10653fc8de4fSPavan Nikhilesh if (rte_eth_rx_queue_setup(i, 0, NB_RX_DESC, 10663fc8de4fSPavan Nikhilesh rte_socket_id(), NULL, t->pool) < 0) { 10673fc8de4fSPavan Nikhilesh evt_err("Failed to setup eth port [%d] rx_queue: %d.", 10683fc8de4fSPavan Nikhilesh i, 0); 10693fc8de4fSPavan Nikhilesh return -EINVAL; 10703fc8de4fSPavan Nikhilesh } 10713fc8de4fSPavan Nikhilesh 10723fc8de4fSPavan Nikhilesh if (rte_eth_tx_queue_setup(i, 0, NB_TX_DESC, 10733fc8de4fSPavan Nikhilesh rte_socket_id(), NULL) < 0) { 10743fc8de4fSPavan Nikhilesh evt_err("Failed to setup eth port [%d] tx_queue: %d.", 10753fc8de4fSPavan Nikhilesh i, 0); 10763fc8de4fSPavan Nikhilesh return -EINVAL; 10773fc8de4fSPavan Nikhilesh } 10783fc8de4fSPavan Nikhilesh 107970e51a0eSIvan Ilchenko ret = rte_eth_promiscuous_enable(i); 108070e51a0eSIvan Ilchenko if (ret != 0) { 108170e51a0eSIvan Ilchenko evt_err("Failed to enable promiscuous mode for eth port [%d]: %s", 108270e51a0eSIvan Ilchenko i, rte_strerror(-ret)); 108370e51a0eSIvan Ilchenko return ret; 108470e51a0eSIvan Ilchenko } 10853fc8de4fSPavan Nikhilesh } 10863fc8de4fSPavan Nikhilesh 10873fc8de4fSPavan Nikhilesh return 0; 10883fc8de4fSPavan Nikhilesh } 10893fc8de4fSPavan Nikhilesh 10907f3daf34SPavan Nikhilesh void perf_ethdev_destroy(struct evt_test *test, struct evt_options *opt) 10917f3daf34SPavan Nikhilesh { 10928728ccf3SThomas Monjalon uint16_t i; 10937f3daf34SPavan Nikhilesh RTE_SET_USED(test); 10947f3daf34SPavan Nikhilesh 10957f3daf34SPavan Nikhilesh if (opt->prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR) { 10968728ccf3SThomas Monjalon RTE_ETH_FOREACH_DEV(i) { 10973617aae5SPavan Nikhilesh rte_event_eth_rx_adapter_stop(i); 10987f3daf34SPavan Nikhilesh rte_eth_dev_stop(i); 10997f3daf34SPavan Nikhilesh } 11007f3daf34SPavan Nikhilesh } 11017f3daf34SPavan Nikhilesh } 11027f3daf34SPavan Nikhilesh 110341c219e6SJerin Jacob int 1104*de2bc16eSShijith Thotton perf_cryptodev_setup(struct evt_test *test, struct evt_options *opt) 1105*de2bc16eSShijith Thotton { 1106*de2bc16eSShijith Thotton uint8_t cdev_count, cdev_id, nb_plcores, nb_qps; 1107*de2bc16eSShijith Thotton struct test_perf *t = evt_test_priv(test); 1108*de2bc16eSShijith Thotton unsigned int max_session_size; 1109*de2bc16eSShijith Thotton uint32_t nb_sessions; 1110*de2bc16eSShijith Thotton int ret; 1111*de2bc16eSShijith Thotton 1112*de2bc16eSShijith Thotton if (opt->prod_type != EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR) 1113*de2bc16eSShijith Thotton return 0; 1114*de2bc16eSShijith Thotton 1115*de2bc16eSShijith Thotton cdev_count = rte_cryptodev_count(); 1116*de2bc16eSShijith Thotton if (cdev_count == 0) { 1117*de2bc16eSShijith Thotton evt_err("No crypto devices available\n"); 1118*de2bc16eSShijith Thotton return -ENODEV; 1119*de2bc16eSShijith Thotton } 1120*de2bc16eSShijith Thotton 1121*de2bc16eSShijith Thotton t->ca_op_pool = rte_crypto_op_pool_create( 1122*de2bc16eSShijith Thotton "crypto_op_pool", RTE_CRYPTO_OP_TYPE_SYMMETRIC, opt->pool_sz, 1123*de2bc16eSShijith Thotton 128, 0, rte_socket_id()); 1124*de2bc16eSShijith Thotton if (t->ca_op_pool == NULL) { 1125*de2bc16eSShijith Thotton evt_err("Failed to create crypto op pool"); 1126*de2bc16eSShijith Thotton return -ENOMEM; 1127*de2bc16eSShijith Thotton } 1128*de2bc16eSShijith Thotton 1129*de2bc16eSShijith Thotton nb_sessions = evt_nr_active_lcores(opt->plcores) * t->nb_flows; 1130*de2bc16eSShijith Thotton t->ca_sess_pool = rte_cryptodev_sym_session_pool_create( 1131*de2bc16eSShijith Thotton "ca_sess_pool", nb_sessions, 0, 0, 1132*de2bc16eSShijith Thotton sizeof(union rte_event_crypto_metadata), SOCKET_ID_ANY); 1133*de2bc16eSShijith Thotton if (t->ca_sess_pool == NULL) { 1134*de2bc16eSShijith Thotton evt_err("Failed to create sym session pool"); 1135*de2bc16eSShijith Thotton ret = -ENOMEM; 1136*de2bc16eSShijith Thotton goto err; 1137*de2bc16eSShijith Thotton } 1138*de2bc16eSShijith Thotton 1139*de2bc16eSShijith Thotton max_session_size = 0; 1140*de2bc16eSShijith Thotton for (cdev_id = 0; cdev_id < cdev_count; cdev_id++) { 1141*de2bc16eSShijith Thotton unsigned int session_size; 1142*de2bc16eSShijith Thotton 1143*de2bc16eSShijith Thotton session_size = 1144*de2bc16eSShijith Thotton rte_cryptodev_sym_get_private_session_size(cdev_id); 1145*de2bc16eSShijith Thotton if (session_size > max_session_size) 1146*de2bc16eSShijith Thotton max_session_size = session_size; 1147*de2bc16eSShijith Thotton } 1148*de2bc16eSShijith Thotton 1149*de2bc16eSShijith Thotton max_session_size += sizeof(union rte_event_crypto_metadata); 1150*de2bc16eSShijith Thotton t->ca_sess_priv_pool = rte_mempool_create( 1151*de2bc16eSShijith Thotton "ca_sess_priv_pool", nb_sessions, max_session_size, 0, 0, NULL, 1152*de2bc16eSShijith Thotton NULL, NULL, NULL, SOCKET_ID_ANY, 0); 1153*de2bc16eSShijith Thotton if (t->ca_sess_priv_pool == NULL) { 1154*de2bc16eSShijith Thotton evt_err("failed to create sym session private pool"); 1155*de2bc16eSShijith Thotton ret = -ENOMEM; 1156*de2bc16eSShijith Thotton goto err; 1157*de2bc16eSShijith Thotton } 1158*de2bc16eSShijith Thotton 1159*de2bc16eSShijith Thotton /* 1160*de2bc16eSShijith Thotton * Calculate number of needed queue pairs, based on the amount of 1161*de2bc16eSShijith Thotton * available number of logical cores and crypto devices. For instance, 1162*de2bc16eSShijith Thotton * if there are 4 cores and 2 crypto devices, 2 queue pairs will be set 1163*de2bc16eSShijith Thotton * up per device. 1164*de2bc16eSShijith Thotton */ 1165*de2bc16eSShijith Thotton nb_plcores = evt_nr_active_lcores(opt->plcores); 1166*de2bc16eSShijith Thotton nb_qps = (nb_plcores % cdev_count) ? (nb_plcores / cdev_count) + 1 : 1167*de2bc16eSShijith Thotton nb_plcores / cdev_count; 1168*de2bc16eSShijith Thotton for (cdev_id = 0; cdev_id < cdev_count; cdev_id++) { 1169*de2bc16eSShijith Thotton struct rte_cryptodev_qp_conf qp_conf; 1170*de2bc16eSShijith Thotton struct rte_cryptodev_config conf; 1171*de2bc16eSShijith Thotton struct rte_cryptodev_info info; 1172*de2bc16eSShijith Thotton int qp_id; 1173*de2bc16eSShijith Thotton 1174*de2bc16eSShijith Thotton rte_cryptodev_info_get(cdev_id, &info); 1175*de2bc16eSShijith Thotton if (nb_qps > info.max_nb_queue_pairs) { 1176*de2bc16eSShijith Thotton evt_err("Not enough queue pairs per cryptodev (%u)", 1177*de2bc16eSShijith Thotton nb_qps); 1178*de2bc16eSShijith Thotton ret = -EINVAL; 1179*de2bc16eSShijith Thotton goto err; 1180*de2bc16eSShijith Thotton } 1181*de2bc16eSShijith Thotton 1182*de2bc16eSShijith Thotton conf.nb_queue_pairs = nb_qps; 1183*de2bc16eSShijith Thotton conf.socket_id = SOCKET_ID_ANY; 1184*de2bc16eSShijith Thotton conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY; 1185*de2bc16eSShijith Thotton 1186*de2bc16eSShijith Thotton ret = rte_cryptodev_configure(cdev_id, &conf); 1187*de2bc16eSShijith Thotton if (ret) { 1188*de2bc16eSShijith Thotton evt_err("Failed to configure cryptodev (%u)", cdev_id); 1189*de2bc16eSShijith Thotton goto err; 1190*de2bc16eSShijith Thotton } 1191*de2bc16eSShijith Thotton 1192*de2bc16eSShijith Thotton qp_conf.nb_descriptors = NB_CRYPTODEV_DESCRIPTORS; 1193*de2bc16eSShijith Thotton qp_conf.mp_session = t->ca_sess_pool; 1194*de2bc16eSShijith Thotton qp_conf.mp_session_private = t->ca_sess_priv_pool; 1195*de2bc16eSShijith Thotton 1196*de2bc16eSShijith Thotton for (qp_id = 0; qp_id < conf.nb_queue_pairs; qp_id++) { 1197*de2bc16eSShijith Thotton ret = rte_cryptodev_queue_pair_setup( 1198*de2bc16eSShijith Thotton cdev_id, qp_id, &qp_conf, 1199*de2bc16eSShijith Thotton rte_cryptodev_socket_id(cdev_id)); 1200*de2bc16eSShijith Thotton if (ret) { 1201*de2bc16eSShijith Thotton evt_err("Failed to setup queue pairs on cryptodev %u\n", 1202*de2bc16eSShijith Thotton cdev_id); 1203*de2bc16eSShijith Thotton goto err; 1204*de2bc16eSShijith Thotton } 1205*de2bc16eSShijith Thotton } 1206*de2bc16eSShijith Thotton } 1207*de2bc16eSShijith Thotton 1208*de2bc16eSShijith Thotton return 0; 1209*de2bc16eSShijith Thotton err: 1210*de2bc16eSShijith Thotton for (cdev_id = 0; cdev_id < cdev_count; cdev_id++) 1211*de2bc16eSShijith Thotton rte_cryptodev_close(cdev_id); 1212*de2bc16eSShijith Thotton 1213*de2bc16eSShijith Thotton rte_mempool_free(t->ca_op_pool); 1214*de2bc16eSShijith Thotton rte_mempool_free(t->ca_sess_pool); 1215*de2bc16eSShijith Thotton rte_mempool_free(t->ca_sess_priv_pool); 1216*de2bc16eSShijith Thotton 1217*de2bc16eSShijith Thotton return ret; 1218*de2bc16eSShijith Thotton } 1219*de2bc16eSShijith Thotton 1220*de2bc16eSShijith Thotton void 1221*de2bc16eSShijith Thotton perf_cryptodev_destroy(struct evt_test *test, struct evt_options *opt) 1222*de2bc16eSShijith Thotton { 1223*de2bc16eSShijith Thotton uint8_t cdev_id, cdev_count = rte_cryptodev_count(); 1224*de2bc16eSShijith Thotton struct test_perf *t = evt_test_priv(test); 1225*de2bc16eSShijith Thotton uint16_t port; 1226*de2bc16eSShijith Thotton 1227*de2bc16eSShijith Thotton if (opt->prod_type != EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR) 1228*de2bc16eSShijith Thotton return; 1229*de2bc16eSShijith Thotton 1230*de2bc16eSShijith Thotton for (port = t->nb_workers; port < perf_nb_event_ports(opt); port++) { 1231*de2bc16eSShijith Thotton struct rte_cryptodev_sym_session *sess; 1232*de2bc16eSShijith Thotton struct prod_data *p = &t->prod[port]; 1233*de2bc16eSShijith Thotton uint32_t flow_id; 1234*de2bc16eSShijith Thotton uint8_t cdev_id; 1235*de2bc16eSShijith Thotton 1236*de2bc16eSShijith Thotton for (flow_id = 0; flow_id < t->nb_flows; flow_id++) { 1237*de2bc16eSShijith Thotton sess = p->ca.crypto_sess[flow_id]; 1238*de2bc16eSShijith Thotton cdev_id = p->ca.cdev_id; 1239*de2bc16eSShijith Thotton rte_cryptodev_sym_session_clear(cdev_id, sess); 1240*de2bc16eSShijith Thotton rte_cryptodev_sym_session_free(sess); 1241*de2bc16eSShijith Thotton } 1242*de2bc16eSShijith Thotton 1243*de2bc16eSShijith Thotton rte_event_crypto_adapter_queue_pair_del( 1244*de2bc16eSShijith Thotton TEST_PERF_CA_ID, p->ca.cdev_id, p->ca.cdev_qp_id); 1245*de2bc16eSShijith Thotton } 1246*de2bc16eSShijith Thotton 1247*de2bc16eSShijith Thotton rte_event_crypto_adapter_free(TEST_PERF_CA_ID); 1248*de2bc16eSShijith Thotton 1249*de2bc16eSShijith Thotton for (cdev_id = 0; cdev_id < cdev_count; cdev_id++) { 1250*de2bc16eSShijith Thotton rte_cryptodev_stop(cdev_id); 1251*de2bc16eSShijith Thotton rte_cryptodev_close(cdev_id); 1252*de2bc16eSShijith Thotton } 1253*de2bc16eSShijith Thotton 1254*de2bc16eSShijith Thotton rte_mempool_free(t->ca_op_pool); 1255*de2bc16eSShijith Thotton rte_mempool_free(t->ca_sess_pool); 1256*de2bc16eSShijith Thotton rte_mempool_free(t->ca_sess_priv_pool); 1257*de2bc16eSShijith Thotton } 1258*de2bc16eSShijith Thotton 1259*de2bc16eSShijith Thotton int 126041c219e6SJerin Jacob perf_mempool_setup(struct evt_test *test, struct evt_options *opt) 126141c219e6SJerin Jacob { 126241c219e6SJerin Jacob struct test_perf *t = evt_test_priv(test); 126341c219e6SJerin Jacob 1264d008f20bSPavan Nikhilesh if (opt->prod_type == EVT_PROD_TYPE_SYNT || 1265d008f20bSPavan Nikhilesh opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) { 126641c219e6SJerin Jacob t->pool = rte_mempool_create(test->name, /* mempool name */ 126741c219e6SJerin Jacob opt->pool_sz, /* number of elements*/ 126841c219e6SJerin Jacob sizeof(struct perf_elt), /* element size*/ 126941c219e6SJerin Jacob 512, /* cache size*/ 127041c219e6SJerin Jacob 0, NULL, NULL, 127141c219e6SJerin Jacob perf_elt_init, /* obj constructor */ 127241c219e6SJerin Jacob NULL, opt->socket_id, 0); /* flags */ 12738577cc1aSPavan Nikhilesh } else { 12748577cc1aSPavan Nikhilesh t->pool = rte_pktmbuf_pool_create(test->name, /* mempool name */ 12758577cc1aSPavan Nikhilesh opt->pool_sz, /* number of elements*/ 12768577cc1aSPavan Nikhilesh 512, /* cache size*/ 12778577cc1aSPavan Nikhilesh 0, 12788577cc1aSPavan Nikhilesh RTE_MBUF_DEFAULT_BUF_SIZE, 12798577cc1aSPavan Nikhilesh opt->socket_id); /* flags */ 12808577cc1aSPavan Nikhilesh 12818577cc1aSPavan Nikhilesh } 12828577cc1aSPavan Nikhilesh 128341c219e6SJerin Jacob if (t->pool == NULL) { 128441c219e6SJerin Jacob evt_err("failed to create mempool"); 128541c219e6SJerin Jacob return -ENOMEM; 128641c219e6SJerin Jacob } 128741c219e6SJerin Jacob 128841c219e6SJerin Jacob return 0; 128941c219e6SJerin Jacob } 129041c219e6SJerin Jacob 129141c219e6SJerin Jacob void 129241c219e6SJerin Jacob perf_mempool_destroy(struct evt_test *test, struct evt_options *opt) 129341c219e6SJerin Jacob { 129441c219e6SJerin Jacob RTE_SET_USED(opt); 129541c219e6SJerin Jacob struct test_perf *t = evt_test_priv(test); 129641c219e6SJerin Jacob 129741c219e6SJerin Jacob rte_mempool_free(t->pool); 129841c219e6SJerin Jacob } 1299ffbae86fSJerin Jacob 1300ffbae86fSJerin Jacob int 1301ffbae86fSJerin Jacob perf_test_setup(struct evt_test *test, struct evt_options *opt) 1302ffbae86fSJerin Jacob { 1303ffbae86fSJerin Jacob void *test_perf; 1304ffbae86fSJerin Jacob 1305ffbae86fSJerin Jacob test_perf = rte_zmalloc_socket(test->name, sizeof(struct test_perf), 1306ffbae86fSJerin Jacob RTE_CACHE_LINE_SIZE, opt->socket_id); 1307ffbae86fSJerin Jacob if (test_perf == NULL) { 1308ffbae86fSJerin Jacob evt_err("failed to allocate test_perf memory"); 1309ffbae86fSJerin Jacob goto nomem; 1310ffbae86fSJerin Jacob } 1311ffbae86fSJerin Jacob test->test_priv = test_perf; 1312ffbae86fSJerin Jacob 1313ffbae86fSJerin Jacob struct test_perf *t = evt_test_priv(test); 1314ffbae86fSJerin Jacob 1315d008f20bSPavan Nikhilesh if (opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) { 1316d008f20bSPavan Nikhilesh t->outstand_pkts = opt->nb_timers * 1317d008f20bSPavan Nikhilesh evt_nr_active_lcores(opt->plcores); 1318d008f20bSPavan Nikhilesh t->nb_pkts = opt->nb_timers; 1319d008f20bSPavan Nikhilesh } else { 1320d008f20bSPavan Nikhilesh t->outstand_pkts = opt->nb_pkts * 1321d008f20bSPavan Nikhilesh evt_nr_active_lcores(opt->plcores); 1322d008f20bSPavan Nikhilesh t->nb_pkts = opt->nb_pkts; 1323d008f20bSPavan Nikhilesh } 1324d008f20bSPavan Nikhilesh 1325ffbae86fSJerin Jacob t->nb_workers = evt_nr_active_lcores(opt->wlcores); 1326ffbae86fSJerin Jacob t->done = false; 1327ffbae86fSJerin Jacob t->nb_flows = opt->nb_flows; 1328ffbae86fSJerin Jacob t->result = EVT_TEST_FAILED; 1329ffbae86fSJerin Jacob t->opt = opt; 1330ffbae86fSJerin Jacob memcpy(t->sched_type_list, opt->sched_type_list, 1331ffbae86fSJerin Jacob sizeof(opt->sched_type_list)); 1332ffbae86fSJerin Jacob return 0; 1333ffbae86fSJerin Jacob nomem: 1334ffbae86fSJerin Jacob return -ENOMEM; 1335ffbae86fSJerin Jacob } 1336ffbae86fSJerin Jacob 1337ffbae86fSJerin Jacob void 1338ffbae86fSJerin Jacob perf_test_destroy(struct evt_test *test, struct evt_options *opt) 1339ffbae86fSJerin Jacob { 1340ffbae86fSJerin Jacob RTE_SET_USED(opt); 1341ffbae86fSJerin Jacob 1342ffbae86fSJerin Jacob rte_free(test->test_priv); 1343ffbae86fSJerin Jacob } 1344