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

2015-12-07 Thread David Marchand
Hello Kamil,

On Mon, Dec 7, 2015 at 5:57 PM, Kamil Rytarowski <
Kamil.Rytarowski at caviumnetworks.com> wrote:

> 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
>
> Signed-off-by: Kamil Rytarowski 
> ---
>  lib/librte_eal/linuxapp/eal/eal.c | 21 -
>  1 file changed, 20 insertions(+), 1 deletion(-)
>
> diff --git a/lib/librte_eal/linuxapp/eal/eal.c
> b/lib/librte_eal/linuxapp/eal/eal.c
> index 635ec36..6cab906 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 
> @@ -902,7 +904,10 @@ int
>  rte_eal_check_module(const char *module_name)
>  {
> char mod_name[30]; /* Any module names can be longer than 30
> bytes? */
> +   char sysfs_mod_name[PATH_MAX];
> +   struct stat st;
> int ret = 0;
> +   int rv;
> int n;
>
> if (NULL == module_name)
> @@ -918,9 +923,23 @@ rte_eal_check_module(const char *module_name)
> n = fscanf(fd, "%29s %*[^\n]", mod_name);
> if ((n == 1) && !strcmp(mod_name, module_name)) {
> ret = 1;
> -   break;
> +   goto finish;
> }
> }
> +   RTE_LOG(DEBUG, EAL, "Module %s not found in /proc/modules",
> +   module_name);
> +
> +   /* A module might be builtin, try sysfs */
> +   snprintf(sysfs_mod_name, PATH_MAX, "/sys/module/%s", module_name);
> +   if ((rv = stat(sysfs_mod_name, &st)) == 0) {
> +   ret = 1;
> +   goto finish;
> +   }
> +
> +   RTE_LOG(DEBUG, EAL, "Open %s failed! error %i (%s)\n",
> +   sysfs_mod_name, errno, strerror(errno));
> +
> +finish:
> fclose(fd);
>
> return ret;
>

Well, in the end, won't all modules end up in /sys/module ?
So, I would say we can get rid of /proc/modules parsing.

The only thing that bothers me is this comment in the kernel documentation :


/sys/module/MODULENAME
The name of the module that is in the kernel.
This
module name will always show up if the module is loaded as
a
dynamic module.  If it is built directly into the kernel,
it
will only show up if it has a version or at least
one

parameter.


Note: The conditions of creation in the built-in case are
not
by design and may be removed in the
future.

But, at the moment, I suppose we are fine.


-- 
David Marchand


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

2015-12-07 Thread Kamil Rytarowski
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

Signed-off-by: Kamil Rytarowski 
---
 lib/librte_eal/linuxapp/eal/eal.c | 21 -
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/linuxapp/eal/eal.c 
b/lib/librte_eal/linuxapp/eal/eal.c
index 635ec36..6cab906 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 
@@ -902,7 +904,10 @@ int
 rte_eal_check_module(const char *module_name)
 {
char mod_name[30]; /* Any module names can be longer than 30 bytes? */
+   char sysfs_mod_name[PATH_MAX];
+   struct stat st;
int ret = 0;
+   int rv;
int n;

if (NULL == module_name)
@@ -918,9 +923,23 @@ rte_eal_check_module(const char *module_name)
n = fscanf(fd, "%29s %*[^\n]", mod_name);
if ((n == 1) && !strcmp(mod_name, module_name)) {
ret = 1;
-   break;
+   goto finish;
}
}
+   RTE_LOG(DEBUG, EAL, "Module %s not found in /proc/modules",
+   module_name);
+
+   /* A module might be builtin, try sysfs */
+   snprintf(sysfs_mod_name, PATH_MAX, "/sys/module/%s", module_name);
+   if ((rv = stat(sysfs_mod_name, &st)) == 0) {
+   ret = 1;
+   goto finish;
+   }
+
+   RTE_LOG(DEBUG, EAL, "Open %s failed! error %i (%s)\n",
+   sysfs_mod_name, errno, strerror(errno));
+
+finish:
fclose(fd);

return ret;
-- 
2.5.0