From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id B2358A0032;
	Thu,  1 Sep 2022 16:22:31 +0200 (CEST)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id E543A42B95;
	Thu,  1 Sep 2022 16:21:15 +0200 (CEST)
Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31])
 by mails.dpdk.org (Postfix) with ESMTP id 3A91242B6C
 for <dev@dpdk.org>; Thu,  1 Sep 2022 16:21:08 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
 d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
 t=1662042068; x=1693578068;
 h=from:to:cc:subject:date:message-id:in-reply-to:
 references:mime-version:content-transfer-encoding;
 bh=DRd8UcwHbOafRWt3Y8Tq/jluSc7qNRU7WPHtU2gkQng=;
 b=KmTfzz/e8pPhYysGac++74s+glvy3X8Ysli7xKmCZGXNQJTjHvwgW5bF
 OhrzDqcoQsSo0UUjeAEibOcu7Ln90hUOrNPQskoSBzPs6hkwKonaai4YW
 55/H8UT2ttwc49+1ja3J6Oqrl4tRbF8KGgGEzfC6cYBXxRDsW1OY4ZwAC
 APxH05JtgDulOM8ARw2a87NlFdOw7H327kiYrWWDZbayXN9ZfLsGAeEHS
 RNs0pxSI9FzpEahiOFK35nQ2F5GS+b1qyA0sohj+4YFyi8pwziwxvjZZ/
 rNxmhZQArtFox8hZ3rMN+dL1LnOonlwacMjInNAwse3/X69RqybBP99fq g==;
X-IronPort-AV: E=McAfee;i="6500,9779,10457"; a="357444051"
X-IronPort-AV: E=Sophos;i="5.93,281,1654585200"; d="scan'208";a="357444051"
Received: from fmsmga004.fm.intel.com ([10.253.24.48])
 by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 01 Sep 2022 07:20:52 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.93,281,1654585200"; d="scan'208";a="680870190"
Received: from silpixa00400573.ir.intel.com (HELO
 silpixa00400573.ger.corp.intel.com.) ([10.237.223.157])
 by fmsmga004.fm.intel.com with ESMTP; 01 Sep 2022 07:20:51 -0700
From: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
To: dev@dpdk.org
Cc: Yogesh Jangra <yogesh.jangra@intel.com>
Subject: [PATCH V3 10/21] net/softnic: add pipeline code generation CLI command
Date: Thu,  1 Sep 2022 14:20:30 +0000
Message-Id: <20220901142041.2628537-11-cristian.dumitrescu@intel.com>
X-Mailer: git-send-email 2.34.1
In-Reply-To: <20220901142041.2628537-1-cristian.dumitrescu@intel.com>
References: <20220804165839.1074817-1-cristian.dumitrescu@intel.com>
 <20220901142041.2628537-1-cristian.dumitrescu@intel.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

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(-)

diff --git a/drivers/net/softnic/rte_eth_softnic_cli.c b/drivers/net/softnic/rte_eth_softnic_cli.c
index 9de17fba8f..f2c2721d55 100644
--- a/drivers/net/softnic/rte_eth_softnic_cli.c
+++ b/drivers/net/softnic/rte_eth_softnic_cli.c
@@ -180,7 +180,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,
@@ -308,6 +356,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)) {
-- 
2.34.1