DPDK patches and discussions
 help / color / mirror / Atom feed
From: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH 1/2] pipeline: modularize the instruction optimizer
Date: Mon, 12 Apr 2021 00:23:37 +0100
Message-ID: <20210411232338.4005-1-cristian.dumitrescu@intel.com> (raw)

Decouple between the different instruction optimizer. Allow each
optimization to run as a separate iteration on the entire instruction
stream.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 lib/librte_pipeline/rte_swx_pipeline.c | 196 ++++++++++++++++++-------
 1 file changed, 142 insertions(+), 54 deletions(-)

diff --git a/lib/librte_pipeline/rte_swx_pipeline.c b/lib/librte_pipeline/rte_swx_pipeline.c
index dc2a155ed..ba828cbda 100644
--- a/lib/librte_pipeline/rte_swx_pipeline.c
+++ b/lib/librte_pipeline/rte_swx_pipeline.c
@@ -8085,8 +8085,34 @@ instr_verify(struct rte_swx_pipeline *p __rte_unused,
 	return 0;
 }
 
+static uint32_t
+instr_compact(struct instruction *instructions,
+	      struct instruction_data *instruction_data,
+	      uint32_t n_instructions)
+{
+	uint32_t i, pos = 0;
+
+	/* Eliminate the invalid instructions that have been optimized out. */
+	for (i = 0; i < n_instructions; i++) {
+		struct instruction *instr = &instructions[i];
+		struct instruction_data *data = &instruction_data[i];
+
+		if (data->invalid)
+			continue;
+
+		if (i != pos) {
+			memcpy(&instructions[pos], instr, sizeof(*instr));
+			memcpy(&instruction_data[pos], data, sizeof(*data));
+		}
+
+		pos++;
+	}
+
+	return pos;
+}
+
 static int
