app/crypto-perf: use single mempool
[dpdk.git] / app / test-crypto-perf / cperf_test_verify.c
index 2b6f3b4..6945c8b 100644 (file)
@@ -44,17 +44,15 @@ struct cperf_verify_ctx {
        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_cryptodev_sym_session *sess;
 
        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;
 };
@@ -72,11 +70,8 @@ cperf_verify_test_free(struct cperf_verify_ctx *ctx)
                        rte_cryptodev_sym_session_free(ctx->sess);
                }
 
-               cperf_free_common_memory(ctx->options,
-                               ctx->pkt_mbuf_pool_in,
-                               ctx->pkt_mbuf_pool_out,
-                               ctx->mbufs_in, ctx->mbufs_out,
-                               ctx->crypto_op_pool);
+               if (ctx->pool)
+                       rte_mempool_free(ctx->pool);
 
                rte_free(ctx);
        }
@@ -102,7 +97,7 @@ cperf_verify_test_constructor(struct rte_mempool *sess_mp,
        ctx->options = options;
        ctx->test_vector = test_vector;
 
-       /* IV goes at the end of the cryptop operation */
+       /* IV goes at the end of the crypto operation */
        uint16_t iv_offset = sizeof(struct rte_crypto_op) +
                sizeof(struct rte_crypto_sym_op);
 
@@ -112,9 +107,8 @@ cperf_verify_test_constructor(struct rte_mempool *sess_mp,
                goto err;
 
        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)
+                       &ctx->src_buf_offset, &ctx->dst_buf_offset,
+                       &ctx->pool) < 0)
                goto err;
 
        return ctx;
@@ -268,7 +262,7 @@ cperf_verify_test_runner(void *test_ctx)
 
        static int only_once;
 
-       uint64_t i, m_idx = 0;
+       uint64_t i;
        uint16_t ops_unused = 0;
 
        struct rte_crypto_op *ops[ctx->options->max_burst_size];
@@ -308,11 +302,9 @@ cperf_verify_test_runner(void *test_ctx)
 
                uint16_t ops_needed = burst_size - ops_unused;
 
-               /* Allocate crypto ops from pool */
-               if (ops_needed != rte_crypto_op_bulk_alloc(
-                               ctx->crypto_op_pool,
-                               RTE_CRYPTO_OP_TYPE_SYMMETRIC,
-                               ops, ops_needed)) {
+               /* Allocate objects containing crypto operations and mbufs */
+               if (rte_mempool_get_bulk(ctx->pool, (void **)ops,
+                                       ops_needed) != 0) {
                        RTE_LOG(ERR, USER1,
                                "Failed to allocate more crypto operations "
                                "from the the crypto operation pool.\n"
@@ -322,8 +314,8 @@ cperf_verify_test_runner(void *test_ctx)
                }
 
                /* Setup crypto op, attach mbuf etc */
-               (ctx->populate_ops)(ops, &ctx->mbufs_in[m_idx],
-                               &ctx->mbufs_out[m_idx],
+               (ctx->populate_ops)(ops, ctx->src_buf_offset,
+                               ctx->dst_buf_offset,
                                ops_needed, ctx->sess, ctx->options,
                                ctx->test_vector, iv_offset);
 
@@ -363,10 +355,6 @@ cperf_verify_test_runner(void *test_ctx)
                ops_deqd = rte_cryptodev_dequeue_burst(ctx->dev_id, ctx->qp_id,
                                ops_processed, ctx->options->max_burst_size);
 
-               m_idx += ops_needed;
-               if (m_idx + ctx->options->max_burst_size > ctx->options->pool_sz)
-                       m_idx = 0;
-
                if (ops_deqd == 0) {
                        /**
                         * Count dequeue polls which didn't return any
@@ -381,13 +369,10 @@ cperf_verify_test_runner(void *test_ctx)
                        if (cperf_verify_op(ops_processed[i], ctx->options,
                                                ctx->test_vector))
                                ops_failed++;
-                       /* free crypto ops so they can be reused. We don't free
-                        * the mbufs here as we don't want to reuse them as
-                        * the crypto operation will change the data and cause
-                        * failures.
-                        */
-                       rte_crypto_op_free(ops_processed[i]);
                }
+               /* Free crypto ops so they can be reused. */
+               rte_mempool_put_bulk(ctx->pool,
+                                       (void **)ops_processed, ops_deqd);
                ops_deqd_total += ops_deqd;
        }
 
@@ -409,13 +394,10 @@ cperf_verify_test_runner(void *test_ctx)
                        if (cperf_verify_op(ops_processed[i], ctx->options,
                                                ctx->test_vector))
                                ops_failed++;
-                       /* free crypto ops so they can be reused. We don't free
-                        * the mbufs here as we don't want to reuse them as
-                        * the crypto operation will change the data and cause
-                        * failures.
-                        */
-                       rte_crypto_op_free(ops_processed[i]);
                }
+               /* Free crypto ops so they can be reused. */
+               rte_mempool_put_bulk(ctx->pool,
+                                       (void **)ops_processed, ops_deqd);
                ops_deqd_total += ops_deqd;
        }