DPDK patches and discussions
 help / color / mirror / Atom feed
From: Rupesh Chiluka <rchiluka@marvell.com>
To: Brian Dooley <brian.dooley@intel.com>
Cc: <dev@dpdk.org>, Rupesh Chiluka <rchiluka@marvell.com>
Subject: [PATCH] app/crypto-perf: avoid infinite loop
Date: Tue, 11 Mar 2025 21:28:50 +0530	[thread overview]
Message-ID: <20250311155850.1043336-1-rchiluka@marvell.com> (raw)

The enqueue/dequeue loop's exit condition is
(ops_enqd_total >= total_ops). If the PMD driver cannot process the
ops (returns zero), ops_enqd_total won't increase, resulting in an
infinite loop. A check is added to process one op to determine
whether PMD can process the packet.

Signed-off-by: Rupesh Chiluka <rchiluka@marvell.com>
---
 app/test-crypto-perf/cperf_test_latency.c    | 54 +++++++++++++++++++
 app/test-crypto-perf/cperf_test_throughput.c | 55 ++++++++++++++++++++
 2 files changed, 109 insertions(+)

diff --git a/app/test-crypto-perf/cperf_test_latency.c b/app/test-crypto-perf/cperf_test_latency.c
index 2dd504b434..b501618d46 100644
--- a/app/test-crypto-perf/cperf_test_latency.c
+++ b/app/test-crypto-perf/cperf_test_latency.c
@@ -140,6 +140,56 @@ store_timestamp(struct rte_crypto_op *op, uint64_t timestamp)
 	priv_data->result->tsc_end = timestamp;
 }
 
