1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Cavium, Inc
7 #include "test_perf_common.h"
9 #define NB_CRYPTODEV_DESCRIPTORS 128
12 perf_test_result(struct evt_test *test, struct evt_options *opt)
17 struct test_perf *t = evt_test_priv(test);
19 printf("Packet distribution across worker cores :\n");
20 for (i = 0; i < t->nb_workers; i++)
21 total += t->worker[i].processed_pkts;
22 for (i = 0; i < t->nb_workers; i++)
23 printf("Worker %d packets: "CLGRN"%"PRIx64" "CLNRM"percentage:"
24 CLGRN" %3.2f"CLNRM"\n", i,
25 t->worker[i].processed_pkts,
26 (((double)t->worker[i].processed_pkts)/total)
33 perf_producer(void *arg)
36 struct prod_data *p = arg;
37 struct test_perf *t = p->t;
38 struct evt_options *opt = t->opt;
39 const uint8_t dev_id = p->dev_id;
40 const uint8_t port = p->port_id;
41 struct rte_mempool *pool = t->pool;
42 const uint64_t nb_pkts = t->nb_pkts;
43 const uint32_t nb_flows = t->nb_flows;
44 uint32_t flow_counter = 0;
46 struct perf_elt *m[BURST_SIZE + 1] = {NULL};
49 if (opt->verbose_level > 1)
50 printf("%s(): lcore %d dev_id %d port=%d queue %d\n", __func__,
51 rte_lcore_id(), dev_id, port, p->queue_id);
54 ev.op = RTE_EVENT_OP_NEW;
55 ev.queue_id = p->queue_id;
56 ev.sched_type = t->opt->sched_type_list[0];
57 ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
58 ev.event_type = RTE_EVENT_TYPE_CPU;
59 ev.sub_event_type = 0; /* stage 0 */
61 while (count < nb_pkts && t->done == false) {
62 if (rte_mempool_get_bulk(pool, (void **)m, BURST_SIZE) < 0)
64 for (i = 0; i < BURST_SIZE; i++) {
65 ev.flow_id = flow_counter++ % nb_flows;
67 m[i]->timestamp = rte_get_timer_cycles();
68 while (rte_event_enqueue_burst(dev_id,
73 m[i]->timestamp = rte_get_timer_cycles();
83 perf_producer_burst(void *arg)
87 struct rte_event_dev_info dev_info;
88 struct prod_data *p = arg;
89 struct test_perf *t = p->t;
90 struct evt_options *opt = t->opt;
91 const uint8_t dev_id = p->dev_id;
92 const uint8_t port = p->port_id;
93 struct rte_mempool *pool = t->pool;
94 const uint64_t nb_pkts = t->nb_pkts;
95 const uint32_t nb_flows = t->nb_flows;
96 uint32_t flow_counter = 0;
99 struct perf_elt *m[MAX_PROD_ENQ_BURST_SIZE + 1];
100 struct rte_event ev[MAX_PROD_ENQ_BURST_SIZE + 1];
101 uint32_t burst_size = opt->prod_enq_burst_sz;
103 memset(m, 0, sizeof(*m) * (MAX_PROD_ENQ_BURST_SIZE + 1));
104 rte_event_dev_info_get(dev_id, &dev_info);
105 if (dev_info.max_event_port_enqueue_depth < burst_size)
106 burst_size = dev_info.max_event_port_enqueue_depth;
108 if (opt->verbose_level > 1)
109 printf("%s(): lcore %d dev_id %d port=%d queue %d\n", __func__,
110 rte_lcore_id(), dev_id, port, p->queue_id);
112 for (i = 0; i < burst_size; i++) {
113 ev[i].op = RTE_EVENT_OP_NEW;
114 ev[i].queue_id = p->queue_id;
115 ev[i].sched_type = t->opt->sched_type_list[0];
116 ev[i].priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
117 ev[i].event_type = RTE_EVENT_TYPE_CPU;
118 ev[i].sub_event_type = 0; /* stage 0 */
121 while (count < nb_pkts && t->done == false) {
122 if (rte_mempool_get_bulk(pool, (void **)m, burst_size) < 0)
124 timestamp = rte_get_timer_cycles();
125 for (i = 0; i < burst_size; i++) {
126 ev[i].flow_id = flow_counter++ % nb_flows;
127 ev[i].event_ptr = m[i];
128 m[i]->timestamp = timestamp;
130 enq = rte_event_enqueue_burst(dev_id, port, ev, burst_size);
131 while (enq < burst_size) {
132 enq += rte_event_enqueue_burst(dev_id, port,
138 timestamp = rte_get_timer_cycles();
139 for (i = enq; i < burst_size; i++)
140 m[i]->timestamp = timestamp;
148 perf_event_timer_producer(void *arg)
151 struct prod_data *p = arg;
152 struct test_perf *t = p->t;
153 struct evt_options *opt = t->opt;
154 uint32_t flow_counter = 0;
156 uint64_t arm_latency = 0;
157 const uint8_t nb_timer_adptrs = opt->nb_timer_adptrs;
158 const uint32_t nb_flows = t->nb_flows;
159 const uint64_t nb_timers = opt->nb_timers;
160 struct rte_mempool *pool = t->pool;
161 struct perf_elt *m[BURST_SIZE + 1] = {NULL};
162 struct rte_event_timer_adapter **adptr = t->timer_adptr;
163 struct rte_event_timer tim;
164 uint64_t timeout_ticks = opt->expiry_nsec / opt->timer_tick_nsec;
166 memset(&tim, 0, sizeof(struct rte_event_timer));
168 opt->optm_timer_tick_nsec
169 ? ceil((double)(timeout_ticks * opt->timer_tick_nsec) /
170 opt->optm_timer_tick_nsec)
172 timeout_ticks += timeout_ticks ? 0 : 1;
173 tim.ev.event_type = RTE_EVENT_TYPE_TIMER;
174 tim.ev.op = RTE_EVENT_OP_NEW;
175 tim.ev.sched_type = t->opt->sched_type_list[0];
176 tim.ev.queue_id = p->queue_id;
177 tim.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
178 tim.state = RTE_EVENT_TIMER_NOT_ARMED;
179 tim.timeout_ticks = timeout_ticks;
181 if (opt->verbose_level > 1)
182 printf("%s(): lcore %d\n", __func__, rte_lcore_id());
184 while (count < nb_timers && t->done == false) {
185 if (rte_mempool_get_bulk(pool, (void **)m, BURST_SIZE) < 0)
187 for (i = 0; i < BURST_SIZE; i++) {
188 rte_prefetch0(m[i + 1]);
190 m[i]->tim.ev.flow_id = flow_counter++ % nb_flows;
191 m[i]->tim.ev.event_ptr = m[i];
192 m[i]->timestamp = rte_get_timer_cycles();
193 while (rte_event_timer_arm_burst(
194 adptr[flow_counter % nb_timer_adptrs],
195 (struct rte_event_timer **)&m[i], 1) != 1) {
198 m[i]->timestamp = rte_get_timer_cycles();
200 arm_latency += rte_get_timer_cycles() - m[i]->timestamp;
206 printf("%s(): lcore %d Average event timer arm latency = %.3f us\n",
207 __func__, rte_lcore_id(),
208 count ? (float)(arm_latency / count) /
209 (rte_get_timer_hz() / 1000000) : 0);
214 perf_event_timer_producer_burst(void *arg)
217 struct prod_data *p = arg;
218 struct test_perf *t = p->t;
219 struct evt_options *opt = t->opt;
220 uint32_t flow_counter = 0;
222 uint64_t arm_latency = 0;
223 const uint8_t nb_timer_adptrs = opt->nb_timer_adptrs;
224 const uint32_t nb_flows = t->nb_flows;
225 const uint64_t nb_timers = opt->nb_timers;
226 struct rte_mempool *pool = t->pool;
227 struct perf_elt *m[BURST_SIZE + 1] = {NULL};
228 struct rte_event_timer_adapter **adptr = t->timer_adptr;
229 struct rte_event_timer tim;
230 uint64_t timeout_ticks = opt->expiry_nsec / opt->timer_tick_nsec;
232 memset(&tim, 0, sizeof(struct rte_event_timer));
234 opt->optm_timer_tick_nsec
235 ? ceil((double)(timeout_ticks * opt->timer_tick_nsec) /
236 opt->optm_timer_tick_nsec)
238 timeout_ticks += timeout_ticks ? 0 : 1;
239 tim.ev.event_type = RTE_EVENT_TYPE_TIMER;
240 tim.ev.op = RTE_EVENT_OP_NEW;
241 tim.ev.sched_type = t->opt->sched_type_list[0];
242 tim.ev.queue_id = p->queue_id;
243 tim.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
244 tim.state = RTE_EVENT_TIMER_NOT_ARMED;
245 tim.timeout_ticks = timeout_ticks;
247 if (opt->verbose_level > 1)
248 printf("%s(): lcore %d\n", __func__, rte_lcore_id());
250 while (count < nb_timers && t->done == false) {
251 if (rte_mempool_get_bulk(pool, (void **)m, BURST_SIZE) < 0)
253 for (i = 0; i < BURST_SIZE; i++) {
254 rte_prefetch0(m[i + 1]);
256 m[i]->tim.ev.flow_id = flow_counter++ % nb_flows;
257 m[i]->tim.ev.event_ptr = m[i];
258 m[i]->timestamp = rte_get_timer_cycles();
260 rte_event_timer_arm_tmo_tick_burst(
261 adptr[flow_counter % nb_timer_adptrs],
262 (struct rte_event_timer **)m,
265 arm_latency += rte_get_timer_cycles() - m[i - 1]->timestamp;
270 printf("%s(): lcore %d Average event timer arm latency = %.3f us\n",
271 __func__, rte_lcore_id(),
272 count ? (float)(arm_latency / count) /
273 (rte_get_timer_hz() / 1000000) : 0);
278 crypto_adapter_enq_op_new(struct prod_data *p)
280 struct rte_cryptodev_sym_session **crypto_sess = p->ca.crypto_sess;
281 struct test_perf *t = p->t;
282 const uint32_t nb_flows = t->nb_flows;
283 const uint64_t nb_pkts = t->nb_pkts;
284 struct rte_mempool *pool = t->pool;
285 struct rte_crypto_sym_op *sym_op;
286 struct evt_options *opt = t->opt;
287 uint16_t qp_id = p->ca.cdev_qp_id;
288 uint8_t cdev_id = p->ca.cdev_id;
289 uint32_t flow_counter = 0;
290 struct rte_crypto_op *op;
295 if (opt->verbose_level > 1)
296 printf("%s(): lcore %d queue %d cdev_id %u cdev_qp_id %u\n",
297 __func__, rte_lcore_id(), p->queue_id, p->ca.cdev_id,
300 len = opt->mbuf_sz ? opt->mbuf_sz : RTE_ETHER_MIN_LEN;
302 while (count < nb_pkts && t->done == false) {
303 m = rte_pktmbuf_alloc(pool);
307 rte_pktmbuf_append(m, len);
308 op = rte_crypto_op_alloc(t->ca_op_pool,
309 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
312 sym_op->cipher.data.offset = 0;
313 sym_op->cipher.data.length = len;
314 rte_crypto_op_attach_sym_session(
315 op, crypto_sess[flow_counter++ % nb_flows]);
317 while (rte_cryptodev_enqueue_burst(cdev_id, qp_id, &op, 1) != 1 &&
326 crypto_adapter_enq_op_fwd(struct prod_data *p)
328 struct rte_cryptodev_sym_session **crypto_sess = p->ca.crypto_sess;
329 const uint8_t dev_id = p->dev_id;
330 const uint8_t port = p->port_id;
331 struct test_perf *t = p->t;
332 const uint32_t nb_flows = t->nb_flows;
333 const uint64_t nb_pkts = t->nb_pkts;
334 struct rte_mempool *pool = t->pool;
335 struct evt_options *opt = t->opt;
336 struct rte_crypto_sym_op *sym_op;
337 uint32_t flow_counter = 0;
338 struct rte_crypto_op *op;
344 if (opt->verbose_level > 1)
345 printf("%s(): lcore %d port %d queue %d cdev_id %u cdev_qp_id %u\n",
346 __func__, rte_lcore_id(), port, p->queue_id,
347 p->ca.cdev_id, p->ca.cdev_qp_id);
350 ev.op = RTE_EVENT_OP_NEW;
351 ev.queue_id = p->queue_id;
352 ev.sched_type = RTE_SCHED_TYPE_ATOMIC;
353 ev.event_type = RTE_EVENT_TYPE_CPU;
354 len = opt->mbuf_sz ? opt->mbuf_sz : RTE_ETHER_MIN_LEN;
356 while (count < nb_pkts && t->done == false) {
357 m = rte_pktmbuf_alloc(pool);
361 rte_pktmbuf_append(m, len);
362 op = rte_crypto_op_alloc(t->ca_op_pool,
363 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
366 sym_op->cipher.data.offset = 0;
367 sym_op->cipher.data.length = len;
368 rte_crypto_op_attach_sym_session(
369 op, crypto_sess[flow_counter++ % nb_flows]);
372 while (rte_event_crypto_adapter_enqueue(dev_id, port, &ev, 1) != 1 &&
381 perf_event_crypto_producer(void *arg)
383 struct prod_data *p = arg;
384 struct evt_options *opt = p->t->opt;
386 if (opt->crypto_adptr_mode == RTE_EVENT_CRYPTO_ADAPTER_OP_NEW)
387 crypto_adapter_enq_op_new(p);
389 crypto_adapter_enq_op_fwd(p);
395 perf_producer_wrapper(void *arg)
397 struct prod_data *p = arg;
398 struct test_perf *t = p->t;
399 bool burst = evt_has_burst_mode(p->dev_id);
401 /* In case of synthetic producer, launch perf_producer or
402 * perf_producer_burst depending on producer enqueue burst size
404 if (t->opt->prod_type == EVT_PROD_TYPE_SYNT &&
405 t->opt->prod_enq_burst_sz == 1)
406 return perf_producer(arg);
407 else if (t->opt->prod_type == EVT_PROD_TYPE_SYNT &&
408 t->opt->prod_enq_burst_sz > 1) {
410 evt_err("This event device does not support burst mode");
412 return perf_producer_burst(arg);
414 else if (t->opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR &&
415 !t->opt->timdev_use_burst)
416 return perf_event_timer_producer(arg);
417 else if (t->opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR &&
418 t->opt->timdev_use_burst)
419 return perf_event_timer_producer_burst(arg);
420 else if (t->opt->prod_type == EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR)
421 return perf_event_crypto_producer(arg);
425 static inline uint64_t
426 processed_pkts(struct test_perf *t)
431 for (i = 0; i < t->nb_workers; i++)
432 total += t->worker[i].processed_pkts;
437 static inline uint64_t
438 total_latency(struct test_perf *t)
443 for (i = 0; i < t->nb_workers; i++)
444 total += t->worker[i].latency;
451 perf_launch_lcores(struct evt_test *test, struct evt_options *opt,
452 int (*worker)(void *))
455 struct test_perf *t = evt_test_priv(test);
459 RTE_LCORE_FOREACH_WORKER(lcore_id) {
460 if (!(opt->wlcores[lcore_id]))
463 ret = rte_eal_remote_launch(worker,
464 &t->worker[port_idx], lcore_id);
466 evt_err("failed to launch worker %d", lcore_id);
472 /* launch producers */
473 RTE_LCORE_FOREACH_WORKER(lcore_id) {
474 if (!(opt->plcores[lcore_id]))
477 ret = rte_eal_remote_launch(perf_producer_wrapper,
478 &t->prod[port_idx], lcore_id);
480 evt_err("failed to launch perf_producer %d", lcore_id);
486 const uint64_t total_pkts = t->outstand_pkts;
488 uint64_t dead_lock_cycles = rte_get_timer_cycles();
489 int64_t dead_lock_remaining = total_pkts;
490 const uint64_t dead_lock_sample = rte_get_timer_hz() * 5;
492 uint64_t perf_cycles = rte_get_timer_cycles();
493 int64_t perf_remaining = total_pkts;
494 const uint64_t perf_sample = rte_get_timer_hz();
496 static float total_mpps;
497 static uint64_t samples;
499 const uint64_t freq_mhz = rte_get_timer_hz() / 1000000;
500 int64_t remaining = t->outstand_pkts - processed_pkts(t);
502 while (t->done == false) {
503 const uint64_t new_cycles = rte_get_timer_cycles();
505 if ((new_cycles - perf_cycles) > perf_sample) {
506 const uint64_t latency = total_latency(t);
507 const uint64_t pkts = processed_pkts(t);
509 remaining = t->outstand_pkts - pkts;
510 float mpps = (float)(perf_remaining-remaining)/1000000;
512 perf_remaining = remaining;
513 perf_cycles = new_cycles;
516 if (opt->fwd_latency && pkts > 0) {
517 printf(CLGRN"\r%.3f mpps avg %.3f mpps [avg fwd latency %.3f us] "CLNRM,
518 mpps, total_mpps/samples,
519 (float)(latency/pkts)/freq_mhz);
521 printf(CLGRN"\r%.3f mpps avg %.3f mpps"CLNRM,
522 mpps, total_mpps/samples);
526 if (remaining <= 0) {
527 t->result = EVT_TEST_SUCCESS;
528 if (opt->prod_type == EVT_PROD_TYPE_SYNT ||
530 EVT_PROD_TYPE_EVENT_TIMER_ADPTR ||
532 EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR) {
539 if (new_cycles - dead_lock_cycles > dead_lock_sample &&
540 (opt->prod_type == EVT_PROD_TYPE_SYNT ||
541 opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR ||
542 opt->prod_type == EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR)) {
543 remaining = t->outstand_pkts - processed_pkts(t);
544 if (dead_lock_remaining == remaining) {
545 rte_event_dev_dump(opt->dev_id, stdout);
546 evt_err("No schedules for seconds, deadlock");
550 dead_lock_remaining = remaining;
551 dead_lock_cycles = new_cycles;
559 perf_event_rx_adapter_setup(struct evt_options *opt, uint8_t stride,
560 struct rte_event_port_conf prod_conf)
564 struct rte_event_eth_rx_adapter_queue_conf queue_conf;
566 memset(&queue_conf, 0,
567 sizeof(struct rte_event_eth_rx_adapter_queue_conf));
568 queue_conf.ev.sched_type = opt->sched_type_list[0];
569 RTE_ETH_FOREACH_DEV(prod) {
572 ret = rte_event_eth_rx_adapter_caps_get(opt->dev_id,
575 evt_err("failed to get event rx adapter[%d]"
580 queue_conf.ev.queue_id = prod * stride;
581 ret = rte_event_eth_rx_adapter_create(prod, opt->dev_id,
584 evt_err("failed to create rx adapter[%d]", prod);
587 ret = rte_event_eth_rx_adapter_queue_add(prod, prod, -1,
590 evt_err("failed to add rx queues to adapter[%d]", prod);
594 if (!(cap & RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT)) {
597 rte_event_eth_rx_adapter_service_id_get(prod,
599 ret = evt_service_setup(service_id);
601 evt_err("Failed to setup service core"
602 " for Rx adapter\n");
612 perf_event_timer_adapter_setup(struct test_perf *t)
616 struct rte_event_timer_adapter_info adapter_info;
617 struct rte_event_timer_adapter *wl;
618 uint8_t nb_producers = evt_nr_active_lcores(t->opt->plcores);
619 uint8_t flags = RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES;
621 if (nb_producers == 1)
622 flags |= RTE_EVENT_TIMER_ADAPTER_F_SP_PUT;
624 for (i = 0; i < t->opt->nb_timer_adptrs; i++) {
625 struct rte_event_timer_adapter_conf config = {
626 .event_dev_id = t->opt->dev_id,
627 .timer_adapter_id = i,
628 .timer_tick_ns = t->opt->timer_tick_nsec,
629 .max_tmo_ns = t->opt->max_tmo_nsec,
630 .nb_timers = t->opt->pool_sz,
634 wl = rte_event_timer_adapter_create(&config);
636 evt_err("failed to create event timer ring %d", i);
640 memset(&adapter_info, 0,
641 sizeof(struct rte_event_timer_adapter_info));
642 rte_event_timer_adapter_get_info(wl, &adapter_info);
643 t->opt->optm_timer_tick_nsec = adapter_info.min_resolution_ns;
645 if (!(adapter_info.caps &
646 RTE_EVENT_TIMER_ADAPTER_CAP_INTERNAL_PORT)) {
647 uint32_t service_id = -1U;
649 rte_event_timer_adapter_service_id_get(wl,
651 ret = evt_service_setup(service_id);
653 evt_err("Failed to setup service core"
654 " for timer adapter\n");
657 rte_service_runstate_set(service_id, 1);
659 t->timer_adptr[i] = wl;
665 perf_event_crypto_adapter_setup(struct test_perf *t, struct prod_data *p)
667 struct evt_options *opt = t->opt;
671 ret = rte_event_crypto_adapter_caps_get(p->dev_id, p->ca.cdev_id, &cap);
673 evt_err("Failed to get crypto adapter capabilities");
677 if (((opt->crypto_adptr_mode == RTE_EVENT_CRYPTO_ADAPTER_OP_NEW) &&
678 !(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW)) ||
679 ((opt->crypto_adptr_mode == RTE_EVENT_CRYPTO_ADAPTER_OP_FORWARD) &&
680 !(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD))) {
681 evt_err("crypto adapter %s mode unsupported\n",
682 opt->crypto_adptr_mode ? "OP_FORWARD" : "OP_NEW");
684 } else if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_SESSION_PRIVATE_DATA)) {
685 evt_err("Storing crypto session not supported");
689 if (cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_QP_EV_BIND) {
690 struct rte_event response_info;
692 response_info.event = 0;
693 response_info.sched_type = RTE_SCHED_TYPE_ATOMIC;
694 response_info.queue_id = p->queue_id;
695 ret = rte_event_crypto_adapter_queue_pair_add(
696 TEST_PERF_CA_ID, p->ca.cdev_id, p->ca.cdev_qp_id,
699 ret = rte_event_crypto_adapter_queue_pair_add(
700 TEST_PERF_CA_ID, p->ca.cdev_id, p->ca.cdev_qp_id, NULL);
706 static struct rte_cryptodev_sym_session *
707 cryptodev_sym_sess_create(struct prod_data *p, struct test_perf *t)
709 struct rte_crypto_sym_xform cipher_xform;
710 struct rte_cryptodev_sym_session *sess;
712 cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
713 cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
714 cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
715 cipher_xform.next = NULL;
717 sess = rte_cryptodev_sym_session_create(t->ca_sess_pool);
719 evt_err("Failed to create sym session");
723 if (rte_cryptodev_sym_session_init(p->ca.cdev_id, sess, &cipher_xform,
724 t->ca_sess_priv_pool)) {
725 evt_err("Failed to init session");
733 perf_event_dev_port_setup(struct evt_test *test, struct evt_options *opt,
734 uint8_t stride, uint8_t nb_queues,
735 const struct rte_event_port_conf *port_conf)
737 struct test_perf *t = evt_test_priv(test);
741 /* setup one port per worker, linking to all queues */
742 for (port = 0; port < evt_nr_active_lcores(opt->wlcores);
744 struct worker_data *w = &t->worker[port];
746 w->dev_id = opt->dev_id;
749 w->processed_pkts = 0;
752 struct rte_event_port_conf conf = *port_conf;
753 conf.event_port_cfg |= RTE_EVENT_PORT_CFG_HINT_WORKER;
755 ret = rte_event_port_setup(opt->dev_id, port, &conf);
757 evt_err("failed to setup port %d", port);
761 ret = rte_event_port_link(opt->dev_id, port, NULL, NULL, 0);
762 if (ret != nb_queues) {
763 evt_err("failed to link all queues to port %d", port);
768 /* port for producers, no links */
769 if (opt->prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR) {
770 for ( ; port < perf_nb_event_ports(opt); port++) {
771 struct prod_data *p = &t->prod[port];
775 struct rte_event_port_conf conf = *port_conf;
776 conf.event_port_cfg |= RTE_EVENT_PORT_CFG_HINT_PRODUCER;
778 ret = perf_event_rx_adapter_setup(opt, stride, conf);
781 } else if (opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) {
783 for ( ; port < perf_nb_event_ports(opt); port++) {
784 struct prod_data *p = &t->prod[port];
785 p->queue_id = prod * stride;
790 ret = perf_event_timer_adapter_setup(t);
793 } else if (opt->prod_type == EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR) {
794 struct rte_event_port_conf conf = *port_conf;
798 ret = rte_event_crypto_adapter_create(TEST_PERF_CA_ID,
799 opt->dev_id, &conf, 0);
801 evt_err("Failed to create crypto adapter");
806 for (; port < perf_nb_event_ports(opt); port++) {
807 struct rte_cryptodev_sym_session *crypto_sess;
808 union rte_event_crypto_metadata m_data;
809 struct prod_data *p = &t->prod[port];
812 if (qp_id == rte_cryptodev_queue_pair_count(cdev_id)) {
817 p->dev_id = opt->dev_id;
819 p->queue_id = prod * stride;
820 p->ca.cdev_id = cdev_id;
821 p->ca.cdev_qp_id = qp_id;
822 p->ca.crypto_sess = rte_zmalloc_socket(
823 NULL, sizeof(crypto_sess) * t->nb_flows,
824 RTE_CACHE_LINE_SIZE, opt->socket_id);
827 m_data.request_info.cdev_id = p->ca.cdev_id;
828 m_data.request_info.queue_pair_id = p->ca.cdev_qp_id;
829 m_data.response_info.sched_type = RTE_SCHED_TYPE_ATOMIC;
830 m_data.response_info.queue_id = p->queue_id;
832 for (flow_id = 0; flow_id < t->nb_flows; flow_id++) {
833 crypto_sess = cryptodev_sym_sess_create(p, t);
834 if (crypto_sess == NULL)
837 m_data.response_info.flow_id = flow_id;
838 rte_cryptodev_sym_session_set_user_data(
839 crypto_sess, &m_data, sizeof(m_data));
840 p->ca.crypto_sess[flow_id] = crypto_sess;
843 conf.event_port_cfg |=
844 RTE_EVENT_PORT_CFG_HINT_PRODUCER |
845 RTE_EVENT_PORT_CFG_HINT_CONSUMER;
847 ret = rte_event_port_setup(opt->dev_id, port, &conf);
849 evt_err("failed to setup port %d", port);
853 ret = perf_event_crypto_adapter_setup(t, p);
862 for ( ; port < perf_nb_event_ports(opt); port++) {
863 struct prod_data *p = &t->prod[port];
865 p->dev_id = opt->dev_id;
867 p->queue_id = prod * stride;
870 struct rte_event_port_conf conf = *port_conf;
871 conf.event_port_cfg |=
872 RTE_EVENT_PORT_CFG_HINT_PRODUCER |
873 RTE_EVENT_PORT_CFG_HINT_CONSUMER;
875 ret = rte_event_port_setup(opt->dev_id, port, &conf);
877 evt_err("failed to setup port %d", port);
888 perf_opt_check(struct evt_options *opt, uint64_t nb_queues)
892 /* N producer + N worker + main when producer cores are used
893 * Else N worker + main when Rx adapter is used
895 lcores = opt->prod_type == EVT_PROD_TYPE_SYNT ? 3 : 2;
897 if (rte_lcore_count() < lcores) {
898 evt_err("test need minimum %d lcores", lcores);
902 /* Validate worker lcores */
903 if (evt_lcores_has_overlap(opt->wlcores, rte_get_main_lcore())) {
904 evt_err("worker lcores overlaps with main lcore");
907 if (evt_lcores_has_overlap_multi(opt->wlcores, opt->plcores)) {
908 evt_err("worker lcores overlaps producer lcores");
911 if (evt_has_disabled_lcore(opt->wlcores)) {
912 evt_err("one or more workers lcores are not enabled");
915 if (!evt_has_active_lcore(opt->wlcores)) {
916 evt_err("minimum one worker is required");
920 if (opt->prod_type == EVT_PROD_TYPE_SYNT ||
921 opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR ||
922 opt->prod_type == EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR) {
923 /* Validate producer lcores */
924 if (evt_lcores_has_overlap(opt->plcores,
925 rte_get_main_lcore())) {
926 evt_err("producer lcores overlaps with main lcore");
929 if (evt_has_disabled_lcore(opt->plcores)) {
930 evt_err("one or more producer lcores are not enabled");
933 if (!evt_has_active_lcore(opt->plcores)) {
934 evt_err("minimum one producer is required");
939 if (evt_has_invalid_stage(opt))
942 if (evt_has_invalid_sched_type(opt))
945 if (nb_queues > EVT_MAX_QUEUES) {
946 evt_err("number of queues exceeds %d", EVT_MAX_QUEUES);
949 if (perf_nb_event_ports(opt) > EVT_MAX_PORTS) {
950 evt_err("number of ports exceeds %d", EVT_MAX_PORTS);
955 if ((opt->nb_stages == 1 &&
956 opt->prod_type != EVT_PROD_TYPE_EVENT_TIMER_ADPTR) &&
958 evt_info("fwd_latency is valid when nb_stages > 1, disabling");
959 opt->fwd_latency = 0;
962 if (opt->fwd_latency && !opt->q_priority) {
963 evt_info("enabled queue priority for latency measurement");
966 if (opt->nb_pkts == 0)
967 opt->nb_pkts = INT64_MAX/evt_nr_active_lcores(opt->plcores);
973 perf_opt_dump(struct evt_options *opt, uint8_t nb_queues)
975 evt_dump("nb_prod_lcores", "%d", evt_nr_active_lcores(opt->plcores));
976 evt_dump_producer_lcores(opt);
977 evt_dump("nb_worker_lcores", "%d", evt_nr_active_lcores(opt->wlcores));
978 evt_dump_worker_lcores(opt);
979 evt_dump_nb_stages(opt);
980 evt_dump("nb_evdev_ports", "%d", perf_nb_event_ports(opt));
981 evt_dump("nb_evdev_queues", "%d", nb_queues);
982 evt_dump_queue_priority(opt);
983 evt_dump_sched_type_list(opt);
984 evt_dump_producer_type(opt);
985 evt_dump("prod_enq_burst_sz", "%d", opt->prod_enq_burst_sz);
989 perf_eventdev_destroy(struct evt_test *test, struct evt_options *opt)
992 struct test_perf *t = evt_test_priv(test);
994 if (opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) {
995 for (i = 0; i < opt->nb_timer_adptrs; i++)
996 rte_event_timer_adapter_stop(t->timer_adptr[i]);
998 rte_event_dev_stop(opt->dev_id);
999 rte_event_dev_close(opt->dev_id);
1003 perf_elt_init(struct rte_mempool *mp, void *arg __rte_unused,
1004 void *obj, unsigned i __rte_unused)
1006 memset(obj, 0, mp->elt_size);
1009 #define NB_RX_DESC 128
1010 #define NB_TX_DESC 512
1012 perf_ethdev_setup(struct evt_test *test, struct evt_options *opt)
1016 struct test_perf *t = evt_test_priv(test);
1017 struct rte_eth_conf port_conf = {
1019 .mq_mode = RTE_ETH_MQ_RX_RSS,
1020 .split_hdr_size = 0,
1025 .rss_hf = RTE_ETH_RSS_IP,
1030 if (opt->prod_type != EVT_PROD_TYPE_ETH_RX_ADPTR)
1033 if (!rte_eth_dev_count_avail()) {
1034 evt_err("No ethernet ports found.");
1038 RTE_ETH_FOREACH_DEV(i) {
1039 struct rte_eth_dev_info dev_info;
1040 struct rte_eth_conf local_port_conf = port_conf;
1042 ret = rte_eth_dev_info_get(i, &dev_info);
1044 evt_err("Error during getting device (port %u) info: %s\n",
1049 local_port_conf.rx_adv_conf.rss_conf.rss_hf &=
1050 dev_info.flow_type_rss_offloads;
1051 if (local_port_conf.rx_adv_conf.rss_conf.rss_hf !=
1052 port_conf.rx_adv_conf.rss_conf.rss_hf) {
1053 evt_info("Port %u modified RSS hash function based on hardware support,"
1054 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
1056 port_conf.rx_adv_conf.rss_conf.rss_hf,
1057 local_port_conf.rx_adv_conf.rss_conf.rss_hf);
1060 if (rte_eth_dev_configure(i, 1, 1, &local_port_conf) < 0) {
1061 evt_err("Failed to configure eth port [%d]", i);
1065 if (rte_eth_rx_queue_setup(i, 0, NB_RX_DESC,
1066 rte_socket_id(), NULL, t->pool) < 0) {
1067 evt_err("Failed to setup eth port [%d] rx_queue: %d.",
1072 if (rte_eth_tx_queue_setup(i, 0, NB_TX_DESC,
1073 rte_socket_id(), NULL) < 0) {
1074 evt_err("Failed to setup eth port [%d] tx_queue: %d.",
1079 ret = rte_eth_promiscuous_enable(i);
1081 evt_err("Failed to enable promiscuous mode for eth port [%d]: %s",
1082 i, rte_strerror(-ret));
1090 void perf_ethdev_destroy(struct evt_test *test, struct evt_options *opt)
1095 if (opt->prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR) {
1096 RTE_ETH_FOREACH_DEV(i) {
1097 rte_event_eth_rx_adapter_stop(i);
1098 rte_eth_dev_stop(i);
1104 perf_cryptodev_setup(struct evt_test *test, struct evt_options *opt)
1106 uint8_t cdev_count, cdev_id, nb_plcores, nb_qps;
1107 struct test_perf *t = evt_test_priv(test);
1108 unsigned int max_session_size;
1109 uint32_t nb_sessions;
1112 if (opt->prod_type != EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR)
1115 cdev_count = rte_cryptodev_count();
1116 if (cdev_count == 0) {
1117 evt_err("No crypto devices available\n");
1121 t->ca_op_pool = rte_crypto_op_pool_create(
1122 "crypto_op_pool", RTE_CRYPTO_OP_TYPE_SYMMETRIC, opt->pool_sz,
1123 128, 0, rte_socket_id());
1124 if (t->ca_op_pool == NULL) {
1125 evt_err("Failed to create crypto op pool");
1129 nb_sessions = evt_nr_active_lcores(opt->plcores) * t->nb_flows;
1130 t->ca_sess_pool = rte_cryptodev_sym_session_pool_create(
1131 "ca_sess_pool", nb_sessions, 0, 0,
1132 sizeof(union rte_event_crypto_metadata), SOCKET_ID_ANY);
1133 if (t->ca_sess_pool == NULL) {
1134 evt_err("Failed to create sym session pool");
1139 max_session_size = 0;
1140 for (cdev_id = 0; cdev_id < cdev_count; cdev_id++) {
1141 unsigned int session_size;
1144 rte_cryptodev_sym_get_private_session_size(cdev_id);
1145 if (session_size > max_session_size)
1146 max_session_size = session_size;
1149 max_session_size += sizeof(union rte_event_crypto_metadata);
1150 t->ca_sess_priv_pool = rte_mempool_create(
1151 "ca_sess_priv_pool", nb_sessions, max_session_size, 0, 0, NULL,
1152 NULL, NULL, NULL, SOCKET_ID_ANY, 0);
1153 if (t->ca_sess_priv_pool == NULL) {
1154 evt_err("failed to create sym session private pool");
1160 * Calculate number of needed queue pairs, based on the amount of
1161 * available number of logical cores and crypto devices. For instance,
1162 * if there are 4 cores and 2 crypto devices, 2 queue pairs will be set
1165 nb_plcores = evt_nr_active_lcores(opt->plcores);
1166 nb_qps = (nb_plcores % cdev_count) ? (nb_plcores / cdev_count) + 1 :
1167 nb_plcores / cdev_count;
1168 for (cdev_id = 0; cdev_id < cdev_count; cdev_id++) {
1169 struct rte_cryptodev_qp_conf qp_conf;
1170 struct rte_cryptodev_config conf;
1171 struct rte_cryptodev_info info;
1174 rte_cryptodev_info_get(cdev_id, &info);
1175 if (nb_qps > info.max_nb_queue_pairs) {
1176 evt_err("Not enough queue pairs per cryptodev (%u)",
1182 conf.nb_queue_pairs = nb_qps;
1183 conf.socket_id = SOCKET_ID_ANY;
1184 conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
1186 ret = rte_cryptodev_configure(cdev_id, &conf);
1188 evt_err("Failed to configure cryptodev (%u)", cdev_id);
1192 qp_conf.nb_descriptors = NB_CRYPTODEV_DESCRIPTORS;
1193 qp_conf.mp_session = t->ca_sess_pool;
1194 qp_conf.mp_session_private = t->ca_sess_priv_pool;
1196 for (qp_id = 0; qp_id < conf.nb_queue_pairs; qp_id++) {
1197 ret = rte_cryptodev_queue_pair_setup(
1198 cdev_id, qp_id, &qp_conf,
1199 rte_cryptodev_socket_id(cdev_id));
1201 evt_err("Failed to setup queue pairs on cryptodev %u\n",
1210 for (cdev_id = 0; cdev_id < cdev_count; cdev_id++)
1211 rte_cryptodev_close(cdev_id);
1213 rte_mempool_free(t->ca_op_pool);
1214 rte_mempool_free(t->ca_sess_pool);
1215 rte_mempool_free(t->ca_sess_priv_pool);
1221 perf_cryptodev_destroy(struct evt_test *test, struct evt_options *opt)
1223 uint8_t cdev_id, cdev_count = rte_cryptodev_count();
1224 struct test_perf *t = evt_test_priv(test);
1227 if (opt->prod_type != EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR)
1230 for (port = t->nb_workers; port < perf_nb_event_ports(opt); port++) {
1231 struct rte_cryptodev_sym_session *sess;
1232 struct prod_data *p = &t->prod[port];
1236 for (flow_id = 0; flow_id < t->nb_flows; flow_id++) {
1237 sess = p->ca.crypto_sess[flow_id];
1238 cdev_id = p->ca.cdev_id;
1239 rte_cryptodev_sym_session_clear(cdev_id, sess);
1240 rte_cryptodev_sym_session_free(sess);
1243 rte_event_crypto_adapter_queue_pair_del(
1244 TEST_PERF_CA_ID, p->ca.cdev_id, p->ca.cdev_qp_id);
1247 rte_event_crypto_adapter_free(TEST_PERF_CA_ID);
1249 for (cdev_id = 0; cdev_id < cdev_count; cdev_id++) {
1250 rte_cryptodev_stop(cdev_id);
1251 rte_cryptodev_close(cdev_id);
1254 rte_mempool_free(t->ca_op_pool);
1255 rte_mempool_free(t->ca_sess_pool);
1256 rte_mempool_free(t->ca_sess_priv_pool);
1260 perf_mempool_setup(struct evt_test *test, struct evt_options *opt)
1262 struct test_perf *t = evt_test_priv(test);
1264 if (opt->prod_type == EVT_PROD_TYPE_SYNT ||
1265 opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) {
1266 t->pool = rte_mempool_create(test->name, /* mempool name */
1267 opt->pool_sz, /* number of elements*/
1268 sizeof(struct perf_elt), /* element size*/
1269 512, /* cache size*/
1271 perf_elt_init, /* obj constructor */
1272 NULL, opt->socket_id, 0); /* flags */
1274 t->pool = rte_pktmbuf_pool_create(test->name, /* mempool name */
1275 opt->pool_sz, /* number of elements*/
1276 512, /* cache size*/
1278 RTE_MBUF_DEFAULT_BUF_SIZE,
1279 opt->socket_id); /* flags */
1283 if (t->pool == NULL) {
1284 evt_err("failed to create mempool");
1292 perf_mempool_destroy(struct evt_test *test, struct evt_options *opt)
1295 struct test_perf *t = evt_test_priv(test);
1297 rte_mempool_free(t->pool);
1301 perf_test_setup(struct evt_test *test, struct evt_options *opt)
1305 test_perf = rte_zmalloc_socket(test->name, sizeof(struct test_perf),
1306 RTE_CACHE_LINE_SIZE, opt->socket_id);
1307 if (test_perf == NULL) {
1308 evt_err("failed to allocate test_perf memory");
1311 test->test_priv = test_perf;
1313 struct test_perf *t = evt_test_priv(test);
1315 if (opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) {
1316 t->outstand_pkts = opt->nb_timers *
1317 evt_nr_active_lcores(opt->plcores);
1318 t->nb_pkts = opt->nb_timers;
1320 t->outstand_pkts = opt->nb_pkts *
1321 evt_nr_active_lcores(opt->plcores);
1322 t->nb_pkts = opt->nb_pkts;
1325 t->nb_workers = evt_nr_active_lcores(opt->wlcores);
1327 t->nb_flows = opt->nb_flows;
1328 t->result = EVT_TEST_FAILED;
1330 memcpy(t->sched_type_list, opt->sched_type_list,
1331 sizeof(opt->sched_type_list));
1338 perf_test_destroy(struct evt_test *test, struct evt_options *opt)
1342 rte_free(test->test_priv);