DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Burakov, Anatoly" <anatoly.burakov@intel.com>
To: Yongxin Liu <yongxin.liu@windriver.com>,
	dev@dpdk.org, thomas@monjalon.net
Subject: Re: [dpdk-dev] [PATCH v4] usertools/devbind: fix binding for built-in kernel drivers
Date: Fri, 20 Nov 2020 10:49:34 +0000	[thread overview]
Message-ID: <3e3536e2-1947-6c85-1069-394dc88b483b@intel.com> (raw)
In-Reply-To: <20201120022233.25498-1-yongxin.liu@windriver.com>

On 20-Nov-20 2:22 AM, Yongxin Liu wrote:
> A driver can be loaded as a dynamic module or a built-in module.
> In commit 681a67288655 ("usertools: check if module is loaded
> before binding"), script only checks modules in /sys/module/.
> 
> However, for built-in kernel driver, it only shows up in /sys/module/,
> if it has a version or at least one parameter. So add check for
> modules in /lib/modules/$(uname -r)/modules.builtin.
> 
> Thanks for Anatoly Burakov's advice.
> 
> Signed-off-by: Yongxin Liu <yongxin.liu@windriver.com>
> ---
> 
> v4:
>   - Replace shell call with platform.uname(). Check file existence
>     before reading.
> 
> v3:
>   - Add built-in module list in loaded_modules for checking
>     instead of removing error check.
> 
> v2:
>   - fix git commit description style in commit log
>   - fix typo spelling
> 
> ---
>   usertools/dpdk-devbind.py | 19 ++++++++++++++++++-
>   1 file changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
> index 99112b7ab..06721709c 100755
> --- a/usertools/dpdk-devbind.py
> +++ b/usertools/dpdk-devbind.py
> @@ -7,6 +7,7 @@
>   import os
>   import getopt
>   import subprocess
> +import platform
>   from glob import glob
>   from os.path import exists, abspath, dirname, basename
>   from os.path import join as path_join
> @@ -181,7 +182,23 @@ def module_is_loaded(module):
>   
>       loaded_modules = sysfs_mods
>   
> -    return module in sysfs_mods
> +    # add built-in modules as loaded
> +    release = platform.uname().release
> +    filename = os.path.join("/lib/modules/", release, "modules.builtin")
> +    if os.path.exists(filename):
> +        try:
> +            f = open(filename, "r")
> +        except:
> +            print("Error: cannot open %s" % filename)
> +            return
> +
> +        builtin_mods = f.readlines()
> +
> +        for mod in builtin_mods:
> +            mod_name = os.path.splitext(os.path.basename(mod))
> +            loaded_modules.append(mod_name[0])
> +

You're not returning a value in error case, this would cause error in 
the caller of this function.

Also, i'd avoid reading the entire file into memory, instead I'd do 
something like this:

try:
     with open(filename) as f:
         loaded_modules += [os.path.splitext(os.path.basename(mod)[0]
                            for mod in f]
except IOError:
     print("Warning: cannot read list of built-in kernel modules")

# continue with regular code

This will be faster, more and readable as well :)

> +    return module in loaded_modules
>   
>   
>   def check_modules():
> 


-- 
Thanks,
Anatoly

  reply	other threads:[~2020-11-20 10:49 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-18  2:58 [dpdk-dev] [PATCH v2] usertools/devbind: fix binding for built-in 1kernel drivers Yongxin Liu
2020-11-18 16:27 ` Burakov, Anatoly
2020-11-19  7:24   ` Liu, Yongxin
2020-11-19  7:16 ` [dpdk-dev] [PATCH v3] usertools/devbind: fix binding for built-in kernel drivers Yongxin Liu
2020-11-19 12:18   ` Burakov, Anatoly
2020-11-20  2:30     ` Liu, Yongxin
2020-11-20  2:22 ` [dpdk-dev] [PATCH v4] " Yongxin Liu
2020-11-20 10:49   ` Burakov, Anatoly [this message]
2020-11-20 11:38   ` Burakov, Anatoly
2020-11-23  3:05 ` [dpdk-dev] [PATCH v5] " Yongxin Liu
2020-12-03  8:25   ` Liu, Yongxin
2021-02-11 10:43     ` Burakov, Anatoly
2021-02-11 22:19       ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3e3536e2-1947-6c85-1069-394dc88b483b@intel.com \
    --to=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    --cc=thomas@monjalon.net \
    --cc=yongxin.liu@windriver.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).