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 70705A0547; Fri, 10 Sep 2021 14:33:31 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7A0AE411EE; Fri, 10 Sep 2021 14:30:58 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mails.dpdk.org (Postfix) with ESMTP id 8839D4114B for ; Fri, 10 Sep 2021 14:30:28 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10102"; a="243386340" X-IronPort-AV: E=Sophos;i="5.85,282,1624345200"; d="scan'208";a="243386340" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2021 05:30:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,282,1624345200"; d="scan'208";a="514279860" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com) ([10.237.223.107]) by orsmga001.jf.intel.com with ESMTP; 10 Sep 2021 05:30:25 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Cc: Cunming Liang Date: Fri, 10 Sep 2021 13:30:02 +0100 Message-Id: <20210910123003.85448-23-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210910123003.85448-1-cristian.dumitrescu@intel.com> References: <20210910123003.85448-1-cristian.dumitrescu@intel.com> Subject: [dpdk-dev] [PATCH 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 0a4ac06467..4be43c94a9 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" @@ -8945,9 +8946,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); @@ -8967,6 +8972,9 @@ rte_swx_pipeline_free(struct rte_swx_pipeline *p) struct_free(p); free(p); + + if (lib) + dlclose(lib); } int @@ -12178,6 +12186,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) { @@ -12195,6 +12321,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 4ad6dd42dd..a210df4856 100644 --- a/lib/pipeline/rte_swx_pipeline_internal.h +++ b/lib/pipeline/rte_swx_pipeline_internal.h @@ -1400,6 +1400,7 @@ struct rte_swx_pipeline { struct instruction *instructions; struct instruction_data *instruction_data; struct thread threads[RTE_SWX_PIPELINE_THREADS_MAX]; + void *lib; uint32_t n_structs; uint32_t n_ports_in; -- 2.17.1