+static int
+cperf_check_single_op(struct cperf_latency_ctx *ctx, uint16_t iv_offset)
+{
+	struct rte_crypto_op *ops[1];
+	uint32_t imix_idx = 0;
+	uint64_t tsc_start = 0;
+	uint64_t ops_enqd = 0, ops_deqd = 0;
+
+	/* Allocate object containing crypto operations and mbufs */
+	if (rte_mempool_get(ctx->pool, (void **)&ops[0]) != 0) {
+		RTE_LOG(ERR, USER1,
+			"Failed to allocate crypto operation "
+			"from the crypto operation pool.\n"
+			"Consider increasing the pool size "
+			"with --pool-sz\n");
+		return -1;
+	}
+
+	/* Setup crypto op, attach mbuf etc */
+	(ctx->populate_ops)(ops, ctx->src_buf_offset,
+		ctx->dst_buf_offset,
+		1, ctx->sess, ctx->options,
+		ctx->test_vector, iv_offset,
+		&imix_idx, &tsc_start);
+
+	ops_enqd = rte_cryptodev_enqueue_burst(ctx->dev_id, ctx->qp_id, ops, 1);
+	if (ops_enqd != 1) {
+		RTE_LOG(ERR, USER1, "PMD cannot process the packet.\n");
+		return -1;
+	}
+
+	/* Dequeue processed burst of ops from crypto device */
+	tsc_start = rte_rdtsc_precise();
+	while (1) {
+		ops_deqd = rte_cryptodev_dequeue_burst(ctx->dev_id, ctx->qp_id,
+				ops, 1);
+
+		if (ops_deqd == 1) {
+			rte_mempool_put(ctx->pool, ops[0]);
+			return 1;
+		}
+
+		/* Check if 1 second timeout has been reached */
+		if ((rte_rdtsc_precise() - tsc_start) > rte_get_tsc_hz()) {
+			RTE_LOG(ERR, USER1, "Dequeue operation timed out.\n");
+			return -1;
+		}
+	}
+}
+
 int
 cperf_latency_test_runner(void *arg)
 {
@@ -190,6 +240,10 @@ cperf_latency_test_runner(void *arg)
 		sizeof(struct rte_crypto_sym_op) +
 		sizeof(struct cperf_op_result *);
 
+	/* Enqueue just one operation to check whether PMD returns error */
+	if (cperf_check_single_op(ctx, iv_offset) < 1)
+		return -1;
+
 	while (test_burst_size <= ctx->options->max_burst_size) {
 		uint64_t ops_enqd = 0, ops_deqd = 0;
 		uint64_t b_idx = 0;
diff --git a/app/test-crypto-perf/cperf_test_throughput.c b/app/test-crypto-perf/cperf_test_throughput.c
index c8960ab855..13b16d9670 100644
--- a/app/test-crypto-perf/cperf_test_throughput.c
+++ b/app/test-crypto-perf/cperf_test_throughput.c
@@ -128,6 +128,57 @@ cperf_verify_init_ops(struct rte_mempool *mp __rte_unused,
 	cperf_mbuf_set(op->sym->m_src, ctx->options, ctx->test_vector);
 }
 
+static int
+cperf_check_single_op(struct cperf_throughput_ctx *ctx, uint16_t iv_offset)
+{
+	struct rte_crypto_op *ops[1];
+	uint32_t imix_idx = 0;
+	uint64_t tsc_start = 0;
+	uint64_t ops_enqd = 0, ops_deqd = 0;
+
+	/* Allocate object containing crypto operations and mbufs */
+	if (rte_mempool_get(ctx->pool, (void **)&ops[0]) != 0) {
+		RTE_LOG(ERR, USER1,
+			"Failed to allocate crypto operation "
+			"from the crypto operation pool.\n"
+			"Consider increasing the pool size "
+			"with --pool-sz\n");
+		return -1;
+	}
+
+	/* Setup crypto op, attach mbuf etc */
+	if (!ctx->options->out_of_place)
+		(ctx->populate_ops)(ops, ctx->src_buf_offset,
+				ctx->dst_buf_offset,
+				1, ctx->sess,
+				ctx->options, ctx->test_vector,
+				iv_offset, &imix_idx, &tsc_start);
+
+	ops_enqd = rte_cryptodev_enqueue_burst(ctx->dev_id, ctx->qp_id, ops, 1);
+	if (ops_enqd != 1) {
+		RTE_LOG(ERR, USER1, "PMD cannot process the packet.\n");
+		return -1;
+	}
+
+	/* Dequeue processed burst of ops from crypto device */
+	tsc_start = rte_rdtsc_precise();
+	while (1) {
+		ops_deqd = rte_cryptodev_dequeue_burst(ctx->dev_id, ctx->qp_id,
+				ops, 1);
+
+		if (ops_deqd == 1) {
+			rte_mempool_put(ctx->pool, ops[0]);
+			return 1;
+		}
+
+		/* Check if 1 second timeout has been reached */
+		if ((rte_rdtsc_precise() - tsc_start) > rte_get_tsc_hz()) {
+			RTE_LOG(ERR, USER1, "Dequeue operation timed out.\n");
+			return -1;
+		}
+	}
+}
+
 int
 cperf_throughput_test_runner(void *test_ctx)
 {
@@ -176,6 +227,10 @@ cperf_throughput_test_runner(void *test_ctx)
 	if (ctx->options->out_of_place)
 		rte_mempool_obj_iter(ctx->pool, cperf_verify_init_ops, (void *)ctx);
 
+	/* Enqueue just one operation to check whether PMD returns error */
+	if (cperf_check_single_op(ctx, iv_offset) < 1)
+		return -1;
+
 	while (test_burst_size <= ctx->options->max_burst_size) {
 		uint64_t ops_enqd = 0, ops_enqd_total = 0, ops_enqd_failed = 0;
 		uint64_t ops_deqd = 0, ops_deqd_total = 0, ops_deqd_failed = 0;
-- 
2.48.1


                 reply	other threads:[~2025-03-12 10:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250311155850.1043336-1-rchiluka@marvell.com \
    --to=rchiluka@marvell.com \
    --cc=brian.dooley@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).