From patchwork Thu Jan 19 16:54:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 91967 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp332889obz; Thu, 19 Jan 2017 07:59:09 -0800 (PST) X-Received: by 10.55.141.133 with SMTP id p127mr8049655qkd.187.1484841548989; Thu, 19 Jan 2017 07:59:08 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id r8si2878696qte.59.2017.01.19.07.59.08; Thu, 19 Jan 2017 07:59:08 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 9E7E060D99; Thu, 19 Jan 2017 15:59:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 5CA1462C3F; Thu, 19 Jan 2017 15:55:32 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 5CB9660649; Thu, 19 Jan 2017 15:55:11 +0000 (UTC) Received: from mail-lf0-f53.google.com (mail-lf0-f53.google.com [209.85.215.53]) by lists.linaro.org (Postfix) with ESMTPS id 79B6260649 for ; Thu, 19 Jan 2017 15:55:05 +0000 (UTC) Received: by mail-lf0-f53.google.com with SMTP id n124so39678330lfd.2 for ; Thu, 19 Jan 2017 07:55:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=w8fdiWwrqu20lxlH3XSFVIuPtBTXIcfvYHoqX2KzrRg=; b=LbBsIKN65eq57wYrf3f3kCo9SkfFr3i8w7nXtmrnN3vuIqozyCL3v09W71mBfNGFc5 Y0GQbGu2UUL6zDyguBTZD5mdVB+eLWfqBBBk10KbS22bZkhDw2HaQags1DTMx0lUYQXl klpwfosuwipnzP4dKRTb/FQ8z9F0xBotiAA7IXNPVcd0MJ8Yd5O1B4npz8t5jLLElmRN HYDaOiupUZkiI5Lx/Kev+KzbpDnzx3YjNREBplHvgfPr3NWr7tVbRWohRMz22MQPBovm T6im0ZOyAxXOhanhZ2SySW2g6cdiMAMhhv1k/xmQN/26gj1ntzh9fgm7D8RN0gIeP9fE JVDA== X-Gm-Message-State: AIkVDXJ+5XTdJjNO7p3aVelkZmajh5+WkbGmWrSJbYKNnTPbLgZP3AeWkIVa4juDlrrRiVocWu4= X-Received: by 10.25.199.213 with SMTP id x204mr414023lff.122.1484841304273; Thu, 19 Jan 2017 07:55:04 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-76-66.cust.bredband2.com. [83.233.76.66]) by smtp.gmail.com with ESMTPSA id b7sm927770lfe.33.2017.01.19.07.55.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Jan 2017 07:55:03 -0800 (PST) From: Christophe Milard To: mike.holmes@linaro.org, bill.fischofer@linaro.org, yi.he@linaro.org, forrest.shi@linaro.org, maxim.uvarov@linaro.com, lng-odp@lists.linaro.org Date: Thu, 19 Jan 2017 17:54:21 +0100 Message-Id: <1484844861-1302-6-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1484844861-1302-1-git-send-email-christophe.milard@linaro.org> References: <1484844861-1302-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv10 5/5] linux-gen: modules: adding initial file to load modules X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" The shared objects listed in the ODP configuration files are loaded at init time. The odp configuration file lists the shared objects to be loaded as shown in the following example: module = { modules = ["enumerator1.so", "driver1.so"]; }; Signed-off-by: Christophe Milard --- configure.ac | 4 +- platform/linux-generic/Makefile.am | 1 + platform/linux-generic/_modules.c | 53 +++++++++++++++++++++++++++ platform/linux-generic/include/odp_internal.h | 3 ++ platform/linux-generic/m4/configure.m4 | 1 + platform/linux-generic/m4/odp_modules.m4 | 11 ++++++ platform/linux-generic/odp_init.c | 7 ++++ 7 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 platform/linux-generic/_modules.c create mode 100644 platform/linux-generic/m4/odp_modules.m4 -- 2.7.4 diff --git a/configure.ac b/configure.ac index 3a20959..e2b4f9d 100644 --- a/configure.ac +++ b/configure.ac @@ -55,7 +55,7 @@ AC_PROG_MAKE_SET AM_PROG_AR #Use libtool -LT_INIT([]) +LT_INIT([dlopen]) AC_SUBST([LIBTOOL_DEPS]) AM_PROG_LIBTOOL @@ -66,7 +66,7 @@ AC_CHECK_FUNCS([bzero clock_gettime gethostbyname getpagesize gettimeofday memse # Checks for header files. AC_HEADER_RESOLV -AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h limits.h netdb.h netinet/in.h stddef.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h sys/time.h unistd.h]) +AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h limits.h netdb.h netinet/in.h stddef.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h sys/time.h unistd.h dlfcn.h]) # Checks for typedefs, structures, and compiler characteristics. AC_HEADER_STDBOOL diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 2d92c97..855f04e 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -176,6 +176,7 @@ __LIB__libodp_linux_la_SOURCES = \ _ishm.c \ _ishmphy.c \ _ishmpool.c \ + _modules.c \ odp_atomic.c \ odp_barrier.c \ odp_bitmap.c \ diff --git a/platform/linux-generic/_modules.c b/platform/linux-generic/_modules.c new file mode 100644 index 0000000..6bb854e --- /dev/null +++ b/platform/linux-generic/_modules.c @@ -0,0 +1,53 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include + +#include +#include +#include +#include +#include + +static int load_modules(void) +{ + config_t *cf; + const config_setting_t *modules_section; + int module_count; + int i; + const char *module_name; + + cf = &odp_global_data.configuration; + modules_section = config_lookup(cf, "module.modules"); + if (!modules_section) + return 0; + + module_count = config_setting_length(modules_section); + if (!module_count) + return 0; + + for (i = 0; i < module_count; i++) { + module_name = config_setting_get_string_elem(modules_section, + i); + if (dlopen(module_name, RTLD_NOW) == NULL) { + ODP_ERR("dlopen failed for %s: %s\n", + module_name, dlerror()); + return -1; + } + ODP_DBG("module %s loaded.\n", module_name); + } + + return 0; +} + +int _odp_modules_init_global(void) +{ + /* load modules (enumerator and drivers...) */ + if (load_modules()) + return -1; + + return 0; +} diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h index 9d1fc58..05c8a42 100644 --- a/platform/linux-generic/include/odp_internal.h +++ b/platform/linux-generic/include/odp_internal.h @@ -71,6 +71,7 @@ enum init_stage { CLASSIFICATION_INIT, TRAFFIC_MNGR_INIT, NAME_TABLE_INIT, + MODULES_INIT, ALL_INIT /* All init stages completed */ }; @@ -129,6 +130,8 @@ int _odp_ishm_init_local(void); int _odp_ishm_term_global(void); int _odp_ishm_term_local(void); +int _odp_modules_init_global(void); + int cpuinfo_parser(FILE *file, system_info_t *sysinfo); uint64_t odp_cpu_hz_current(int id); diff --git a/platform/linux-generic/m4/configure.m4 b/platform/linux-generic/m4/configure.m4 index 5fab0cc..f5f076a 100644 --- a/platform/linux-generic/m4/configure.m4 +++ b/platform/linux-generic/m4/configure.m4 @@ -42,6 +42,7 @@ fi m4_include([platform/linux-generic/m4/odp_pthread.m4]) m4_include([platform/linux-generic/m4/odp_openssl.m4]) m4_include([platform/linux-generic/m4/odp_pcap.m4]) +m4_include([platform/linux-generic/m4/odp_modules.m4]) m4_include([platform/linux-generic/m4/odp_netmap.m4]) m4_include([platform/linux-generic/m4/odp_dpdk.m4]) m4_include([platform/linux-generic/m4/odp_ipc.m4]) diff --git a/platform/linux-generic/m4/odp_modules.m4 b/platform/linux-generic/m4/odp_modules.m4 new file mode 100644 index 0000000..03f61f8 --- /dev/null +++ b/platform/linux-generic/m4/odp_modules.m4 @@ -0,0 +1,11 @@ +########################################################################## +# Check for dlopen and lt equivalent availability +########################################################################## + +AC_SEARCH_LIBS([dlopen], [dl dld], + [ + AM_LDFLAGS="$AM_LDFLAGS -ldl" + ], + [ + AC_MSG_ERROR([Error! dlopen not available!]) + ]) diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c index 0e9167c..2cd8fe3 100644 --- a/platform/linux-generic/odp_init.c +++ b/platform/linux-generic/odp_init.c @@ -259,6 +259,12 @@ int odp_init_global(odp_instance_t *instance, ODP_ERR("ODP name table init failed\n"); goto init_failed; } + stage = NAME_TABLE_INIT; + + if (_odp_modules_init_global()) { + ODP_ERR("ODP modules init failed\n"); + goto init_failed; + } *instance = (odp_instance_t)odp_global_data.main_pid; @@ -284,6 +290,7 @@ int _odp_term_global(enum init_stage stage) switch (stage) { case ALL_INIT: + case MODULES_INIT: case NAME_TABLE_INIT: if (_odp_int_name_tbl_term_global()) { ODP_ERR("Name table term failed.\n");