LCOV - code coverage report
Current view: top level - app/test-eventdev - test_perf_common.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 1130 0.0 %
Date: 2025-07-01 21:32:37 Functions: 0 40 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2017 Cavium, Inc
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <math.h>
       6                 :            : 
       7                 :            : #include "test_perf_common.h"
       8                 :            : 
       9                 :            : #define NB_CRYPTODEV_DESCRIPTORS 4096
      10                 :            : #define DATA_SIZE               512
      11                 :            : #define IV_OFFSET (sizeof(struct rte_crypto_op) + \
      12                 :            :                    sizeof(struct rte_crypto_sym_op) + \
      13                 :            :                    sizeof(union rte_event_crypto_metadata))
      14                 :            : 
      15                 :            : struct modex_test_data {
      16                 :            :         enum rte_crypto_asym_xform_type xform_type;
      17                 :            :         struct {
      18                 :            :                 uint8_t data[DATA_SIZE];
      19                 :            :                 uint16_t len;
      20                 :            :         } base;
      21                 :            :         struct {
      22                 :            :                 uint8_t data[DATA_SIZE];
      23                 :            :                 uint16_t len;
      24                 :            :         } exponent;
      25                 :            :         struct {
      26                 :            :                 uint8_t data[DATA_SIZE];
      27                 :            :                 uint16_t len;
      28                 :            :         } modulus;
      29                 :            :         struct {
      30                 :            :                 uint8_t data[DATA_SIZE];
      31                 :            :                 uint16_t len;
      32                 :            :         } reminder;
      33                 :            :         uint16_t result_len;
      34                 :            : };
      35                 :            : 
      36                 :            : static struct
      37                 :            : modex_test_data modex_test_case = {
      38                 :            :         .xform_type = RTE_CRYPTO_ASYM_XFORM_MODEX,
      39                 :            :         .base = {
      40                 :            :                 .data = {
      41                 :            :                         0xF8, 0xBA, 0x1A, 0x55, 0xD0, 0x2F, 0x85,
      42                 :            :                         0xAE, 0x96, 0x7B, 0xB6, 0x2F, 0xB6, 0xCD,
      43                 :            :                         0xA8, 0xEB, 0x7E, 0x78, 0xA0, 0x50
      44                 :            :                 },
      45                 :            :                 .len = 20,
      46                 :            :         },
      47                 :            :         .exponent = {
      48                 :            :                 .data = {
      49                 :            :                         0x01, 0x00, 0x01
      50                 :            :                 },
      51                 :            :                 .len = 3,
      52                 :            :         },
      53                 :            :         .reminder = {
      54                 :            :                 .data = {
      55                 :            :                         0x2C, 0x60, 0x75, 0x45, 0x98, 0x9D, 0xE0, 0x72,
      56                 :            :                         0xA0, 0x9D, 0x3A, 0x9E, 0x03, 0x38, 0x73, 0x3C,
      57                 :            :                         0x31, 0x83, 0x04, 0xFE, 0x75, 0x43, 0xE6, 0x17,
      58                 :            :                         0x5C, 0x01, 0x29, 0x51, 0x69, 0x33, 0x62, 0x2D,
      59                 :            :                         0x78, 0xBE, 0xAE, 0xC4, 0xBC, 0xDE, 0x7E, 0x2C,
      60                 :            :                         0x77, 0x84, 0xF2, 0xC5, 0x14, 0xB5, 0x2F, 0xF7,
      61                 :            :                         0xC5, 0x94, 0xEF, 0x86, 0x75, 0x75, 0xB5, 0x11,
      62                 :            :                         0xE5, 0x0E, 0x0A, 0x29, 0x76, 0xE2, 0xEA, 0x32,
      63                 :            :                         0x0E, 0x43, 0x77, 0x7E, 0x2C, 0x27, 0xAC, 0x3B,
      64                 :            :                         0x86, 0xA5, 0xDB, 0xC9, 0x48, 0x40, 0xE8, 0x99,
      65                 :            :                         0x9A, 0x0A, 0x3D, 0xD6, 0x74, 0xFA, 0x2E, 0x2E,
      66                 :            :                         0x5B, 0xAF, 0x8C, 0x99, 0x44, 0x2A, 0x67, 0x38,
      67                 :            :                         0x27, 0x41, 0x59, 0x9D, 0xB8, 0x51, 0xC9, 0xF7,
      68                 :            :                         0x43, 0x61, 0x31, 0x6E, 0xF1, 0x25, 0x38, 0x7F,
      69                 :            :                         0xAE, 0xC6, 0xD0, 0xBB, 0x29, 0x76, 0x3F, 0x46,
      70                 :            :                         0x2E, 0x1B, 0xE4, 0x67, 0x71, 0xE3, 0x87, 0x5A
      71                 :            :                 },
      72                 :            :                 .len = 128,
      73                 :            :         },
      74                 :            :         .modulus = {
      75                 :            :                 .data = {
      76                 :            :                         0xb3, 0xa1, 0xaf, 0xb7, 0x13, 0x08, 0x00, 0x0a,
      77                 :            :                         0x35, 0xdc, 0x2b, 0x20, 0x8d, 0xa1, 0xb5, 0xce,
      78                 :            :                         0x47, 0x8a, 0xc3, 0x80, 0xf4, 0x7d, 0x4a, 0xa2,
      79                 :            :                         0x62, 0xfd, 0x61, 0x7f, 0xb5, 0xa8, 0xde, 0x0a,
      80                 :            :                         0x17, 0x97, 0xa0, 0xbf, 0xdf, 0x56, 0x5a, 0x3d,
      81                 :            :                         0x51, 0x56, 0x4f, 0x70, 0x70, 0x3f, 0x63, 0x6a,
      82                 :            :                         0x44, 0x5b, 0xad, 0x84, 0x0d, 0x3f, 0x27, 0x6e,
      83                 :            :                         0x3b, 0x34, 0x91, 0x60, 0x14, 0xb9, 0xaa, 0x72,
      84                 :            :                         0xfd, 0xa3, 0x64, 0xd2, 0x03, 0xa7, 0x53, 0x87,
      85                 :            :                         0x9e, 0x88, 0x0b, 0xc1, 0x14, 0x93, 0x1a, 0x62,
      86                 :            :                         0xff, 0xb1, 0x5d, 0x74, 0xcd, 0x59, 0x63, 0x18,
      87                 :            :                         0x11, 0x3d, 0x4f, 0xba, 0x75, 0xd4, 0x33, 0x4e,
      88                 :            :                         0x23, 0x6b, 0x7b, 0x57, 0x44, 0xe1, 0xd3, 0x03,
      89                 :            :                         0x13, 0xa6, 0xf0, 0x8b, 0x60, 0xb0, 0x9e, 0xee,
      90                 :            :                         0x75, 0x08, 0x9d, 0x71, 0x63, 0x13, 0xcb, 0xa6,
      91                 :            :                         0x81, 0x92, 0x14, 0x03, 0x22, 0x2d, 0xde, 0x55
      92                 :            :                 },
      93                 :            :                 .len = 128,
      94                 :            :         },
      95                 :            :         .result_len = 128,
      96                 :            : };
      97                 :            : 
      98                 :            : int
      99                 :          0 : perf_test_result(struct evt_test *test, struct evt_options *opt)
     100                 :            : {
     101                 :            :         RTE_SET_USED(opt);
     102                 :            :         int i;
     103                 :            :         uint64_t total = 0;
     104                 :            :         struct test_perf *t = evt_test_priv(test);
     105                 :            :         uint8_t is_vec;
     106                 :            : 
     107                 :            :         printf("Packet distribution across worker cores :\n");
     108                 :          0 :         is_vec = (opt->prod_type == EVT_PROD_TYPE_EVENT_VECTOR_ADPTR);
     109                 :          0 :         for (i = 0; i < t->nb_workers; i++)
     110                 :          0 :                 total += is_vec ? t->worker[i].processed_vecs : t->worker[i].processed_pkts;
     111                 :          0 :         for (i = 0; i < t->nb_workers; i++)
     112                 :          0 :                 printf("Worker %d packets: " CLGRN "%" PRIx64 " " CLNRM "percentage:" CLGRN
     113                 :            :                        " %3.2f" CLNRM "\n",
     114                 :            :                        i, is_vec ? t->worker[i].processed_vecs : t->worker[i].processed_pkts,
     115                 :          0 :                        (((double)(is_vec ? t->worker[i].processed_vecs :
     116                 :          0 :                                            t->worker[i].processed_pkts)) /
     117                 :            :                         total) *
     118                 :            :                                100);
     119                 :            : 
     120                 :          0 :         return t->result;
     121                 :            : }
     122                 :            : 
     123                 :            : static inline int
     124                 :          0 : perf_producer(void *arg)
     125                 :            : {
     126                 :            :         int i;
     127                 :            :         struct prod_data *p  = arg;
     128                 :          0 :         struct test_perf *t = p->t;
     129                 :          0 :         struct evt_options *opt = t->opt;
     130                 :          0 :         const uint8_t dev_id = p->dev_id;
     131                 :          0 :         const uint8_t port = p->port_id;
     132                 :          0 :         struct rte_mempool *pool = t->pool;
     133                 :          0 :         const uint64_t nb_pkts = t->nb_pkts;
     134                 :          0 :         const uint32_t nb_flows = t->nb_flows;
     135                 :            :         uint32_t flow_counter = 0;
     136                 :            :         uint64_t count = 0;
     137                 :          0 :         struct perf_elt *m[BURST_SIZE + 1] = {NULL};
     138                 :            :         uint8_t enable_fwd_latency;
     139                 :            :         struct rte_event ev;
     140                 :            : 
     141                 :          0 :         enable_fwd_latency = opt->fwd_latency;
     142                 :          0 :         if (opt->verbose_level > 1)
     143                 :          0 :                 printf("%s(): lcore %d dev_id %d port=%d queue %d\n", __func__,
     144                 :          0 :                                 rte_lcore_id(), dev_id, port, p->queue_id);
     145                 :            : 
     146                 :          0 :         ev.event = 0;
     147                 :            :         ev.op = RTE_EVENT_OP_NEW;
     148                 :          0 :         ev.queue_id = p->queue_id;
     149                 :          0 :         ev.sched_type = t->opt->sched_type_list[0];
     150                 :          0 :         ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
     151                 :          0 :         ev.event_type =  RTE_EVENT_TYPE_CPU;
     152                 :            :         ev.sub_event_type = 0; /* stage 0 */
     153                 :            : 
     154                 :          0 :         while (count < nb_pkts && t->done == false) {
     155                 :          0 :                 if (rte_mempool_get_bulk(pool, (void **)m, BURST_SIZE) < 0)
     156                 :          0 :                         continue;
     157                 :          0 :                 for (i = 0; i < BURST_SIZE; i++) {
     158                 :          0 :                         ev.flow_id = flow_counter++ % nb_flows;
     159                 :          0 :                         ev.event_ptr = m[i];
     160                 :          0 :                         if (enable_fwd_latency)
     161                 :          0 :                                 m[i]->timestamp = rte_get_timer_cycles();
     162                 :          0 :                         while (rte_event_enqueue_new_burst(dev_id, port, &ev,
     163                 :          0 :                                                            1) != 1) {
     164                 :          0 :                                 if (t->done)
     165                 :            :                                         break;
     166                 :            :                                 rte_pause();
     167                 :          0 :                                 if (enable_fwd_latency)
     168                 :          0 :                                         m[i]->timestamp =
     169                 :            :                                                 rte_get_timer_cycles();
     170                 :            :                         }
     171                 :            :                 }
     172                 :          0 :                 count += BURST_SIZE;
     173                 :            :         }
     174                 :            : 
     175                 :          0 :         return 0;
     176                 :            : }
     177                 :            : 
     178                 :            : static inline int
     179                 :          0 : perf_producer_burst(void *arg)
     180                 :          0 : {
     181                 :            :         uint32_t i;
     182                 :            :         uint64_t timestamp;
     183                 :            :         struct prod_data *p  = arg;
     184                 :          0 :         struct test_perf *t = p->t;
     185                 :          0 :         struct evt_options *opt = t->opt;
     186                 :          0 :         const uint8_t dev_id = p->dev_id;
     187                 :          0 :         const uint8_t port = p->port_id;
     188                 :          0 :         struct rte_mempool *pool = t->pool;
     189                 :          0 :         const uint64_t nb_pkts = t->nb_pkts;
     190                 :          0 :         const uint32_t nb_flows = t->nb_flows;
     191                 :            :         uint32_t flow_counter = 0;
     192                 :            :         uint16_t enq = 0;
     193                 :            :         uint64_t count = 0;
     194                 :          0 :         struct perf_elt *m[opt->prod_enq_burst_sz + 1];
     195                 :          0 :         struct rte_event ev[opt->prod_enq_burst_sz + 1];
     196                 :            :         uint32_t burst_size = opt->prod_enq_burst_sz;
     197                 :            :         uint8_t enable_fwd_latency;
     198                 :            : 
     199                 :          0 :         enable_fwd_latency = opt->fwd_latency;
     200                 :            :         memset(m, 0, sizeof(*m) * (opt->prod_enq_burst_sz + 1));
     201                 :          0 :         if (opt->verbose_level > 1)
     202                 :          0 :                 printf("%s(): lcore %d dev_id %d port=%d queue %d\n", __func__,
     203                 :          0 :                                 rte_lcore_id(), dev_id, port, p->queue_id);
     204                 :            : 
     205                 :          0 :         for (i = 0; i < burst_size; i++) {
     206                 :          0 :                 ev[i].op = RTE_EVENT_OP_NEW;
     207                 :          0 :                 ev[i].queue_id = p->queue_id;
     208                 :          0 :                 ev[i].sched_type = t->opt->sched_type_list[0];
     209                 :          0 :                 ev[i].priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
     210                 :          0 :                 ev[i].event_type =  RTE_EVENT_TYPE_CPU;
     211                 :          0 :                 ev[i].sub_event_type = 0; /* stage 0 */
     212                 :            :         }
     213                 :            : 
     214                 :          0 :         while (count < nb_pkts && t->done == false) {
     215                 :          0 :                 if (rte_mempool_get_bulk(pool, (void **)m, burst_size) < 0)
     216                 :          0 :                         continue;
     217                 :            :                 timestamp = rte_get_timer_cycles();
     218                 :          0 :                 for (i = 0; i < burst_size; i++) {
     219                 :          0 :                         ev[i].flow_id = flow_counter++ % nb_flows;
     220                 :          0 :                         ev[i].event_ptr = m[i];
     221                 :          0 :                         if (enable_fwd_latency)
     222                 :          0 :                                 m[i]->timestamp = timestamp;
     223                 :            :                 }
     224                 :          0 :                 enq = rte_event_enqueue_new_burst(dev_id, port, ev, burst_size);
     225                 :          0 :                 while (enq < burst_size) {
     226                 :          0 :                         enq += rte_event_enqueue_new_burst(
     227                 :          0 :                                 dev_id, port, ev + enq, burst_size - enq);
     228                 :          0 :                         if (t->done)
     229                 :            :                                 break;
     230                 :            :                         rte_pause();
     231                 :          0 :                         if (enable_fwd_latency) {
     232                 :            :                                 timestamp = rte_get_timer_cycles();
     233                 :          0 :                                 for (i = enq; i < burst_size; i++)
     234                 :          0 :                                         m[i]->timestamp = timestamp;
     235                 :            :                         }
     236                 :            :                 }
     237                 :          0 :                 count += burst_size;
     238                 :            :         }
     239                 :          0 :         return 0;
     240                 :            : }
     241                 :            : 
     242                 :            : static inline int
     243                 :          0 : perf_event_timer_producer(void *arg)
     244                 :            : {
     245                 :            :         int i;
     246                 :            :         struct prod_data *p  = arg;
     247                 :          0 :         struct test_perf *t = p->t;
     248                 :          0 :         struct evt_options *opt = t->opt;
     249                 :            :         uint32_t flow_counter = 0;
     250                 :            :         uint64_t count = 0;
     251                 :            :         uint64_t arm_latency = 0;
     252                 :          0 :         const uint8_t nb_timer_adptrs = opt->nb_timer_adptrs;
     253                 :          0 :         const uint32_t nb_flows = t->nb_flows;
     254                 :          0 :         const uint64_t nb_timers = opt->nb_timers;
     255                 :          0 :         struct rte_mempool *pool = t->pool;
     256                 :          0 :         struct perf_elt *m[BURST_SIZE + 1] = {NULL};
     257                 :          0 :         struct rte_event_timer_adapter **adptr = t->timer_adptr;
     258                 :            :         struct rte_event_timer tim;
     259                 :          0 :         uint64_t timeout_ticks = opt->expiry_nsec / opt->timer_tick_nsec;
     260                 :            : 
     261                 :            :         memset(&tim, 0, sizeof(struct rte_event_timer));
     262                 :          0 :         timeout_ticks =
     263                 :          0 :                 opt->optm_timer_tick_nsec
     264                 :          0 :                         ? ceil((double)(timeout_ticks * opt->timer_tick_nsec) /
     265                 :            :                                opt->optm_timer_tick_nsec)
     266                 :            :                         : timeout_ticks;
     267                 :          0 :         timeout_ticks += timeout_ticks ? 0 : 1;
     268                 :          0 :         tim.ev.event_type = RTE_EVENT_TYPE_TIMER;
     269                 :            :         tim.ev.op = RTE_EVENT_OP_NEW;
     270                 :          0 :         tim.ev.sched_type = t->opt->sched_type_list[0];
     271                 :          0 :         tim.ev.queue_id = p->queue_id;
     272                 :          0 :         tim.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
     273                 :            :         tim.state = RTE_EVENT_TIMER_NOT_ARMED;
     274                 :          0 :         tim.timeout_ticks = timeout_ticks;
     275                 :            : 
     276                 :          0 :         if (opt->verbose_level > 1)
     277                 :            :                 printf("%s(): lcore %d\n", __func__, rte_lcore_id());
     278                 :            : 
     279                 :          0 :         while (count < nb_timers && t->done == false) {
     280                 :          0 :                 if (rte_mempool_get_bulk(pool, (void **)m, BURST_SIZE) < 0)
     281                 :          0 :                         continue;
     282                 :          0 :                 for (i = 0; i < BURST_SIZE; i++) {
     283                 :          0 :                         rte_prefetch0(m[i + 1]);
     284                 :          0 :                         m[i]->tim = tim;
     285                 :          0 :                         m[i]->tim.ev.flow_id = flow_counter++ % nb_flows;
     286                 :          0 :                         m[i]->tim.ev.event_ptr = m[i];
     287                 :          0 :                         m[i]->timestamp = rte_get_timer_cycles();
     288                 :          0 :                         while (rte_event_timer_arm_burst(
     289                 :          0 :                                adptr[flow_counter % nb_timer_adptrs],
     290                 :          0 :                                (struct rte_event_timer **)&m[i], 1) != 1) {
     291                 :          0 :                                 if (t->done)
     292                 :            :                                         break;
     293                 :          0 :                                 m[i]->timestamp = rte_get_timer_cycles();
     294                 :            :                         }
     295                 :          0 :                         arm_latency += rte_get_timer_cycles() - m[i]->timestamp;
     296                 :            :                 }
     297                 :          0 :                 count += BURST_SIZE;
     298                 :            :         }
     299                 :          0 :         fflush(stdout);
     300                 :            :         rte_delay_ms(1000);
     301                 :          0 :         printf("%s(): lcore %d Average event timer arm latency = %.3f us\n",
     302                 :            :                         __func__, rte_lcore_id(),
     303                 :          0 :                         count ? (float)(arm_latency / count) /
     304                 :          0 :                         (rte_get_timer_hz() / 1000000) : 0);
     305                 :          0 :         return 0;
     306                 :            : }
     307                 :            : 
     308                 :            : static inline int
     309                 :          0 : perf_event_timer_producer_burst(void *arg)
     310                 :            : {
     311                 :            :         int i;
     312                 :            :         struct prod_data *p  = arg;
     313                 :          0 :         struct test_perf *t = p->t;
     314                 :          0 :         struct evt_options *opt = t->opt;
     315                 :            :         uint32_t flow_counter = 0;
     316                 :            :         uint64_t count = 0;
     317                 :            :         uint64_t arm_latency = 0;
     318                 :          0 :         const uint8_t nb_timer_adptrs = opt->nb_timer_adptrs;
     319                 :          0 :         const uint32_t nb_flows = t->nb_flows;
     320                 :          0 :         const uint64_t nb_timers = opt->nb_timers;
     321                 :          0 :         struct rte_mempool *pool = t->pool;
     322                 :          0 :         struct perf_elt *m[BURST_SIZE + 1] = {NULL};
     323                 :          0 :         struct rte_event_timer_adapter **adptr = t->timer_adptr;
     324                 :            :         struct rte_event_timer tim;
     325                 :          0 :         uint64_t timeout_ticks = opt->expiry_nsec / opt->timer_tick_nsec;
     326                 :            : 
     327                 :            :         memset(&tim, 0, sizeof(struct rte_event_timer));
     328                 :          0 :         timeout_ticks =
     329                 :          0 :                 opt->optm_timer_tick_nsec
     330                 :          0 :                         ? ceil((double)(timeout_ticks * opt->timer_tick_nsec) /
     331                 :            :                                opt->optm_timer_tick_nsec)
     332                 :            :                         : timeout_ticks;
     333                 :          0 :         timeout_ticks += timeout_ticks ? 0 : 1;
     334                 :          0 :         tim.ev.event_type = RTE_EVENT_TYPE_TIMER;
     335                 :            :         tim.ev.op = RTE_EVENT_OP_NEW;
     336                 :          0 :         tim.ev.sched_type = t->opt->sched_type_list[0];
     337                 :          0 :         tim.ev.queue_id = p->queue_id;
     338                 :          0 :         tim.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
     339                 :            :         tim.state = RTE_EVENT_TIMER_NOT_ARMED;
     340                 :          0 :         tim.timeout_ticks = timeout_ticks;
     341                 :            : 
     342                 :          0 :         if (opt->verbose_level > 1)
     343                 :            :                 printf("%s(): lcore %d\n", __func__, rte_lcore_id());
     344                 :            : 
     345                 :          0 :         while (count < nb_timers && t->done == false) {
     346                 :          0 :                 if (rte_mempool_get_bulk(pool, (void **)m, BURST_SIZE) < 0)
     347                 :          0 :                         continue;
     348                 :          0 :                 for (i = 0; i < BURST_SIZE; i++) {
     349                 :          0 :                         rte_prefetch0(m[i + 1]);
     350                 :          0 :                         m[i]->tim = tim;
     351                 :          0 :                         m[i]->tim.ev.flow_id = flow_counter++ % nb_flows;
     352                 :          0 :                         m[i]->tim.ev.event_ptr = m[i];
     353                 :          0 :                         m[i]->timestamp = rte_get_timer_cycles();
     354                 :            :                 }
     355                 :          0 :                 rte_event_timer_arm_tmo_tick_burst(
     356                 :          0 :                                 adptr[flow_counter % nb_timer_adptrs],
     357                 :            :                                 (struct rte_event_timer **)m,
     358                 :            :                                 tim.timeout_ticks,
     359                 :            :                                 BURST_SIZE);
     360                 :          0 :                 arm_latency += rte_get_timer_cycles() - m[i - 1]->timestamp;
     361                 :          0 :                 count += BURST_SIZE;
     362                 :            :         }
     363                 :          0 :         fflush(stdout);
     364                 :            :         rte_delay_ms(1000);
     365                 :          0 :         printf("%s(): lcore %d Average event timer arm latency = %.3f us\n",
     366                 :            :                         __func__, rte_lcore_id(),
     367                 :          0 :                         count ? (float)(arm_latency / count) /
     368                 :          0 :                         (rte_get_timer_hz() / 1000000) : 0);
     369                 :          0 :         return 0;
     370                 :            : }
     371                 :            : 
     372                 :            : static inline void
     373                 :          0 : crypto_adapter_enq_op_new(struct prod_data *p)
     374                 :            : {
     375                 :          0 :         struct test_perf *t = p->t;
     376                 :          0 :         const uint32_t nb_flows = t->nb_flows;
     377                 :          0 :         const uint64_t nb_pkts = t->nb_pkts;
     378                 :          0 :         struct rte_mempool *pool = t->pool;
     379                 :            :         uint16_t data_length, data_offset;
     380                 :          0 :         struct evt_options *opt = t->opt;
     381                 :          0 :         uint16_t qp_id = p->ca.cdev_qp_id;
     382                 :          0 :         uint8_t cdev_id = p->ca.cdev_id;
     383                 :            :         uint64_t alloc_failures = 0;
     384                 :            :         uint32_t flow_counter = 0;
     385                 :            :         struct rte_crypto_op *op;
     386                 :            :         uint16_t len, offset;
     387                 :            :         struct rte_mbuf *m;
     388                 :            :         uint64_t count = 0;
     389                 :            : 
     390                 :          0 :         if (opt->verbose_level > 1)
     391                 :          0 :                 printf("%s(): lcore %d queue %d cdev_id %u cdev_qp_id %u\n",
     392                 :          0 :                        __func__, rte_lcore_id(), p->queue_id, p->ca.cdev_id,
     393                 :            :                        p->ca.cdev_qp_id);
     394                 :            : 
     395                 :            :         offset = sizeof(struct perf_elt);
     396                 :          0 :         len = RTE_MAX(RTE_ETHER_MIN_LEN + offset, opt->mbuf_sz);
     397                 :            : 
     398                 :          0 :         if (opt->crypto_cipher_bit_mode) {
     399                 :            :                 data_offset = offset << 3;
     400                 :          0 :                 data_length = (len - offset) << 3;
     401                 :            :         } else {
     402                 :            :                 data_offset = offset;
     403                 :          0 :                 data_length = len - offset;
     404                 :            :         }
     405                 :            : 
     406                 :          0 :         while (count < nb_pkts && t->done == false) {
     407                 :          0 :                 if (opt->crypto_op_type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
     408                 :            :                         struct rte_crypto_sym_op *sym_op;
     409                 :            : 
     410                 :          0 :                         op = rte_crypto_op_alloc(t->ca_op_pool,
     411                 :            :                                          RTE_CRYPTO_OP_TYPE_SYMMETRIC);
     412                 :          0 :                         if (unlikely(op == NULL)) {
     413                 :          0 :                                 alloc_failures++;
     414                 :          0 :                                 continue;
     415                 :            :                         }
     416                 :            : 
     417                 :          0 :                         m = rte_pktmbuf_alloc(pool);
     418                 :          0 :                         if (unlikely(m == NULL)) {
     419                 :          0 :                                 alloc_failures++;
     420                 :          0 :                                 rte_crypto_op_free(op);
     421                 :          0 :                                 continue;
     422                 :            :                         }
     423                 :            : 
     424                 :            :                         rte_pktmbuf_append(m, len);
     425                 :          0 :                         sym_op = op->sym;
     426                 :          0 :                         sym_op->m_src = m;
     427                 :            : 
     428                 :          0 :                         sym_op->cipher.data.offset = data_offset;
     429                 :          0 :                         sym_op->cipher.data.length = data_length;
     430                 :            : 
     431                 :          0 :                         rte_crypto_op_attach_sym_session(
     432                 :          0 :                                 op, p->ca.crypto_sess[flow_counter++ % nb_flows]);
     433                 :            :                 } else {
     434                 :            :                         struct rte_crypto_asym_op *asym_op;
     435                 :            :                         uint8_t *result;
     436                 :            : 
     437                 :          0 :                         if (rte_mempool_get(pool, (void **)&result)) {
     438                 :          0 :                                 alloc_failures++;
     439                 :          0 :                                 continue;
     440                 :            :                         }
     441                 :            : 
     442                 :          0 :                         op = rte_crypto_op_alloc(t->ca_op_pool,
     443                 :            :                                          RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
     444                 :          0 :                         if (unlikely(op == NULL)) {
     445                 :          0 :                                 alloc_failures++;
     446                 :          0 :                                 rte_mempool_put(pool, result);
     447                 :          0 :                                 continue;
     448                 :            :                         }
     449                 :            : 
     450                 :            :                         asym_op = op->asym;
     451                 :          0 :                         asym_op->modex.base.data = modex_test_case.base.data;
     452                 :          0 :                         asym_op->modex.base.length = modex_test_case.base.len;
     453                 :          0 :                         asym_op->modex.result.data = result;
     454                 :          0 :                         asym_op->modex.result.length = modex_test_case.result_len;
     455                 :          0 :                         rte_crypto_op_attach_asym_session(
     456                 :          0 :                                 op, p->ca.crypto_sess[flow_counter++ % nb_flows]);
     457                 :            :                 }
     458                 :          0 :                 while (rte_cryptodev_enqueue_burst(cdev_id, qp_id, &op, 1) != 1 &&
     459                 :          0 :                                 t->done == false)
     460                 :            :                         rte_pause();
     461                 :            : 
     462                 :          0 :                 count++;
     463                 :            :         }
     464                 :            : 
     465                 :          0 :         if (opt->verbose_level > 1 && alloc_failures)
     466                 :            :                 printf("%s(): lcore %d allocation failures: %"PRIu64"\n",
     467                 :            :                        __func__, rte_lcore_id(), alloc_failures);
     468                 :          0 : }
     469                 :            : 
     470                 :            : static inline void
     471                 :          0 : crypto_adapter_enq_op_fwd(struct prod_data *p)
     472                 :            : {
     473                 :          0 :         const uint8_t dev_id = p->dev_id;
     474                 :          0 :         const uint8_t port = p->port_id;
     475                 :          0 :         struct test_perf *t = p->t;
     476                 :          0 :         const uint32_t nb_flows = t->nb_flows;
     477                 :          0 :         const uint64_t nb_pkts = t->nb_pkts;
     478                 :          0 :         struct rte_mempool *pool = t->pool;
     479                 :          0 :         struct evt_options *opt = t->opt;
     480                 :            :         uint64_t alloc_failures = 0;
     481                 :            :         uint32_t flow_counter = 0;
     482                 :            :         struct rte_crypto_op *op;
     483                 :            :         uint16_t len, offset;
     484                 :            :         struct rte_event ev;
     485                 :            :         struct rte_mbuf *m;
     486                 :            :         uint64_t count = 0;
     487                 :            : 
     488                 :          0 :         if (opt->verbose_level > 1)
     489                 :          0 :                 printf("%s(): lcore %d port %d queue %d cdev_id %u cdev_qp_id %u\n",
     490                 :          0 :                        __func__, rte_lcore_id(), port, p->queue_id,
     491                 :          0 :                        p->ca.cdev_id, p->ca.cdev_qp_id);
     492                 :            : 
     493                 :          0 :         ev.event = 0;
     494                 :            :         ev.op = RTE_EVENT_OP_NEW;
     495                 :          0 :         ev.queue_id = p->queue_id;
     496                 :          0 :         ev.sched_type = RTE_SCHED_TYPE_ATOMIC;
     497                 :          0 :         ev.event_type = RTE_EVENT_TYPE_CPU;
     498                 :            : 
     499                 :            :         offset = sizeof(struct perf_elt);
     500                 :          0 :         len = RTE_MAX(RTE_ETHER_MIN_LEN + offset, opt->mbuf_sz);
     501                 :            : 
     502                 :          0 :         while (count < nb_pkts && t->done == false) {
     503                 :          0 :                 if (opt->crypto_op_type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
     504                 :            :                         struct rte_crypto_sym_op *sym_op;
     505                 :            : 
     506                 :          0 :                         op = rte_crypto_op_alloc(t->ca_op_pool,
     507                 :            :                                          RTE_CRYPTO_OP_TYPE_SYMMETRIC);
     508                 :          0 :                         if (unlikely(op == NULL)) {
     509                 :          0 :                                 alloc_failures++;
     510                 :          0 :                                 continue;
     511                 :            :                         }
     512                 :            : 
     513                 :          0 :                         m = rte_pktmbuf_alloc(pool);
     514                 :          0 :                         if (unlikely(m == NULL)) {
     515                 :          0 :                                 alloc_failures++;
     516                 :          0 :                                 rte_crypto_op_free(op);
     517                 :          0 :                                 continue;
     518                 :            :                         }
     519                 :            : 
     520                 :            :                         rte_pktmbuf_append(m, len);
     521                 :            :                         sym_op = op->sym;
     522                 :          0 :                         sym_op->m_src = m;
     523                 :          0 :                         sym_op->cipher.data.offset = offset;
     524                 :          0 :                         sym_op->cipher.data.length = len - offset;
     525                 :          0 :                         rte_crypto_op_attach_sym_session(
     526                 :          0 :                                 op, p->ca.crypto_sess[flow_counter++ % nb_flows]);
     527                 :            :                 } else {
     528                 :            :                         struct rte_crypto_asym_op *asym_op;
     529                 :            :                         uint8_t *result;
     530                 :            : 
     531                 :          0 :                         if (rte_mempool_get(pool, (void **)&result)) {
     532                 :          0 :                                 alloc_failures++;
     533                 :          0 :                                 continue;
     534                 :            :                         }
     535                 :            : 
     536                 :          0 :                         op = rte_crypto_op_alloc(t->ca_op_pool,
     537                 :            :                                          RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
     538                 :          0 :                         if (unlikely(op == NULL)) {
     539                 :          0 :                                 alloc_failures++;
     540                 :          0 :                                 rte_mempool_put(pool, result);
     541                 :          0 :                                 continue;
     542                 :            :                         }
     543                 :            : 
     544                 :            :                         asym_op = op->asym;
     545                 :          0 :                         asym_op->modex.base.data = modex_test_case.base.data;
     546                 :          0 :                         asym_op->modex.base.length = modex_test_case.base.len;
     547                 :          0 :                         asym_op->modex.result.data = result;
     548                 :          0 :                         asym_op->modex.result.length = modex_test_case.result_len;
     549                 :          0 :                         rte_crypto_op_attach_asym_session(
     550                 :          0 :                                 op, p->ca.crypto_sess[flow_counter++ % nb_flows]);
     551                 :            :                 }
     552                 :          0 :                 ev.event_ptr = op;
     553                 :            : 
     554                 :          0 :                 while (rte_event_crypto_adapter_enqueue(dev_id, port, &ev, 1) != 1 &&
     555                 :          0 :                        t->done == false)
     556                 :            :                         rte_pause();
     557                 :            : 
     558                 :          0 :                 count++;
     559                 :            :         }
     560                 :            : 
     561                 :          0 :         if (opt->verbose_level > 1 && alloc_failures)
     562                 :            :                 printf("%s(): lcore %d allocation failures: %"PRIu64"\n",
     563                 :            :                        __func__, rte_lcore_id(), alloc_failures);
     564                 :          0 : }
     565                 :            : 
     566                 :            : static inline void
     567                 :          0 : dma_adapter_enq_op_fwd(struct prod_data *p)
     568                 :            : {
     569                 :          0 :         struct rte_event_dma_adapter_op *ops[BURST_SIZE] = {NULL};
     570                 :          0 :         struct test_perf *t = p->t;
     571                 :          0 :         const uint32_t nb_flows = t->nb_flows;
     572                 :          0 :         const uint64_t nb_pkts = t->nb_pkts;
     573                 :            :         struct rte_event_dma_adapter_op op;
     574                 :            :         struct rte_event evts[BURST_SIZE];
     575                 :          0 :         const uint8_t dev_id = p->dev_id;
     576                 :          0 :         struct evt_options *opt = t->opt;
     577                 :          0 :         const uint8_t port = p->port_id;
     578                 :            :         uint32_t flow_counter = 0;
     579                 :            :         struct rte_mempool *pool;
     580                 :            :         struct rte_event ev;
     581                 :            :         uint8_t *src, *dst;
     582                 :            :         uint64_t count = 0;
     583                 :            :         uint32_t flow;
     584                 :            :         int i;
     585                 :            : 
     586                 :          0 :         pool = t->pool;
     587                 :          0 :         if (opt->verbose_level > 1)
     588                 :          0 :                 printf("%s(): lcore %d port %d queue %d dma_dev_id %u dma_dev_vchan_id %u\n",
     589                 :          0 :                        __func__, rte_lcore_id(), port, p->queue_id,
     590                 :          0 :                        p->da.dma_dev_id, p->da.vchan_id);
     591                 :            : 
     592                 :          0 :         src = rte_zmalloc(NULL, nb_flows * RTE_CACHE_LINE_SIZE, RTE_CACHE_LINE_SIZE);
     593                 :          0 :         dst = rte_zmalloc(NULL, nb_flows * RTE_CACHE_LINE_SIZE, RTE_CACHE_LINE_SIZE);
     594                 :          0 :         if (!src || !dst) {
     595                 :          0 :                 rte_free(src);
     596                 :          0 :                 rte_free(dst);
     597                 :          0 :                 evt_err("Failed to alloc memory for src/dst");
     598                 :          0 :                 return;
     599                 :            :         }
     600                 :            : 
     601                 :          0 :         ev.event = 0;
     602                 :            :         ev.op = RTE_EVENT_OP_NEW;
     603                 :          0 :         ev.queue_id = p->queue_id;
     604                 :          0 :         ev.sched_type = RTE_SCHED_TYPE_ATOMIC;
     605                 :          0 :         ev.event_type = RTE_EVENT_TYPE_CPU;
     606                 :            : 
     607                 :          0 :         op.dma_dev_id = p->da.dma_dev_id;
     608                 :          0 :         op.vchan = p->da.vchan_id;
     609                 :          0 :         op.op_mp = pool;
     610                 :          0 :         op.flags = RTE_DMA_OP_FLAG_SUBMIT;
     611                 :          0 :         op.nb_src = 1;
     612                 :          0 :         op.nb_dst = 1;
     613                 :            : 
     614                 :          0 :         while (count < nb_pkts && t->done == false) {
     615                 :          0 :                 if (rte_mempool_get_bulk(pool, (void **)ops, BURST_SIZE) < 0)
     616                 :          0 :                         continue;
     617                 :          0 :                 for (i = 0; i < BURST_SIZE; i++) {
     618                 :          0 :                         flow = flow_counter++ % nb_flows;
     619                 :          0 :                         *ops[i] = op;
     620                 :          0 :                         ops[i]->src_dst_seg[0].addr = (rte_iova_t)&src[flow * RTE_CACHE_LINE_SIZE];
     621                 :          0 :                         ops[i]->src_dst_seg[1].addr = (rte_iova_t)&dst[flow * RTE_CACHE_LINE_SIZE];
     622                 :          0 :                         ops[i]->src_dst_seg[0].length = RTE_CACHE_LINE_SIZE;
     623                 :          0 :                         ops[i]->src_dst_seg[1].length = RTE_CACHE_LINE_SIZE;
     624                 :            : 
     625                 :          0 :                         evts[i].event = ev.event;
     626                 :          0 :                         evts[i].flow_id = flow;
     627                 :          0 :                         evts[i].event_ptr = ops[i];
     628                 :            :                 }
     629                 :            : 
     630                 :          0 :                 i = rte_event_dma_adapter_enqueue(dev_id, port, evts, BURST_SIZE);
     631                 :          0 :                 while (i < BURST_SIZE) {
     632                 :          0 :                         i += rte_event_dma_adapter_enqueue(dev_id, port, evts + i, BURST_SIZE - i);
     633                 :          0 :                         if (t->done)
     634                 :            :                                 break;
     635                 :            :                         rte_pause();
     636                 :            :                 }
     637                 :            : 
     638                 :          0 :                 count += BURST_SIZE;
     639                 :            :         }
     640                 :            : }
     641                 :            : 
     642                 :            : static inline int
     643                 :            : perf_event_dma_producer(void *arg)
     644                 :            : {
     645                 :            :         struct prod_data *p = arg;
     646                 :            : 
     647                 :            :         /* Only fwd mode is supported. */
     648                 :          0 :         dma_adapter_enq_op_fwd(p);
     649                 :            : 
     650                 :            :         return 0;
     651                 :            : }
     652                 :            : 
     653                 :            : static inline int
     654                 :          0 : perf_event_crypto_producer(void *arg)
     655                 :            : {
     656                 :            :         struct prod_data *p = arg;
     657                 :          0 :         struct evt_options *opt = p->t->opt;
     658                 :            : 
     659                 :          0 :         if (opt->crypto_adptr_mode == RTE_EVENT_CRYPTO_ADAPTER_OP_NEW)
     660                 :          0 :                 crypto_adapter_enq_op_new(p);
     661                 :            :         else
     662                 :          0 :                 crypto_adapter_enq_op_fwd(p);
     663                 :            : 
     664                 :          0 :         return 0;
     665                 :            : }
     666                 :            : 
     667                 :            : static void
     668                 :          0 : crypto_adapter_enq_op_new_burst(struct prod_data *p)
     669                 :            : {
     670                 :          0 :         const struct test_perf *t = p->t;
     671                 :          0 :         const struct evt_options *opt = t->opt;
     672                 :            : 
     673                 :            :         struct rte_mbuf *m, *pkts_burst[MAX_PROD_ENQ_BURST_SIZE];
     674                 :            :         struct rte_crypto_op *ops_burst[MAX_PROD_ENQ_BURST_SIZE];
     675                 :          0 :         const uint32_t burst_size = opt->prod_enq_burst_sz;
     676                 :            :         uint8_t *result[MAX_PROD_ENQ_BURST_SIZE];
     677                 :          0 :         const uint32_t nb_flows = t->nb_flows;
     678                 :          0 :         const uint64_t nb_pkts = t->nb_pkts;
     679                 :            :         uint16_t len, enq, nb_alloc, offset;
     680                 :          0 :         struct rte_mempool *pool = t->pool;
     681                 :          0 :         uint16_t qp_id = p->ca.cdev_qp_id;
     682                 :          0 :         uint8_t cdev_id = p->ca.cdev_id;
     683                 :            :         uint64_t alloc_failures = 0;
     684                 :            :         uint32_t flow_counter = 0;
     685                 :            :         uint64_t count = 0;
     686                 :            :         uint32_t  i;
     687                 :            : 
     688                 :          0 :         if (opt->verbose_level > 1)
     689                 :          0 :                 printf("%s(): lcore %d queue %d cdev_id %u cdev_qp_id %u\n",
     690                 :          0 :                        __func__, rte_lcore_id(), p->queue_id, p->ca.cdev_id,
     691                 :            :                        p->ca.cdev_qp_id);
     692                 :            : 
     693                 :            :         offset = sizeof(struct perf_elt);
     694                 :          0 :         len = RTE_MAX(RTE_ETHER_MIN_LEN + offset, opt->mbuf_sz);
     695                 :            : 
     696                 :          0 :         while (count < nb_pkts && t->done == false) {
     697                 :          0 :                 if (opt->crypto_op_type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
     698                 :            :                         struct rte_crypto_sym_op *sym_op;
     699                 :            :                         int ret;
     700                 :            : 
     701                 :          0 :                         nb_alloc = rte_crypto_op_bulk_alloc(t->ca_op_pool,
     702                 :            :                                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, ops_burst, burst_size);
     703                 :          0 :                         if (unlikely(nb_alloc != burst_size)) {
     704                 :          0 :                                 alloc_failures++;
     705                 :          0 :                                 continue;
     706                 :            :                         }
     707                 :            : 
     708                 :          0 :                         ret = rte_pktmbuf_alloc_bulk(pool, pkts_burst, burst_size);
     709                 :          0 :                         if (unlikely(ret != 0)) {
     710                 :          0 :                                 alloc_failures++;
     711                 :          0 :                                 rte_mempool_put_bulk(t->ca_op_pool, (void **)ops_burst, burst_size);
     712                 :          0 :                                 continue;
     713                 :            :                         }
     714                 :            : 
     715                 :          0 :                         for (i = 0; i < burst_size; i++) {
     716                 :          0 :                                 m = pkts_burst[i];
     717                 :            :                                 rte_pktmbuf_append(m, len);
     718                 :          0 :                                 sym_op = ops_burst[i]->sym;
     719                 :          0 :                                 sym_op->m_src = m;
     720                 :          0 :                                 sym_op->cipher.data.offset = offset;
     721                 :          0 :                                 sym_op->cipher.data.length = len - offset;
     722                 :          0 :                                 rte_crypto_op_attach_sym_session(ops_burst[i],
     723                 :          0 :                                                 p->ca.crypto_sess[flow_counter++ % nb_flows]);
     724                 :            :                         }
     725                 :            :                 } else {
     726                 :            :                         struct rte_crypto_asym_op *asym_op;
     727                 :            : 
     728                 :          0 :                         nb_alloc = rte_crypto_op_bulk_alloc(t->ca_op_pool,
     729                 :            :                                         RTE_CRYPTO_OP_TYPE_ASYMMETRIC, ops_burst, burst_size);
     730                 :          0 :                         if (unlikely(nb_alloc != burst_size)) {
     731                 :          0 :                                 alloc_failures++;
     732                 :          0 :                                 continue;
     733                 :            :                         }
     734                 :            : 
     735                 :          0 :                         if (rte_mempool_get_bulk(pool, (void **)result, burst_size)) {
     736                 :          0 :                                 alloc_failures++;
     737                 :          0 :                                 rte_mempool_put_bulk(t->ca_op_pool, (void **)ops_burst, burst_size);
     738                 :          0 :                                 continue;
     739                 :            :                         }
     740                 :            : 
     741                 :          0 :                         for (i = 0; i < burst_size; i++) {
     742                 :          0 :                                 asym_op = ops_burst[i]->asym;
     743                 :          0 :                                 asym_op->modex.base.data = modex_test_case.base.data;
     744                 :          0 :                                 asym_op->modex.base.length = modex_test_case.base.len;
     745                 :          0 :                                 asym_op->modex.result.data = result[i];
     746                 :          0 :                                 asym_op->modex.result.length = modex_test_case.result_len;
     747                 :          0 :                                 rte_crypto_op_attach_asym_session(ops_burst[i],
     748                 :          0 :                                                 p->ca.crypto_sess[flow_counter++ % nb_flows]);
     749                 :            :                         }
     750                 :            :                 }
     751                 :            : 
     752                 :            :                 enq = 0;
     753                 :          0 :                 while (!t->done) {
     754                 :          0 :                         enq += rte_cryptodev_enqueue_burst(cdev_id, qp_id, ops_burst + enq,
     755                 :          0 :                                         burst_size - enq);
     756                 :          0 :                         if (enq == burst_size)
     757                 :            :                                 break;
     758                 :            :                 }
     759                 :            : 
     760                 :          0 :                 count += burst_size;
     761                 :            :         }
     762                 :            : 
     763                 :          0 :         if (opt->verbose_level > 1 && alloc_failures)
     764                 :            :                 printf("%s(): lcore %d allocation failures: %"PRIu64"\n",
     765                 :            :                        __func__, rte_lcore_id(), alloc_failures);
     766                 :          0 : }
     767                 :            : 
     768                 :            : static void
     769                 :          0 : crypto_adapter_enq_op_fwd_burst(struct prod_data *p)
     770                 :            : {
     771                 :          0 :         const struct test_perf *t = p->t;
     772                 :          0 :         const struct evt_options *opt = t->opt;
     773                 :            : 
     774                 :            :         struct rte_mbuf *m, *pkts_burst[MAX_PROD_ENQ_BURST_SIZE];
     775                 :            :         struct rte_crypto_op *ops_burst[MAX_PROD_ENQ_BURST_SIZE];
     776                 :          0 :         const uint32_t burst_size = opt->prod_enq_burst_sz;
     777                 :            :         struct rte_event ev[MAX_PROD_ENQ_BURST_SIZE];
     778                 :            :         uint8_t *result[MAX_PROD_ENQ_BURST_SIZE];
     779                 :          0 :         const uint32_t nb_flows = t->nb_flows;
     780                 :          0 :         const uint64_t nb_pkts = t->nb_pkts;
     781                 :            :         uint16_t len, enq, nb_alloc, offset;
     782                 :          0 :         struct rte_mempool *pool = t->pool;
     783                 :          0 :         const uint8_t dev_id = p->dev_id;
     784                 :          0 :         const uint8_t port = p->port_id;
     785                 :            :         uint64_t alloc_failures = 0;
     786                 :            :         uint32_t flow_counter = 0;
     787                 :            :         uint64_t count = 0;
     788                 :            :         uint32_t  i;
     789                 :            : 
     790                 :          0 :         if (opt->verbose_level > 1)
     791                 :          0 :                 printf("%s(): lcore %d port %d queue %d cdev_id %u cdev_qp_id %u\n",
     792                 :          0 :                        __func__, rte_lcore_id(), port, p->queue_id,
     793                 :          0 :                        p->ca.cdev_id, p->ca.cdev_qp_id);
     794                 :            : 
     795                 :            :         offset = sizeof(struct perf_elt);
     796                 :          0 :         len = RTE_MAX(RTE_ETHER_MIN_LEN + offset, opt->mbuf_sz);
     797                 :            : 
     798                 :          0 :         for (i = 0; i < burst_size; i++) {
     799                 :          0 :                 ev[i].event = 0;
     800                 :          0 :                 ev[i].op = RTE_EVENT_OP_NEW;
     801                 :          0 :                 ev[i].queue_id = p->queue_id;
     802                 :          0 :                 ev[i].sched_type = RTE_SCHED_TYPE_ATOMIC;
     803                 :          0 :                 ev[i].event_type = RTE_EVENT_TYPE_CPU;
     804                 :            :         }
     805                 :            : 
     806                 :          0 :         while (count < nb_pkts && t->done == false) {
     807                 :          0 :                 if (opt->crypto_op_type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
     808                 :            :                         struct rte_crypto_sym_op *sym_op;
     809                 :            :                         int ret;
     810                 :            : 
     811                 :          0 :                         nb_alloc = rte_crypto_op_bulk_alloc(t->ca_op_pool,
     812                 :            :                                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, ops_burst, burst_size);
     813                 :          0 :                         if (unlikely(nb_alloc != burst_size)) {
     814                 :          0 :                                 alloc_failures++;
     815                 :          0 :                                 continue;
     816                 :            :                         }
     817                 :            : 
     818                 :          0 :                         ret = rte_pktmbuf_alloc_bulk(pool, pkts_burst, burst_size);
     819                 :          0 :                         if (unlikely(ret != 0)) {
     820                 :          0 :                                 alloc_failures++;
     821                 :          0 :                                 rte_mempool_put_bulk(t->ca_op_pool, (void **)ops_burst, burst_size);
     822                 :          0 :                                 continue;
     823                 :            :                         }
     824                 :            : 
     825                 :          0 :                         for (i = 0; i < burst_size; i++) {
     826                 :          0 :                                 m = pkts_burst[i];
     827                 :            :                                 rte_pktmbuf_append(m, len);
     828                 :          0 :                                 sym_op = ops_burst[i]->sym;
     829                 :          0 :                                 sym_op->m_src = m;
     830                 :          0 :                                 sym_op->cipher.data.offset = offset;
     831                 :          0 :                                 sym_op->cipher.data.length = len - offset;
     832                 :          0 :                                 rte_crypto_op_attach_sym_session(ops_burst[i],
     833                 :          0 :                                                 p->ca.crypto_sess[flow_counter++ % nb_flows]);
     834                 :          0 :                                 ev[i].event_ptr = ops_burst[i];
     835                 :            :                         }
     836                 :            :                 } else {
     837                 :            :                         struct rte_crypto_asym_op *asym_op;
     838                 :            : 
     839                 :          0 :                         nb_alloc = rte_crypto_op_bulk_alloc(t->ca_op_pool,
     840                 :            :                                         RTE_CRYPTO_OP_TYPE_ASYMMETRIC, ops_burst, burst_size);
     841                 :          0 :                         if (unlikely(nb_alloc != burst_size)) {
     842                 :          0 :                                 alloc_failures++;
     843                 :          0 :                                 continue;
     844                 :            :                         }
     845                 :            : 
     846                 :          0 :                         if (rte_mempool_get_bulk(pool, (void **)result, burst_size)) {
     847                 :          0 :                                 alloc_failures++;
     848                 :          0 :                                 rte_mempool_put_bulk(t->ca_op_pool, (void **)ops_burst, burst_size);
     849                 :          0 :                                 continue;
     850                 :            :                         }
     851                 :            : 
     852                 :          0 :                         for (i = 0; i < burst_size; i++) {
     853                 :          0 :                                 asym_op = ops_burst[i]->asym;
     854                 :          0 :                                 asym_op->modex.base.data = modex_test_case.base.data;
     855                 :          0 :                                 asym_op->modex.base.length = modex_test_case.base.len;
     856                 :          0 :                                 asym_op->modex.result.data = result[i];
     857                 :          0 :                                 asym_op->modex.result.length = modex_test_case.result_len;
     858                 :          0 :                                 rte_crypto_op_attach_asym_session(ops_burst[i],
     859                 :          0 :                                                 p->ca.crypto_sess[flow_counter++ % nb_flows]);
     860                 :          0 :                                 ev[i].event_ptr = ops_burst[i];
     861                 :            :                         }
     862                 :            :                 }
     863                 :            : 
     864                 :            :                 enq = 0;
     865                 :          0 :                 while (!t->done) {
     866                 :          0 :                         enq += rte_event_crypto_adapter_enqueue(dev_id, port, ev + enq,
     867                 :          0 :                                         burst_size - enq);
     868                 :          0 :                         if (enq == burst_size)
     869                 :            :                                 break;
     870                 :            :                 }
     871                 :            : 
     872                 :          0 :                 count += burst_size;
     873                 :            :         }
     874                 :            : 
     875                 :          0 :         if (opt->verbose_level > 1 && alloc_failures)
     876                 :            :                 printf("%s(): lcore %d allocation failures: %"PRIu64"\n",
     877                 :            :                        __func__, rte_lcore_id(), alloc_failures);
     878                 :          0 : }
     879                 :            : 
     880                 :            : static inline int
     881                 :          0 : perf_event_crypto_producer_burst(void *arg)
     882                 :            : {
     883                 :            :         struct prod_data *p = arg;
     884                 :          0 :         struct evt_options *opt = p->t->opt;
     885                 :            : 
     886                 :          0 :         if (opt->crypto_adptr_mode == RTE_EVENT_CRYPTO_ADAPTER_OP_NEW)
     887                 :          0 :                 crypto_adapter_enq_op_new_burst(p);
     888                 :            :         else
     889                 :          0 :                 crypto_adapter_enq_op_fwd_burst(p);
     890                 :            : 
     891                 :          0 :         return 0;
     892                 :            : }
     893                 :            : 
     894                 :            : static int
     895                 :          0 : perf_event_vector_producer(struct prod_data *p)
     896                 :            : {
     897                 :          0 :         struct rte_event_vector_adapter *adptr = p->va.vector_adptr;
     898                 :          0 :         struct evt_options *opt = p->t->opt;
     899                 :            :         const struct test_perf *t = p->t;
     900                 :            :         uint64_t objs[BURST_SIZE];
     901                 :            :         uint16_t enq;
     902                 :            : 
     903                 :          0 :         if (opt->verbose_level > 1)
     904                 :            :                 printf("%s(): lcore %d vector adapter %p\n", __func__, rte_lcore_id(), adptr);
     905                 :            : 
     906                 :          0 :         while (t->done == false) {
     907                 :          0 :                 enq = rte_event_vector_adapter_enqueue(adptr, objs, BURST_SIZE, 0);
     908                 :          0 :                 while (enq < BURST_SIZE) {
     909                 :          0 :                         enq += rte_event_vector_adapter_enqueue(adptr, objs + enq, BURST_SIZE - enq,
     910                 :            :                                                                 0);
     911                 :          0 :                         if (t->done)
     912                 :            :                                 break;
     913                 :            :                         rte_pause();
     914                 :            :                 }
     915                 :            :         }
     916                 :          0 :         return 0;
     917                 :            : }
     918                 :            : 
     919                 :            : static int
     920                 :          0 : perf_producer_wrapper(void *arg)
     921                 :            : {
     922                 :            :         struct rte_event_dev_info dev_info;
     923                 :            :         struct prod_data *p  = arg;
     924                 :          0 :         struct test_perf *t = p->t;
     925                 :            : 
     926                 :          0 :         rte_event_dev_info_get(p->dev_id, &dev_info);
     927                 :          0 :         if (!t->opt->prod_enq_burst_sz) {
     928                 :          0 :                 t->opt->prod_enq_burst_sz = MAX_PROD_ENQ_BURST_SIZE;
     929                 :          0 :                 if (dev_info.max_event_port_enqueue_depth > 0 &&
     930                 :            :                     (uint32_t)dev_info.max_event_port_enqueue_depth <
     931                 :            :                             t->opt->prod_enq_burst_sz)
     932                 :          0 :                         t->opt->prod_enq_burst_sz =
     933                 :            :                                 dev_info.max_event_port_enqueue_depth;
     934                 :            :         }
     935                 :            : 
     936                 :            :         /* In case of synthetic producer, launch perf_producer or
     937                 :            :          * perf_producer_burst depending on producer enqueue burst size
     938                 :            :          */
     939                 :          0 :         if (t->opt->prod_type == EVT_PROD_TYPE_SYNT &&
     940                 :          0 :                         t->opt->prod_enq_burst_sz == 1)
     941                 :          0 :                 return perf_producer(arg);
     942                 :          0 :         else if (t->opt->prod_type == EVT_PROD_TYPE_SYNT &&
     943                 :          0 :                         t->opt->prod_enq_burst_sz > 1) {
     944                 :          0 :                 if (dev_info.max_event_port_enqueue_depth == 1)
     945                 :          0 :                         evt_err("This event device does not support burst mode");
     946                 :            :                 else
     947                 :          0 :                         return perf_producer_burst(arg);
     948                 :            :         }
     949                 :          0 :         else if (t->opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR &&
     950                 :          0 :                         !t->opt->timdev_use_burst)
     951                 :          0 :                 return perf_event_timer_producer(arg);
     952                 :          0 :         else if (t->opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR &&
     953                 :          0 :                         t->opt->timdev_use_burst)
     954                 :          0 :                 return perf_event_timer_producer_burst(arg);
     955                 :          0 :         else if (t->opt->prod_type == EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR) {
     956                 :          0 :                 if (t->opt->prod_enq_burst_sz > 1)
     957                 :          0 :                         return perf_event_crypto_producer_burst(arg);
     958                 :            :                 else
     959                 :          0 :                         return perf_event_crypto_producer(arg);
     960                 :          0 :         } else if (t->opt->prod_type == EVT_PROD_TYPE_EVENT_DMA_ADPTR)
     961                 :          0 :                 return perf_event_dma_producer(arg);
     962                 :          0 :         else if (t->opt->prod_type == EVT_PROD_TYPE_EVENT_VECTOR_ADPTR)
     963                 :          0 :                 return perf_event_vector_producer(p);
     964                 :            : 
     965                 :            :         return 0;
     966                 :            : }
     967                 :            : 
     968                 :            : static inline uint64_t
     969                 :            : processed_pkts(struct test_perf *t)
     970                 :            : {
     971                 :            :         uint8_t i;
     972                 :            :         uint64_t total = 0;
     973                 :            : 
     974                 :          0 :         for (i = 0; i < t->nb_workers; i++)
     975                 :          0 :                 total += t->worker[i].processed_pkts;
     976                 :            : 
     977                 :            :         return total;
     978                 :            : }
     979                 :            : 
     980                 :            : static inline uint64_t
     981                 :            : processed_vecs(struct test_perf *t)
     982                 :            : {
     983                 :            :         uint8_t i;
     984                 :            :         uint64_t total = 0;
     985                 :            : 
     986                 :          0 :         for (i = 0; i < t->nb_workers; i++)
     987                 :          0 :                 total += t->worker[i].processed_vecs;
     988                 :            : 
     989                 :            :         return total;
     990                 :            : }
     991                 :            : 
     992                 :            : static inline uint64_t
     993                 :            : total_latency(struct test_perf *t)
     994                 :            : {
     995                 :            :         uint8_t i;
     996                 :            :         uint64_t total = 0;
     997                 :            : 
     998                 :          0 :         for (i = 0; i < t->nb_workers; i++)
     999                 :          0 :                 total += t->worker[i].latency;
    1000                 :            : 
    1001                 :            :         return total;
    1002                 :            : }
    1003                 :            : 
    1004                 :            : static void
    1005                 :          0 : check_work_status(struct test_perf *t, struct evt_options *opt)
    1006                 :            : {
    1007                 :          0 :         const uint64_t dead_lock_sample = rte_get_timer_hz() * 5;
    1008                 :          0 :         const uint64_t freq_mhz = rte_get_timer_hz() / 1000000;
    1009                 :            :         uint64_t dead_lock_cycles = rte_get_timer_cycles();
    1010                 :            :         const uint64_t perf_sample = rte_get_timer_hz();
    1011                 :            :         uint64_t perf_cycles = rte_get_timer_cycles();
    1012                 :          0 :         const uint64_t total_pkts = t->outstand_pkts;
    1013                 :          0 :         int64_t dead_lock_remaining = total_pkts;
    1014                 :            :         int64_t perf_remaining  = total_pkts;
    1015                 :            :         static uint64_t samples;
    1016                 :            :         static float total_mpps;
    1017                 :            :         int64_t remaining;
    1018                 :            :         uint8_t is_vec;
    1019                 :            : 
    1020                 :          0 :         is_vec = (t->opt->prod_type == EVT_PROD_TYPE_EVENT_VECTOR_ADPTR);
    1021                 :          0 :         remaining = t->outstand_pkts - (is_vec ? processed_vecs(t) : processed_pkts(t));
    1022                 :            : 
    1023                 :          0 :         while (t->done == false) {
    1024                 :            :                 const uint64_t new_cycles = rte_get_timer_cycles();
    1025                 :            : 
    1026                 :          0 :                 if ((new_cycles - perf_cycles) > perf_sample) {
    1027                 :            :                         const uint64_t latency = total_latency(t);
    1028                 :          0 :                         const uint64_t pkts = is_vec ? processed_vecs(t) : processed_pkts(t);
    1029                 :            :                         uint64_t fallback_pkts = processed_pkts(t);
    1030                 :            : 
    1031                 :          0 :                         remaining = t->outstand_pkts - pkts;
    1032                 :          0 :                         float mpps = (float)(perf_remaining - remaining) / 1E6;
    1033                 :            : 
    1034                 :            :                         perf_remaining = remaining;
    1035                 :            :                         perf_cycles = new_cycles;
    1036                 :          0 :                         total_mpps += mpps;
    1037                 :          0 :                         ++samples;
    1038                 :            : 
    1039                 :          0 :                         if (opt->fwd_latency && pkts > 0) {
    1040                 :          0 :                                 if (is_vec) {
    1041                 :          0 :                                         printf(CLGRN
    1042                 :            :                                                "\r%.3f mvps avg %.3f mvps [avg fwd latency %.3f us] "
    1043                 :            :                                                "fallback mpps %.3f" CLNRM,
    1044                 :          0 :                                                mpps, total_mpps / samples,
    1045                 :          0 :                                                (float)(latency / pkts) / freq_mhz,
    1046                 :            :                                                fallback_pkts / 1E6);
    1047                 :            :                                 } else {
    1048                 :          0 :                                         printf(CLGRN
    1049                 :            :                                                "\r%.3f mpps avg %.3f mpps [avg fwd latency %.3f us] "
    1050                 :            :                                                CLNRM,
    1051                 :          0 :                                                mpps, total_mpps / samples,
    1052                 :          0 :                                                (float)(latency / pkts) / freq_mhz);
    1053                 :            :                                 }
    1054                 :            :                         } else {
    1055                 :          0 :                                 if (is_vec) {
    1056                 :          0 :                                         printf(CLGRN
    1057                 :            :                                                "\r%.3f mvps avg %.3f mvps fallback mpps %.3f" CLNRM,
    1058                 :          0 :                                                mpps, total_mpps / samples, fallback_pkts / 1E6);
    1059                 :            :                                 } else {
    1060                 :          0 :                                         printf(CLGRN "\r%.3f mpps avg %.3f mpps" CLNRM, mpps,
    1061                 :          0 :                                                total_mpps / samples);
    1062                 :            :                                 }
    1063                 :            :                         }
    1064                 :          0 :                         fflush(stdout);
    1065                 :            : 
    1066                 :          0 :                         if (remaining <= 0) {
    1067                 :          0 :                                 t->result = EVT_TEST_SUCCESS;
    1068                 :          0 :                                 if (opt->prod_type != EVT_PROD_TYPE_ETH_RX_ADPTR) {
    1069                 :          0 :                                         t->done = true;
    1070                 :          0 :                                         break;
    1071                 :            :                                 }
    1072                 :            :                         }
    1073                 :            :                 }
    1074                 :          0 :                 if (new_cycles - dead_lock_cycles > dead_lock_sample &&
    1075                 :          0 :                     (opt->prod_type != EVT_PROD_TYPE_ETH_RX_ADPTR)) {
    1076                 :          0 :                         remaining =
    1077                 :          0 :                                 t->outstand_pkts - (is_vec ? processed_vecs(t) : processed_pkts(t));
    1078                 :          0 :                         if (dead_lock_remaining == remaining) {
    1079                 :          0 :                                 rte_event_dev_dump(opt->dev_id, stdout);
    1080                 :          0 :                                 evt_err("No schedules for seconds, deadlock");
    1081                 :          0 :                                 t->done = true;
    1082                 :          0 :                                 break;
    1083                 :            :                         }
    1084                 :            :                         dead_lock_remaining = remaining;
    1085                 :            :                         dead_lock_cycles = new_cycles;
    1086                 :            :                 }
    1087                 :            :         }
    1088                 :            :         printf("\n");
    1089                 :          0 : }
    1090                 :            : 
    1091                 :            : int
    1092                 :          0 : perf_launch_lcores(struct evt_test *test, struct evt_options *opt, int (*worker)(void *))
    1093                 :            : {
    1094                 :            :         int ret, lcore_id;
    1095                 :            :         struct test_perf *t = evt_test_priv(test);
    1096                 :            : 
    1097                 :            :         int port_idx = 0;
    1098                 :            :         /* launch workers */
    1099                 :          0 :         RTE_LCORE_FOREACH_WORKER(lcore_id)
    1100                 :            :         {
    1101                 :          0 :                 if (!(opt->wlcores[lcore_id]))
    1102                 :          0 :                         continue;
    1103                 :            : 
    1104                 :          0 :                 ret = rte_eal_remote_launch(worker, &t->worker[port_idx], lcore_id);
    1105                 :          0 :                 if (ret) {
    1106                 :          0 :                         evt_err("failed to launch worker %d", lcore_id);
    1107                 :          0 :                         return ret;
    1108                 :            :                 }
    1109                 :          0 :                 port_idx++;
    1110                 :            :         }
    1111                 :            : 
    1112                 :            :         /* launch producers */
    1113                 :          0 :         RTE_LCORE_FOREACH_WORKER(lcore_id)
    1114                 :            :         {
    1115                 :          0 :                 if (!(opt->plcores[lcore_id]))
    1116                 :          0 :                         continue;
    1117                 :            : 
    1118                 :          0 :                 ret = rte_eal_remote_launch(perf_producer_wrapper, &t->prod[port_idx], lcore_id);
    1119                 :          0 :                 if (ret) {
    1120                 :          0 :                         evt_err("failed to launch perf_producer %d", lcore_id);
    1121                 :          0 :                         return ret;
    1122                 :            :                 }
    1123                 :          0 :                 port_idx++;
    1124                 :            :         }
    1125                 :            : 
    1126                 :          0 :         check_work_status(t, opt);
    1127                 :            : 
    1128                 :          0 :         return 0;
    1129                 :            : }
    1130                 :            : 
    1131                 :            : static int
    1132                 :          0 : perf_event_rx_adapter_setup(struct evt_options *opt, uint8_t stride,
    1133                 :            :                 struct rte_event_port_conf prod_conf)
    1134                 :            : {
    1135                 :            :         int ret = 0;
    1136                 :            :         uint16_t prod;
    1137                 :            :         struct rte_event_eth_rx_adapter_queue_conf queue_conf;
    1138                 :            : 
    1139                 :            :         memset(&queue_conf, 0,
    1140                 :            :                         sizeof(struct rte_event_eth_rx_adapter_queue_conf));
    1141                 :          0 :         queue_conf.ev.sched_type = opt->sched_type_list[0];
    1142                 :          0 :         RTE_ETH_FOREACH_DEV(prod) {
    1143                 :            :                 uint32_t cap;
    1144                 :            : 
    1145                 :          0 :                 ret = rte_event_eth_rx_adapter_caps_get(opt->dev_id,
    1146                 :            :                                 prod, &cap);
    1147                 :          0 :                 if (ret) {
    1148                 :          0 :                         evt_err("failed to get event rx adapter[%d]"
    1149                 :            :                                         " capabilities",
    1150                 :            :                                         opt->dev_id);
    1151                 :          0 :                         return ret;
    1152                 :            :                 }
    1153                 :          0 :                 queue_conf.ev.queue_id = prod * stride;
    1154                 :          0 :                 ret = rte_event_eth_rx_adapter_create(prod, opt->dev_id,
    1155                 :            :                                 &prod_conf);
    1156                 :          0 :                 if (ret) {
    1157                 :          0 :                         evt_err("failed to create rx adapter[%d]", prod);
    1158                 :          0 :                         return ret;
    1159                 :            :                 }
    1160                 :          0 :                 ret = rte_event_eth_rx_adapter_queue_add(prod, prod, -1,
    1161                 :            :                                 &queue_conf);
    1162                 :          0 :                 if (ret) {
    1163                 :          0 :                         evt_err("failed to add rx queues to adapter[%d]", prod);
    1164                 :          0 :                         return ret;
    1165                 :            :                 }
    1166                 :            : 
    1167                 :          0 :                 if (!(cap & RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT)) {
    1168                 :            :                         uint32_t service_id;
    1169                 :            : 
    1170                 :          0 :                         rte_event_eth_rx_adapter_service_id_get(prod,
    1171                 :            :                                         &service_id);
    1172                 :          0 :                         ret = evt_service_setup(service_id);
    1173                 :          0 :                         if (ret) {
    1174                 :          0 :                                 evt_err("Failed to setup service core"
    1175                 :            :                                                 " for Rx adapter\n");
    1176                 :          0 :                                 return ret;
    1177                 :            :                         }
    1178                 :            :                 }
    1179                 :            :         }
    1180                 :            : 
    1181                 :            :         return ret;
    1182                 :            : }
    1183                 :            : 
    1184                 :            : static int
    1185                 :          0 : perf_event_timer_adapter_setup(struct test_perf *t)
    1186                 :            : {
    1187                 :            :         int i;
    1188                 :            :         int ret;
    1189                 :            :         struct rte_event_timer_adapter_info adapter_info;
    1190                 :            :         struct rte_event_timer_adapter *wl;
    1191                 :          0 :         uint8_t nb_producers = evt_nr_active_lcores(t->opt->plcores);
    1192                 :            :         uint8_t flags = RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES;
    1193                 :            : 
    1194                 :          0 :         if (nb_producers == 1)
    1195                 :            :                 flags |= RTE_EVENT_TIMER_ADAPTER_F_SP_PUT;
    1196                 :            : 
    1197                 :          0 :         for (i = 0; i < t->opt->nb_timer_adptrs; i++) {
    1198                 :          0 :                 struct rte_event_timer_adapter_conf config = {
    1199                 :          0 :                         .event_dev_id = t->opt->dev_id,
    1200                 :            :                         .timer_adapter_id = i,
    1201                 :          0 :                         .timer_tick_ns = t->opt->timer_tick_nsec,
    1202                 :          0 :                         .max_tmo_ns = t->opt->max_tmo_nsec,
    1203                 :          0 :                         .nb_timers = t->opt->pool_sz,
    1204                 :            :                         .flags = flags,
    1205                 :            :                 };
    1206                 :            : 
    1207                 :          0 :                 wl = rte_event_timer_adapter_create(&config);
    1208                 :          0 :                 if (wl == NULL) {
    1209                 :          0 :                         evt_err("failed to create event timer ring %d", i);
    1210                 :          0 :                         return rte_errno;
    1211                 :            :                 }
    1212                 :            : 
    1213                 :            :                 memset(&adapter_info, 0,
    1214                 :            :                                 sizeof(struct rte_event_timer_adapter_info));
    1215                 :          0 :                 rte_event_timer_adapter_get_info(wl, &adapter_info);
    1216                 :          0 :                 t->opt->optm_timer_tick_nsec = adapter_info.min_resolution_ns;
    1217                 :            : 
    1218                 :          0 :                 if (!(adapter_info.caps &
    1219                 :            :                                 RTE_EVENT_TIMER_ADAPTER_CAP_INTERNAL_PORT)) {
    1220                 :          0 :                         uint32_t service_id = -1U;
    1221                 :            : 
    1222                 :          0 :                         rte_event_timer_adapter_service_id_get(wl,
    1223                 :            :                                         &service_id);
    1224                 :          0 :                         ret = evt_service_setup(service_id);
    1225                 :          0 :                         if (ret) {
    1226                 :          0 :                                 evt_err("Failed to setup service core"
    1227                 :            :                                                 " for timer adapter\n");
    1228                 :          0 :                                 return ret;
    1229                 :            :                         }
    1230                 :          0 :                         rte_service_runstate_set(service_id, 1);
    1231                 :            :                 }
    1232                 :          0 :                 t->timer_adptr[i] = wl;
    1233                 :            :         }
    1234                 :            :         return 0;
    1235                 :            : }
    1236                 :            : 
    1237                 :            : static int
    1238                 :          0 : perf_event_crypto_adapter_setup(struct test_perf *t, struct prod_data *p)
    1239                 :            : {
    1240                 :            :         struct rte_event_crypto_adapter_queue_conf conf;
    1241                 :          0 :         struct evt_options *opt = t->opt;
    1242                 :            :         uint32_t cap;
    1243                 :            :         int ret;
    1244                 :            : 
    1245                 :            :         memset(&conf, 0, sizeof(conf));
    1246                 :            : 
    1247                 :          0 :         ret = rte_event_crypto_adapter_caps_get(p->dev_id, p->ca.cdev_id, &cap);
    1248                 :          0 :         if (ret) {
    1249                 :          0 :                 evt_err("Failed to get crypto adapter capabilities");
    1250                 :          0 :                 return ret;
    1251                 :            :         }
    1252                 :            : 
    1253                 :          0 :         if (((opt->crypto_adptr_mode == RTE_EVENT_CRYPTO_ADAPTER_OP_NEW) &&
    1254                 :          0 :              !(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW)) ||
    1255                 :          0 :             ((opt->crypto_adptr_mode == RTE_EVENT_CRYPTO_ADAPTER_OP_FORWARD) &&
    1256                 :          0 :              !(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD))) {
    1257                 :          0 :                 evt_err("crypto adapter %s mode unsupported\n",
    1258                 :            :                         opt->crypto_adptr_mode ? "OP_FORWARD" : "OP_NEW");
    1259                 :          0 :                 return -ENOTSUP;
    1260                 :          0 :         } else if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_SESSION_PRIVATE_DATA)) {
    1261                 :          0 :                 evt_err("Storing crypto session not supported");
    1262                 :          0 :                 return -ENOTSUP;
    1263                 :            :         }
    1264                 :            : 
    1265                 :          0 :         if (opt->ena_vector) {
    1266                 :            :                 struct rte_event_crypto_adapter_vector_limits limits;
    1267                 :            : 
    1268                 :          0 :                 if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_EVENT_VECTOR)) {
    1269                 :          0 :                         evt_err("Crypto adapter doesn't support event vector");
    1270                 :          0 :                         return -EINVAL;
    1271                 :            :                 }
    1272                 :            : 
    1273                 :          0 :                 ret = rte_event_crypto_adapter_vector_limits_get(p->dev_id, p->ca.cdev_id, &limits);
    1274                 :          0 :                 if (ret) {
    1275                 :          0 :                         evt_err("Failed to get crypto adapter's vector limits");
    1276                 :          0 :                         return ret;
    1277                 :            :                 }
    1278                 :            : 
    1279                 :          0 :                 if (opt->vector_size < limits.min_sz || opt->vector_size > limits.max_sz) {
    1280                 :          0 :                         evt_err("Vector size [%d] not within limits max[%d] min[%d]",
    1281                 :            :                                 opt->vector_size, limits.max_sz, limits.min_sz);
    1282                 :          0 :                         return -EINVAL;
    1283                 :            :                 }
    1284                 :            : 
    1285                 :          0 :                 if (limits.log2_sz && !rte_is_power_of_2(opt->vector_size)) {
    1286                 :          0 :                         evt_err("Vector size [%d] not power of 2", opt->vector_size);
    1287                 :          0 :                         return -EINVAL;
    1288                 :            :                 }
    1289                 :            : 
    1290                 :          0 :                 if (opt->vector_tmo_nsec > limits.max_timeout_ns ||
    1291                 :          0 :                         opt->vector_tmo_nsec < limits.min_timeout_ns) {
    1292                 :          0 :                         evt_err("Vector timeout [%" PRIu64 "] not within limits "
    1293                 :            :                                 "max[%" PRIu64 "] min[%" PRIu64 "]",
    1294                 :            :                                 opt->vector_tmo_nsec, limits.max_timeout_ns, limits.min_timeout_ns);
    1295                 :          0 :                         return -EINVAL;
    1296                 :            :                 }
    1297                 :            : 
    1298                 :          0 :                 conf.vector_mp = t->ca_vector_pool;
    1299                 :          0 :                 conf.vector_sz = opt->vector_size;
    1300                 :          0 :                 conf.vector_timeout_ns = opt->vector_tmo_nsec;
    1301                 :          0 :                 conf.flags |= RTE_EVENT_CRYPTO_ADAPTER_EVENT_VECTOR;
    1302                 :            :         }
    1303                 :            : 
    1304                 :          0 :         if (cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_QP_EV_BIND) {
    1305                 :          0 :                 conf.ev.sched_type = RTE_SCHED_TYPE_ATOMIC;
    1306                 :          0 :                 conf.ev.queue_id = p->queue_id;
    1307                 :            :         }
    1308                 :            : 
    1309                 :          0 :         ret = rte_event_crypto_adapter_queue_pair_add(
    1310                 :          0 :                 TEST_PERF_CA_ID, p->ca.cdev_id, p->ca.cdev_qp_id, &conf);
    1311                 :            : 
    1312                 :          0 :         return ret;
    1313                 :            : }
    1314                 :            : 
    1315                 :            : static int
    1316                 :          0 : perf_event_dma_adapter_setup(struct test_perf *t, struct prod_data *p)
    1317                 :            : {
    1318                 :          0 :         struct evt_options *opt = t->opt;
    1319                 :            :         struct rte_event event;
    1320                 :            :         uint32_t cap;
    1321                 :            :         int ret;
    1322                 :            : 
    1323                 :          0 :         ret = rte_event_dma_adapter_caps_get(p->dev_id, p->da.dma_dev_id, &cap);
    1324                 :          0 :         if (ret) {
    1325                 :          0 :                 evt_err("Failed to get dma adapter capabilities");
    1326                 :          0 :                 return ret;
    1327                 :            :         }
    1328                 :            : 
    1329                 :          0 :         if (((opt->dma_adptr_mode == RTE_EVENT_DMA_ADAPTER_OP_NEW) &&
    1330                 :          0 :              !(cap & RTE_EVENT_DMA_ADAPTER_CAP_INTERNAL_PORT_OP_NEW)) ||
    1331                 :          0 :             ((opt->dma_adptr_mode == RTE_EVENT_DMA_ADAPTER_OP_FORWARD) &&
    1332                 :          0 :              !(cap & RTE_EVENT_DMA_ADAPTER_CAP_INTERNAL_PORT_OP_FWD))) {
    1333                 :          0 :                 evt_err("dma adapter %s mode unsupported\n",
    1334                 :            :                         opt->dma_adptr_mode ? "OP_FORWARD" : "OP_NEW");
    1335                 :          0 :                 return -ENOTSUP;
    1336                 :            :         }
    1337                 :            : 
    1338                 :          0 :         if (cap & RTE_EVENT_DMA_ADAPTER_CAP_INTERNAL_PORT_VCHAN_EV_BIND)
    1339                 :          0 :                 ret = rte_event_dma_adapter_vchan_add(TEST_PERF_DA_ID, p->da.dma_dev_id,
    1340                 :          0 :                                                       p->da.vchan_id, &event);
    1341                 :            :         else
    1342                 :          0 :                 ret = rte_event_dma_adapter_vchan_add(TEST_PERF_DA_ID, p->da.dma_dev_id,
    1343                 :          0 :                                                       p->da.vchan_id, NULL);
    1344                 :            : 
    1345                 :            :         return ret;
    1346                 :            : }
    1347                 :            : 
    1348                 :            : static void *
    1349                 :          0 : cryptodev_sym_sess_create(struct prod_data *p, struct test_perf *t)
    1350                 :            : {
    1351                 :            :         const struct rte_cryptodev_symmetric_capability *cap;
    1352                 :            :         struct rte_cryptodev_sym_capability_idx cap_idx;
    1353                 :            :         enum rte_crypto_cipher_algorithm cipher_algo;
    1354                 :            :         struct rte_crypto_sym_xform cipher_xform;
    1355                 :          0 :         struct evt_options *opt = t->opt;
    1356                 :            :         uint16_t key_size;
    1357                 :            :         uint16_t iv_size;
    1358                 :            :         void *sess;
    1359                 :            : 
    1360                 :          0 :         cipher_algo = opt->crypto_cipher_alg;
    1361                 :          0 :         key_size = opt->crypto_cipher_key_sz;
    1362                 :          0 :         iv_size = opt->crypto_cipher_iv_sz;
    1363                 :            : 
    1364                 :            :         /* Check if device supports the algorithm */
    1365                 :          0 :         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
    1366                 :          0 :         cap_idx.algo.cipher = cipher_algo;
    1367                 :            : 
    1368                 :          0 :         cap = rte_cryptodev_sym_capability_get(p->ca.cdev_id, &cap_idx);
    1369                 :          0 :         if (cap == NULL) {
    1370                 :          0 :                 evt_err("Device doesn't support cipher algorithm [%s]. Test Skipped\n",
    1371                 :            :                         rte_cryptodev_get_cipher_algo_string(cipher_algo));
    1372                 :          0 :                 return NULL;
    1373                 :            :         }
    1374                 :            : 
    1375                 :            :         /* Check if device supports key size and IV size */
    1376                 :          0 :         if (rte_cryptodev_sym_capability_check_cipher(cap, key_size,
    1377                 :            :                         iv_size) < 0) {
    1378                 :          0 :                 evt_err("Device doesn't support cipher configuration:\n"
    1379                 :            :                         "cipher algo [%s], key sz [%d], iv sz [%d]. Test Skipped\n",
    1380                 :            :                         rte_cryptodev_get_cipher_algo_string(cipher_algo), key_size, iv_size);
    1381                 :          0 :                 return NULL;
    1382                 :            :         }
    1383                 :            : 
    1384                 :          0 :         cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
    1385                 :          0 :         cipher_xform.cipher.algo = cipher_algo;
    1386                 :          0 :         cipher_xform.cipher.key.data = opt->crypto_cipher_key;
    1387                 :          0 :         cipher_xform.cipher.key.length = key_size;
    1388                 :          0 :         cipher_xform.cipher.iv.length = iv_size;
    1389                 :          0 :         cipher_xform.cipher.iv.offset = IV_OFFSET;
    1390                 :          0 :         cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
    1391                 :          0 :         cipher_xform.next = NULL;
    1392                 :            : 
    1393                 :          0 :         sess = rte_cryptodev_sym_session_create(p->ca.cdev_id, &cipher_xform,
    1394                 :            :                         t->ca_sess_pool);
    1395                 :          0 :         if (sess == NULL) {
    1396                 :          0 :                 evt_err("Failed to create sym session");
    1397                 :          0 :                 return NULL;
    1398                 :            :         }
    1399                 :            : 
    1400                 :            :         return sess;
    1401                 :            : }
    1402                 :            : 
    1403                 :            : static void *
    1404                 :          0 : cryptodev_asym_sess_create(struct prod_data *p, struct test_perf *t)
    1405                 :            : {
    1406                 :            :         const struct rte_cryptodev_asymmetric_xform_capability *capability;
    1407                 :            :         struct rte_cryptodev_asym_capability_idx cap_idx;
    1408                 :            :         struct rte_crypto_asym_xform xform;
    1409                 :            :         void *sess;
    1410                 :            : 
    1411                 :          0 :         xform.next = NULL;
    1412                 :          0 :         xform.xform_type = RTE_CRYPTO_ASYM_XFORM_MODEX;
    1413                 :          0 :         cap_idx.type = xform.xform_type;
    1414                 :          0 :         capability = rte_cryptodev_asym_capability_get(p->ca.cdev_id, &cap_idx);
    1415                 :          0 :         if (capability == NULL) {
    1416                 :          0 :                 evt_err("Device doesn't support MODEX. Test Skipped\n");
    1417                 :          0 :                 return NULL;
    1418                 :            :         }
    1419                 :            : 
    1420                 :          0 :         xform.modex.modulus.data = modex_test_case.modulus.data;
    1421                 :          0 :         xform.modex.modulus.length = modex_test_case.modulus.len;
    1422                 :          0 :         xform.modex.exponent.data = modex_test_case.exponent.data;
    1423                 :          0 :         xform.modex.exponent.length = modex_test_case.exponent.len;
    1424                 :            : 
    1425                 :          0 :         if (rte_cryptodev_asym_session_create(p->ca.cdev_id, &xform,
    1426                 :            :                         t->ca_asym_sess_pool, &sess)) {
    1427                 :          0 :                 evt_err("Failed to create asym session");
    1428                 :          0 :                 return NULL;
    1429                 :            :         }
    1430                 :            : 
    1431                 :          0 :         return sess;
    1432                 :            : }
    1433                 :            : 
    1434                 :            : int
    1435                 :          0 : perf_event_dev_port_setup(struct evt_test *test, struct evt_options *opt,
    1436                 :            :                                 uint8_t stride, uint8_t nb_queues,
    1437                 :            :                                 const struct rte_event_port_conf *port_conf)
    1438                 :            : {
    1439                 :            :         struct test_perf *t = evt_test_priv(test);
    1440                 :            :         uint16_t port, prod;
    1441                 :            :         int ret = -1;
    1442                 :            : 
    1443                 :            :         /* setup one port per worker, linking to all queues */
    1444                 :          0 :         for (port = 0; port < evt_nr_active_lcores(opt->wlcores);
    1445                 :          0 :                                 port++) {
    1446                 :            :                 struct worker_data *w = &t->worker[port];
    1447                 :            : 
    1448                 :          0 :                 w->dev_id = opt->dev_id;
    1449                 :          0 :                 w->port_id = port;
    1450                 :          0 :                 w->t = t;
    1451                 :          0 :                 w->processed_pkts = 0;
    1452                 :          0 :                 w->latency = 0;
    1453                 :            : 
    1454                 :          0 :                 struct rte_event_port_conf conf = *port_conf;
    1455                 :          0 :                 conf.event_port_cfg |= RTE_EVENT_PORT_CFG_HINT_WORKER;
    1456                 :            : 
    1457                 :          0 :                 ret = rte_event_port_setup(opt->dev_id, port, &conf);
    1458                 :          0 :                 if (ret) {
    1459                 :          0 :                         evt_err("failed to setup port %d", port);
    1460                 :          0 :                         return ret;
    1461                 :            :                 }
    1462                 :            : 
    1463                 :          0 :                 ret = rte_event_port_link(opt->dev_id, port, NULL, NULL, 0);
    1464                 :          0 :                 if (ret != nb_queues) {
    1465                 :          0 :                         evt_err("failed to link all queues to port %d", port);
    1466                 :          0 :                         return -EINVAL;
    1467                 :            :                 }
    1468                 :            :         }
    1469                 :            : 
    1470                 :            :         /* port for producers, no links */
    1471                 :          0 :         if (opt->prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR) {
    1472                 :          0 :                 for ( ; port < perf_nb_event_ports(opt); port++) {
    1473                 :            :                         struct prod_data *p = &t->prod[port];
    1474                 :          0 :                         p->t = t;
    1475                 :            :                 }
    1476                 :            : 
    1477                 :          0 :                 struct rte_event_port_conf conf = *port_conf;
    1478                 :          0 :                 conf.event_port_cfg |= RTE_EVENT_PORT_CFG_HINT_PRODUCER;
    1479                 :            : 
    1480                 :          0 :                 ret = perf_event_rx_adapter_setup(opt, stride, conf);
    1481                 :          0 :                 if (ret)
    1482                 :          0 :                         return ret;
    1483                 :          0 :         } else if (opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) {
    1484                 :            :                 prod = 0;
    1485                 :          0 :                 for ( ; port < perf_nb_event_ports(opt); port++) {
    1486                 :            :                         struct prod_data *p = &t->prod[port];
    1487                 :          0 :                         p->queue_id = prod * stride;
    1488                 :          0 :                         p->t = t;
    1489                 :          0 :                         prod++;
    1490                 :            :                 }
    1491                 :            : 
    1492                 :          0 :                 ret = perf_event_timer_adapter_setup(t);
    1493                 :          0 :                 if (ret)
    1494                 :          0 :                         return ret;
    1495                 :          0 :         } else if (opt->prod_type == EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR) {
    1496                 :          0 :                 struct rte_event_port_conf conf = *port_conf;
    1497                 :            :                 uint8_t cdev_id = 0;
    1498                 :            :                 uint16_t qp_id = 0;
    1499                 :            : 
    1500                 :          0 :                 ret = rte_event_crypto_adapter_create(TEST_PERF_CA_ID,
    1501                 :          0 :                                                       opt->dev_id, &conf, 0);
    1502                 :          0 :                 if (ret) {
    1503                 :          0 :                         evt_err("Failed to create crypto adapter");
    1504                 :          0 :                         return ret;
    1505                 :            :                 }
    1506                 :            : 
    1507                 :            :                 prod = 0;
    1508                 :          0 :                 for (; port < perf_nb_event_ports(opt); port++) {
    1509                 :            :                         union rte_event_crypto_metadata m_data;
    1510                 :          0 :                         struct prod_data *p = &t->prod[port];
    1511                 :            :                         uint32_t flow_id;
    1512                 :            : 
    1513                 :          0 :                         if (qp_id == rte_cryptodev_queue_pair_count(cdev_id)) {
    1514                 :          0 :                                 cdev_id++;
    1515                 :            :                                 qp_id = 0;
    1516                 :            :                         }
    1517                 :            : 
    1518                 :          0 :                         p->dev_id = opt->dev_id;
    1519                 :          0 :                         p->port_id = port;
    1520                 :          0 :                         p->queue_id = prod * stride;
    1521                 :          0 :                         p->ca.cdev_id = cdev_id;
    1522                 :          0 :                         p->ca.cdev_qp_id = qp_id;
    1523                 :          0 :                         p->ca.crypto_sess = rte_zmalloc_socket(
    1524                 :          0 :                                 NULL, sizeof(void *) * t->nb_flows,
    1525                 :            :                                 RTE_CACHE_LINE_SIZE, opt->socket_id);
    1526                 :          0 :                         p->t = t;
    1527                 :            : 
    1528                 :          0 :                         ret = perf_event_crypto_adapter_setup(t, p);
    1529                 :          0 :                         if (ret)
    1530                 :          0 :                                 return ret;
    1531                 :            : 
    1532                 :          0 :                         m_data.request_info.cdev_id = p->ca.cdev_id;
    1533                 :          0 :                         m_data.request_info.queue_pair_id = p->ca.cdev_qp_id;
    1534                 :          0 :                         m_data.response_info.sched_type = RTE_SCHED_TYPE_ATOMIC;
    1535                 :          0 :                         m_data.response_info.queue_id = p->queue_id;
    1536                 :            : 
    1537                 :          0 :                         for (flow_id = 0; flow_id < t->nb_flows; flow_id++) {
    1538                 :          0 :                                 m_data.response_info.flow_id = flow_id;
    1539                 :          0 :                                 if (opt->crypto_op_type ==
    1540                 :            :                                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
    1541                 :            :                                         void *sess;
    1542                 :            : 
    1543                 :          0 :                                         sess = cryptodev_sym_sess_create(p, t);
    1544                 :          0 :                                         if (sess == NULL)
    1545                 :            :                                                 return -ENOMEM;
    1546                 :            : 
    1547                 :          0 :                                         ret = rte_cryptodev_session_event_mdata_set(
    1548                 :            :                                                 cdev_id,
    1549                 :            :                                                 sess,
    1550                 :            :                                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC,
    1551                 :            :                                                 RTE_CRYPTO_OP_WITH_SESSION,
    1552                 :            :                                                 &m_data, sizeof(m_data));
    1553                 :          0 :                                         if (ret)
    1554                 :          0 :                                                 return ret;
    1555                 :          0 :                                         p->ca.crypto_sess[flow_id] = sess;
    1556                 :            :                                 } else {
    1557                 :            :                                         void *sess;
    1558                 :            : 
    1559                 :          0 :                                         sess = cryptodev_asym_sess_create(p, t);
    1560                 :          0 :                                         if (sess == NULL)
    1561                 :            :                                                 return -ENOMEM;
    1562                 :          0 :                                         ret = rte_cryptodev_session_event_mdata_set(
    1563                 :            :                                                 cdev_id,
    1564                 :            :                                                 sess,
    1565                 :            :                                                 RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
    1566                 :            :                                                 RTE_CRYPTO_OP_WITH_SESSION,
    1567                 :            :                                                 &m_data, sizeof(m_data));
    1568                 :          0 :                                         if (ret)
    1569                 :          0 :                                                 return ret;
    1570                 :          0 :                                         p->ca.crypto_sess[flow_id] = sess;
    1571                 :            :                                 }
    1572                 :            :                         }
    1573                 :            : 
    1574                 :          0 :                         conf.event_port_cfg |=
    1575                 :            :                                 RTE_EVENT_PORT_CFG_HINT_PRODUCER |
    1576                 :            :                                 RTE_EVENT_PORT_CFG_HINT_CONSUMER;
    1577                 :            : 
    1578                 :          0 :                         ret = rte_event_port_setup(opt->dev_id, port, &conf);
    1579                 :          0 :                         if (ret) {
    1580                 :          0 :                                 evt_err("failed to setup port %d", port);
    1581                 :          0 :                                 return ret;
    1582                 :            :                         }
    1583                 :            : 
    1584                 :          0 :                         qp_id++;
    1585                 :          0 :                         prod++;
    1586                 :            :                 }
    1587                 :          0 :         }  else if (opt->prod_type == EVT_PROD_TYPE_EVENT_DMA_ADPTR) {
    1588                 :          0 :                 struct rte_event_port_conf conf = *port_conf;
    1589                 :            :                 uint8_t dma_dev_id = 0;
    1590                 :            :                 uint16_t vchan_id = 0;
    1591                 :            : 
    1592                 :          0 :                 ret = rte_event_dma_adapter_create(TEST_PERF_DA_ID, opt->dev_id, &conf, 0);
    1593                 :          0 :                 if (ret) {
    1594                 :          0 :                         evt_err("Failed to create dma adapter");
    1595                 :          0 :                         return ret;
    1596                 :            :                 }
    1597                 :            : 
    1598                 :            :                 prod = 0;
    1599                 :          0 :                 for (; port < perf_nb_event_ports(opt); port++) {
    1600                 :          0 :                         struct prod_data *p = &t->prod[port];
    1601                 :            : 
    1602                 :          0 :                         p->dev_id = opt->dev_id;
    1603                 :          0 :                         p->port_id = port;
    1604                 :          0 :                         p->queue_id = prod * stride;
    1605                 :          0 :                         p->da.dma_dev_id = dma_dev_id;
    1606                 :          0 :                         p->da.vchan_id = vchan_id;
    1607                 :          0 :                         p->t = t;
    1608                 :            : 
    1609                 :          0 :                         ret = perf_event_dma_adapter_setup(t, p);
    1610                 :          0 :                         if (ret)
    1611                 :          0 :                                 return ret;
    1612                 :            : 
    1613                 :          0 :                         conf.event_port_cfg |=
    1614                 :            :                                 RTE_EVENT_PORT_CFG_HINT_PRODUCER |
    1615                 :            :                                 RTE_EVENT_PORT_CFG_HINT_CONSUMER;
    1616                 :            : 
    1617                 :          0 :                         ret = rte_event_port_setup(opt->dev_id, port, &conf);
    1618                 :          0 :                         if (ret) {
    1619                 :          0 :                                 evt_err("failed to setup port %d", port);
    1620                 :          0 :                                 return ret;
    1621                 :            :                         }
    1622                 :            : 
    1623                 :          0 :                         prod++;
    1624                 :            :                 }
    1625                 :          0 :         } else if (opt->prod_type == EVT_PROD_TYPE_EVENT_VECTOR_ADPTR) {
    1626                 :            :                 struct rte_event_vector_adapter_conf conf;
    1627                 :            :                 struct rte_event_vector_adapter_info info;
    1628                 :            : 
    1629                 :          0 :                 ret = rte_event_vector_adapter_info_get(opt->dev_id, &info);
    1630                 :            : 
    1631                 :          0 :                 if (opt->vector_size < info.min_vector_sz ||
    1632                 :          0 :                     opt->vector_size > info.max_vector_sz) {
    1633                 :          0 :                         evt_err("Vector size [%d] not within limits max[%d] min[%d]",
    1634                 :            :                                 opt->vector_size, info.max_vector_sz, info.min_vector_sz);
    1635                 :          0 :                         return -EINVAL;
    1636                 :            :                 }
    1637                 :            : 
    1638                 :          0 :                 if (opt->vector_tmo_nsec > info.max_vector_timeout_ns ||
    1639                 :          0 :                     opt->vector_tmo_nsec < info.min_vector_timeout_ns) {
    1640                 :          0 :                         evt_err("Vector timeout [%" PRIu64 "] not within limits "
    1641                 :            :                                 "max[%" PRIu64 "] min[%" PRIu64 "]",
    1642                 :            :                                 opt->vector_tmo_nsec, info.max_vector_timeout_ns,
    1643                 :            :                                 info.min_vector_timeout_ns);
    1644                 :          0 :                         return -EINVAL;
    1645                 :            :                 }
    1646                 :            : 
    1647                 :            :                 memset(&conf, 0, sizeof(struct rte_event_vector_adapter_conf));
    1648                 :          0 :                 conf.event_dev_id = opt->dev_id;
    1649                 :          0 :                 conf.vector_sz = opt->vector_size;
    1650                 :          0 :                 conf.vector_timeout_ns = opt->vector_tmo_nsec;
    1651                 :          0 :                 conf.socket_id = opt->socket_id;
    1652                 :          0 :                 conf.vector_mp = t->pool;
    1653                 :            : 
    1654                 :          0 :                 conf.ev.sched_type = opt->sched_type_list[0];
    1655                 :          0 :                 conf.ev.event_type = RTE_EVENT_TYPE_VECTOR | RTE_EVENT_TYPE_CPU;
    1656                 :            : 
    1657                 :          0 :                 conf.ev_fallback.event_type = RTE_EVENT_TYPE_CPU;
    1658                 :            : 
    1659                 :            :                 prod = 0;
    1660                 :          0 :                 for (; port < perf_nb_event_ports(opt); port++) {
    1661                 :            :                         struct rte_event_vector_adapter *vector_adptr;
    1662                 :            :                         struct prod_data *p = &t->prod[port];
    1663                 :            :                         uint32_t service_id;
    1664                 :            : 
    1665                 :          0 :                         p->queue_id = prod * stride;
    1666                 :          0 :                         p->t = t;
    1667                 :            : 
    1668                 :          0 :                         conf.ev.queue_id = p->queue_id;
    1669                 :            : 
    1670                 :          0 :                         vector_adptr = rte_event_vector_adapter_create(&conf);
    1671                 :          0 :                         if (vector_adptr == NULL) {
    1672                 :          0 :                                 evt_err("Failed to create vector adapter for port %d", port);
    1673                 :          0 :                                 return -ENOMEM;
    1674                 :            :                         }
    1675                 :          0 :                         p->va.vector_adptr = vector_adptr;
    1676                 :          0 :                         prod++;
    1677                 :            : 
    1678                 :          0 :                         if (rte_event_vector_adapter_service_id_get(vector_adptr, &service_id) ==
    1679                 :            :                             0) {
    1680                 :          0 :                                 ret = evt_service_setup(service_id);
    1681                 :          0 :                                 if (ret) {
    1682                 :          0 :                                         evt_err("Failed to setup service core"
    1683                 :            :                                                 " for vector adapter\n");
    1684                 :          0 :                                         return ret;
    1685                 :            :                                 }
    1686                 :          0 :                                 rte_service_runstate_set(service_id, 1);
    1687                 :            :                         }
    1688                 :            :                 }
    1689                 :            :         } else {
    1690                 :            :                 prod = 0;
    1691                 :          0 :                 for ( ; port < perf_nb_event_ports(opt); port++) {
    1692                 :            :                         struct prod_data *p = &t->prod[port];
    1693                 :            : 
    1694                 :          0 :                         p->dev_id = opt->dev_id;
    1695                 :          0 :                         p->port_id = port;
    1696                 :          0 :                         p->queue_id = prod * stride;
    1697                 :          0 :                         p->t = t;
    1698                 :            : 
    1699                 :          0 :                         struct rte_event_port_conf conf = *port_conf;
    1700                 :          0 :                         conf.event_port_cfg |=
    1701                 :            :                                 RTE_EVENT_PORT_CFG_HINT_PRODUCER |
    1702                 :            :                                 RTE_EVENT_PORT_CFG_HINT_CONSUMER;
    1703                 :            : 
    1704                 :          0 :                         ret = rte_event_port_setup(opt->dev_id, port, &conf);
    1705                 :          0 :                         if (ret) {
    1706                 :          0 :                                 evt_err("failed to setup port %d", port);
    1707                 :          0 :                                 return ret;
    1708                 :            :                         }
    1709                 :          0 :                         prod++;
    1710                 :            :                 }
    1711                 :            :         }
    1712                 :            : 
    1713                 :            :         return ret;
    1714                 :            : }
    1715                 :            : 
    1716                 :            : int
    1717                 :          0 : perf_opt_check(struct evt_options *opt, uint64_t nb_queues)
    1718                 :            : {
    1719                 :            :         unsigned int lcores;
    1720                 :            : 
    1721                 :            :         /* N producer + N worker + main when producer cores are used
    1722                 :            :          * Else N worker + main when Rx adapter is used
    1723                 :            :          */
    1724                 :          0 :         lcores = opt->prod_type == EVT_PROD_TYPE_SYNT ? 3 : 2;
    1725                 :            : 
    1726                 :          0 :         if (rte_lcore_count() < lcores) {
    1727                 :          0 :                 evt_err("test need minimum %d lcores", lcores);
    1728                 :          0 :                 return -1;
    1729                 :            :         }
    1730                 :            : 
    1731                 :            :         /* Validate worker lcores */
    1732                 :          0 :         if (evt_lcores_has_overlap(opt->wlcores, rte_get_main_lcore())) {
    1733                 :          0 :                 evt_err("worker lcores overlaps with main lcore");
    1734                 :          0 :                 return -1;
    1735                 :            :         }
    1736                 :          0 :         if (evt_lcores_has_overlap_multi(opt->wlcores, opt->plcores)) {
    1737                 :          0 :                 evt_err("worker lcores overlaps producer lcores");
    1738                 :          0 :                 return -1;
    1739                 :            :         }
    1740                 :          0 :         if (evt_has_disabled_lcore(opt->wlcores)) {
    1741                 :          0 :                 evt_err("one or more workers lcores are not enabled");
    1742                 :          0 :                 return -1;
    1743                 :            :         }
    1744                 :          0 :         if (!evt_has_active_lcore(opt->wlcores)) {
    1745                 :          0 :                 evt_err("minimum one worker is required");
    1746                 :          0 :                 return -1;
    1747                 :            :         }
    1748                 :            : 
    1749                 :          0 :         if (opt->prod_type == EVT_PROD_TYPE_SYNT ||
    1750                 :          0 :             opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR ||
    1751                 :          0 :             opt->prod_type == EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR ||
    1752                 :            :             opt->prod_type == EVT_PROD_TYPE_EVENT_DMA_ADPTR) {
    1753                 :            :                 /* Validate producer lcores */
    1754                 :          0 :                 if (evt_lcores_has_overlap(opt->plcores,
    1755                 :          0 :                                         rte_get_main_lcore())) {
    1756                 :          0 :                         evt_err("producer lcores overlaps with main lcore");
    1757                 :          0 :                         return -1;
    1758                 :            :                 }
    1759                 :          0 :                 if (evt_has_disabled_lcore(opt->plcores)) {
    1760                 :          0 :                         evt_err("one or more producer lcores are not enabled");
    1761                 :          0 :                         return -1;
    1762                 :            :                 }
    1763                 :          0 :                 if (!evt_has_active_lcore(opt->plcores)) {
    1764                 :          0 :                         evt_err("minimum one producer is required");
    1765                 :          0 :                         return -1;
    1766                 :            :                 }
    1767                 :            :         }
    1768                 :            : 
    1769                 :          0 :         if (evt_has_invalid_stage(opt))
    1770                 :            :                 return -1;
    1771                 :            : 
    1772                 :          0 :         if (evt_has_invalid_sched_type(opt))
    1773                 :            :                 return -1;
    1774                 :            : 
    1775                 :          0 :         if (nb_queues > EVT_MAX_QUEUES) {
    1776                 :          0 :                 evt_err("number of queues exceeds %d", EVT_MAX_QUEUES);
    1777                 :          0 :                 return -1;
    1778                 :            :         }
    1779                 :          0 :         if (perf_nb_event_ports(opt) > EVT_MAX_PORTS) {
    1780                 :          0 :                 evt_err("number of ports exceeds %d", EVT_MAX_PORTS);
    1781                 :          0 :                 return -1;
    1782                 :            :         }
    1783                 :            : 
    1784                 :            :         /* Fixups */
    1785                 :          0 :         if ((opt->nb_stages == 1 &&
    1786                 :          0 :                         opt->prod_type != EVT_PROD_TYPE_EVENT_TIMER_ADPTR) &&
    1787                 :            :                         opt->fwd_latency) {
    1788                 :          0 :                 evt_info("fwd_latency is valid when nb_stages > 1, disabling");
    1789                 :          0 :                 opt->fwd_latency = 0;
    1790                 :            :         }
    1791                 :            : 
    1792                 :          0 :         if (opt->fwd_latency && !opt->q_priority) {
    1793                 :          0 :                 evt_info("enabled queue priority for latency measurement");
    1794                 :          0 :                 opt->q_priority = 1;
    1795                 :            :         }
    1796                 :          0 :         if (opt->nb_pkts == 0)
    1797                 :          0 :                 opt->nb_pkts = INT64_MAX/evt_nr_active_lcores(opt->plcores);
    1798                 :            : 
    1799                 :            :         return 0;
    1800                 :            : }
    1801                 :            : 
    1802                 :            : void
    1803                 :          0 : perf_opt_dump(struct evt_options *opt, uint8_t nb_queues)
    1804                 :            : {
    1805                 :          0 :         evt_dump("nb_prod_lcores", "%d", evt_nr_active_lcores(opt->plcores));
    1806                 :          0 :         evt_dump_producer_lcores(opt);
    1807                 :          0 :         evt_dump("nb_worker_lcores", "%d", evt_nr_active_lcores(opt->wlcores));
    1808                 :          0 :         evt_dump_worker_lcores(opt);
    1809                 :            :         evt_dump_nb_stages(opt);
    1810                 :            :         evt_dump("nb_evdev_ports", "%d", perf_nb_event_ports(opt));
    1811                 :          0 :         evt_dump("nb_evdev_queues", "%d", nb_queues);
    1812                 :          0 :         evt_dump_queue_priority(opt);
    1813                 :          0 :         evt_dump_sched_type_list(opt);
    1814                 :          0 :         evt_dump_producer_type(opt);
    1815                 :          0 :         evt_dump("prod_enq_burst_sz", "%d", opt->prod_enq_burst_sz);
    1816                 :          0 : }
    1817                 :            : 
    1818                 :            : static void
    1819                 :          0 : perf_event_port_flush(uint8_t dev_id __rte_unused, struct rte_event ev,
    1820                 :            :                       void *args)
    1821                 :            : {
    1822                 :          0 :         rte_mempool_put(args, ev.event_ptr);
    1823                 :          0 : }
    1824                 :            : 
    1825                 :            : void
    1826                 :          0 : perf_worker_cleanup(struct rte_mempool *const pool, uint8_t dev_id,
    1827                 :            :                     uint8_t port_id, struct rte_event events[], uint16_t nb_enq,
    1828                 :            :                     uint16_t nb_deq)
    1829                 :            : {
    1830                 :            :         int i;
    1831                 :            : 
    1832                 :          0 :         if (nb_deq) {
    1833                 :          0 :                 for (i = nb_enq; i < nb_deq; i++)
    1834                 :          0 :                         rte_mempool_put(pool, events[i].event_ptr);
    1835                 :            : 
    1836                 :          0 :                 for (i = nb_enq; i < nb_deq; i++)
    1837                 :          0 :                         events[i].op = RTE_EVENT_OP_RELEASE;
    1838                 :          0 :                 rte_event_enqueue_burst(dev_id, port_id, events + nb_enq, nb_deq - nb_enq);
    1839                 :            :         }
    1840                 :          0 :         rte_event_port_quiesce(dev_id, port_id, perf_event_port_flush, pool);
    1841                 :          0 : }
    1842                 :            : 
    1843                 :            : void
    1844                 :          0 : perf_eventdev_destroy(struct evt_test *test, struct evt_options *opt)
    1845                 :            : {
    1846                 :            :         int i;
    1847                 :            :         struct test_perf *t = evt_test_priv(test);
    1848                 :            : 
    1849                 :          0 :         if (opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) {
    1850                 :          0 :                 for (i = 0; i < opt->nb_timer_adptrs; i++)
    1851                 :          0 :                         rte_event_timer_adapter_stop(t->timer_adptr[i]);
    1852                 :            :         }
    1853                 :            : 
    1854                 :          0 :         if (opt->prod_type == EVT_PROD_TYPE_EVENT_VECTOR_ADPTR) {
    1855                 :          0 :                 for (i = 0; i < evt_nr_active_lcores(opt->plcores); i++) {
    1856                 :            :                         struct prod_data *p = &t->prod[i];
    1857                 :            :                         uint32_t service_id;
    1858                 :            : 
    1859                 :          0 :                         if (p->va.vector_adptr) {
    1860                 :          0 :                                 if (rte_event_vector_adapter_service_id_get(p->va.vector_adptr,
    1861                 :            :                                                                             &service_id) == 0)
    1862                 :          0 :                                         rte_service_runstate_set(service_id, 0);
    1863                 :          0 :                                 rte_event_vector_adapter_destroy(p->va.vector_adptr);
    1864                 :            :                         }
    1865                 :            :                 }
    1866                 :            :         }
    1867                 :          0 :         rte_event_dev_stop(opt->dev_id);
    1868                 :          0 :         rte_event_dev_close(opt->dev_id);
    1869                 :          0 : }
    1870                 :            : 
    1871                 :            : static inline void
    1872                 :          0 : perf_elt_init(struct rte_mempool *mp, void *arg __rte_unused,
    1873                 :            :             void *obj, unsigned i __rte_unused)
    1874                 :            : {
    1875                 :          0 :         memset(obj, 0, mp->elt_size);
    1876                 :          0 : }
    1877                 :            : 
    1878                 :            : #define NB_RX_DESC                      128
    1879                 :            : #define NB_TX_DESC                      512
    1880                 :            : int
    1881                 :          0 : perf_ethdev_setup(struct evt_test *test, struct evt_options *opt)
    1882                 :            : {
    1883                 :            :         uint16_t i;
    1884                 :            :         int ret;
    1885                 :            :         struct test_perf *t = evt_test_priv(test);
    1886                 :          0 :         struct rte_eth_conf port_conf = {
    1887                 :            :                 .rxmode = {
    1888                 :            :                         .mq_mode = RTE_ETH_MQ_RX_RSS,
    1889                 :            :                 },
    1890                 :            :                 .rx_adv_conf = {
    1891                 :            :                         .rss_conf = {
    1892                 :            :                                 .rss_key = NULL,
    1893                 :            :                                 .rss_hf = RTE_ETH_RSS_IP,
    1894                 :            :                         },
    1895                 :            :                 },
    1896                 :            :         };
    1897                 :            : 
    1898                 :          0 :         if (opt->prod_type != EVT_PROD_TYPE_ETH_RX_ADPTR)
    1899                 :            :                 return 0;
    1900                 :            : 
    1901                 :          0 :         if (!rte_eth_dev_count_avail()) {
    1902                 :          0 :                 evt_err("No ethernet ports found.");
    1903                 :          0 :                 return -ENODEV;
    1904                 :            :         }
    1905                 :            : 
    1906                 :          0 :         RTE_ETH_FOREACH_DEV(i) {
    1907                 :            :                 struct rte_eth_dev_info dev_info;
    1908                 :          0 :                 struct rte_eth_conf local_port_conf = port_conf;
    1909                 :            : 
    1910                 :          0 :                 ret = rte_eth_dev_info_get(i, &dev_info);
    1911                 :          0 :                 if (ret != 0) {
    1912                 :          0 :                         evt_err("Error during getting device (port %u) info: %s\n",
    1913                 :            :                                         i, strerror(-ret));
    1914                 :          0 :                         return ret;
    1915                 :            :                 }
    1916                 :            : 
    1917                 :          0 :                 local_port_conf.rx_adv_conf.rss_conf.rss_hf &=
    1918                 :          0 :                         dev_info.flow_type_rss_offloads;
    1919                 :          0 :                 if (local_port_conf.rx_adv_conf.rss_conf.rss_hf !=
    1920                 :            :                                 port_conf.rx_adv_conf.rss_conf.rss_hf) {
    1921                 :          0 :                         evt_info("Port %u modified RSS hash function based on hardware support,"
    1922                 :            :                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
    1923                 :            :                                 i,
    1924                 :            :                                 port_conf.rx_adv_conf.rss_conf.rss_hf,
    1925                 :            :                                 local_port_conf.rx_adv_conf.rss_conf.rss_hf);
    1926                 :            :                 }
    1927                 :            : 
    1928                 :          0 :                 if (rte_eth_dev_configure(i, 1, 1, &local_port_conf) < 0) {
    1929                 :          0 :                         evt_err("Failed to configure eth port [%d]", i);
    1930                 :          0 :                         return -EINVAL;
    1931                 :            :                 }
    1932                 :            : 
    1933                 :          0 :                 if (rte_eth_rx_queue_setup(i, 0, NB_RX_DESC,
    1934                 :            :                                 rte_socket_id(), NULL, t->pool) < 0) {
    1935                 :          0 :                         evt_err("Failed to setup eth port [%d] rx_queue: %d.",
    1936                 :            :                                         i, 0);
    1937                 :          0 :                         return -EINVAL;
    1938                 :            :                 }
    1939                 :            : 
    1940                 :          0 :                 if (rte_eth_tx_queue_setup(i, 0, NB_TX_DESC,
    1941                 :            :                                         rte_socket_id(), NULL) < 0) {
    1942                 :          0 :                         evt_err("Failed to setup eth port [%d] tx_queue: %d.",
    1943                 :            :                                         i, 0);
    1944                 :          0 :                         return -EINVAL;
    1945                 :            :                 }
    1946                 :            : 
    1947                 :          0 :                 ret = rte_eth_promiscuous_enable(i);
    1948                 :          0 :                 if (ret != 0) {
    1949                 :          0 :                         evt_err("Failed to enable promiscuous mode for eth port [%d]: %s",
    1950                 :            :                                 i, rte_strerror(-ret));
    1951                 :          0 :                         return ret;
    1952                 :            :                 }
    1953                 :            :         }
    1954                 :            : 
    1955                 :            :         return 0;
    1956                 :            : }
    1957                 :            : 
    1958                 :            : void
    1959                 :          0 : perf_ethdev_rx_stop(struct evt_test *test, struct evt_options *opt)
    1960                 :            : {
    1961                 :            :         uint16_t i;
    1962                 :            :         RTE_SET_USED(test);
    1963                 :            : 
    1964                 :          0 :         if (opt->prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR) {
    1965                 :          0 :                 RTE_ETH_FOREACH_DEV(i) {
    1966                 :          0 :                         rte_event_eth_rx_adapter_stop(i);
    1967                 :          0 :                         rte_event_eth_rx_adapter_queue_del(i, i, -1);
    1968                 :          0 :                         rte_eth_dev_rx_queue_stop(i, 0);
    1969                 :            :                 }
    1970                 :            :         }
    1971                 :          0 : }
    1972                 :            : 
    1973                 :            : void
    1974                 :          0 : perf_ethdev_destroy(struct evt_test *test, struct evt_options *opt)
    1975                 :            : {
    1976                 :            :         uint16_t i;
    1977                 :            :         RTE_SET_USED(test);
    1978                 :            : 
    1979                 :          0 :         if (opt->prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR) {
    1980                 :          0 :                 RTE_ETH_FOREACH_DEV(i) {
    1981                 :          0 :                         rte_event_eth_tx_adapter_stop(i);
    1982                 :          0 :                         rte_event_eth_tx_adapter_queue_del(i, i, -1);
    1983                 :          0 :                         rte_eth_dev_tx_queue_stop(i, 0);
    1984                 :          0 :                         rte_eth_dev_stop(i);
    1985                 :            :                 }
    1986                 :            :         }
    1987                 :          0 : }
    1988                 :            : 
    1989                 :            : int
    1990                 :          0 : perf_cryptodev_setup(struct evt_test *test, struct evt_options *opt)
    1991                 :            : {
    1992                 :            :         uint8_t cdev_count, cdev_id, nb_plcores, nb_qps;
    1993                 :            :         struct test_perf *t = evt_test_priv(test);
    1994                 :            :         unsigned int max_session_size;
    1995                 :            :         uint32_t nb_sessions;
    1996                 :            :         int ret;
    1997                 :            : 
    1998                 :          0 :         if (opt->prod_type != EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR)
    1999                 :            :                 return 0;
    2000                 :            : 
    2001                 :          0 :         cdev_count = rte_cryptodev_count();
    2002                 :          0 :         if (cdev_count == 0) {
    2003                 :          0 :                 evt_err("No crypto devices available\n");
    2004                 :          0 :                 return -ENODEV;
    2005                 :            :         }
    2006                 :            : 
    2007                 :          0 :         t->ca_op_pool = rte_crypto_op_pool_create(
    2008                 :          0 :                 "crypto_op_pool", opt->crypto_op_type, opt->pool_sz,
    2009                 :            :                 128, sizeof(union rte_event_crypto_metadata) + EVT_CRYPTO_MAX_IV_SIZE,
    2010                 :          0 :                 rte_socket_id());
    2011                 :          0 :         if (t->ca_op_pool == NULL) {
    2012                 :          0 :                 evt_err("Failed to create crypto op pool");
    2013                 :          0 :                 return -ENOMEM;
    2014                 :            :         }
    2015                 :            : 
    2016                 :          0 :         nb_sessions = evt_nr_active_lcores(opt->plcores) * t->nb_flows;
    2017                 :          0 :         t->ca_asym_sess_pool = rte_cryptodev_asym_session_pool_create(
    2018                 :            :                 "ca_asym_sess_pool", nb_sessions, 0,
    2019                 :            :                 sizeof(union rte_event_crypto_metadata), SOCKET_ID_ANY);
    2020                 :          0 :         if (t->ca_asym_sess_pool == NULL) {
    2021                 :          0 :                 evt_err("Failed to create sym session pool");
    2022                 :            :                 ret = -ENOMEM;
    2023                 :          0 :                 goto err;
    2024                 :            :         }
    2025                 :            : 
    2026                 :            :         max_session_size = 0;
    2027                 :          0 :         for (cdev_id = 0; cdev_id < cdev_count; cdev_id++) {
    2028                 :            :                 unsigned int session_size;
    2029                 :            : 
    2030                 :            :                 session_size =
    2031                 :          0 :                         rte_cryptodev_sym_get_private_session_size(cdev_id);
    2032                 :            :                 if (session_size > max_session_size)
    2033                 :            :                         max_session_size = session_size;
    2034                 :            :         }
    2035                 :            : 
    2036                 :          0 :         t->ca_sess_pool = rte_cryptodev_sym_session_pool_create(
    2037                 :            :                 "ca_sess_pool", nb_sessions, max_session_size, 0,
    2038                 :            :                 sizeof(union rte_event_crypto_metadata), SOCKET_ID_ANY);
    2039                 :          0 :         if (t->ca_sess_pool == NULL) {
    2040                 :          0 :                 evt_err("Failed to create sym session pool");
    2041                 :            :                 ret = -ENOMEM;
    2042                 :          0 :                 goto err;
    2043                 :            :         }
    2044                 :            : 
    2045                 :          0 :         if (opt->ena_vector) {
    2046                 :          0 :                 unsigned int nb_elem = (opt->pool_sz / opt->vector_size) * 2;
    2047                 :          0 :                 nb_elem = RTE_MAX(512U, nb_elem);
    2048                 :          0 :                 nb_elem += evt_nr_active_lcores(opt->wlcores) * 32;
    2049                 :          0 :                 t->ca_vector_pool = rte_event_vector_pool_create("vector_pool", nb_elem, 32,
    2050                 :            :                                 opt->vector_size, opt->socket_id);
    2051                 :          0 :                 if (t->ca_vector_pool == NULL) {
    2052                 :          0 :                         evt_err("Failed to create event vector pool");
    2053                 :            :                         ret = -ENOMEM;
    2054                 :          0 :                         goto err;
    2055                 :            :                 }
    2056                 :            :         }
    2057                 :            : 
    2058                 :            :         /*
    2059                 :            :          * Calculate number of needed queue pairs, based on the amount of
    2060                 :            :          * available number of logical cores and crypto devices. For instance,
    2061                 :            :          * if there are 4 cores and 2 crypto devices, 2 queue pairs will be set
    2062                 :            :          * up per device.
    2063                 :            :          */
    2064                 :          0 :         nb_plcores = evt_nr_active_lcores(opt->plcores);
    2065                 :          0 :         nb_qps = (nb_plcores % cdev_count) ? (nb_plcores / cdev_count) + 1 :
    2066                 :            :                                              nb_plcores / cdev_count;
    2067                 :          0 :         for (cdev_id = 0; cdev_id < cdev_count; cdev_id++) {
    2068                 :            :                 struct rte_cryptodev_qp_conf qp_conf;
    2069                 :            :                 struct rte_cryptodev_config conf;
    2070                 :            :                 struct rte_cryptodev_info info;
    2071                 :            :                 int qp_id;
    2072                 :            : 
    2073                 :          0 :                 rte_cryptodev_info_get(cdev_id, &info);
    2074                 :          0 :                 if (nb_qps > info.max_nb_queue_pairs) {
    2075                 :          0 :                         evt_err("Not enough queue pairs per cryptodev (%u)",
    2076                 :            :                                 nb_qps);
    2077                 :            :                         ret = -EINVAL;
    2078                 :          0 :                         goto err;
    2079                 :            :                 }
    2080                 :            : 
    2081                 :          0 :                 conf.nb_queue_pairs = nb_qps;
    2082                 :          0 :                 conf.socket_id = SOCKET_ID_ANY;
    2083                 :          0 :                 conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
    2084                 :            : 
    2085                 :          0 :                 ret = rte_cryptodev_configure(cdev_id, &conf);
    2086                 :          0 :                 if (ret) {
    2087                 :          0 :                         evt_err("Failed to configure cryptodev (%u)", cdev_id);
    2088                 :          0 :                         goto err;
    2089                 :            :                 }
    2090                 :            : 
    2091                 :          0 :                 qp_conf.nb_descriptors = NB_CRYPTODEV_DESCRIPTORS;
    2092                 :          0 :                 qp_conf.mp_session = t->ca_sess_pool;
    2093                 :            : 
    2094                 :          0 :                 for (qp_id = 0; qp_id < conf.nb_queue_pairs; qp_id++) {
    2095                 :          0 :                         ret = rte_cryptodev_queue_pair_setup(
    2096                 :            :                                 cdev_id, qp_id, &qp_conf,
    2097                 :            :                                 rte_cryptodev_socket_id(cdev_id));
    2098                 :          0 :                         if (ret) {
    2099                 :          0 :                                 evt_err("Failed to setup queue pairs on cryptodev %u\n",
    2100                 :            :                                         cdev_id);
    2101                 :          0 :                                 goto err;
    2102                 :            :                         }
    2103                 :            :                 }
    2104                 :            :         }
    2105                 :            : 
    2106                 :            :         return 0;
    2107                 :          0 : err:
    2108                 :          0 :         for (cdev_id = 0; cdev_id < cdev_count; cdev_id++)
    2109                 :          0 :                 rte_cryptodev_close(cdev_id);
    2110                 :            : 
    2111                 :          0 :         rte_mempool_free(t->ca_op_pool);
    2112                 :          0 :         rte_mempool_free(t->ca_sess_pool);
    2113                 :          0 :         rte_mempool_free(t->ca_asym_sess_pool);
    2114                 :          0 :         rte_mempool_free(t->ca_vector_pool);
    2115                 :            : 
    2116                 :          0 :         return ret;
    2117                 :            : }
    2118                 :            : 
    2119                 :            : void
    2120                 :          0 : perf_cryptodev_destroy(struct evt_test *test, struct evt_options *opt)
    2121                 :            : {
    2122                 :          0 :         uint8_t cdev_id, cdev_count = rte_cryptodev_count();
    2123                 :            :         struct test_perf *t = evt_test_priv(test);
    2124                 :            :         uint16_t port;
    2125                 :            : 
    2126                 :          0 :         if (opt->prod_type != EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR)
    2127                 :            :                 return;
    2128                 :            : 
    2129                 :          0 :         for (port = t->nb_workers; port < perf_nb_event_ports(opt); port++) {
    2130                 :            :                 void *sess;
    2131                 :            :                 struct prod_data *p = &t->prod[port];
    2132                 :            :                 uint32_t flow_id;
    2133                 :            :                 uint8_t cdev_id;
    2134                 :            : 
    2135                 :          0 :                 for (flow_id = 0; flow_id < t->nb_flows; flow_id++) {
    2136                 :          0 :                         sess = p->ca.crypto_sess[flow_id];
    2137                 :          0 :                         cdev_id = p->ca.cdev_id;
    2138                 :          0 :                         rte_cryptodev_sym_session_free(cdev_id, sess);
    2139                 :            :                 }
    2140                 :            : 
    2141                 :          0 :                 rte_event_crypto_adapter_queue_pair_del(
    2142                 :          0 :                         TEST_PERF_CA_ID, p->ca.cdev_id, p->ca.cdev_qp_id);
    2143                 :            :         }
    2144                 :            : 
    2145                 :          0 :         rte_event_crypto_adapter_free(TEST_PERF_CA_ID);
    2146                 :            : 
    2147                 :          0 :         for (cdev_id = 0; cdev_id < cdev_count; cdev_id++) {
    2148                 :          0 :                 rte_cryptodev_stop(cdev_id);
    2149                 :          0 :                 rte_cryptodev_close(cdev_id);
    2150                 :            :         }
    2151                 :            : 
    2152                 :          0 :         rte_mempool_free(t->ca_op_pool);
    2153                 :          0 :         rte_mempool_free(t->ca_sess_pool);
    2154                 :          0 :         rte_mempool_free(t->ca_asym_sess_pool);
    2155                 :          0 :         rte_mempool_free(t->ca_vector_pool);
    2156                 :            : }
    2157                 :            : 
    2158                 :            : int
    2159                 :          0 : perf_dmadev_setup(struct evt_test *test, struct evt_options *opt)
    2160                 :            : {
    2161                 :          0 :         const struct rte_dma_conf conf = { .nb_vchans = 1};
    2162                 :          0 :         const struct rte_dma_vchan_conf qconf = {
    2163                 :            :                         .direction = RTE_DMA_DIR_MEM_TO_MEM,
    2164                 :            :                         .nb_desc = 1024,
    2165                 :            :         };
    2166                 :            :         uint8_t dma_dev_count, dma_dev_id = 0;
    2167                 :            :         int vchan_id;
    2168                 :            :         int ret;
    2169                 :            : 
    2170                 :            :         RTE_SET_USED(test);
    2171                 :          0 :         if (opt->prod_type != EVT_PROD_TYPE_EVENT_DMA_ADPTR)
    2172                 :            :                 return 0;
    2173                 :            : 
    2174                 :          0 :         dma_dev_count = rte_dma_count_avail();
    2175                 :          0 :         if (dma_dev_count == 0) {
    2176                 :          0 :                 evt_err("No dma devices available\n");
    2177                 :          0 :                 return -ENODEV;
    2178                 :            :         }
    2179                 :            : 
    2180                 :          0 :         ret = rte_dma_configure(dma_dev_id, &conf);
    2181                 :          0 :         if (ret) {
    2182                 :          0 :                 evt_err("Failed to configure dma dev (%u)", dma_dev_id);
    2183                 :          0 :                 goto err;
    2184                 :            :         }
    2185                 :            : 
    2186                 :          0 :         for (vchan_id = 0; vchan_id < conf.nb_vchans; vchan_id++) {
    2187                 :          0 :                 ret = rte_dma_vchan_setup(dma_dev_id, vchan_id, &qconf);
    2188                 :          0 :                 if (ret) {
    2189                 :          0 :                         evt_err("Failed to setup vchan on dma dev %u\n",
    2190                 :            :                                 dma_dev_id);
    2191                 :          0 :                         goto err;
    2192                 :            :                 }
    2193                 :            :         }
    2194                 :            : 
    2195                 :            :         return 0;
    2196                 :          0 : err:
    2197                 :          0 :         rte_dma_close(dma_dev_id);
    2198                 :            : 
    2199                 :          0 :         return ret;
    2200                 :            : }
    2201                 :            : 
    2202                 :            : void
    2203                 :          0 : perf_dmadev_destroy(struct evt_test *test, struct evt_options *opt)
    2204                 :            : {
    2205                 :            :         uint8_t dma_dev_id = 0;
    2206                 :            :         struct test_perf *t = evt_test_priv(test);
    2207                 :            :         uint16_t port;
    2208                 :            : 
    2209                 :          0 :         if (opt->prod_type != EVT_PROD_TYPE_EVENT_DMA_ADPTR)
    2210                 :            :                 return;
    2211                 :            : 
    2212                 :          0 :         for (port = t->nb_workers; port < perf_nb_event_ports(opt); port++) {
    2213                 :            :                 struct prod_data *p = &t->prod[port];
    2214                 :            : 
    2215                 :          0 :                 rte_event_dma_adapter_vchan_del(TEST_PERF_DA_ID, p->da.dma_dev_id, p->da.vchan_id);
    2216                 :            :         }
    2217                 :            : 
    2218                 :          0 :         rte_event_dma_adapter_free(TEST_PERF_DA_ID);
    2219                 :            : 
    2220                 :          0 :         rte_dma_stop(dma_dev_id);
    2221                 :          0 :         rte_dma_close(dma_dev_id);
    2222                 :            : }
    2223                 :            : 
    2224                 :            : int
    2225                 :          0 : perf_mempool_setup(struct evt_test *test, struct evt_options *opt)
    2226                 :            : {
    2227                 :            :         struct test_perf *t = evt_test_priv(test);
    2228                 :            :         unsigned int cache_sz;
    2229                 :            : 
    2230                 :          0 :         cache_sz = RTE_MIN(RTE_MEMPOOL_CACHE_MAX_SIZE, (opt->pool_sz / 1.5) / t->nb_workers);
    2231                 :          0 :         if (opt->prod_type == EVT_PROD_TYPE_SYNT ||
    2232                 :            :                         opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) {
    2233                 :          0 :                 t->pool = rte_mempool_create(test->name, /* mempool name */
    2234                 :            :                                 opt->pool_sz, /* number of elements*/
    2235                 :            :                                 sizeof(struct perf_elt), /* element size*/
    2236                 :            :                                 cache_sz, /* cache size*/
    2237                 :            :                                 0, NULL, NULL,
    2238                 :            :                                 perf_elt_init, /* obj constructor */
    2239                 :            :                                 NULL, opt->socket_id, 0); /* flags */
    2240                 :          0 :         } else if (opt->prod_type == EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR &&
    2241                 :          0 :                    opt->crypto_op_type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
    2242                 :          0 :                 t->pool = rte_mempool_create(test->name, /* mempool name */
    2243                 :            :                                 opt->pool_sz, /* number of elements*/
    2244                 :          0 :                                 sizeof(struct perf_elt) + modex_test_case.result_len,
    2245                 :            :                                 /* element size*/
    2246                 :            :                                 cache_sz, /* cache size*/
    2247                 :            :                                 0, NULL, NULL,
    2248                 :            :                                 NULL, /* obj constructor */
    2249                 :            :                                 NULL, opt->socket_id, 0); /* flags */
    2250                 :          0 :         } else if (opt->prod_type == EVT_PROD_TYPE_EVENT_DMA_ADPTR) {
    2251                 :          0 :                 t->pool = rte_mempool_create(test->name,   /* mempool name */
    2252                 :            :                                              opt->pool_sz, /* number of elements*/
    2253                 :            :                                              sizeof(struct rte_event_dma_adapter_op) +
    2254                 :            :                                                      (sizeof(struct rte_dma_sge) * 2),
    2255                 :            :                                              cache_sz,                 /* cache size*/
    2256                 :            :                                              0, NULL, NULL, NULL,      /* obj constructor */
    2257                 :            :                                              NULL, opt->socket_id, 0); /* flags */
    2258                 :          0 :         } else if (opt->prod_type == EVT_PROD_TYPE_EVENT_VECTOR_ADPTR) {
    2259                 :          0 :                 t->pool = rte_event_vector_pool_create(test->name, opt->pool_sz, cache_sz,
    2260                 :          0 :                                                        opt->vector_size, opt->socket_id);
    2261                 :            :         } else {
    2262                 :          0 :                 t->pool = rte_pktmbuf_pool_create(test->name, /* mempool name */
    2263                 :            :                                 opt->pool_sz, /* number of elements*/
    2264                 :            :                                 cache_sz, /* cache size*/
    2265                 :            :                                 0,
    2266                 :            :                                 RTE_MBUF_DEFAULT_BUF_SIZE,
    2267                 :            :                                 opt->socket_id); /* flags */
    2268                 :            :         }
    2269                 :            : 
    2270                 :          0 :         if (t->pool == NULL) {
    2271                 :          0 :                 evt_err("failed to create mempool");
    2272                 :          0 :                 return -ENOMEM;
    2273                 :            :         }
    2274                 :            : 
    2275                 :            :         return 0;
    2276                 :            : }
    2277                 :            : 
    2278                 :            : void
    2279                 :          0 : perf_mempool_destroy(struct evt_test *test, struct evt_options *opt)
    2280                 :            : {
    2281                 :            :         RTE_SET_USED(opt);
    2282                 :            :         struct test_perf *t = evt_test_priv(test);
    2283                 :            : 
    2284                 :          0 :         rte_mempool_free(t->pool);
    2285                 :          0 : }
    2286                 :            : 
    2287                 :            : int
    2288                 :          0 : perf_test_setup(struct evt_test *test, struct evt_options *opt)
    2289                 :            : {
    2290                 :            :         void *test_perf;
    2291                 :            : 
    2292                 :          0 :         test_perf = rte_zmalloc_socket(test->name, sizeof(struct test_perf),
    2293                 :            :                                 RTE_CACHE_LINE_SIZE, opt->socket_id);
    2294                 :          0 :         if (test_perf  == NULL) {
    2295                 :          0 :                 evt_err("failed to allocate test_perf memory");
    2296                 :          0 :                 goto nomem;
    2297                 :            :         }
    2298                 :          0 :         test->test_priv = test_perf;
    2299                 :            : 
    2300                 :            :         struct test_perf *t = evt_test_priv(test);
    2301                 :            : 
    2302                 :          0 :         if (opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) {
    2303                 :          0 :                 t->outstand_pkts = opt->nb_timers *
    2304                 :          0 :                         evt_nr_active_lcores(opt->plcores);
    2305                 :          0 :                 t->nb_pkts = opt->nb_timers;
    2306                 :            :         } else {
    2307                 :          0 :                 t->outstand_pkts = opt->nb_pkts *
    2308                 :          0 :                         evt_nr_active_lcores(opt->plcores);
    2309                 :          0 :                 t->nb_pkts = opt->nb_pkts;
    2310                 :            :         }
    2311                 :            : 
    2312                 :          0 :         t->nb_workers = evt_nr_active_lcores(opt->wlcores);
    2313                 :          0 :         t->done = false;
    2314                 :          0 :         t->nb_flows = opt->nb_flows;
    2315                 :          0 :         t->result = EVT_TEST_FAILED;
    2316                 :          0 :         t->opt = opt;
    2317                 :          0 :         memcpy(t->sched_type_list, opt->sched_type_list,
    2318                 :            :                         sizeof(opt->sched_type_list));
    2319                 :          0 :         return 0;
    2320                 :            : nomem:
    2321                 :          0 :         return -ENOMEM;
    2322                 :            : }
    2323                 :            : 
    2324                 :            : void
    2325                 :          0 : perf_test_destroy(struct evt_test *test, struct evt_options *opt)
    2326                 :            : {
    2327                 :            :         RTE_SET_USED(opt);
    2328                 :            : 
    2329                 :          0 :         rte_free(test->test_priv);
    2330                 :          0 : }

Generated by: LCOV version 1.14