DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ophir Munk <ophirmu@nvidia.com>
To: dev@dpdk.org, Ori Kam <orika@nvidia.com>,
	Ophir Munk <ophirmu@nvidia.com>
Cc: Thomas Monjalon <thomas@monjalon.net>
Subject: [dpdk-dev] [PATCH v2 3/6] app/regex: read data file once at startup
Date: Sun, 20 Dec 2020 10:41:45 +0000
Message-ID: <20201220104148.13961-4-ophirmu@nvidia.com> (raw)
In-Reply-To: <20201220104148.13961-1-ophirmu@nvidia.com>

Up to this commit the input data file was read from scratch for each QP,
which is redundant. Starting from this commit the data file is read only
once at startup. Each QP will clone the data.

Signed-off-by: Ophir Munk <ophirmu@nvidia.com>
---
 app/test-regex/main.c | 63 +++++++++++++++++++++++++++++++--------------------
 1 file changed, 39 insertions(+), 24 deletions(-)

diff --git a/app/test-regex/main.c b/app/test-regex/main.c
index d225267..9bafd02 100644
--- a/app/test-regex/main.c
+++ b/app/test-regex/main.c
@@ -180,6 +180,19 @@ read_file(char *file, char **buf)
 }
 
 static int
+clone_buf(char *data_buf, char **buf, long data_len)
+{
+	char *dest_buf;
+	dest_buf =
+		rte_malloc(NULL, sizeof(char) * (data_len + 1), 4096);
+	if (!dest_buf)
+		return -ENOMEM;
+	memcpy(dest_buf, data_buf, data_len + 1);
+	*buf = dest_buf;
+	return 0;
+}
+
+static int
 init_port(uint16_t *nb_max_payload, char *rules_file, uint8_t *nb_max_matches,
 	  uint32_t nb_qps)
 {
@@ -262,12 +275,11 @@ extbuf_free_cb(void *addr __rte_unused, void *fcb_opaque __rte_unused)
 
 static int
 run_regex(uint32_t nb_jobs,
-	  uint16_t nb_max_payload, bool perf_mode, uint32_t nb_iterations,
-	  char *data_file, uint8_t nb_max_matches, uint32_t nb_qps)
+	  bool perf_mode, uint32_t nb_iterations,
+	  uint8_t nb_max_matches, uint32_t nb_qps,
+	  char *data_buf, long data_len, long job_len)
 {
 	char *buf = NULL;
-	long buf_len = 0;
-	long job_len = 0;
 	uint32_t actual_jobs = 0;
 	uint32_t i;
 	uint16_t qp_id;
@@ -344,22 +356,8 @@ run_regex(uint32_t nb_jobs,
 			}
 		}
 
