From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 37B74A00C4; Thu, 28 Jul 2022 00:37:22 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7284D42B88; Thu, 28 Jul 2022 00:36:52 +0200 (CEST) Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id E9C5142826 for ; Thu, 28 Jul 2022 00:36:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1658961408; x=1690497408; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=B96s1TUQYXQUFbf2LJ54XtvuQrgnSSS22HsbLwweC8M=; b=UgIn2sudtwKkHagOCO+agETwPhtsY6Yl6+GJ0PqtyKX+4ZJqcXvZUEPn XfimBqcio5TFbXZM1AQgoLuwkR0/aajDGkrKIlQtaz9aEjZMsFoTdBh/N Koxv/LS7aTBsV7n1E0mk8bB4FYh1lHmcGPhDaulaKafZ6ZBeRr/gZyxg5 w51cRXHWmzWAYWyX8ioSfBr3LLxC8DaEpJ/vvF52+1K3etisgVPSSvHrJ 1tSg2QVsDC7wc+1kWS1W2Lp8Vsfdw6L5c/mfflT94zi4POVfqO8ZKJ0jd HCYICDeSawY5Hd5bJAJCU9TXRIlkWeyngWFqQmyPQmI9Os1LMyeZV0ArG g==; X-IronPort-AV: E=McAfee;i="6400,9594,10421"; a="350068828" X-IronPort-AV: E=Sophos;i="5.93,196,1654585200"; d="scan'208";a="350068828" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jul 2022 15:36:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,196,1654585200"; d="scan'208";a="628567631" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com.) ([10.237.223.157]) by orsmga008.jf.intel.com with ESMTP; 27 Jul 2022 15:36:46 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Cc: "Kamalakannan R ." Subject: [PATCH V3 07/17] pipeline: add API for pipeline code generation Date: Wed, 27 Jul 2022 22:36:29 +0000 Message-Id: <20220727223639.598932-7-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220727223639.598932-1-cristian.dumitrescu@intel.com> References: <20220718132603.339314-1-cristian.dumitrescu@intel.com> <20220727223639.598932-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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Previously, the C code generation for the pipeline was hidden under the hood; now, we make this an explicit API operation. Besides the functions for the pipeline actions and the pipeline instructions, the generated C source code now includes the pipeline specification structure required for the pipeline configuration operations. Signed-off-by: Cristian Dumitrescu Signed-off-by: Kamalakannan R. --- lib/pipeline/rte_swx_pipeline.c | 94 +++++++++++++++++++++++++++++++++ lib/pipeline/rte_swx_pipeline.h | 25 +++++++++ lib/pipeline/version.map | 1 + 3 files changed, 120 insertions(+) diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c index c8ccded4f8..dd5f7107fa 100644 --- a/lib/pipeline/rte_swx_pipeline.c +++ b/lib/pipeline/rte_swx_pipeline.c @@ -20,6 +20,7 @@ #include #include "rte_swx_pipeline_internal.h" +#include "rte_swx_pipeline_spec.h" #define CHECK(condition, err_code) \ do { \ @@ -13581,3 +13582,96 @@ pipeline_compile(struct rte_swx_pipeline *p) return status; } + +int +rte_swx_pipeline_codegen(FILE *spec_file, + FILE *code_file, + uint32_t *err_line, + const char **err_msg) + +{ + struct rte_swx_pipeline *p = NULL; + struct pipeline_spec *s = NULL; + struct instruction_group_list *igl = NULL; + struct action *a; + int status = 0; + + /* Check input arguments. */ + if (!spec_file || !code_file) { + if (err_line) + *err_line = 0; + if (err_msg) + *err_msg = "Invalid input argument."; + status = -EINVAL; + goto free; + } + + /* Pipeline configuration. */ + s = pipeline_spec_parse(spec_file, err_line, err_msg); + if (!s) { + status = -EINVAL; + goto free; + } + + status = rte_swx_pipeline_config(&p, NULL, 0); + if (status) { + if (err_line) + *err_line = 0; + if (err_msg) + *err_msg = "Pipeline configuration error."; + goto free; + } + + status = pipeline_spec_configure(p, s, err_msg); + if (status) { + if (err_line) + *err_line = 0; + goto free; + } + + /* + * Pipeline code generation. + */ + + /* Instruction Group List (IGL) computation: the pipeline configuration must be done first, + * but there is no need for the pipeline build to be done as well. + */ + igl = instruction_group_list_create(p); + if (!igl) { + if (err_line) + *err_line = 0; + if (err_msg) + *err_msg = "Memory allocation failed."; + status = -ENOMEM; + goto free; + } + + /* Header file inclusion. */ + fprintf(code_file, "#include \"rte_swx_pipeline_internal.h\"\n"); + fprintf(code_file, "#include \"rte_swx_pipeline_spec.h\"\n\n"); + + /* Code generation for the pipeline specification. */ + pipeline_spec_codegen(code_file, s); + fprintf(code_file, "\n"); + + /* Code generation for the action instructions. */ + TAILQ_FOREACH(a, &p->actions, node) { + fprintf(code_file, "/**\n * Action %s\n */\n\n", a->name); + + action_data_codegen(a, code_file); + fprintf(code_file, "\n"); + + action_instr_codegen(a, code_file); + fprintf(code_file, "\n"); + } + + /* Code generation for the pipeline instructions. */ + instruction_group_list_codegen(igl, p, code_file); + +free: + instruction_group_list_free(igl); + rte_swx_pipeline_free(p); + pipeline_spec_free(s); + + return status; +} diff --git a/lib/pipeline/rte_swx_pipeline.h b/lib/pipeline/rte_swx_pipeline.h index ef50a0fa70..724607b87c 100644 --- a/lib/pipeline/rte_swx_pipeline.h +++ b/lib/pipeline/rte_swx_pipeline.h @@ -957,6 +957,31 @@ __rte_experimental int rte_swx_pipeline_build(struct rte_swx_pipeline *p); +/** + * Pipeline C code generate based on input specification file + * + * @param[in] spec_file + * Pipeline specification file (.spec) provided as input. + * @param[in] code_file + * Pipeline C language file (.c) to be generated. + * @param[out] err_line + * In case of error and non-NULL, the line number within the *spec* file where + * the error occurred. The first line number in the file is 1. + * @param[out] err_msg + * In case of error and non-NULL, the error message. + * @return + * 0 on success or the following error codes otherwise: + * -EINVAL: Invalid argument; + * -ENOMEM: Not enough space/cannot allocate memory; + * -EEXIST: Resource with the same name already exists. + */ +__rte_experimental +int +rte_swx_pipeline_codegen(FILE *spec_file, + FILE *code_file, + uint32_t *err_line, + const char **err_msg); + /** * Pipeline build from specification file * diff --git a/lib/pipeline/version.map b/lib/pipeline/version.map index 50029aadcf..8d95005a5b 100644 --- a/lib/pipeline/version.map +++ b/lib/pipeline/version.map @@ -148,5 +148,6 @@ EXPERIMENTAL { #added in 22.11 rte_swx_ctl_pipeline_find; + rte_swx_pipeline_codegen; rte_swx_pipeline_find; }; -- 2.34.1