[dpdk-dev,v7,2/2] eal/linux: Add support for handling built-in kernel modules

Message ID 1453986834-31128-2-git-send-email-krytarowski@caviumnetworks.com (mailing list archive)
State Accepted, archived
Headers

Commit Message

Kamil Rytarowski Jan. 28, 2016, 1:13 p.m. UTC
  From: Kamil Rytarowski <Kamil.Rytarowski@caviumnetworks.com>

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 <Kamil.Rytarowski@caviumnetworks.com>
Acked-by: David Marchand <david.marchand@6wind.com>
Acked-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 lib/librte_eal/linuxapp/eal/eal.c | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)
  

Comments

Thomas Monjalon Feb. 9, 2016, 2:56 p.m. UTC | #1
2016-01-28 14:13, krytarowski@caviumnetworks.com:
> From: Kamil Rytarowski <Kamil.Rytarowski@caviumnetworks.com>
> 
> 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 <Kamil.Rytarowski@caviumnetworks.com>
> Acked-by: David Marchand <david.marchand@6wind.com>
> Acked-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>

An include is missing:
#include <sys/stat.h>
After adding this line,
Series applied, thanks
  
Kamil Rytarowski Feb. 9, 2016, 4:07 p.m. UTC | #2
Thank you!

W dniu 09.02.2016 o 15:56, Thomas Monjalon pisze:
> 2016-01-28 14:13, krytarowski@caviumnetworks.com:
>> From: Kamil Rytarowski <Kamil.Rytarowski@caviumnetworks.com>
>>
>> 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 <Kamil.Rytarowski@caviumnetworks.com>
>> Acked-by: David Marchand <david.marchand@6wind.com>
>> Acked-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
> An include is missing:
> #include <sys/stat.h>
> After adding this line,
> Series applied, thanks
>
  

Patch

diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 635ec36..21a4a32 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -901,27 +901,33 @@  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;
+	char sysfs_mod_name[PATH_MAX];
+	struct stat st;
 	int n;
 
 	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, "sysfs is not mounted! error %i (%s)\n",
+			errno, 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 */
+	n = snprintf(sysfs_mod_name, PATH_MAX, "/sys/module/%s", module_name);
+	if (n < 0 || n > PATH_MAX) {
+		RTE_LOG(DEBUG, EAL, "Could not format module path\n");
+		return -1;
 	}
-	fclose(fd);
 
-	return ret;
+	if (stat(sysfs_mod_name, &st) != 0) {
+		RTE_LOG(DEBUG, EAL, "Module %s not found! error %i (%s)\n",
+		        sysfs_mod_name, errno, strerror(errno));
+		return 0;
+	}
+
+	/* Module has been found */
+	return 1;
 }