doc: add vDPA features table
[dpdk.git] / app / test-crypto-perf / cperf_test_pmd_cyclecount.c
index 0c949f0..74371fa 100644 (file)
@@ -1,33 +1,5 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) 2017 Intel Corporation. All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2017 Intel Corporation
  */
 
 #include <stdbool.h>
 
 #include "cperf_ops.h"
 #include "cperf_test_pmd_cyclecount.h"
+#include "cperf_test_common.h"
 
 #define PRETTY_HDR_FMT "%12s%12s%12s%12s%12s%12s%12s%12s%12s%12s\n\n"
 #define PRETTY_LINE_FMT "%12u%12u%12u%12u%12u%12u%12u%12.0f%12.0f%12.0f\n"
 #define CSV_HDR_FMT "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n"
-#define CSV_LINE_FMT "%10u;%10u;%u;%u;%u;%u;%u;%.f3;%.f3;%.f3\n"
+#define CSV_LINE_FMT "%10u;%10u;%u;%u;%u;%u;%u;%.3f;%.3f;%.3f\n"
 
 struct cperf_pmd_cyclecount_ctx {
        uint8_t dev_id;
        uint16_t qp_id;
        uint8_t lcore_id;
 
-       struct rte_mempool *pkt_mbuf_pool_in;
-       struct rte_mempool *pkt_mbuf_pool_out;
-       struct rte_mbuf **mbufs_in;
-       struct rte_mbuf **mbufs_out;
-
-       struct rte_mempool *crypto_op_pool;
+       struct rte_mempool *pool;
        struct rte_crypto_op **ops;
        struct rte_crypto_op **ops_processed;
 
@@ -63,6 +31,9 @@ struct cperf_pmd_cyclecount_ctx {
 
        cperf_populate_ops_t populate_ops;
 
+       uint32_t src_buf_offset;
+       uint32_t dst_buf_offset;
+
        const struct cperf_options *options;
        const struct cperf_test_vector *test_vector;
 };
@@ -86,38 +57,16 @@ static const uint16_t iv_offset =
                sizeof(struct rte_crypto_op) + sizeof(struct rte_crypto_sym_op);
 
 static void
-cperf_pmd_cyclecount_test_free(struct cperf_pmd_cyclecount_ctx *ctx,
-               uint32_t mbuf_nb)
+cperf_pmd_cyclecount_test_free(struct cperf_pmd_cyclecount_ctx *ctx)
 {
-       uint32_t i;
-
        if (ctx) {
                if (ctx->sess) {
                        rte_cryptodev_sym_session_clear(ctx->dev_id, ctx->sess);
                        rte_cryptodev_sym_session_free(ctx->sess);
                }
 
-               if (ctx->mbufs_in) {
-                       for (i = 0; i < mbuf_nb; i++)
-                               rte_pktmbuf_free(ctx->mbufs_in[i]);
-
-                       rte_free(ctx->mbufs_in);
-               }
-
-               if (ctx->mbufs_out) {
-                       for (i = 0; i < mbuf_nb; i++) {
-                               if (ctx->mbufs_out[i] != NULL)
-                                       rte_pktmbuf_free(ctx->mbufs_out[i]);
-                       }
-
-                       rte_free(ctx->mbufs_out);
-               }
-
-               if (ctx->pkt_mbuf_pool_in)
-                       rte_mempool_free(ctx->pkt_mbuf_pool_in);
-
-               if (ctx->pkt_mbuf_pool_out)
-                       rte_mempool_free(ctx->pkt_mbuf_pool_out);
+               if (ctx->pool)
+                       rte_mempool_free(ctx->pool);
 
                if (ctx->ops)
                        rte_free(ctx->ops);
@@ -125,107 +74,19 @@ cperf_pmd_cyclecount_test_free(struct cperf_pmd_cyclecount_ctx *ctx,
                if (ctx->ops_processed)
                        rte_free(ctx->ops_processed);
 
-               if (ctx->crypto_op_pool)
-                       rte_mempool_free(ctx->crypto_op_pool);
-
                rte_free(ctx);
        }
 }
 
-static struct rte_mbuf *
-cperf_mbuf_create(struct rte_mempool *mempool, uint32_t segments_nb,
-               const struct cperf_options *options,
-               const struct cperf_test_vector *test_vector)
-{
-       struct rte_mbuf *mbuf;
-       uint32_t segment_sz = options->max_buffer_size / segments_nb;
-       uint32_t last_sz = options->max_buffer_size % segments_nb;
-       uint8_t *mbuf_data;
-       uint8_t *test_data =
-                       (options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
-                       test_vector->plaintext.data :
-                       test_vector->ciphertext.data;
-
-       mbuf = rte_pktmbuf_alloc(mempool);
-       if (mbuf == NULL)
-               goto error;
-
-       mbuf_data = (uint8_t *)rte_pktmbuf_append(mbuf, segment_sz);
-       if (mbuf_data == NULL)
-               goto error;
-
-       memcpy(mbuf_data, test_data, segment_sz);
-       test_data += segment_sz;
-       segments_nb--;
-
-       while (segments_nb) {
-               struct rte_mbuf *m;
-
-               m = rte_pktmbuf_alloc(mempool);
-               if (m == NULL)
-                       goto error;
-
-               rte_pktmbuf_chain(mbuf, m);
-
-               mbuf_data = (uint8_t *)rte_pktmbuf_append(mbuf, segment_sz);
-               if (mbuf_data == NULL)
-                       goto error;
-
-               memcpy(mbuf_data, test_data, segment_sz);
-               test_data += segment_sz;
-               segments_nb--;
-       }
-
-       if (last_sz) {
-               mbuf_data = (uint8_t *)rte_pktmbuf_append(mbuf, last_sz);
-               if (mbuf_data == NULL)
-                       goto error;
-
-               memcpy(mbuf_data, test_data, last_sz);
-       }
-
-       if (options->op_type != CPERF_CIPHER_ONLY) {
-               mbuf_data = (uint8_t *)rte_pktmbuf_append(
-                               mbuf, options->digest_sz);
-               if (mbuf_data == NULL)
-                       goto error;
-       }
-
-       if (options->op_type == CPERF_AEAD) {
-               uint8_t *aead = (uint8_t *)rte_pktmbuf_prepend(
-                               mbuf, RTE_ALIGN_CEIL(options->aead_aad_sz, 16));
-
-               if (aead == NULL)
-                       goto error;
-
-               memcpy(aead, test_vector->aad.data, test_vector->aad.length);
-       }
-
-       return mbuf;
-error:
-       if (mbuf != NULL)
-               rte_pktmbuf_free(mbuf);
-
-       return NULL;
-}
-
 void *
 cperf_pmd_cyclecount_test_constructor(struct rte_mempool *sess_mp,
+               struct rte_mempool *sess_priv_mp,
                uint8_t dev_id, uint16_t qp_id,
                const struct cperf_options *options,
                const struct cperf_test_vector *test_vector,
                const struct cperf_op_fns *op_fns)
 {
        struct cperf_pmd_cyclecount_ctx *ctx = NULL;
-       unsigned int mbuf_idx = 0;
-       char pool_name[32] = "";
-       uint16_t dataroom_sz = RTE_PKTMBUF_HEADROOM +
-                       RTE_CACHE_LINE_ROUNDUP(
-                                       (options->max_buffer_size /
-                                                       options->segments_nb) +
-                                       (options->max_buffer_size %
-                                                       options->segments_nb) +
-                                       options->digest_sz);
 
        /* preallocate buffers for crypto ops as they can get quite big */
        size_t alloc_sz = sizeof(struct rte_crypto_op *) *
@@ -246,69 +107,14 @@ cperf_pmd_cyclecount_test_constructor(struct rte_mempool *sess_mp,
        uint16_t iv_offset = sizeof(struct rte_crypto_op) +
                        sizeof(struct rte_crypto_sym_op);
 
-       ctx->sess = op_fns->sess_create(
-                       sess_mp, dev_id, options, test_vector, iv_offset);
+       ctx->sess = op_fns->sess_create(sess_mp, sess_priv_mp, dev_id, options,
+                       test_vector, iv_offset);
        if (ctx->sess == NULL)
                goto err;
 
-       snprintf(pool_name, sizeof(pool_name), "cperf_pool_in_cdev_%d", dev_id);
-
-       ctx->pkt_mbuf_pool_in = rte_pktmbuf_pool_create(pool_name,
-                       options->pool_sz * options->segments_nb, 0, 0,
-                       dataroom_sz, rte_socket_id());
-
-       if (ctx->pkt_mbuf_pool_in == NULL)
-               goto err;
-
-       /* Generate mbufs_in with plaintext populated for test */
-       ctx->mbufs_in = rte_malloc(NULL,
-                       (sizeof(struct rte_mbuf *) * options->pool_sz), 0);
-
-       for (mbuf_idx = 0; mbuf_idx < options->pool_sz; mbuf_idx++) {
-               ctx->mbufs_in[mbuf_idx] = cperf_mbuf_create(
-                               ctx->pkt_mbuf_pool_in, options->segments_nb,
-                               options, test_vector);
-               if (ctx->mbufs_in[mbuf_idx] == NULL)
-                       goto err;
-       }
-
-       if (options->out_of_place == 1) {
-               snprintf(pool_name, sizeof(pool_name), "cperf_pool_out_cdev_%d",
-                               dev_id);
-
-               ctx->pkt_mbuf_pool_out = rte_pktmbuf_pool_create(pool_name,
-                               options->pool_sz, 0, 0, dataroom_sz,
-                               rte_socket_id());
-
-               if (ctx->pkt_mbuf_pool_out == NULL)
-                       goto err;
-       }
-
-       ctx->mbufs_out = rte_malloc(NULL,
-                       (sizeof(struct rte_mbuf *) * options->pool_sz), 0);
-
-       for (mbuf_idx = 0; mbuf_idx < options->pool_sz; mbuf_idx++) {
-               if (options->out_of_place == 1) {
-                       ctx->mbufs_out[mbuf_idx] = cperf_mbuf_create(
-                                       ctx->pkt_mbuf_pool_out, 1, options,
-                                       test_vector);
-                       if (ctx->mbufs_out[mbuf_idx] == NULL)
-                               goto err;
-               } else {
-                       ctx->mbufs_out[mbuf_idx] = NULL;
-               }
-       }
-
-       snprintf(pool_name, sizeof(pool_name), "cperf_op_pool_cdev_%d", dev_id);
-
-       uint16_t priv_size = test_vector->cipher_iv.length +
-                       test_vector->auth_iv.length +
-                       test_vector->aead_iv.length;
-
-       ctx->crypto_op_pool = rte_crypto_op_pool_create(pool_name,
-                       RTE_CRYPTO_OP_TYPE_SYMMETRIC, options->pool_sz, 512,
-                       priv_size, rte_socket_id());
-       if (ctx->crypto_op_pool == NULL)
+       if (cperf_alloc_common_memory(options, test_vector, dev_id, qp_id, 0,
+                       &ctx->src_buf_offset, &ctx->dst_buf_offset,
+                       &ctx->pool) < 0)
                goto err;
 
        ctx->ops = rte_malloc("ops", alloc_sz, 0);
@@ -322,7 +128,7 @@ cperf_pmd_cyclecount_test_constructor(struct rte_mempool *sess_mp,
        return ctx;
 
 err:
-       cperf_pmd_cyclecount_test_free(ctx, mbuf_idx);
+       cperf_pmd_cyclecount_test_free(ctx);
 
        return NULL;
 }
@@ -336,25 +142,33 @@ pmd_cyclecount_bench_ops(struct pmd_cyclecount_state *state, uint32_t cur_op,
        uint32_t iter_ops_needed =
                        RTE_MIN(state->opts->nb_descriptors, iter_ops_left);
        uint32_t cur_iter_op;
+       uint32_t imix_idx = 0;
 
        for (cur_iter_op = 0; cur_iter_op < iter_ops_needed;
                        cur_iter_op += test_burst_size) {
-               uint32_t burst_size = RTE_MIN(state->opts->total_ops - cur_op,
+               uint32_t burst_size = RTE_MIN(iter_ops_needed - cur_iter_op,
                                test_burst_size);
                struct rte_crypto_op **ops = &state->ctx->ops[cur_iter_op];
 
-               if (burst_size != rte_crypto_op_bulk_alloc(
-                               state->ctx->crypto_op_pool,
-                               RTE_CRYPTO_OP_TYPE_SYMMETRIC,
-                               ops, burst_size))
-                       return -1;
+               /* Allocate objects containing crypto operations and mbufs */
+               if (rte_mempool_get_bulk(state->ctx->pool, (void **)ops,
+                                       burst_size) != 0) {
+                       RTE_LOG(ERR, USER1,
+                                       "Failed to allocate more crypto operations "
+                                       "from the crypto operation pool.\n"
+                                       "Consider increasing the pool size "
+                                       "with --pool-sz\n");
+                               return -1;
+               }
 
                /* Setup crypto op, attach mbuf etc */
                (state->ctx->populate_ops)(ops,
-                               &state->ctx->mbufs_in[cur_iter_op],
-                               &state->ctx->mbufs_out[cur_iter_op], burst_size,
+                               state->ctx->src_buf_offset,
+                               state->ctx->dst_buf_offset,
+                               burst_size,
                                state->ctx->sess, state->opts,
-                               state->ctx->test_vector, iv_offset);
+                               state->ctx->test_vector, iv_offset,
+                               &imix_idx);
 
 #ifdef CPERF_LINEARIZATION_ENABLE
                /* Check if source mbufs require coalescing */
@@ -366,7 +180,7 @@ pmd_cyclecount_bench_ops(struct pmd_cyclecount_state *state, uint32_t cur_op,
                        }
                }
 #endif /* CPERF_LINEARIZATION_ENABLE */
-               rte_mempool_put_bulk(state->ctx->crypto_op_pool, (void **)ops,
+               rte_mempool_put_bulk(state->ctx->pool, (void **)ops,
                                burst_size);
        }
 
@@ -379,6 +193,7 @@ pmd_cyclecount_build_ops(struct pmd_cyclecount_state *state,
                uint32_t iter_ops_needed, uint16_t test_burst_size)
 {
        uint32_t cur_iter_op;
+       uint32_t imix_idx = 0;
 
        for (cur_iter_op = 0; cur_iter_op < iter_ops_needed;
                        cur_iter_op += test_burst_size) {
@@ -386,18 +201,25 @@ pmd_cyclecount_build_ops(struct pmd_cyclecount_state *state,
                                iter_ops_needed - cur_iter_op, test_burst_size);
                struct rte_crypto_op **ops = &state->ctx->ops[cur_iter_op];
 
-               if (burst_size != rte_crypto_op_bulk_alloc(
-                               state->ctx->crypto_op_pool,
-                               RTE_CRYPTO_OP_TYPE_SYMMETRIC,
-                               ops, burst_size))
-                       return -1;
+               /* Allocate objects containing crypto operations and mbufs */
+               if (rte_mempool_get_bulk(state->ctx->pool, (void **)ops,
+                                       burst_size) != 0) {
+                       RTE_LOG(ERR, USER1,
+                                       "Failed to allocate more crypto operations "
+                                       "from the crypto operation pool.\n"
+                                       "Consider increasing the pool size "
+                                       "with --pool-sz\n");
+                               return -1;
+               }
 
                /* Setup crypto op, attach mbuf etc */
                (state->ctx->populate_ops)(ops,
-                               &state->ctx->mbufs_in[cur_iter_op],
-                               &state->ctx->mbufs_out[cur_iter_op], burst_size,
+                               state->ctx->src_buf_offset,
+                               state->ctx->dst_buf_offset,
+                               burst_size,
                                state->ctx->sess, state->opts,
-                               state->ctx->test_vector, iv_offset);
+                               state->ctx->test_vector, iv_offset,
+                               &imix_idx);
        }
        return 0;
 }
@@ -544,7 +366,7 @@ pmd_cyclecount_bench_burst_sz(
                 * we may not have processed all ops that we allocated, so
                 * free everything we've allocated.
                 */
-               rte_mempool_put_bulk(state->ctx->crypto_op_pool,
+               rte_mempool_put_bulk(state->ctx->pool,
                                (void **)state->ctx->ops, iter_ops_allocd);
        }
 
@@ -569,7 +391,7 @@ cperf_pmd_cyclecount_test_runner(void *test_ctx)
        state.lcore = rte_lcore_id();
        state.linearize = 0;
 
-       static int only_once;
+       static rte_atomic16_t display_once = RTE_ATOMIC16_INIT(0);
        static bool warmup = true;
 
        /*
@@ -583,7 +405,7 @@ cperf_pmd_cyclecount_test_runner(void *test_ctx)
        struct rte_cryptodev_info dev_info;
 
        /* Check if source mbufs require coalescing */
-       if (opts->segments_nb > 1) {
+       if (opts->segments_sz < ctx->options->max_buffer_size) {
                rte_cryptodev_info_get(state.ctx->dev_id, &dev_info);
                if ((dev_info.feature_flags &
                                    RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER) ==
@@ -615,13 +437,12 @@ cperf_pmd_cyclecount_test_runner(void *test_ctx)
                }
 
                if (!opts->csv) {
-                       if (!only_once)
+                       if (rte_atomic16_test_and_set(&display_once))
                                printf(PRETTY_HDR_FMT, "lcore id", "Buf Size",
                                                "Burst Size", "Enqueued",
                                                "Dequeued", "Enq Retries",
                                                "Deq Retries", "Cycles/Op",
                                                "Cycles/Enq", "Cycles/Deq");
-                       only_once = 1;
 
                        printf(PRETTY_LINE_FMT, state.ctx->lcore_id,
                                        opts->test_buffer_size, test_burst_size,
@@ -632,13 +453,12 @@ cperf_pmd_cyclecount_test_runner(void *test_ctx)
                                        state.cycles_per_enq,
                                        state.cycles_per_deq);
                } else {
-                       if (!only_once)
+                       if (rte_atomic16_test_and_set(&display_once))
                                printf(CSV_HDR_FMT, "# lcore id", "Buf Size",
                                                "Burst Size", "Enqueued",
                                                "Dequeued", "Enq Retries",
                                                "Deq Retries", "Cycles/Op",
                                                "Cycles/Enq", "Cycles/Deq");
-                       only_once = 1;
 
                        printf(CSV_LINE_FMT, state.ctx->lcore_id,
                                        opts->test_buffer_size, test_burst_size,
@@ -671,5 +491,5 @@ cperf_pmd_cyclecount_test_destructor(void *arg)
        if (ctx == NULL)
                return;
 
-       cperf_pmd_cyclecount_test_free(ctx, ctx->options->pool_sz);
+       cperf_pmd_cyclecount_test_free(ctx);
 }