test/crypto-perf: fix ARMv8 session creation
[dpdk.git] / test / test / test_cryptodev_perf.c
index 7193d18..8febd1a 100644 (file)
@@ -53,6 +53,7 @@
 struct crypto_testsuite_params {
        struct rte_mempool *mbuf_mp;
        struct rte_mempool *op_mpool;
+       struct rte_mempool *sess_mp;
 
        uint16_t nb_queue_pairs;
 
@@ -107,6 +108,8 @@ struct symmetric_session_attrs {
        uint32_t digest_len;
 };
 
+static struct rte_cryptodev_sym_session *test_crypto_session;
+
 #define ALIGN_POW2_ROUNDUP(num, align) \
        (((num) + (align) - 1) & ~((align) - 1))
 
@@ -155,18 +158,18 @@ struct crypto_unittest_params {
        uint8_t *digest;
 };
 
-static struct rte_cryptodev_sym_session *
+static int
 test_perf_create_snow3g_session(uint8_t dev_id, enum chain_mode chain,
                enum rte_crypto_cipher_algorithm cipher_algo,
                unsigned int cipher_key_len,
                enum rte_crypto_auth_algorithm auth_algo);
-static struct rte_cryptodev_sym_session *
+static int
 test_perf_create_openssl_session(uint8_t dev_id, enum chain_mode chain,
                enum rte_crypto_cipher_algorithm cipher_algo,
                unsigned int cipher_key_len,
                enum rte_crypto_auth_algorithm auth_algo,
                enum rte_crypto_aead_algorithm aead_algo);
-static struct rte_cryptodev_sym_session *
+static int
 test_perf_create_armv8_session(uint8_t dev_id, enum chain_mode chain,
                enum rte_crypto_cipher_algorithm cipher_algo,
                unsigned int cipher_key_len,
@@ -404,7 +407,20 @@ testsuite_setup(void)
 
        ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
        ts_params->conf.socket_id = SOCKET_ID_ANY;
-       ts_params->conf.session_mp.nb_objs = info.sym.max_nb_sessions;
+
+       unsigned int session_size = sizeof(struct rte_cryptodev_sym_session) +
+               rte_cryptodev_get_private_session_size(ts_params->dev_id);
+
+       ts_params->sess_mp = rte_mempool_create(
+                               "test_sess_mp_perf",
+                               info.sym.max_nb_sessions,
+                               session_size,
+                               0, 0, NULL, NULL, NULL,
+                               NULL, SOCKET_ID_ANY,
+                               0);
+
+       TEST_ASSERT_NOT_NULL(ts_params->sess_mp,
+                       "session mempool allocation failed");
 
        TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->dev_id,
                        &ts_params->conf),
@@ -417,7 +433,8 @@ testsuite_setup(void)
                TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
                        ts_params->dev_id, qp_id,
                                &ts_params->qp_conf,
-                               rte_cryptodev_socket_id(ts_params->dev_id)),
+                               rte_cryptodev_socket_id(ts_params->dev_id),
+                               ts_params->sess_mp),
                                "Failed to setup queue pair %u on cryptodev %u",
                                qp_id, ts_params->dev_id);
        }
@@ -436,6 +453,12 @@ testsuite_teardown(void)
        if (ts_params->op_mpool != NULL)
                RTE_LOG(DEBUG, USER1, "CRYPTO_PERF_OP POOL count %u\n",
                rte_mempool_avail_count(ts_params->op_mpool));
+       /* Free session mempool */
+       if (ts_params->sess_mp != NULL) {
+               rte_mempool_free(ts_params->sess_mp);
+               ts_params->sess_mp = NULL;
+       }
+
 }
 
 static int
@@ -467,9 +490,11 @@ ut_teardown(void)
        unsigned i;
 
        /* free crypto session structure */
