From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kamil Rytarowski Subject: [PATCH v3 2/2] eal/linux: Add support for handling built-in kernel modules Date: Mon, 7 Dec 2015 19:36:05 +0100 Message-ID: <1449513365-22282-2-git-send-email-Kamil.Rytarowski@caviumnetworks.com> References: <1449507460-32038-1-git-send-email-Kamil.Rytarowski@caviumnetworks.com> <1449513365-22282-1-git-send-email-Kamil.Rytarowski@caviumnetworks.com> Mime-Version: 1.0 Content-Type: text/plain To: Return-path: Received: from na01-bn1-obe.outbound.protection.outlook.com (mail-bn1bon0093.outbound.protection.outlook.com [157.56.111.93]) by dpdk.org (Postfix) with ESMTP id 572199A92 for ; Mon, 7 Dec 2015 19:36:31 +0100 (CET) In-Reply-To: <1449513365-22282-1-git-send-email-Kamil.Rytarowski@caviumnetworks.com> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Currently rte_eal_check_module() detects Linux kernel modules via reading /proc/modules. Built-in ones aren't listed there and therefore they are not being found by the script. Add support for checking built-in modules with parsing the sysfs files This commit obsoletes the /proc/modules parsing approach. Signed-off-by: Kamil Rytarowski --- lib/librte_eal/linuxapp/eal/eal.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c index 635ec36..539188f 100644 --- a/lib/librte_eal/linuxapp/eal/eal.c +++ b/lib/librte_eal/linuxapp/eal/eal.c @@ -52,6 +52,8 @@ #if defined(RTE_ARCH_X86_64) || defined(RTE_ARCH_I686) #include #endif +#include +#include #include #include @@ -901,27 +903,27 @@ int rte_eal_has_hugepages(void) int rte_eal_check_module(const char *module_name) { - char mod_name[30]; /* Any module names can be longer than 30 bytes? */ - int ret = 0; - int n; + char sysfs_mod_name[PATH_MAX]; + struct stat st; if (NULL == module_name) return -1; - FILE *fd = fopen("/proc/modules", "r"); - if (NULL == fd) { - RTE_LOG(ERR, EAL, "Open /proc/modules failed!" - " error %i (%s)\n", errno, strerror(errno)); + /* Check if there is sysfs mounted */ + if (stat("/sys/module", &st) != 0) { + RTE_LOG(DEBUG, EAL, "Open /sys/module failed: %s\n", + strerror(errno)); return -1; } - while (!feof(fd)) { - n = fscanf(fd, "%29s %*[^\n]", mod_name); - if ((n == 1) && !strcmp(mod_name, module_name)) { - ret = 1; - break; - } + + /* A module might be built-in, therefore try sysfs */ + snprintf(sysfs_mod_name, PATH_MAX, "/sys/module/%s", module_name); + if (stat(sysfs_mod_name, &st) != 0) { + RTE_LOG(DEBUG, EAL, "Open %s failed! error %i (%s)\n", + sysfs_mod_name, errno, strerror(errno)); + return 0; } - fclose(fd); - return ret; + /* Module has been found */ + return 1; } -- 2.5.0