LCOV - code coverage report
Current view: top level - app/test-crypto-perf - main.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 331 0.0 %
Date: 2024-04-01 19:00:53 Functions: 0 6 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) 2016-2017 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <stdio.h>
       6                 :            : #include <stdlib.h>
       7                 :            : #include <unistd.h>
       8                 :            : 
       9                 :            : #include <rte_malloc.h>
      10                 :            : #include <rte_random.h>
      11                 :            : #include <rte_eal.h>
      12                 :            : #include <rte_errno.h>
      13                 :            : #include <rte_cryptodev.h>
      14                 :            : #ifdef RTE_CRYPTO_SCHEDULER
      15                 :            : #include <rte_cryptodev_scheduler.h>
      16                 :            : #endif
      17                 :            : 
      18                 :            : #include "cperf.h"
      19                 :            : #include "cperf_options.h"
      20                 :            : #include "cperf_test_vector_parsing.h"
      21                 :            : #include "cperf_test_throughput.h"
      22                 :            : #include "cperf_test_latency.h"
      23                 :            : #include "cperf_test_verify.h"
      24                 :            : #include "cperf_test_pmd_cyclecount.h"
      25                 :            : 
      26                 :            : static struct {
      27                 :            :         struct rte_mempool *sess_mp;
      28                 :            : } session_pool_socket[RTE_MAX_NUMA_NODES];
      29                 :            : 
      30                 :            : const char *cperf_test_type_strs[] = {
      31                 :            :         [CPERF_TEST_TYPE_THROUGHPUT] = "throughput",
      32                 :            :         [CPERF_TEST_TYPE_LATENCY] = "latency",
      33                 :            :         [CPERF_TEST_TYPE_VERIFY] = "verify",
      34                 :            :         [CPERF_TEST_TYPE_PMDCC] = "pmd-cyclecount"
      35                 :            : };
      36                 :            : 
      37                 :            : const char *cperf_op_type_strs[] = {
      38                 :            :         [CPERF_CIPHER_ONLY] = "cipher-only",
      39                 :            :         [CPERF_AUTH_ONLY] = "auth-only",
      40                 :            :         [CPERF_CIPHER_THEN_AUTH] = "cipher-then-auth",
      41                 :            :         [CPERF_AUTH_THEN_CIPHER] = "auth-then-cipher",
      42                 :            :         [CPERF_AEAD] = "aead",
      43                 :            :         [CPERF_PDCP] = "pdcp",
      44                 :            :         [CPERF_DOCSIS] = "docsis",
      45                 :            :         [CPERF_IPSEC] = "ipsec",
      46                 :            :         [CPERF_ASYM_MODEX] = "modex",
      47                 :            :         [CPERF_TLS] = "tls-record"
      48                 :            : };
      49                 :            : 
      50                 :            : const struct cperf_test cperf_testmap[] = {
      51                 :            :                 [CPERF_TEST_TYPE_THROUGHPUT] = {
      52                 :            :                                 cperf_throughput_test_constructor,
      53                 :            :                                 cperf_throughput_test_runner,
      54                 :            :                                 cperf_throughput_test_destructor
      55                 :            :                 },
      56                 :            :                 [CPERF_TEST_TYPE_LATENCY] = {
      57                 :            :                                 cperf_latency_test_constructor,
      58                 :            :                                 cperf_latency_test_runner,
      59                 :            :                                 cperf_latency_test_destructor
      60                 :            :                 },
      61                 :            :                 [CPERF_TEST_TYPE_VERIFY] = {
      62                 :            :                                 cperf_verify_test_constructor,
      63                 :            :                                 cperf_verify_test_runner,
      64                 :            :                                 cperf_verify_test_destructor
      65                 :            :                 },
      66                 :            :                 [CPERF_TEST_TYPE_PMDCC] = {
      67                 :            :                                 cperf_pmd_cyclecount_test_constructor,
      68                 :            :                                 cperf_pmd_cyclecount_test_runner,
      69                 :            :                                 cperf_pmd_cyclecount_test_destructor
      70                 :            :                 }
      71                 :            : };
      72                 :            : 
      73                 :            : static int
      74                 :          0 : create_asym_op_pool_socket(int32_t socket_id, uint32_t nb_sessions)
      75                 :            : {
      76                 :            :         char mp_name[RTE_MEMPOOL_NAMESIZE];
      77                 :            :         struct rte_mempool *mpool = NULL;
      78                 :            : 
      79                 :          0 :         if (session_pool_socket[socket_id].sess_mp == NULL) {
      80                 :            :                 snprintf(mp_name, RTE_MEMPOOL_NAMESIZE, "perf_asym_sess_pool%u",
      81                 :            :                          socket_id);
      82                 :          0 :                 mpool = rte_cryptodev_asym_session_pool_create(mp_name,
      83                 :            :                                 nb_sessions, 0, 0, socket_id);
      84                 :          0 :                 if (mpool == NULL) {
      85                 :            :                         printf("Cannot create pool \"%s\" on socket %d\n",
      86                 :            :                                mp_name, socket_id);
      87                 :          0 :                         return -ENOMEM;
      88                 :            :                 }
      89                 :          0 :                 session_pool_socket[socket_id].sess_mp = mpool;
      90                 :            :         }
      91                 :            :         return 0;
      92                 :            : }
      93                 :            : 
      94                 :            : static int
      95                 :          0 : fill_session_pool_socket(int32_t socket_id, uint32_t session_priv_size,
      96                 :            :                 uint32_t nb_sessions)
      97                 :            : {
      98                 :            :         char mp_name[RTE_MEMPOOL_NAMESIZE];
      99                 :            :         struct rte_mempool *sess_mp;
     100                 :            : 
     101                 :          0 :         if (session_pool_socket[socket_id].sess_mp == NULL) {
     102                 :            : 
     103                 :            :                 snprintf(mp_name, RTE_MEMPOOL_NAMESIZE,
     104                 :            :                         "sess_mp_%u", socket_id);
     105                 :            : 
     106                 :          0 :                 sess_mp = rte_cryptodev_sym_session_pool_create(mp_name,
     107                 :            :                                         nb_sessions, session_priv_size, 0, 0,
     108                 :            :                                         socket_id);
     109                 :            : 
     110                 :          0 :                 if (sess_mp == NULL) {
     111                 :            :                         printf("Cannot create pool \"%s\" on socket %d\n",
     112                 :            :                                 mp_name, socket_id);
     113                 :          0 :                         return -ENOMEM;
     114                 :            :                 }
     115                 :            : 
     116                 :            :                 printf("Allocated pool \"%s\" on socket %d\n",
     117                 :            :                         mp_name, socket_id);
     118                 :          0 :                 session_pool_socket[socket_id].sess_mp = sess_mp;
     119                 :            :         }
     120                 :            : 
     121                 :            :         return 0;
     122                 :            : }
     123                 :            : 
     124                 :            : static int
     125                 :          0 : cperf_initialize_cryptodev(struct cperf_options *opts, uint8_t *enabled_cdevs)
     126                 :            : {
     127                 :            :         uint8_t enabled_cdev_count = 0, nb_lcores, cdev_id;
     128                 :            :         uint32_t sessions_needed = 0;
     129                 :            :         unsigned int i, j;
     130                 :            :         int ret;
     131                 :            : 
     132                 :          0 :         enabled_cdev_count = rte_cryptodev_devices_get(opts->device_type,
     133                 :            :                         enabled_cdevs, RTE_CRYPTO_MAX_DEVS);
     134                 :          0 :         if (enabled_cdev_count == 0) {
     135                 :            :                 printf("No crypto devices type %s available\n",
     136                 :            :                                 opts->device_type);
     137                 :          0 :                 return -EINVAL;
     138                 :            :         }
     139                 :            : 
     140                 :          0 :         nb_lcores = rte_lcore_count() - 1;
     141                 :            : 
     142                 :          0 :         if (nb_lcores < 1) {
     143                 :          0 :                 RTE_LOG(ERR, USER1,
     144                 :            :                         "Number of enabled cores need to be higher than 1\n");
     145                 :          0 :                 return -EINVAL;
     146                 :            :         }
     147                 :            : 
     148                 :            :         /*
     149                 :            :          * Use less number of devices,
     150                 :            :          * if there are more available than cores.
     151                 :            :          */
     152                 :            :         if (enabled_cdev_count > nb_lcores)
     153                 :            :                 enabled_cdev_count = nb_lcores;
     154                 :            : 
     155                 :            :         /* Create a mempool shared by all the devices */
     156                 :            :         uint32_t max_sess_size = 0, sess_size;
     157                 :            : 
     158                 :          0 :         for (cdev_id = 0; cdev_id < rte_cryptodev_count(); cdev_id++) {
     159                 :          0 :                 sess_size = rte_cryptodev_sym_get_private_session_size(cdev_id);
     160                 :            :                 if (sess_size > max_sess_size)
     161                 :            :                         max_sess_size = sess_size;
     162                 :            :         }
     163                 :            : #ifdef RTE_LIB_SECURITY
     164                 :          0 :         for (cdev_id = 0; cdev_id < rte_cryptodev_count(); cdev_id++) {
     165                 :          0 :                 sess_size = rte_security_session_get_size(
     166                 :            :                                 rte_cryptodev_get_sec_ctx(cdev_id));
     167                 :            :                 if (sess_size > max_sess_size)
     168                 :            :                         max_sess_size = sess_size;
     169                 :            :         }
     170                 :            : #endif
     171                 :            :         /*
     172                 :            :          * Calculate number of needed queue pairs, based on the amount
     173                 :            :          * of available number of logical cores and crypto devices.
     174                 :            :          * For instance, if there are 4 cores and 2 crypto devices,
     175                 :            :          * 2 queue pairs will be set up per device.
     176                 :            :          */
     177                 :          0 :         opts->nb_qps = (nb_lcores % enabled_cdev_count) ?
     178                 :          0 :                                 (nb_lcores / enabled_cdev_count) + 1 :
     179                 :            :                                 nb_lcores / enabled_cdev_count;
     180                 :            : 
     181                 :          0 :         for (i = 0; i < enabled_cdev_count &&
     182                 :          0 :                         i < RTE_CRYPTO_MAX_DEVS; i++) {
     183                 :          0 :                 cdev_id = enabled_cdevs[i];
     184                 :            : #ifdef RTE_CRYPTO_SCHEDULER
     185                 :            :                 /*
     186                 :            :                  * If multi-core scheduler is used, limit the number
     187                 :            :                  * of queue pairs to 1, as there is no way to know
     188                 :            :                  * how many cores are being used by the PMD, and
     189                 :            :                  * how many will be available for the application.
     190                 :            :                  */
     191                 :          0 :                 if (!strcmp((const char *)opts->device_type, "crypto_scheduler") &&
     192                 :          0 :                                 rte_cryptodev_scheduler_mode_get(cdev_id) ==
     193                 :            :                                 CDEV_SCHED_MODE_MULTICORE)
     194                 :          0 :                         opts->nb_qps = 1;
     195                 :            : #endif
     196                 :            : 
     197                 :            :                 struct rte_cryptodev_info cdev_info;
     198                 :          0 :                 int socket_id = rte_cryptodev_socket_id(cdev_id);
     199                 :            : 
     200                 :            :                 /* Use the first socket if SOCKET_ID_ANY is returned. */
     201                 :          0 :                 if (socket_id == SOCKET_ID_ANY)
     202                 :            :                         socket_id = 0;
     203                 :            : 
     204                 :          0 :                 rte_cryptodev_info_get(cdev_id, &cdev_info);
     205                 :            : 
     206                 :          0 :                 if (opts->op_type == CPERF_ASYM_MODEX) {
     207                 :          0 :                         if ((cdev_info.feature_flags &
     208                 :            :                              RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) == 0)
     209                 :          0 :                                 continue;
     210                 :            :                 }
     211                 :            : 
     212                 :          0 :                 if (opts->nb_qps > cdev_info.max_nb_queue_pairs) {
     213                 :            :                         printf("Number of needed queue pairs is higher "
     214                 :            :                                 "than the maximum number of queue pairs "
     215                 :            :                                 "per device.\n");
     216                 :            :                         printf("Lower the number of cores or increase "
     217                 :            :                                 "the number of crypto devices\n");
     218                 :          0 :                         return -EINVAL;
     219                 :            :                 }
     220                 :          0 :                 struct rte_cryptodev_config conf = {
     221                 :            :                         .nb_queue_pairs = opts->nb_qps,
     222                 :            :                         .socket_id = socket_id,
     223                 :            :                 };
     224                 :            : 
     225                 :          0 :                 switch (opts->op_type) {
     226                 :          0 :                 case CPERF_ASYM_MODEX:
     227                 :          0 :                         conf.ff_disable |= (RTE_CRYPTODEV_FF_SECURITY |
     228                 :            :                                             RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO);
     229                 :          0 :                         break;
     230                 :          0 :                 case CPERF_CIPHER_ONLY:
     231                 :            :                 case CPERF_AUTH_ONLY:
     232                 :            :                 case CPERF_CIPHER_THEN_AUTH:
     233                 :            :                 case CPERF_AUTH_THEN_CIPHER:
     234                 :            :                 case CPERF_AEAD:
     235                 :          0 :                         conf.ff_disable |= RTE_CRYPTODEV_FF_SECURITY;
     236                 :            :                         /* Fall through */
     237                 :          0 :                 case CPERF_PDCP:
     238                 :            :                 case CPERF_DOCSIS:
     239                 :            :                 case CPERF_IPSEC:
     240                 :            :                 case CPERF_TLS:
     241                 :            :                         /* Fall through */
     242                 :            :                 default:
     243                 :          0 :                         conf.ff_disable |= RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO;
     244                 :            :                 }
     245                 :            : 
     246                 :          0 :                 struct rte_cryptodev_qp_conf qp_conf = {
     247                 :          0 :                         .nb_descriptors = opts->nb_descriptors
     248                 :            :                 };
     249                 :            : 
     250                 :            :                 /**
     251                 :            :                  * Device info specifies the min headroom and tailroom
     252                 :            :                  * requirement for the crypto PMD. This need to be honoured
     253                 :            :                  * by the application, while creating mbuf.
     254                 :            :                  */
     255                 :          0 :                 if (opts->headroom_sz < cdev_info.min_mbuf_headroom_req) {
     256                 :            :                         /* Update headroom */
     257                 :          0 :                         opts->headroom_sz = cdev_info.min_mbuf_headroom_req;
     258                 :            :                 }
     259                 :          0 :                 if (opts->tailroom_sz < cdev_info.min_mbuf_tailroom_req) {
     260                 :            :                         /* Update tailroom */
     261                 :          0 :                         opts->tailroom_sz = cdev_info.min_mbuf_tailroom_req;
     262                 :            :                 }
     263                 :            : 
     264                 :            :                 /* Update segment size to include headroom & tailroom */
     265                 :          0 :                 opts->segment_sz += (opts->headroom_sz + opts->tailroom_sz);
     266                 :            : 
     267                 :          0 :                 uint32_t dev_max_nb_sess = cdev_info.sym.max_nb_sessions;
     268                 :          0 :                 if (!strcmp((const char *)opts->device_type,
     269                 :            :                                         "crypto_scheduler")) {
     270                 :            : #ifdef RTE_CRYPTO_SCHEDULER
     271                 :          0 :                         uint32_t nb_workers =
     272                 :          0 :                                 rte_cryptodev_scheduler_workers_get(cdev_id,
     273                 :            :                                                                 NULL);
     274                 :            :                         /* scheduler session header per lcore + 1 session per worker qp */
     275                 :          0 :                         sessions_needed = nb_lcores + enabled_cdev_count *
     276                 :          0 :                                 opts->nb_qps * nb_workers;
     277                 :            : #endif
     278                 :            :                 } else
     279                 :          0 :                         sessions_needed = enabled_cdev_count * opts->nb_qps;
     280                 :            : 
     281                 :            :                 /*
     282                 :            :                  * A single session is required per queue pair
     283                 :            :                  * in each device
     284                 :            :                  */
     285                 :          0 :                 if (dev_max_nb_sess != 0 && dev_max_nb_sess < opts->nb_qps) {
     286                 :          0 :                         RTE_LOG(ERR, USER1,
     287                 :            :                                 "Device does not support at least "
     288                 :            :                                 "%u sessions\n", opts->nb_qps);
     289                 :          0 :                         return -ENOTSUP;
     290                 :            :                 }
     291                 :            : 
     292                 :          0 :                 if (opts->op_type == CPERF_ASYM_MODEX)
     293                 :          0 :                         ret = create_asym_op_pool_socket(socket_id,
     294                 :            :                                                          sessions_needed);
     295                 :            :                 else
     296                 :          0 :                         ret = fill_session_pool_socket(socket_id, max_sess_size,
     297                 :            :                                                        sessions_needed);
     298                 :          0 :                 if (ret < 0)
     299                 :          0 :                         return ret;
     300                 :            : 
     301                 :          0 :                 qp_conf.mp_session = session_pool_socket[socket_id].sess_mp;
     302                 :            : 
     303                 :          0 :                 if (opts->op_type == CPERF_ASYM_MODEX) {
     304                 :          0 :                         qp_conf.mp_session = NULL;
     305                 :            :                 }
     306                 :            : 
     307                 :          0 :                 ret = rte_cryptodev_configure(cdev_id, &conf);
     308                 :          0 :                 if (ret < 0) {
     309                 :            :                         printf("Failed to configure cryptodev %u", cdev_id);
     310                 :          0 :                         return -EINVAL;
     311                 :            :                 }
     312                 :            : 
     313                 :          0 :                 for (j = 0; j < opts->nb_qps; j++) {
     314                 :          0 :                         ret = rte_cryptodev_queue_pair_setup(cdev_id, j,
     315                 :            :                                 &qp_conf, socket_id);
     316                 :          0 :                         if (ret < 0) {
     317                 :            :                                 printf("Failed to setup queue pair %u on "
     318                 :            :                                         "cryptodev %u",       j, cdev_id);
     319                 :          0 :                                 return -EINVAL;
     320                 :            :                         }
     321                 :            :                 }
     322                 :            : 
     323                 :          0 :                 ret = rte_cryptodev_start(cdev_id);
     324                 :          0 :                 if (ret < 0) {
     325                 :            :                         printf("Failed to start device %u: error %d\n",
     326                 :            :                                         cdev_id, ret);
     327                 :          0 :                         return -EPERM;
     328                 :            :                 }
     329                 :            :         }
     330                 :            : 
     331                 :          0 :         return enabled_cdev_count;
     332                 :            : }
     333                 :            : 
     334                 :            : static int
     335                 :          0 : cperf_verify_devices_capabilities(struct cperf_options *opts,
     336                 :            :                 uint8_t *enabled_cdevs, uint8_t nb_cryptodevs)
     337                 :            : {
     338                 :            :         struct rte_cryptodev_sym_capability_idx cap_idx;
     339                 :            :         const struct rte_cryptodev_symmetric_capability *capability;
     340                 :            :         struct rte_cryptodev_asym_capability_idx asym_cap_idx;
     341                 :            :         const struct rte_cryptodev_asymmetric_xform_capability *asym_capability;
     342                 :            : 
     343                 :            : 
     344                 :            :         uint8_t i, cdev_id;
     345                 :            :         int ret;
     346                 :            : 
     347                 :          0 :         for (i = 0; i < nb_cryptodevs; i++) {
     348                 :            : 
     349                 :          0 :                 cdev_id = enabled_cdevs[i];
     350                 :            : 
     351                 :          0 :                 if (opts->op_type == CPERF_ASYM_MODEX) {
     352                 :          0 :                         asym_cap_idx.type = RTE_CRYPTO_ASYM_XFORM_MODEX;
     353                 :          0 :                         asym_capability = rte_cryptodev_asym_capability_get(
     354                 :            :                                 cdev_id, &asym_cap_idx);
     355                 :          0 :                         if (asym_capability == NULL)
     356                 :            :                                 return -1;
     357                 :            : 
     358                 :          0 :                         ret = rte_cryptodev_asym_xform_capability_check_modlen(
     359                 :          0 :                                 asym_capability, opts->modex_data->modulus.len);
     360                 :          0 :                         if (ret != 0)
     361                 :          0 :                                 return ret;
     362                 :            : 
     363                 :            :                 }
     364                 :            : 
     365                 :          0 :                 if (opts->op_type == CPERF_AUTH_ONLY ||
     366                 :          0 :                                 opts->op_type == CPERF_CIPHER_THEN_AUTH ||
     367                 :            :                                 opts->op_type == CPERF_AUTH_THEN_CIPHER) {
     368                 :            : 
     369                 :          0 :                         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
     370                 :          0 :                         cap_idx.algo.auth = opts->auth_algo;
     371                 :            : 
     372                 :          0 :                         capability = rte_cryptodev_sym_capability_get(cdev_id,
     373                 :            :                                         &cap_idx);
     374                 :          0 :                         if (capability == NULL)
     375                 :            :                                 return -1;
     376                 :            : 
     377                 :          0 :                         ret = rte_cryptodev_sym_capability_check_auth(
     378                 :            :                                         capability,
     379                 :          0 :                                         opts->auth_key_sz,
     380                 :          0 :                                         opts->digest_sz,
     381                 :          0 :                                         opts->auth_iv_sz);
     382                 :          0 :                         if (ret != 0)
     383                 :          0 :                                 return ret;
     384                 :            :                 }
     385                 :            : 
     386                 :          0 :                 if (opts->op_type == CPERF_CIPHER_ONLY ||
     387                 :          0 :                                 opts->op_type == CPERF_CIPHER_THEN_AUTH ||
     388                 :            :                                 opts->op_type == CPERF_AUTH_THEN_CIPHER) {
     389                 :            : 
     390                 :          0 :                         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
     391                 :          0 :                         cap_idx.algo.cipher = opts->cipher_algo;
     392                 :            : 
     393                 :          0 :                         capability = rte_cryptodev_sym_capability_get(cdev_id,
     394                 :            :                                         &cap_idx);
     395                 :          0 :                         if (capability == NULL)
     396                 :            :                                 return -1;
     397                 :            : 
     398                 :          0 :                         ret = rte_cryptodev_sym_capability_check_cipher(
     399                 :            :                                         capability,
     400                 :          0 :                                         opts->cipher_key_sz,
     401                 :          0 :                                         opts->cipher_iv_sz);
     402                 :          0 :                         if (ret != 0)
     403                 :          0 :                                 return ret;
     404                 :            :                 }
     405                 :            : 
     406                 :          0 :                 if (opts->op_type == CPERF_AEAD) {
     407                 :            : 
     408                 :          0 :                         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
     409                 :          0 :                         cap_idx.algo.aead = opts->aead_algo;
     410                 :            : 
     411                 :          0 :                         capability = rte_cryptodev_sym_capability_get(cdev_id,
     412                 :            :                                         &cap_idx);
     413                 :          0 :                         if (capability == NULL)
     414                 :            :                                 return -1;
     415                 :            : 
     416                 :          0 :                         ret = rte_cryptodev_sym_capability_check_aead(
     417                 :            :                                         capability,
     418                 :          0 :                                         opts->aead_key_sz,
     419                 :          0 :                                         opts->digest_sz,
     420                 :          0 :                                         opts->aead_aad_sz,
     421                 :          0 :                                         opts->aead_iv_sz);
     422                 :          0 :                         if (ret != 0)
     423                 :          0 :                                 return ret;
     424                 :            :                 }
     425                 :            :         }
     426                 :            : 
     427                 :            :         return 0;
     428                 :            : }
     429                 :            : 
     430                 :            : static int
     431                 :          0 : cperf_check_test_vector(struct cperf_options *opts,
     432                 :            :                 struct cperf_test_vector *test_vec)
     433                 :            : {
     434                 :          0 :         if (opts->op_type == CPERF_CIPHER_ONLY) {
     435                 :          0 :                 if (opts->cipher_algo == RTE_CRYPTO_CIPHER_NULL) {
     436                 :          0 :                         if (test_vec->plaintext.data == NULL)
     437                 :          0 :                                 return -1;
     438                 :            :                 } else {
     439                 :          0 :                         if (test_vec->plaintext.data == NULL)
     440                 :            :                                 return -1;
     441                 :          0 :                         if (test_vec->plaintext.length < opts->max_buffer_size)
     442                 :            :                                 return -1;
     443                 :          0 :                         if (test_vec->ciphertext.data == NULL)
     444                 :            :                                 return -1;
     445                 :          0 :                         if (test_vec->ciphertext.length < opts->max_buffer_size)
     446                 :            :                                 return -1;
     447                 :            :                         /* Cipher IV is only required for some algorithms */
     448                 :          0 :                         if (opts->cipher_iv_sz &&
     449                 :          0 :                                         test_vec->cipher_iv.data == NULL)
     450                 :            :                                 return -1;
     451                 :          0 :                         if (test_vec->cipher_iv.length != opts->cipher_iv_sz)
     452                 :            :                                 return -1;
     453                 :          0 :                         if (test_vec->cipher_key.data == NULL)
     454                 :            :                                 return -1;
     455                 :          0 :                         if (test_vec->cipher_key.length != opts->cipher_key_sz)
     456                 :          0 :                                 return -1;
     457                 :            :                 }
     458                 :          0 :         } else if (opts->op_type == CPERF_AUTH_ONLY) {
     459                 :          0 :                 if (opts->auth_algo != RTE_CRYPTO_AUTH_NULL) {
     460                 :          0 :                         if (test_vec->plaintext.data == NULL)
     461                 :            :                                 return -1;
     462                 :          0 :                         if (test_vec->plaintext.length < opts->max_buffer_size)
     463                 :            :                                 return -1;
     464                 :            :                         /* Auth key is only required for some algorithms */
     465                 :          0 :                         if (opts->auth_key_sz &&
     466                 :          0 :                                         test_vec->auth_key.data == NULL)
     467                 :            :                                 return -1;
     468                 :          0 :                         if (test_vec->auth_key.length != opts->auth_key_sz)
     469                 :            :                                 return -1;
     470                 :          0 :                         if (test_vec->auth_iv.length != opts->auth_iv_sz)
     471                 :            :                                 return -1;
     472                 :            :                         /* Auth IV is only required for some algorithms */
     473                 :          0 :                         if (opts->auth_iv_sz && test_vec->auth_iv.data == NULL)
     474                 :            :                                 return -1;
     475                 :          0 :                         if (test_vec->digest.data == NULL)
     476                 :            :                                 return -1;
     477                 :          0 :                         if (test_vec->digest.length < opts->digest_sz)
     478                 :          0 :                                 return -1;
     479                 :            :                 }
     480                 :            : 
     481                 :          0 :         } else if (opts->op_type == CPERF_CIPHER_THEN_AUTH ||
     482                 :            :                         opts->op_type == CPERF_AUTH_THEN_CIPHER) {
     483                 :          0 :                 if (opts->cipher_algo == RTE_CRYPTO_CIPHER_NULL) {
     484                 :          0 :                         if (test_vec->plaintext.data == NULL)
     485                 :            :                                 return -1;
     486                 :          0 :                         if (test_vec->plaintext.length < opts->max_buffer_size)
     487                 :            :                                 return -1;
     488                 :            :                 } else {
     489                 :          0 :                         if (test_vec->plaintext.data == NULL)
     490                 :            :                                 return -1;
     491                 :          0 :                         if (test_vec->plaintext.length < opts->max_buffer_size)
     492                 :            :                                 return -1;
     493                 :          0 :                         if (test_vec->ciphertext.data == NULL)
     494                 :            :                                 return -1;
     495                 :          0 :                         if (test_vec->ciphertext.length < opts->max_buffer_size)
     496                 :            :                                 return -1;
     497                 :          0 :                         if (test_vec->cipher_iv.data == NULL)
     498                 :            :                                 return -1;
     499                 :          0 :                         if (test_vec->cipher_iv.length != opts->cipher_iv_sz)
     500                 :            :                                 return -1;
     501                 :          0 :                         if (test_vec->cipher_key.data == NULL)
     502                 :            :                                 return -1;
     503                 :          0 :                         if (test_vec->cipher_key.length != opts->cipher_key_sz)
     504                 :            :                                 return -1;
     505                 :            :                 }
     506                 :          0 :                 if (opts->auth_algo != RTE_CRYPTO_AUTH_NULL) {
     507                 :          0 :                         if (test_vec->auth_key.data == NULL)
     508                 :            :                                 return -1;
     509                 :          0 :                         if (test_vec->auth_key.length != opts->auth_key_sz)
     510                 :            :                                 return -1;
     511                 :          0 :                         if (test_vec->auth_iv.length != opts->auth_iv_sz)
     512                 :            :                                 return -1;
     513                 :            :                         /* Auth IV is only required for some algorithms */
     514                 :          0 :                         if (opts->auth_iv_sz && test_vec->auth_iv.data == NULL)
     515                 :            :                                 return -1;
     516                 :          0 :                         if (test_vec->digest.data == NULL)
     517                 :            :                                 return -1;
     518                 :          0 :                         if (test_vec->digest.length < opts->digest_sz)
     519                 :          0 :                                 return -1;
     520                 :            :                 }
     521                 :          0 :         } else if (opts->op_type == CPERF_AEAD) {
     522                 :          0 :                 if (test_vec->plaintext.data == NULL)
     523                 :            :                         return -1;
     524                 :          0 :                 if (test_vec->plaintext.length < opts->max_buffer_size)
     525                 :            :                         return -1;
     526                 :          0 :                 if (test_vec->ciphertext.data == NULL)
     527                 :            :                         return -1;
     528                 :          0 :                 if (test_vec->ciphertext.length < opts->max_buffer_size)
     529                 :            :                         return -1;
     530                 :          0 :                 if (test_vec->aead_key.data == NULL)
     531                 :            :                         return -1;
     532                 :          0 :                 if (test_vec->aead_key.length != opts->aead_key_sz)
     533                 :            :                         return -1;
     534                 :          0 :                 if (test_vec->aead_iv.data == NULL)
     535                 :            :                         return -1;
     536                 :          0 :                 if (test_vec->aead_iv.length != opts->aead_iv_sz)
     537                 :            :                         return -1;
     538                 :          0 :                 if (test_vec->aad.data == NULL)
     539                 :            :                         return -1;
     540                 :          0 :                 if (test_vec->aad.length != opts->aead_aad_sz)
     541                 :            :                         return -1;
     542                 :          0 :                 if (test_vec->digest.data == NULL)
     543                 :            :                         return -1;
     544                 :          0 :                 if (test_vec->digest.length < opts->digest_sz)
     545                 :          0 :                         return -1;
     546                 :            :         }
     547                 :            :         return 0;
     548                 :            : }
     549                 :            : 
     550                 :            : int
     551                 :          0 : main(int argc, char **argv)
     552                 :            : {
     553                 :          0 :         struct cperf_options opts = {0};
     554                 :            :         struct cperf_test_vector *t_vec = NULL;
     555                 :            :         struct cperf_op_fns op_fns;
     556                 :          0 :         void *ctx[RTE_MAX_LCORE] = { };
     557                 :            :         int nb_cryptodevs = 0;
     558                 :            :         uint16_t total_nb_qps = 0;
     559                 :            :         uint8_t cdev_id, i;
     560                 :          0 :         uint8_t enabled_cdevs[RTE_CRYPTO_MAX_DEVS] = { 0 };
     561                 :            : 
     562                 :            :         uint8_t buffer_size_idx = 0;
     563                 :            : 
     564                 :            :         int ret;
     565                 :            :         uint32_t lcore_id;
     566                 :            :         bool cap_unsupported = false;
     567                 :            : 
     568                 :            :         /* Initialise DPDK EAL */
     569                 :          0 :         ret = rte_eal_init(argc, argv);
     570                 :          0 :         if (ret < 0)
     571                 :          0 :                 rte_exit(EXIT_FAILURE, "Invalid EAL arguments!\n");
     572                 :          0 :         argc -= ret;
     573                 :          0 :         argv += ret;
     574                 :            : 
     575                 :          0 :         cperf_options_default(&opts);
     576                 :            : 
     577                 :          0 :         ret = cperf_options_parse(&opts, argc, argv);
     578                 :          0 :         if (ret) {
     579                 :          0 :                 RTE_LOG(ERR, USER1, "Parsing one or more user options failed\n");
     580                 :          0 :                 goto err;
     581                 :            :         }
     582                 :            : 
     583                 :          0 :         ret = cperf_options_check(&opts);
     584                 :          0 :         if (ret) {
     585                 :          0 :                 RTE_LOG(ERR, USER1,
     586                 :            :                                 "Checking one or more user options failed\n");
     587                 :          0 :                 goto err;
     588                 :            :         }
     589                 :            : 
     590                 :          0 :         nb_cryptodevs = cperf_initialize_cryptodev(&opts, enabled_cdevs);
     591                 :            : 
     592                 :          0 :         if (!opts.silent)
     593                 :          0 :                 cperf_options_dump(&opts);
     594                 :            : 
     595                 :          0 :         if (nb_cryptodevs < 1) {
     596                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to initialise requested crypto "
     597                 :            :                                 "device type\n");
     598                 :            :                 nb_cryptodevs = 0;
     599                 :          0 :                 goto err;
     600                 :            :         }
     601                 :            : 
     602                 :          0 :         ret = cperf_verify_devices_capabilities(&opts, enabled_cdevs,
     603                 :            :                         nb_cryptodevs);
     604                 :          0 :         if (ret) {
     605                 :          0 :                 RTE_LOG(ERR, USER1, "Crypto device type does not support "
     606                 :            :                                 "capabilities requested\n");
     607                 :            :                 cap_unsupported = true;
     608                 :          0 :                 goto err;
     609                 :            :         }
     610                 :            : 
     611                 :          0 :         if (opts.test_file != NULL) {
     612                 :          0 :                 t_vec = cperf_test_vector_get_from_file(&opts);
     613                 :          0 :                 if (t_vec == NULL) {
     614                 :          0 :                         RTE_LOG(ERR, USER1,
     615                 :            :                                         "Failed to create test vector for"
     616                 :            :                                         " specified file\n");
     617                 :          0 :                         goto err;
     618                 :            :                 }
     619                 :            : 
     620                 :          0 :                 if (cperf_check_test_vector(&opts, t_vec)) {
     621                 :          0 :                         RTE_LOG(ERR, USER1, "Incomplete necessary test vectors"
     622                 :            :                                         "\n");
     623                 :          0 :                         goto err;
     624                 :            :                 }
     625                 :            :         } else {
     626                 :          0 :                 t_vec = cperf_test_vector_get_dummy(&opts);
     627                 :          0 :                 if (t_vec == NULL) {
     628                 :          0 :                         RTE_LOG(ERR, USER1,
     629                 :            :                                         "Failed to create test vector for"
     630                 :            :                                         " specified algorithms\n");
     631                 :          0 :                         goto err;
     632                 :            :                 }
     633                 :            :         }
     634                 :            : 
     635                 :          0 :         ret = cperf_get_op_functions(&opts, &op_fns);
     636                 :          0 :         if (ret) {
     637                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to find function ops set for "
     638                 :            :                                 "specified algorithms combination\n");
     639                 :          0 :                 goto err;
     640                 :            :         }
     641                 :            : 
     642                 :          0 :         if (!opts.silent && opts.test != CPERF_TEST_TYPE_THROUGHPUT &&
     643                 :            :                         opts.test != CPERF_TEST_TYPE_LATENCY)
     644                 :          0 :                 show_test_vector(t_vec);
     645                 :            : 
     646                 :          0 :         total_nb_qps = nb_cryptodevs * opts.nb_qps;
     647                 :            : 
     648                 :            :         i = 0;
     649                 :            :         uint8_t qp_id = 0, cdev_index = 0;
     650                 :          0 :         RTE_LCORE_FOREACH_WORKER(lcore_id) {
     651                 :            : 
     652                 :          0 :                 if (i == total_nb_qps)
     653                 :            :                         break;
     654                 :            : 
     655                 :          0 :                 cdev_id = enabled_cdevs[cdev_index];
     656                 :            : 
     657                 :          0 :                 int socket_id = rte_cryptodev_socket_id(cdev_id);
     658                 :            : 
     659                 :            :                 /* Use the first socket if SOCKET_ID_ANY is returned. */
     660                 :          0 :                 if (socket_id == SOCKET_ID_ANY)
     661                 :            :                         socket_id = 0;
     662                 :            : 
     663                 :          0 :                 ctx[i] = cperf_testmap[opts.test].constructor(
     664                 :            :                                 session_pool_socket[socket_id].sess_mp,
     665                 :            :                                 cdev_id, qp_id,
     666                 :            :                                 &opts, t_vec, &op_fns);
     667                 :          0 :                 if (ctx[i] == NULL) {
     668                 :          0 :                         RTE_LOG(ERR, USER1, "Test run constructor failed\n");
     669                 :          0 :                         goto err;
     670                 :            :                 }
     671                 :          0 :                 qp_id = (qp_id + 1) % opts.nb_qps;
     672                 :          0 :                 if (qp_id == 0)
     673                 :          0 :                         cdev_index++;
     674                 :          0 :                 i++;
     675                 :            :         }
     676                 :            : 
     677                 :          0 :         if (opts.imix_distribution_count != 0) {
     678                 :          0 :                 uint8_t buffer_size_count = opts.buffer_size_count;
     679                 :          0 :                 uint16_t distribution_total[buffer_size_count];
     680                 :            :                 uint32_t op_idx;
     681                 :            :                 uint32_t test_average_size = 0;
     682                 :            :                 const uint32_t *buffer_size_list = opts.buffer_size_list;
     683                 :            :                 const uint32_t *imix_distribution_list = opts.imix_distribution_list;
     684                 :            : 
     685                 :          0 :                 opts.imix_buffer_sizes = rte_malloc(NULL,
     686                 :          0 :                                         sizeof(uint32_t) * opts.pool_sz,
     687                 :            :                                         0);
     688                 :            :                 /*
     689                 :            :                  * Calculate accumulated distribution of
     690                 :            :                  * probabilities per packet size
     691                 :            :                  */
     692                 :          0 :                 distribution_total[0] = imix_distribution_list[0];
     693                 :          0 :                 for (i = 1; i < buffer_size_count; i++)
     694                 :          0 :                         distribution_total[i] = imix_distribution_list[i] +
     695                 :          0 :                                 distribution_total[i-1];
     696                 :            : 
     697                 :            :                 /* Calculate a random sequence of packet sizes, based on distribution */
     698                 :          0 :                 for (op_idx = 0; op_idx < opts.pool_sz; op_idx++) {
     699                 :          0 :                         uint16_t random_number = rte_rand() %
     700                 :          0 :                                 distribution_total[buffer_size_count - 1];
     701                 :          0 :                         for (i = 0; i < buffer_size_count; i++)
     702                 :          0 :                                 if (random_number < distribution_total[i])
     703                 :            :                                         break;
     704                 :            : 
     705                 :          0 :                         opts.imix_buffer_sizes[op_idx] = buffer_size_list[i];
     706                 :            :                 }
     707                 :            : 
     708                 :            :                 /* Calculate average buffer size for the IMIX distribution */
     709                 :          0 :                 for (i = 0; i < buffer_size_count; i++)
     710                 :          0 :                         test_average_size += buffer_size_list[i] *
     711                 :          0 :                                 imix_distribution_list[i];
     712                 :            : 
     713                 :          0 :                 opts.test_buffer_size = test_average_size /
     714                 :          0 :                                 distribution_total[buffer_size_count - 1];
     715                 :            : 
     716                 :            :                 i = 0;
     717                 :          0 :                 RTE_LCORE_FOREACH_WORKER(lcore_id) {
     718                 :            : 
     719                 :          0 :                         if (i == total_nb_qps)
     720                 :            :                                 break;
     721                 :            : 
     722                 :          0 :                         rte_eal_remote_launch(cperf_testmap[opts.test].runner,
     723                 :            :                                 ctx[i], lcore_id);
     724                 :          0 :                         i++;
     725                 :            :                 }
     726                 :            :                 i = 0;
     727                 :          0 :                 RTE_LCORE_FOREACH_WORKER(lcore_id) {
     728                 :            : 
     729                 :          0 :                         if (i == total_nb_qps)
     730                 :            :                                 break;
     731                 :          0 :                         ret |= rte_eal_wait_lcore(lcore_id);
     732                 :          0 :                         i++;
     733                 :            :                 }
     734                 :            : 
     735                 :          0 :                 if (ret != EXIT_SUCCESS)
     736                 :          0 :                         goto err;
     737                 :            :         } else {
     738                 :            : 
     739                 :            :                 /* Get next size from range or list */
     740                 :          0 :                 if (opts.inc_buffer_size != 0)
     741                 :          0 :                         opts.test_buffer_size = opts.min_buffer_size;
     742                 :            :                 else
     743                 :          0 :                         opts.test_buffer_size = opts.buffer_size_list[0];
     744                 :            : 
     745                 :          0 :                 while (opts.test_buffer_size <= opts.max_buffer_size) {
     746                 :            :                         i = 0;
     747                 :          0 :                         RTE_LCORE_FOREACH_WORKER(lcore_id) {
     748                 :            : 
     749                 :          0 :                                 if (i == total_nb_qps)
     750                 :            :                                         break;
     751                 :            : 
     752                 :          0 :                                 rte_eal_remote_launch(cperf_testmap[opts.test].runner,
     753                 :            :                                         ctx[i], lcore_id);
     754                 :          0 :                                 i++;
     755                 :            :                         }
     756                 :            :                         i = 0;
     757                 :          0 :                         RTE_LCORE_FOREACH_WORKER(lcore_id) {
     758                 :            : 
     759                 :          0 :                                 if (i == total_nb_qps)
     760                 :            :                                         break;
     761                 :          0 :                                 ret |= rte_eal_wait_lcore(lcore_id);
     762                 :          0 :                                 i++;
     763                 :            :                         }
     764                 :            : 
     765                 :          0 :                         if (ret != EXIT_SUCCESS)
     766                 :          0 :                                 goto err;
     767                 :            : 
     768                 :            :                         /* Get next size from range or list */
     769                 :          0 :                         if (opts.inc_buffer_size != 0)
     770                 :          0 :                                 opts.test_buffer_size += opts.inc_buffer_size;
     771                 :            :                         else {
     772                 :          0 :                                 if (++buffer_size_idx == opts.buffer_size_count)
     773                 :            :                                         break;
     774                 :          0 :                                 opts.test_buffer_size =
     775                 :          0 :                                         opts.buffer_size_list[buffer_size_idx];
     776                 :            :                         }
     777                 :            :                 }
     778                 :            :         }
     779                 :            : 
     780                 :            :         i = 0;
     781                 :          0 :         RTE_LCORE_FOREACH_WORKER(lcore_id) {
     782                 :            : 
     783                 :          0 :                 if (i == total_nb_qps)
     784                 :            :                         break;
     785                 :            : 
     786                 :          0 :                 cperf_testmap[opts.test].destructor(ctx[i]);
     787                 :          0 :                 i++;
     788                 :            :         }
     789                 :            : 
     790                 :          0 :         for (i = 0; i < nb_cryptodevs &&
     791                 :          0 :                         i < RTE_CRYPTO_MAX_DEVS; i++) {
     792                 :          0 :                 rte_cryptodev_stop(enabled_cdevs[i]);
     793                 :          0 :                 ret = rte_cryptodev_close(enabled_cdevs[i]);
     794                 :          0 :                 if (ret)
     795                 :          0 :                         RTE_LOG(ERR, USER1,
     796                 :            :                                         "Crypto device close error %d\n", ret);
     797                 :            :         }
     798                 :            : 
     799                 :          0 :         free_test_vector(t_vec, &opts);
     800                 :            : 
     801                 :            :         printf("\n");
     802                 :          0 :         return EXIT_SUCCESS;
     803                 :            : 
     804                 :          0 : err:
     805                 :            :         i = 0;
     806                 :          0 :         RTE_LCORE_FOREACH_WORKER(lcore_id) {
     807                 :          0 :                 if (i == total_nb_qps)
     808                 :            :                         break;
     809                 :            : 
     810                 :          0 :                 if (ctx[i] && cperf_testmap[opts.test].destructor)
     811                 :          0 :                         cperf_testmap[opts.test].destructor(ctx[i]);
     812                 :          0 :                 i++;
     813                 :            :         }
     814                 :            : 
     815                 :          0 :         for (i = 0; i < nb_cryptodevs &&
     816                 :          0 :                         i < RTE_CRYPTO_MAX_DEVS; i++) {
     817                 :          0 :                 rte_cryptodev_stop(enabled_cdevs[i]);
     818                 :          0 :                 ret = rte_cryptodev_close(enabled_cdevs[i]);
     819                 :          0 :                 if (ret)
     820                 :          0 :                         RTE_LOG(ERR, USER1,
     821                 :            :                                         "Crypto device close error %d\n", ret);
     822                 :            : 
     823                 :            :         }
     824                 :          0 :         rte_free(opts.imix_buffer_sizes);
     825                 :          0 :         free_test_vector(t_vec, &opts);
     826                 :            : 
     827                 :          0 :         if (rte_errno == ENOTSUP || cap_unsupported) {
     828                 :          0 :                 RTE_LOG(ERR, USER1, "Unsupported case: errno: %u\n", rte_errno);
     829                 :          0 :                 return -ENOTSUP;
     830                 :            :         }
     831                 :            :         printf("\n");
     832                 :          0 :         return EXIT_FAILURE;
     833                 :            : }

Generated by: LCOV version 1.14