-       if (ut_params->sess)
-               rte_cryptodev_sym_session_free(ts_params->dev_id,
+       if (ut_params->sess) {
+               rte_cryptodev_sym_session_clear(ts_params->dev_id,
                                ut_params->sess);
+               rte_cryptodev_sym_session_free(ut_params->sess);
+       }
 
        /* free crypto operation structure */
        if (ut_params->op)
@@ -1949,10 +1974,13 @@ test_perf_crypto_qp_vary_burst_size(uint16_t dev_num)
        ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA256;
 
        /* Create Crypto session*/
-       ut_params->sess = rte_cryptodev_sym_session_create(ts_params->dev_id,
-               &ut_params->cipher_xform);
 
-       TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
+       test_crypto_session = rte_cryptodev_sym_session_create(ts_params->sess_mp);
+
+       rte_cryptodev_sym_session_init(ts_params->dev_id, test_crypto_session,
+                       &ut_params->cipher_xform, ts_params->sess_mp);
+
+       TEST_ASSERT_NOT_NULL(test_crypto_session, "Session creation failed");
 
        /* Generate Crypto op data structure(s) */
        for (i = 0; i < num_to_submit ; i++) {
@@ -1974,7 +2002,7 @@ test_perf_crypto_qp_vary_burst_size(uint16_t dev_num)
                                rte_crypto_op_alloc(ts_params->op_mpool,
                                                RTE_CRYPTO_OP_TYPE_SYMMETRIC);
 
-               rte_crypto_op_attach_sym_session(op, ut_params->sess);
+               rte_crypto_op_attach_sym_session(op, test_crypto_session);
 
                op->sym->auth.digest.data = ut_params->digest;
                op->sym->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(m,
@@ -2085,9 +2113,12 @@ test_perf_snow3G_optimise_cyclecount(struct perf_test_params *pparams)
        }
 
        /* Create Crypto session*/
-       sess = test_perf_create_snow3g_session(ts_params->dev_id,
+       if (test_perf_create_snow3g_session(ts_params->dev_id,
                        pparams->chain, pparams->cipher_algo,
-                       pparams->key_length, pparams->auth_algo);
+                       pparams->key_length, pparams->auth_algo) == 0)
+               sess = test_crypto_session;
+       else
+               sess = NULL;
        TEST_ASSERT_NOT_NULL(sess, "Session creation failed");
 
        /* Generate Crypto op data structure(s)*/
@@ -2191,7 +2222,10 @@ test_perf_snow3G_optimise_cyclecount(struct perf_test_params *pparams)
                rte_pktmbuf_free(c_ops[i]->sym->m_src);
                rte_crypto_op_free(c_ops[i]);
        }
-       rte_cryptodev_sym_session_free(ts_params->dev_id, sess);
+
+       rte_cryptodev_sym_session_clear(ts_params->dev_id,
+                               sess);
+       rte_cryptodev_sym_session_free(sess);
 
        return TEST_SUCCESS;
 }
@@ -2270,10 +2304,13 @@ test_perf_openssl_optimise_cyclecount(struct perf_test_params *pparams)
        }
 
        /* Create Crypto session*/
-       sess = test_perf_create_openssl_session(ts_params->dev_id,
+       if (test_perf_create_openssl_session(ts_params->dev_id,
                        pparams->chain, pparams->cipher_algo,
                        pparams->key_length, pparams->auth_algo,
-                       pparams->aead_algo);
+                       pparams->aead_algo) == 0)
+               sess = test_crypto_session;
+       else
+               sess = NULL;
        TEST_ASSERT_NOT_NULL(sess, "Session creation failed");
 
        /* Generate Crypto op data structure(s)*/
@@ -2405,7 +2442,9 @@ test_perf_openssl_optimise_cyclecount(struct perf_test_params *pparams)
                rte_pktmbuf_free(c_ops[i]->sym->m_src);
                rte_crypto_op_free(c_ops[i]);
        }
-       rte_cryptodev_sym_session_free(ts_params->dev_id, sess);
+
+       rte_cryptodev_sym_session_clear(ts_params->dev_id, sess);
+       rte_cryptodev_sym_session_free(sess);
 
        return TEST_SUCCESS;
 }
@@ -2432,10 +2471,12 @@ test_perf_armv8_optimise_cyclecount(struct perf_test_params *pparams)
        }
 
        /* Create Crypto session*/
