app/crypto-perf: support multiple queue pairs
authorPablo de Lara <pablo.de.lara.guarch@intel.com>
Wed, 4 Oct 2017 03:46:12 +0000 (04:46 +0100)
committerPablo de Lara <pablo.de.lara.guarch@intel.com>
Thu, 12 Oct 2017 14:14:45 +0000 (15:14 +0100)
Add support for multiple queue pairs, when there are
more logical cores available than crypto devices enabled.
For instance, if there are 4 cores available and
2 crypto devices, each device will have two queue pairs.

This is useful to have multiple logical cores using
a single crypto device, without needing to initialize
a crypto device per core.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
Acked-by: Akhil Goyal <akhil.goyal@nxp.com>
app/test-crypto-perf/Makefile
app/test-crypto-perf/cperf_options.h
app/test-crypto-perf/cperf_options_parsing.c
app/test-crypto-perf/cperf_test_common.c
app/test-crypto-perf/cperf_test_common.h
app/test-crypto-perf/cperf_test_latency.c
app/test-crypto-perf/cperf_test_pmd_cyclecount.c
app/test-crypto-perf/cperf_test_throughput.c
app/test-crypto-perf/cperf_test_verify.c
app/test-crypto-perf/main.c

index 25ae395..c75d7ed 100644 (file)
@@ -47,4 +47,8 @@ SRCS-y += cperf_test_verify.c
 SRCS-y += cperf_test_vector_parsing.c
 SRCS-y += cperf_test_common.c
 
+ifeq ($(CONFIG_RTE_LIBRTE_PMD_CRYPTO_SCHEDULER),y)
+LDLIBS += -lrte_pmd_crypto_scheduler
+endif
+
 include $(RTE_SDK)/mk/rte.app.mk