-instr_pattern_extract_many_detect(struct instruction *instr,
+instr_pattern_extract_many_search(struct instruction *instr,
 				  struct instruction_data *data,
 				  uint32_t n_instr,
 				  uint32_t *n_pattern_instr)
@@ -8115,9 +8141,9 @@ instr_pattern_extract_many_detect(struct instruction *instr,
 }
 
 static void
-instr_pattern_extract_many_optimize(struct instruction *instr,
-				    struct instruction_data *data,
-				    uint32_t n_instr)
+instr_pattern_extract_many_replace(struct instruction *instr,
+				   struct instruction_data *data,
+				   uint32_t n_instr)
 {
 	uint32_t i;
 
@@ -8131,8 +8157,46 @@ instr_pattern_extract_many_optimize(struct instruction *instr,
 	}
 }
 
+static uint32_t
+instr_pattern_extract_many_optimize(struct instruction *instructions,
+				    struct instruction_data *instruction_data,
+				    uint32_t n_instructions)
+{
+	uint32_t i;
+
+	for (i = 0; i < n_instructions; ) {
+		struct instruction *instr = &instructions[i];
+		struct instruction_data *data = &instruction_data[i];
+		uint32_t n_instr = 0;
+		int detected;
+
+		/* Extract many. */
+		detected = instr_pattern_extract_many_search(instr,
+							     data,
+							     n_instructions - i,
+							     &n_instr);
+		if (detected) {
+			instr_pattern_extract_many_replace(instr,
+							   data,
+							   n_instr);
+			i += n_instr;
+			continue;
+		}
+
+		/* No pattern starting at the current instruction. */
+		i++;
+	}
+
+	/* Eliminate the invalid instructions that have been optimized out. */
+	n_instructions = instr_compact(instructions,
+				       instruction_data,
+				       n_instructions);
+
+	return n_instructions;
+}
+
 static int
-instr_pattern_emit_many_tx_detect(struct instruction *instr,
+instr_pattern_emit_many_tx_search(struct instruction *instr,
 				  struct instruction_data *data,
 				  uint32_t n_instr,
 				  uint32_t *n_pattern_instr)
@@ -8169,9 +8233,9 @@ instr_pattern_emit_many_tx_detect(struct instruction *instr,
 }
 
 static void
-instr_pattern_emit_many_tx_optimize(struct instruction *instr,
-				    struct instruction_data *data,
-				    uint32_t n_instr)
+instr_pattern_emit_many_tx_replace(struct instruction *instr,
+				   struct instruction_data *data,
+				   uint32_t n_instr)
 {
 	uint32_t i;
 
@@ -8192,8 +8256,46 @@ instr_pattern_emit_many_tx_optimize(struct instruction *instr,
 	data[i].invalid = 1;
 }
 
+static uint32_t
+instr_pattern_emit_many_tx_optimize(struct instruction *instructions,
+				    struct instruction_data *instruction_data,
+				    uint32_t n_instructions)
+{
+	uint32_t i;
+
+	for (i = 0; i < n_instructions; ) {
+		struct instruction *instr = &instructions[i];
+		struct instruction_data *data = &instruction_data[i];
+		uint32_t n_instr = 0;
+		int detected;
+
+		/* Emit many + TX. */
+		detected = instr_pattern_emit_many_tx_search(instr,
+							     data,
+							     n_instructions - i,
+							     &n_instr);
+		if (detected) {
+			instr_pattern_emit_many_tx_replace(instr,
+							   data,
+							   n_instr);
+			i += n_instr;
+			continue;
+		}
+
+		/* No pattern starting at the current instruction. */
+		i++;
+	}
+
+	/* Eliminate the invalid instructions that have been optimized out. */
+	n_instructions = instr_compact(instructions,
+				       instruction_data,
+				       n_instructions);
+
+	return n_instructions;
+}
+
 static int
-instr_pattern_dma_many_detect(struct instruction *instr,
+instr_pattern_dma_many_search(struct instruction *instr,
 			      struct instruction_data *data,
 			      uint32_t n_instr,
 			      uint32_t *n_pattern_instr)
@@ -8222,9 +8324,9 @@ instr_pattern_dma_many_detect(struct instruction *instr,
 }
 
 static void
-instr_pattern_dma_many_optimize(struct instruction *instr,
-				struct instruction_data *data,
-				uint32_t n_instr)
+instr_pattern_dma_many_replace(struct instruction *instr,
+			       struct instruction_data *data,
+			       uint32_t n_instr)
 {
 	uint32_t i;
 
@@ -8240,11 +8342,11 @@ instr_pattern_dma_many_optimize(struct instruction *instr,
 }
 
 static uint32_t
-instr_optimize(struct instruction *instructions,
+instr_pattern_dma_many_optimize(struct instruction *instructions,
 	       struct instruction_data *instruction_data,
 	       uint32_t n_instructions)
 {
-	uint32_t i, pos = 0;
+	uint32_t i;
 
 	for (i = 0; i < n_instructions; ) {
 		struct instruction *instr = &instructions[i];
@@ -8252,39 +8354,13 @@ instr_optimize(struct instruction *instructions,
 		uint32_t n_instr = 0;
 		int detected;
 
-		/* Extract many. */
-		detected = instr_pattern_extract_many_detect(instr,
-							     data,
-							     n_instructions - i,
-							     &n_instr);
-		if (detected) {
-			instr_pattern_extract_many_optimize(instr,
-							    data,
-							    n_instr);
-			i += n_instr;
-			continue;
-		}
-
-		/* Emit many + TX. */
-		detected = instr_pattern_emit_many_tx_detect(instr,
-							     data,
-							     n_instructions - i,
-							     &n_instr);
-		if (detected) {
-			instr_pattern_emit_many_tx_optimize(instr,
-							    data,
-							    n_instr);
-			i += n_instr;
-			continue;
-		}
-
 		/* DMA many. */
-		detected = instr_pattern_dma_many_detect(instr,
+		detected = instr_pattern_dma_many_search(instr,
 							 data,
 							 n_instructions - i,
 							 &n_instr);
 		if (detected) {
-			instr_pattern_dma_many_optimize(instr, data, n_instr);
+			instr_pattern_dma_many_replace(instr, data, n_instr);
 			i += n_instr;
 			continue;
 		}
@@ -8294,22 +8370,34 @@ instr_optimize(struct instruction *instructions,
 	}
 
 	/* Eliminate the invalid instructions that have been optimized out. */
-	for (i = 0; i < n_instructions; i++) {
-		struct instruction *instr = &instructions[i];
-		struct instruction_data *data = &instruction_data[i];
+	n_instructions = instr_compact(instructions,
+				       instruction_data,
+				       n_instructions);
 
-		if (data->invalid)
-			continue;
+	return n_instructions;
+}
 
-		if (i != pos) {
-			memcpy(&instructions[pos], instr, sizeof(*instr));
-			memcpy(&instruction_data[pos], data, sizeof(*data));
-		}
+static uint32_t
+instr_optimize(struct instruction *instructions,
+	       struct instruction_data *instruction_data,
+	       uint32_t n_instructions)
+{
+	/* Extract many. */
+	n_instructions = instr_pattern_extract_many_optimize(instructions,
+							     instruction_data,
+							     n_instructions);
 
-		pos++;
-	}
+	/* Emit many + TX. */
+	n_instructions = instr_pattern_emit_many_tx_optimize(instructions,
+							     instruction_data,
+							     n_instructions);
 
-	return pos;
+	/* DMA many. */
+	n_instructions = instr_pattern_dma_many_optimize(instructions,
+							 instruction_data,
+							 n_instructions);
+
+	return n_instructions;
 }
 
 static int
-- 
2.17.1


             reply	other threads:[~2021-04-11 23:23 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-11 23:23 Cristian Dumitrescu [this message]
2021-04-11 23:23 ` [dpdk-dev] [PATCH 2/2] pipeline: autodetect endianness of action args Cristian Dumitrescu
2021-04-20  0:48   ` Thomas Monjalon
2021-04-20 10:04     ` Dumitrescu, Cristian
2021-04-20 10:06       ` Thomas Monjalon
2021-04-20 10:20         ` Dumitrescu, Cristian
2021-04-20 14:48           ` Aaron Conole
2021-04-20 19:57   ` Thomas Monjalon
2021-04-21  7:49     ` Ali Alnubani
2021-04-21 12:57       ` Aaron Conole
2021-04-21 13:03         ` Ali Alnubani
2021-04-21 13:21           ` Aaron Conole
2021-04-21 13:58       ` Dumitrescu, Cristian
2021-04-21 14:24         ` Ali Alnubani
2021-04-21 15:10           ` Dumitrescu, Cristian

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=20210411232338.4005-1-cristian.dumitrescu@intel.com \
    --to=cristian.dumitrescu@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

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