-		buf_len = read_file(data_file, &buf);
-		if (buf_len <= 0) {
-			printf("Error, can't read file, or file is empty.\n");
-			res = -EXIT_FAILURE;
-			goto end;
-		}
-
-		job_len = buf_len / nb_jobs;
-		if (job_len == 0) {
-			printf("Error, To many jobs, for the given input.\n");
-			res = -EXIT_FAILURE;
-			goto end;
-		}
-
-		if (job_len > nb_max_payload) {
-			printf("Error, not enough jobs to cover input.\n");
+		if (clone_buf(data_buf, &buf, data_len)) {
+			printf("Error, can't clone buf.\n");
 			res = -EXIT_FAILURE;
 			goto end;
 		}
@@ -367,8 +365,8 @@ run_regex(uint32_t nb_jobs,
 		/* Assign each mbuf with the data to handle. */
 		actual_jobs = 0;
 		pos = 0;
-		for (i = 0; (pos < buf_len) && (i < nb_jobs) ; i++) {
-			long act_job_len = RTE_MIN(job_len, buf_len - pos);
+		for (i = 0; (pos < data_len) && (i < nb_jobs) ; i++) {
+			long act_job_len = RTE_MIN(job_len, data_len - pos);
 			rte_pktmbuf_attach_extbuf(ops[i]->mbuf, &buf[pos], 0,
 					act_job_len, &shinfo);
 			jobs_ctx[i].mbuf = ops[i]->mbuf;
@@ -505,6 +503,9 @@ main(int argc, char **argv)
 	uint16_t nb_max_payload = 0;
 	uint8_t nb_max_matches = 0;
 	uint32_t nb_qps = 1;
+	char *data_buf;
+	long data_len;
+	long job_len;
 
 	/* Init EAL. */
 	ret = rte_eal_init(argc, argv);
@@ -522,10 +523,24 @@ main(int argc, char **argv)
 			&nb_max_matches, nb_qps);
 	if (ret < 0)
 		rte_exit(EXIT_FAILURE, "init port failed\n");
-	ret = run_regex(nb_jobs, nb_max_payload, perf_mode,
-			nb_iterations, data_file, nb_max_matches, nb_qps);
+
+	data_len = read_file(data_file, &data_buf);
+	if (data_len <= 0)
+		rte_exit(EXIT_FAILURE, "Error, can't read file, or file is empty.\n");
+
+	job_len = data_len / nb_jobs;
+	if (job_len == 0)
+		rte_exit(EXIT_FAILURE, "Error, To many jobs, for the given input.\n");
+
+	if (job_len > nb_max_payload)
+		rte_exit(EXIT_FAILURE, "Error, not enough jobs to cover input.\n");
+
+	ret = run_regex(nb_jobs, perf_mode,
+			nb_iterations, nb_max_matches, nb_qps,
+			data_buf, data_len, job_len);
 	if (ret < 0) {
 		rte_exit(EXIT_FAILURE, "RegEx function failed\n");
 	}
+	rte_free(data_buf);
 	return EXIT_SUCCESS;
 }
-- 
2.8.4


  parent reply	other threads:[~2020-12-20 10:42 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-16 16:49 [dpdk-dev] [PATCH v1 0/6] regex multi Q with multi cores support Ophir Munk
2020-12-16 16:49 ` [dpdk-dev] [PATCH v1 1/6] app/regex: move mem pool creation to worker routine Ophir Munk
2020-12-20 10:41   ` [dpdk-dev] [PATCH v2 0/6] regex multi Q with multi cores support Ophir Munk
2020-12-20 10:41     ` [dpdk-dev] [PATCH v2 1/6] app/regex: move mem pool creation to worker routine Ophir Munk
2021-01-10 11:10       ` [dpdk-dev] [PATCH v3 0/6] regex multi Q with multi cores support Ophir Munk
2021-01-10 11:10         ` [dpdk-dev] [PATCH v3 1/6] app/regex: move mem pool creation to worker routine Ophir Munk
2021-01-10 11:10         ` [dpdk-dev] [PATCH v3 2/6] app/regex: support multi QPs Ophir Munk
2021-01-10 11:10         ` [dpdk-dev] [PATCH v3 3/6] app/regex: read data file once at startup Ophir Munk
2021-01-10 11:10         ` [dpdk-dev] [PATCH v3 4/6] app/regex: support multi cores Ophir Munk
2021-01-10 11:10         ` [dpdk-dev] [PATCH v3 5/6] app/regex: support performance measurements per QP Ophir Munk
2021-01-10 11:10         ` [dpdk-dev] [PATCH v3 6/6] app/regex: replace Linux clock() API with rdtsc Ophir Munk
2021-01-12 23:05         ` [dpdk-dev] [PATCH v3 0/6] regex multi Q with multi cores support Thomas Monjalon
2020-12-20 10:41     ` [dpdk-dev] [PATCH v2 2/6] app/regex: support multi QPs Ophir Munk
2020-12-20 10:41     ` Ophir Munk [this message]
2020-12-20 10:41     ` [dpdk-dev] [PATCH v2 4/6] app/regex: support multi cores Ophir Munk
2020-12-20 10:41     ` [dpdk-dev] [PATCH v2 5/6] app/regex: support performance measurements per QP Ophir Munk
2021-01-08  9:08       ` Thomas Monjalon
2021-01-10 11:16         ` Ophir Munk
2021-01-10 22:55           ` Thomas Monjalon
2021-01-11 19:07             ` David Christensen
2020-12-20 10:41     ` [dpdk-dev] [PATCH v2 6/6] app/regex: replace Linux clock() API with rdtsc Ophir Munk
2021-01-04 14:01     ` [dpdk-dev] [PATCH v2 0/6] regex multi Q with multi cores support Ori Kam
2020-12-16 16:49 ` [dpdk-dev] [PATCH v1 2/6] app/regex: support multi QPs Ophir Munk
2020-12-16 16:49 ` [dpdk-dev] [PATCH v1 3/6] app/regex: read data file once at startup Ophir Munk
2020-12-16 16:49 ` [dpdk-dev] [PATCH v1 4/6] app/regex: support multi cores Ophir Munk
2020-12-16 16:49 ` [dpdk-dev] [PATCH v1 5/6] app/regex: support performance measurements per QP Ophir Munk
2020-12-16 16:49 ` [dpdk-dev] [PATCH v1 6/6] app/regex: replace Linux clock() API with rdtsc Ophir Munk
2020-12-17 11:52 ` [dpdk-dev] [PATCH v1 0/6] regex multi Q with multi cores support Ori Kam

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=20201220104148.13961-4-ophirmu@nvidia.com \
    --to=ophirmu@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=orika@nvidia.com \
    --cc=thomas@monjalon.net \
    /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

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git