index 6d339f4..da4fb47 100644 (file)
@@ -74,6 +74,7 @@ struct cperf_options {
        uint32_t segment_sz;
        uint32_t test_buffer_size;
        uint32_t nb_descriptors;
+       uint16_t nb_qps;
 
        uint32_t sessionless:1;
        uint32_t out_of_place:1;
index 3974c81..72c515a 100644 (file)
@@ -747,6 +747,7 @@ cperf_options_default(struct cperf_options *opts)
 
        strncpy(opts->device_type, "crypto_aesni_mb",
                        sizeof(opts->device_type));
+       opts->nb_qps = 1;
 
        opts->op_type = CPERF_CIPHER_THEN_AUTH;
 
@@ -1044,6 +1045,7 @@ cperf_options_dump(struct cperf_options *opts)
        printf("#\n");
        printf("# cryptodev type: %s\n", opts->device_type);
        printf("#\n");
+       printf("# number of queue pairs per device: %u\n", opts->nb_qps);
        printf("# crypto operation: %s\n", cperf_op_type_strs[opts->op_type]);
        printf("# sessionless: %s\n", opts->sessionless ? "yes" : "no");
        printf("# out of place: %s\n", opts->out_of_place ? "yes" : "no");
index 25eb970..65f0be7 100644 (file)
@@ -108,7 +108,8 @@ error:
 int
 cperf_alloc_common_memory(const struct cperf_options *options,
                        const struct cperf_test_vector *test_vector,
-                       uint8_t dev_id, size_t extra_op_priv_size,
+                       uint8_t dev_id, uint16_t qp_id,
+                       size_t extra_op_priv_size,
                        struct rte_mempool **pkt_mbuf_pool_in,
                        struct rte_mempool **pkt_mbuf_pool_out,
                        struct rte_mbuf ***mbufs_in,
@@ -118,8 +119,8 @@ cperf_alloc_common_memory(const struct cperf_options *options,
        unsigned int mbuf_idx = 0;
        char pool_name[32] = "";
 
-       snprintf(pool_name, sizeof(pool_name), "cperf_pool_in_cdev_%d",
-                       dev_id);
+       snprintf(pool_name, sizeof(pool_name), "cperf_pool_in_cdev_%u_qp_%u",
+                       dev_id, qp_id);
 
        uint32_t max_size = options->max_buffer_size + options->digest_sz;
        uint16_t segments_nb = (max_size % options->segment_sz) ?
@@ -153,8 +154,8 @@ cperf_alloc_common_memory(const struct cperf_options *options,
                        options->pool_sz), 0);
 
        if (options->out_of_place == 1) {
-               snprintf(pool_name, sizeof(pool_name), "cperf_pool_out_cdev_%d",
-                               dev_id);
+               snprintf(pool_name, sizeof(pool_name), "cperf_pool_out_cdev_%u_qp_%u",
+                               dev_id, qp_id);
 
                *pkt_mbuf_pool_out = rte_pktmbuf_pool_create(
                                pool_name, options->pool_sz, 0, 0,
@@ -173,8 +174,8 @@ cperf_alloc_common_memory(const struct cperf_options *options,
                }
        }
 
-       snprintf(pool_name, sizeof(pool_name), "cperf_op_pool_cdev_%d",
-                       dev_id);
+       snprintf(pool_name, sizeof(pool_name), "cperf_op_pool_cdev_%u_qp_%u",
+                       dev_id, qp_id);
 
        uint16_t priv_size = RTE_ALIGN_CEIL(test_vector->cipher_iv.length +
                test_vector->auth_iv.length + test_vector->aead_iv.length +
index 766d643..ad29431 100644 (file)
@@ -43,7 +43,8 @@
 int
 cperf_alloc_common_memory(const struct cperf_options *options,
                        const struct cperf_test_vector *test_vector,
-                       uint8_t dev_id, size_t extra_op_priv_size,
+                       uint8_t dev_id, uint16_t qp_id,
+                       size_t extra_op_priv_size,
                        struct rte_mempool **pkt_mbuf_pool_in,
                        struct rte_mempool **pkt_mbuf_pool_out,
                        struct rte_mbuf ***mbufs_in,
index 2dc9c0c..313665e 100644 (file)
@@ -124,7 +124,7 @@ cperf_latency_test_constructor(struct rte_mempool *sess_mp,
        if (ctx->sess == NULL)
                goto err;
 
-       if (cperf_alloc_common_memory(options, test_vector, dev_id,
+       if (cperf_alloc_common_memory(options, test_vector, dev_id, qp_id,
                        extra_op_priv_size,
                        &ctx->pkt_mbuf_pool_in, &ctx->pkt_mbuf_pool_out,
                        &ctx->mbufs_in, &ctx->mbufs_out,
@@ -417,7 +417,5 @@ cperf_latency_test_destructor(void *arg)
        if (ctx == NULL)
                return;
 
-       rte_cryptodev_stop(ctx->dev_id);
-
        cperf_latency_test_free(ctx);
 }
index 81f403c..13a270f 100644 (file)
@@ -143,7 +143,7 @@ cperf_pmd_cyclecount_test_constructor(struct rte_mempool *sess_mp,
        if (ctx->sess == NULL)
                goto err;
 
-       if (cperf_alloc_common_memory(options, test_vector, dev_id, 0,
+       if (cperf_alloc_common_memory(options, test_vector, dev_id, qp_id, 0,
                        &ctx->pkt_mbuf_pool_in, &ctx->pkt_mbuf_pool_out,
                        &ctx->mbufs_in, &ctx->mbufs_out,
                        &ctx->crypto_op_pool) < 0)
index 8d54642..bc7d889 100644 (file)
@@ -107,7 +107,7 @@ cperf_throughput_test_constructor(struct rte_mempool *sess_mp,
        if (ctx->sess == NULL)
                goto err;
 
-       if (cperf_alloc_common_memory(options, test_vector, dev_id, 0,
+       if (cperf_alloc_common_memory(options, test_vector, dev_id, qp_id, 0,
                        &ctx->pkt_mbuf_pool_in, &ctx->pkt_mbuf_pool_out,
                        &ctx->mbufs_in, &ctx->mbufs_out,
                        &ctx->crypto_op_pool) < 0)
@@ -368,7 +368,5 @@ cperf_throughput_test_destructor(void *arg)
        if (ctx == NULL)
                return;
 
-       rte_cryptodev_stop(ctx->dev_id);
-
        cperf_throughput_test_free(ctx);
 }
index c57d672..2b6f3b4 100644 (file)
@@ -111,7 +111,7 @@ cperf_verify_test_constructor(struct rte_mempool *sess_mp,
        if (ctx->sess == NULL)
                goto err;
 
-       if (cperf_alloc_common_memory(options, test_vector, dev_id, 0,
+       if (cperf_alloc_common_memory(options, test_vector, dev_id, qp_id, 0,
                        &ctx->pkt_mbuf_pool_in, &ctx->pkt_mbuf_pool_out,
                        &ctx->mbufs_in, &ctx->mbufs_out,
                        &ctx->crypto_op_pool) < 0)
@@ -469,7 +469,5 @@ cperf_verify_test_destructor(void *arg)
        if (ctx == NULL)
                return;
 
-       rte_cryptodev_stop(ctx->dev_id);
-
        cperf_verify_test_free(ctx);
 }
index ffa7180..aaa5830 100644 (file)
@@ -35,6 +35,9 @@
 
 #include <rte_eal.h>
 #include <rte_cryptodev.h>
+#ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
+#include <rte_cryptodev_scheduler.h>
+#endif
 
 #include "cperf.h"
 #include "cperf_options.h"
@@ -90,7 +93,7 @@ cperf_initialize_cryptodev(struct cperf_options *opts, uint8_t *enabled_cdevs,
                        struct rte_mempool *session_pool_socket[])
 {
        uint8_t enabled_cdev_count = 0, nb_lcores, cdev_id;
-       unsigned int i;
+       unsigned int i, j;
        int ret;
 
        enabled_cdev_count = rte_cryptodev_devices_get(opts->device_type,
@@ -119,21 +122,53 @@ cperf_initialize_cryptodev(struct cperf_options *opts, uint8_t *enabled_cdevs,
                        max_sess_size = sess_size;
        }
 
+       /*
+        * Calculate number of needed queue pairs, based on the amount
+        * of available number of logical cores and crypto devices.
+        * For instance, if there are 4 cores and 2 crypto devices,
+        * 2 queue pairs will be set up per device.
+        */
+       opts->nb_qps = (nb_lcores % enabled_cdev_count) ?
+                               (nb_lcores / enabled_cdev_count) + 1 :
+                               nb_lcores / enabled_cdev_count;
+
        for (i = 0; i < enabled_cdev_count &&
                        i < RTE_CRYPTO_MAX_DEVS; i++) {
                cdev_id = enabled_cdevs[i];
+#ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
+               /*
+                * If multi-core scheduler is used, limit the number
+                * of queue pairs to 1, as there is no way to know
+                * how many cores are being used by the PMD, and
+                * how many will be available for the application.
+                */
+               if (!strcmp((const char *)opts->device_type, "crypto_scheduler") &&
+                               rte_cryptodev_scheduler_mode_get(cdev_id) ==
+                               CDEV_SCHED_MODE_MULTICORE)
+                       opts->nb_qps = 1;
+#endif
+
+               struct rte_cryptodev_info cdev_info;
                uint8_t socket_id = rte_cryptodev_socket_id(cdev_id);
 
+               rte_cryptodev_info_get(cdev_id, &cdev_info);
+               if (opts->nb_qps > cdev_info.max_nb_queue_pairs) {
+                       printf("Number of needed queue pairs is higher "
+                               "than the maximum number of queue pairs "
+                               "per device.\n");
+                       printf("Lower the number of cores or increase "
+                               "the number of crypto devices\n");
+                       return -EINVAL;
+               }
                struct rte_cryptodev_config conf = {
-                               .nb_queue_pairs = 1,
-                               .socket_id = socket_id
+                       .nb_queue_pairs = opts->nb_qps,
+                       .socket_id = socket_id
                };
 
                struct rte_cryptodev_qp_conf qp_conf = {
-                           .nb_descriptors = opts->nb_descriptors
+                       .nb_descriptors = opts->nb_descriptors
                };
 
-
                if (session_pool_socket[socket_id] == NULL) {
                        char mp_name[RTE_MEMPOOL_NAMESIZE];
                        struct rte_mempool *sess_mp;
@@ -165,14 +200,16 @@ cperf_initialize_cryptodev(struct cperf_options *opts, uint8_t *enabled_cdevs,
                        return -EINVAL;
                }
 
-               ret = rte_cryptodev_queue_pair_setup(cdev_id, 0,
+               for (j = 0; j < opts->nb_qps; j++) {
+                       ret = rte_cryptodev_queue_pair_setup(cdev_id, j,
                                &qp_conf, socket_id,
                                session_pool_socket[socket_id]);
                        if (ret < 0) {
                                printf("Failed to setup queue pair %u on "
-                                       "cryptodev %u", 0, cdev_id);
+                                       "cryptodev %u", j, cdev_id);
                                return -EINVAL;
                        }
+               }
 
                ret = rte_cryptodev_start(cdev_id);
                if (ret < 0) {
@@ -417,11 +454,12 @@ main(int argc, char **argv)
                goto err;
        }
 
+       nb_cryptodevs = cperf_initialize_cryptodev(&opts, enabled_cdevs,
+                       session_pool_socket);
+
        if (!opts.silent)
                cperf_options_dump(&opts);
 
-       nb_cryptodevs = cperf_initialize_cryptodev(&opts, enabled_cdevs,
-                       session_pool_socket);
        if (nb_cryptodevs < 1) {
                RTE_LOG(ERR, USER1, "Failed to initialise requested crypto "
                                "device type\n");
@@ -471,23 +509,29 @@ main(int argc, char **argv)
        if (!opts.silent)
                show_test_vector(t_vec);
 
+       uint16_t total_nb_qps = nb_cryptodevs * opts.nb_qps;
+
        i = 0;
+       uint8_t qp_id = 0, cdev_index = 0;
        RTE_LCORE_FOREACH_SLAVE(lcore_id) {
 
-               if (i == nb_cryptodevs)
+               if (i == total_nb_qps)
                        break;
 
-               cdev_id = enabled_cdevs[i];
+               cdev_id = enabled_cdevs[cdev_index];
 
                uint8_t socket_id = rte_cryptodev_socket_id(cdev_id);
 
-               ctx[cdev_id] = cperf_testmap[opts.test].constructor(
-                               session_pool_socket[socket_id], cdev_id, 0,
+               ctx[i] = cperf_testmap[opts.test].constructor(
+                               session_pool_socket[socket_id], cdev_id, qp_id,
                                &opts, t_vec, &op_fns);
-               if (ctx[cdev_id] == NULL) {
+               if (ctx[i] == NULL) {
                        RTE_LOG(ERR, USER1, "Test run constructor failed\n");
                        goto err;
                }
+               qp_id = (qp_id + 1) % opts.nb_qps;
+               if (qp_id == 0)
+                       cdev_index++;
                i++;
        }
 
@@ -501,19 +545,17 @@ main(int argc, char **argv)
                i = 0;
                RTE_LCORE_FOREACH_SLAVE(lcore_id) {
 
-                       if (i == nb_cryptodevs)
+                       if (i == total_nb_qps)
                                break;
 
-                       cdev_id = enabled_cdevs[i];
-
                        rte_eal_remote_launch(cperf_testmap[opts.test].runner,
-                               ctx[cdev_id], lcore_id);
+                               ctx[i], lcore_id);
                        i++;
                }
                i = 0;
                RTE_LCORE_FOREACH_SLAVE(lcore_id) {
 
-                       if (i == nb_cryptodevs)
+                       if (i == total_nb_qps)
                                break;
                        rte_eal_wait_lcore(lcore_id);
                        i++;
@@ -532,15 +574,17 @@ main(int argc, char **argv)
        i = 0;
        RTE_LCORE_FOREACH_SLAVE(lcore_id) {
 
-               if (i == nb_cryptodevs)
+               if (i == total_nb_qps)
                        break;
 
-               cdev_id = enabled_cdevs[i];
-
-               cperf_testmap[opts.test].destructor(ctx[cdev_id]);
+               cperf_testmap[opts.test].destructor(ctx[i]);
                i++;
        }
 
+       for (i = 0; i < nb_cryptodevs &&
+                       i < RTE_CRYPTO_MAX_DEVS; i++)
+               rte_cryptodev_stop(enabled_cdevs[i]);
+
        free_test_vector(t_vec, &opts);
 
        printf("\n");
@@ -549,16 +593,20 @@ main(int argc, char **argv)
 err:
        i = 0;
        RTE_LCORE_FOREACH_SLAVE(lcore_id) {
-               if (i == nb_cryptodevs)
+               if (i == total_nb_qps)
                        break;
 
                cdev_id = enabled_cdevs[i];
 
-               if (ctx[cdev_id] && cperf_testmap[opts.test].destructor)
-                       cperf_testmap[opts.test].destructor(ctx[cdev_id]);
+               if (ctx[i] && cperf_testmap[opts.test].destructor)
+                       cperf_testmap[opts.test].destructor(ctx[i]);
                i++;
        }
 
+       for (i = 0; i < nb_cryptodevs &&
+                       i < RTE_CRYPTO_MAX_DEVS; i++)
+               rte_cryptodev_stop(enabled_cdevs[i]);
+
        free_test_vector(t_vec, &opts);
 
        printf("\n");