[10/21] net/softnic: add pipeline code generation CLI command

Message ID 20220804165839.1074817-11-cristian.dumitrescu@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Andrew Rybchenko
Headers
Series net/softnic: replace the legacy pipeline with SWX pipeline |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Cristian Dumitrescu Aug. 4, 2022, 4:58 p.m. UTC
  Add CLI command for pipeline code generation.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
Signed-off-by: Yogesh Jangra <yogesh.jangra@intel.com>
---
 drivers/net/softnic/rte_eth_softnic_cli.c | 57 ++++++++++++++++++++++-
 1 file changed, 56 insertions(+), 1 deletion(-)
  

Patch

diff --git a/drivers/net/softnic/rte_eth_softnic_cli.c b/drivers/net/softnic/rte_eth_softnic_cli.c
index c87a481355..f42db41996 100644
--- a/drivers/net/softnic/rte_eth_softnic_cli.c
+++ b/drivers/net/softnic/rte_eth_softnic_cli.c
@@ -182,7 +182,55 @@  cmd_swq(struct pmd_internals *softnic,
 }
 
 /**
- * thread <thread_id> pipeline <pipeline_name> enable
+ * pipeline codegen <spec_file> <code_file>
+ */
+static void
+cmd_softnic_pipeline_codegen(struct pmd_internals *softnic __rte_unused,
+	char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size)
+{
+	FILE *spec_file = NULL;
+	FILE *code_file = NULL;
+	uint32_t err_line;
+	const char *err_msg;
+	int status;
+
+	if (n_tokens != 4) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	spec_file = fopen(tokens[2], "r");
+	if (!spec_file) {
+		snprintf(out, out_size, "Cannot open file %s.\n", tokens[2]);
+		return;
+	}
+
+	code_file = fopen(tokens[3], "w");
+	if (!code_file) {
+		snprintf(out, out_size, "Cannot open file %s.\n", tokens[3]);
+		return;
+	}
+
+	status = rte_swx_pipeline_codegen(spec_file,
+					  code_file,
+					  &err_line,
+					  &err_msg);
+
+	fclose(spec_file);
+	fclose(code_file);
+
+	if (status) {
+		snprintf(out, out_size, "Error %d at line %u: %s\n.",
+			status, err_line, err_msg);
+		return;
+	}
+}
+
+/**
+ * thread <thread_id> pipeline <pipeline_name> enable [ period <timer_period_ms> ]
  */
 static void
 cmd_softnic_thread_pipeline_enable(struct pmd_internals *softnic,
@@ -310,6 +358,13 @@  softnic_cli_process(char *in, char *out, size_t out_size, void *arg)
 		return;
 	}
 
+	if (!strcmp(tokens[0], "pipeline")) {
+		if ((n_tokens >= 2) && !strcmp(tokens[1], "codegen")) {
+			cmd_softnic_pipeline_codegen(softnic, tokens, n_tokens, out, out_size);
+			return;
+		}
+	}
+
 	if (strcmp(tokens[0], "thread") == 0) {
 		if (n_tokens >= 5 &&
 			(strcmp(tokens[4], "enable") == 0)) {