-       sess = test_perf_create_armv8_session(ts_params->dev_id,
+       if (test_perf_create_armv8_session(ts_params->dev_id,
                        pparams->chain, pparams->cipher_algo,
-                       pparams->key_length, pparams->auth_algo);
-       TEST_ASSERT_NOT_NULL(sess, "Session creation failed");
+                       pparams->key_length, pparams->auth_algo) == 0)
+               sess = test_crypto_session;
+       else
+               sess = NULL;
 
        /* Generate Crypto op data structure(s)*/
        for (i = 0; i < num_to_submit ; i++) {
@@ -2652,12 +2693,13 @@ static uint8_t snow3g_hash_key[] = {
                0x1E, 0x26, 0x98, 0xD2, 0xE2, 0x2A, 0xD5, 0x7E
 };
 
-static struct rte_cryptodev_sym_session *
+static int
 test_perf_create_aes_sha_session(uint8_t dev_id, enum chain_mode chain,
                enum rte_crypto_cipher_algorithm cipher_algo,
                unsigned cipher_key_len,
                enum rte_crypto_auth_algorithm auth_algo)
 {
+       struct crypto_testsuite_params *ts_params = &testsuite_params;
        struct rte_crypto_sym_xform cipher_xform = { 0 };
        struct rte_crypto_sym_xform auth_xform = { 0 };
 
@@ -2681,33 +2723,42 @@ test_perf_create_aes_sha_session(uint8_t dev_id, enum chain_mode chain,
                auth_xform.auth.digest_length =
                                        get_auth_digest_length(auth_algo);
        }
+
+       test_crypto_session = rte_cryptodev_sym_session_create(ts_params->sess_mp);
        switch (chain) {
        case CIPHER_HASH:
                cipher_xform.next = &auth_xform;
                auth_xform.next = NULL;
                /* Create Crypto session*/
-               return rte_cryptodev_sym_session_create(dev_id, &cipher_xform);
+               return rte_cryptodev_sym_session_init(dev_id,
+                               test_crypto_session, &cipher_xform,
+                               ts_params->sess_mp);
        case HASH_CIPHER:
                auth_xform.next = &cipher_xform;
                cipher_xform.next = NULL;
                /* Create Crypto session*/
-               return rte_cryptodev_sym_session_create(dev_id, &auth_xform);
+               return rte_cryptodev_sym_session_init(dev_id,
+                               test_crypto_session, &auth_xform,
+                               ts_params->sess_mp);
        case CIPHER_ONLY:
                cipher_xform.next = NULL;
                /* Create Crypto session*/
-               return rte_cryptodev_sym_session_create(dev_id, &cipher_xform);
+               return rte_cryptodev_sym_session_init(dev_id,
+                               test_crypto_session, &cipher_xform,
+                               ts_params->sess_mp);
        default:
-               return NULL;
+               return -1;
        }
 }
 
 #define SNOW3G_CIPHER_IV_LENGTH 16
 
-static struct rte_cryptodev_sym_session *
+static int
 test_perf_create_snow3g_session(uint8_t dev_id, enum chain_mode chain,
                enum rte_crypto_cipher_algorithm cipher_algo, unsigned cipher_key_len,
                enum rte_crypto_auth_algorithm auth_algo)
 {
+       struct crypto_testsuite_params *ts_params = &testsuite_params;
        struct rte_crypto_sym_xform cipher_xform = {0};
        struct rte_crypto_sym_xform auth_xform = {0};
 
@@ -2735,37 +2786,47 @@ test_perf_create_snow3g_session(uint8_t dev_id, enum chain_mode chain,
        auth_xform.auth.iv.offset = IV_OFFSET + SNOW3G_CIPHER_IV_LENGTH;
        auth_xform.auth.iv.length = SNOW3G_CIPHER_IV_LENGTH;
 
+       test_crypto_session = rte_cryptodev_sym_session_create(ts_params->sess_mp);
        switch (chain) {
        case CIPHER_HASH:
                cipher_xform.next = &auth_xform;
                auth_xform.next = NULL;
                /* Create Crypto session*/
-               return rte_cryptodev_sym_session_create(dev_id, &cipher_xform);
+               return rte_cryptodev_sym_session_init(dev_id,
+                               test_crypto_session, &cipher_xform,
+                               ts_params->sess_mp);
        case HASH_CIPHER:
                auth_xform.next = &cipher_xform;
                cipher_xform.next = NULL;
                /* Create Crypto session*/
-               return rte_cryptodev_sym_session_create(dev_id, &auth_xform);
+               return rte_cryptodev_sym_session_init(dev_id,
+                               test_crypto_session, &auth_xform,
+                               ts_params->sess_mp);
        case CIPHER_ONLY:
                cipher_xform.next = NULL;
                /* Create Crypto session*/
-               return rte_cryptodev_sym_session_create(dev_id, &cipher_xform);
+               return rte_cryptodev_sym_session_init(dev_id,
+                               test_crypto_session, &cipher_xform,
+                               ts_params->sess_mp);
        case HASH_ONLY:
                auth_xform.next = NULL;
                /* Create Crypto session */
-               return rte_cryptodev_sym_session_create(dev_id, &auth_xform);
+               return rte_cryptodev_sym_session_init(dev_id,
+                               test_crypto_session, &auth_xform,
+                               ts_params->sess_mp);
        default:
-               return NULL;
+               return -1;
        }
 }
 
-static struct rte_cryptodev_sym_session *
+static int
 test_perf_create_openssl_session(uint8_t dev_id, enum chain_mode chain,
                enum rte_crypto_cipher_algorithm cipher_algo,
                unsigned int key_len,
                enum rte_crypto_auth_algorithm auth_algo,
                enum rte_crypto_aead_algorithm aead_algo)
 {
+       struct crypto_testsuite_params *ts_params = &testsuite_params;
        struct rte_crypto_sym_xform cipher_xform = { 0 };
        struct rte_crypto_sym_xform auth_xform = { 0 };
        struct rte_crypto_sym_xform aead_xform = { 0 };
@@ -2789,7 +2850,7 @@ test_perf_create_openssl_session(uint8_t dev_id, enum chain_mode chain,
                        cipher_xform.cipher.iv.length = AES_CIPHER_IV_LENGTH;
                        break;
                default:
-                       return NULL;
+                       return -1;
                }
 
                cipher_xform.cipher.key.length = key_len;
@@ -2804,7 +2865,7 @@ test_perf_create_openssl_session(uint8_t dev_id, enum chain_mode chain,
                        auth_xform.auth.key.data = hmac_sha_key;
                        break;
                default:
-                       return NULL;
+                       return -1;
                }
 
                auth_xform.auth.key.length =  get_auth_key_max_length(auth_algo);
@@ -2824,37 +2885,45 @@ test_perf_create_openssl_session(uint8_t dev_id, enum chain_mode chain,
                        aead_xform.aead.digest_length = get_aead_digest_length(aead_algo);
                        break;
                default:
-                       return NULL;
+                       return -1;
                }
 
                aead_xform.aead.key.length = key_len;
        }
 
+       test_crypto_session = rte_cryptodev_sym_session_create(ts_params->sess_mp);
        switch (chain) {
        case CIPHER_HASH:
                cipher_xform.next = &auth_xform;
                auth_xform.next = NULL;
                /* Create Crypto session*/
-               return rte_cryptodev_sym_session_create(dev_id, &cipher_xform);
+               return rte_cryptodev_sym_session_init(dev_id,
+                               test_crypto_session, &cipher_xform,
+                               ts_params->sess_mp);
        case HASH_CIPHER:
                auth_xform.next = &cipher_xform;
                cipher_xform.next = NULL;
                /* Create Crypto session*/
-               return rte_cryptodev_sym_session_create(dev_id, &auth_xform);
+               return rte_cryptodev_sym_session_init(dev_id,
+                               test_crypto_session, &auth_xform,
+                               ts_params->sess_mp);
        case AEAD:
                /* Create Crypto session*/
-               return rte_cryptodev_sym_session_create(dev_id, &aead_xform);
+               return rte_cryptodev_sym_session_init(dev_id,
+                               test_crypto_session, &aead_xform,
+                               ts_params->sess_mp);
        default:
-               return NULL;
+               return -1;
        }
 }
 
-static struct rte_cryptodev_sym_session *
+static int
 test_perf_create_armv8_session(uint8_t dev_id, enum chain_mode chain,
                enum rte_crypto_cipher_algorithm cipher_algo,
                unsigned int cipher_key_len,
                enum rte_crypto_auth_algorithm auth_algo)
 {
+       struct crypto_testsuite_params *ts_params = &testsuite_params;
        struct rte_crypto_sym_xform cipher_xform = { 0 };
        struct rte_crypto_sym_xform auth_xform = { 0 };
 
@@ -2867,7 +2936,7 @@ test_perf_create_armv8_session(uint8_t dev_id, enum chain_mode chain,
                cipher_xform.cipher.key.data = aes_cbc_128_key;
                break;
        default:
-               return NULL;
+               return -1;
        }
 
        cipher_xform.cipher.key.length = cipher_key_len;
@@ -2881,6 +2950,8 @@ test_perf_create_armv8_session(uint8_t dev_id, enum chain_mode chain,
 
        auth_xform.auth.digest_length = get_auth_digest_length(auth_algo);
 
+       test_crypto_session = rte_cryptodev_sym_session_create(ts_params->sess_mp);
+
        switch (chain) {
        case CIPHER_HASH:
                cipher_xform.next = &auth_xform;
@@ -2888,16 +2959,20 @@ test_perf_create_armv8_session(uint8_t dev_id, enum chain_mode chain,
                /* Encrypt and hash the result */
                cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
                /* Create Crypto session*/
-               return rte_cryptodev_sym_session_create(dev_id, &cipher_xform);
+               return rte_cryptodev_sym_session_init(dev_id,
+                               test_crypto_session, &cipher_xform,
+                               ts_params->sess_mp);
        case HASH_CIPHER:
                auth_xform.next = &cipher_xform;
                cipher_xform.next = NULL;
                /* Hash encrypted message and decrypt */
                cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
                /* Create Crypto session*/
-               return rte_cryptodev_sym_session_create(dev_id, &auth_xform);
+               return rte_cryptodev_sym_session_init(dev_id,
+                               test_crypto_session, &auth_xform,
+                               ts_params->sess_mp);
        default:
-               return NULL;
+               return -1;
        }
 }
 
@@ -3147,9 +3222,12 @@ test_perf_aes_sha(uint8_t dev_id, uint16_t queue_id,
        }
 
        /* Create Crypto session*/
-       sess = test_perf_create_aes_sha_session(ts_params->dev_id,
+       if (test_perf_create_aes_sha_session(ts_params->dev_id,
                        pparams->chain, pparams->cipher_algo,
-                       pparams->key_length, pparams->auth_algo);
+                       pparams->key_length, pparams->auth_algo) == 0)
+               sess = test_crypto_session;
+       else
+               sess = NULL;
        TEST_ASSERT_NOT_NULL(sess, "Session creation failed");
 
        /* Generate a burst of crypto operations */
@@ -3244,7 +3322,9 @@ test_perf_aes_sha(uint8_t dev_id, uint16_t queue_id,
 
        for (i = 0; i < pparams->burst_size * NUM_MBUF_SETS; i++)
                rte_pktmbuf_free(mbufs[i]);
-       rte_cryptodev_sym_session_free(dev_id, sess);
+
+       rte_cryptodev_sym_session_clear(ts_params->dev_id, sess);
+       rte_cryptodev_sym_session_free(sess);
 
        printf("\n");
        return TEST_SUCCESS;
@@ -3280,9 +3360,12 @@ test_perf_snow3g(uint8_t dev_id, uint16_t queue_id,
        }
 
        /* Create Crypto session*/
-       sess = test_perf_create_snow3g_session(ts_params->dev_id,
+       if (test_perf_create_snow3g_session(ts_params->dev_id,
                        pparams->chain, pparams->cipher_algo,
-                       pparams->key_length, pparams->auth_algo);
+                       pparams->key_length, pparams->auth_algo) == 0)
+               sess = test_crypto_session;
+       else
+               sess = NULL;
        TEST_ASSERT_NOT_NULL(sess, "Session creation failed");
 
        /* Generate a burst of crypto operations */
@@ -3409,7 +3492,9 @@ test_perf_snow3g(uint8_t dev_id, uint16_t queue_id,
 
        for (i = 0; i < pparams->burst_size * NUM_MBUF_SETS; i++)
                rte_pktmbuf_free(mbufs[i]);
-       rte_cryptodev_sym_session_free(dev_id, sess);
+
+       rte_cryptodev_sym_session_clear(ts_params->dev_id, sess);
+       rte_cryptodev_sym_session_free(sess);
 
        printf("\n");
        return TEST_SUCCESS;
@@ -3466,10 +3551,13 @@ test_perf_openssl(uint8_t dev_id, uint16_t queue_id,
        }
 
        /* Create Crypto session*/
-       sess = test_perf_create_openssl_session(ts_params->dev_id,
+       if (test_perf_create_openssl_session(ts_params->dev_id,
                        pparams->chain, pparams->cipher_algo,
                        pparams->key_length, pparams->auth_algo,
-                       pparams->aead_algo);
+                       pparams->aead_algo) == 0)
+               sess = test_crypto_session;
+       else
+               sess = NULL;
        TEST_ASSERT_NOT_NULL(sess, "Session creation failed");
 
        /* Generate a burst of crypto operations */
@@ -3562,7 +3650,9 @@ test_perf_openssl(uint8_t dev_id, uint16_t queue_id,
 
        for (i = 0; i < pparams->burst_size * NUM_MBUF_SETS; i++)
                rte_pktmbuf_free(mbufs[i]);
-       rte_cryptodev_sym_session_free(dev_id, sess);
+
+       rte_cryptodev_sym_session_clear(ts_params->dev_id, sess);
+       rte_cryptodev_sym_session_free(sess);
 
        printf("\n");
        return TEST_SUCCESS;
@@ -3597,9 +3687,12 @@ test_perf_armv8(uint8_t dev_id, uint16_t queue_id,
        }
 
        /* Create Crypto session*/
-       sess = test_perf_create_armv8_session(ts_params->dev_id,
+       if (test_perf_create_armv8_session(ts_params->dev_id,
                        pparams->chain, pparams->cipher_algo,
-                       pparams->key_length, pparams->auth_algo);
+                       pparams->key_length, pparams->auth_algo) == 0)
+               sess = test_crypto_session;
+       else
+               sess = NULL;
        TEST_ASSERT_NOT_NULL(sess, "Session creation failed");
 
        /* Generate a burst of crypto operations */
@@ -4157,7 +4250,7 @@ test_perf_aes_cbc_vary_burst_size(void)
 static struct rte_cryptodev_sym_session *
 test_perf_create_session(uint8_t dev_id, struct perf_test_params *pparams)
 {
-       static struct rte_cryptodev_sym_session *sess;
+       struct crypto_testsuite_params *ts_params = &testsuite_params;
        struct rte_crypto_sym_xform aead_xform = { 0 };
 
        uint8_t aead_key[pparams->session_attrs->key_aead_len];
@@ -4177,9 +4270,12 @@ test_perf_create_session(uint8_t dev_id, struct perf_test_params *pparams)
        aead_xform.aead.add_auth_data_length = pparams->session_attrs->aad_len;
        aead_xform.aead.digest_length = pparams->session_attrs->digest_len;
 
-       sess = rte_cryptodev_sym_session_create(dev_id, &aead_xform);
+       test_crypto_session = rte_cryptodev_sym_session_create(ts_params->sess_mp);
+
+       rte_cryptodev_sym_session_init(dev_id, test_crypto_session,
+                               &aead_xform, ts_params->sess_mp);
 
-       return sess;
+       return test_crypto_session;
 }
 
 static inline struct rte_crypto_op *
@@ -4398,7 +4494,9 @@ perf_AES_GCM(uint8_t dev_id, uint16_t queue_id,
 
        for (i = 0; i < burst; i++)
                rte_pktmbuf_free(mbufs[i]);
-       rte_cryptodev_sym_session_free(dev_id, sess);
+
+       rte_cryptodev_sym_session_clear(ts_params->dev_id, sess);
+       rte_cryptodev_sym_session_free(sess);
 
        return 0;
 }