From patchwork Mon Sep 13 16:44:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Dumitrescu X-Patchwork-Id: 98793 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5655BA0C45; Mon, 13 Sep 2021 18:47:25 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A14A6411BE; Mon, 13 Sep 2021 18:45:16 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mails.dpdk.org (Postfix) with ESMTP id 3C6AE411A0 for ; Mon, 13 Sep 2021 18:45:12 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10106"; a="201239228" X-IronPort-AV: E=Sophos;i="5.85,290,1624345200"; d="scan'208";a="201239228" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2021 09:45:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,290,1624345200"; d="scan'208";a="507429286" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com) ([10.237.223.107]) by fmsmga008.fm.intel.com with ESMTP; 13 Sep 2021 09:45:10 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Cc: Cunming Liang Date: Mon, 13 Sep 2021 17:44:42 +0100 Message-Id: <20210913164443.16875-23-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210913164443.16875-1-cristian.dumitrescu@intel.com> References: <20210910133713.93103-1-cristian.dumitrescu@intel.com> <20210913164443.16875-1-cristian.dumitrescu@intel.com> Subject: [dpdk-dev] [PATCH V3 23/24] pipeline: build shared object for pipeline 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 Sender: "dev" Build the generated C file into a shared object library. Signed-off-by: Cristian Dumitrescu Signed-off-by: Cunming Liang --- lib/pipeline/rte_swx_pipeline.c | 131 +++++++++++++++++++++++ lib/pipeline/rte_swx_pipeline_internal.h | 1 + 2 files changed, 132 insertions(+) diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c index e669dd09d2..02519a05a9 100644 --- a/lib/pipeline/rte_swx_pipeline.c +++ b/lib/pipeline/rte_swx_pipeline.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "rte_swx_pipeline_internal.h" @@ -8968,9 +8969,13 @@ rte_swx_pipeline_config(struct rte_swx_pipeline **p, int numa_node) void rte_swx_pipeline_free(struct rte_swx_pipeline *p) { + void *lib; + if (!p) return; + lib = p->lib; + free(p->instruction_data); free(p->instructions); @@ -8991,6 +8996,9 @@ rte_swx_pipeline_free(struct rte_swx_pipeline *p) struct_free(p); free(p); + + if (lib) + dlclose(lib); } int @@ -12205,6 +12213,124 @@ pipeline_codegen(struct rte_swx_pipeline *p, struct instruction_group_list *igl) return 0; } +#ifndef RTE_SWX_PIPELINE_CMD_MAX_SIZE +#define RTE_SWX_PIPELINE_CMD_MAX_SIZE 4096 +#endif + +static int +pipeline_libload(struct rte_swx_pipeline *p, struct instruction_group_list *igl) +{ + struct action *a; + struct instruction_group *g; + char *dir_in, *buffer = NULL; + const char *dir_out; + int status = 0; + + /* Get the environment variables. */ + dir_in = getenv("RTE_INSTALL_DIR"); + if (!dir_in) { + status = -EINVAL; + goto free; + } + + dir_out = "/tmp"; + + /* Memory allocation for the command buffer. */ + buffer = malloc(RTE_SWX_PIPELINE_CMD_MAX_SIZE); + if (!buffer) { + status = -ENOMEM; + goto free; + } + + snprintf(buffer, + RTE_SWX_PIPELINE_CMD_MAX_SIZE, + "gcc -c -O3 -fpic -Wno-deprecated-declarations -o %s/pipeline.o %s/pipeline.c " + "-I %s/lib/pipeline " + "-I %s/lib/eal/include " + "-I %s/lib/eal/x86/include " + "-I %s/lib/eal/include/generic " + "-I %s/lib/meter " + "-I %s/lib/port " + "-I %s/lib/table " + "-I %s/lib/pipeline " + "-I %s/config " + "-I %s/build " + "-I %s/lib/eal/linux/include " + ">%s/pipeline.log 2>&1 " + "&& " + "gcc -shared %s/pipeline.o -o %s/libpipeline.so " + ">>%s/pipeline.log 2>&1", + dir_out, + dir_out, + dir_in, + dir_in, + dir_in, + dir_in, + dir_in, + dir_in, + dir_in, + dir_in, + dir_in, + dir_in, + dir_in, + dir_out, + dir_out, + dir_out, + dir_out); + + /* Build the shared object library. */ + status = system(buffer); + if (status) + goto free; + + /* Open library. */ + snprintf(buffer, + RTE_SWX_PIPELINE_CMD_MAX_SIZE, + "%s/libpipeline.so", + dir_out); + + p->lib = dlopen(buffer, RTLD_LAZY); + if (!p->lib) { + status = -EIO; + goto free; + } + + /* Get the action function symbols. */ + TAILQ_FOREACH(a, &p->actions, node) { + snprintf(buffer, RTE_SWX_PIPELINE_CMD_MAX_SIZE, "action_%s_run", a->name); + + p->action_funcs[a->id] = dlsym(p->lib, buffer); + if (!p->action_funcs[a->id]) { + status = -EINVAL; + goto free; + } + } + + /* Get the pipeline function symbols. */ + TAILQ_FOREACH(g, igl, node) { + if (g->first_instr_id == g->last_instr_id) + continue; + + snprintf(buffer, RTE_SWX_PIPELINE_CMD_MAX_SIZE, "pipeline_func_%u", g->group_id); + + g->func = dlsym(p->lib, buffer); + if (!g->func) { + status = -EINVAL; + goto free; + } + } + +free: + if (status && p->lib) { + dlclose(p->lib); + p->lib = NULL; + } + + free(buffer); + + return status; +} + static int pipeline_compile(struct rte_swx_pipeline *p) { @@ -12222,6 +12348,11 @@ pipeline_compile(struct rte_swx_pipeline *p) if (status) goto free; + /* Build and load the shared object library. */ + status = pipeline_libload(p, igl); + if (status) + goto free; + free: instruction_group_list_free(igl); diff --git a/lib/pipeline/rte_swx_pipeline_internal.h b/lib/pipeline/rte_swx_pipeline_internal.h index 64625b40c6..3baae55737 100644 --- a/lib/pipeline/rte_swx_pipeline_internal.h +++ b/lib/pipeline/rte_swx_pipeline_internal.h @@ -1407,6 +1407,7 @@ struct rte_swx_pipeline { struct instruction_data *instruction_data; instr_exec_t *instruction_table; struct thread threads[RTE_SWX_PIPELINE_THREADS_MAX]; + void *lib; uint32_t n_structs; uint32_t n_ports_in;