From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id DCBA1A04DD; Fri, 20 Nov 2020 11:49:43 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 1999DC87E; Fri, 20 Nov 2020 11:49:42 +0100 (CET) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 732B63B5 for ; Fri, 20 Nov 2020 11:49:40 +0100 (CET) IronPort-SDR: Sqrpca+0NEKQo7/QtBQprTJKHJpBbJ+eeYF0U77hCStFFjO8qMCNGkgZ3KvHNL3qfSaJcGHVm5 btzLlmCLa2pQ== X-IronPort-AV: E=McAfee;i="6000,8403,9810"; a="189554191" X-IronPort-AV: E=Sophos;i="5.78,356,1599548400"; d="scan'208";a="189554191" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2020 02:49:38 -0800 IronPort-SDR: XJGlvRGMwO4eyTqmAcAcbrbSegtEeV9nVIP/ZbbGgw048RAUgJSWCl/lrhB2a0JOU77TbDttcw cd5lI8l7ZtjA== X-IronPort-AV: E=Sophos;i="5.78,356,1599548400"; d="scan'208";a="360398890" Received: from aburakov-mobl.ger.corp.intel.com (HELO [10.213.212.249]) ([10.213.212.249]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2020 02:49:37 -0800 To: Yongxin Liu , dev@dpdk.org, thomas@monjalon.net References: <20201118025854.13455-1-yongxin.liu@windriver.com> <20201120022233.25498-1-yongxin.liu@windriver.com> From: "Burakov, Anatoly" Message-ID: <3e3536e2-1947-6c85-1069-394dc88b483b@intel.com> Date: Fri, 20 Nov 2020 10:49:34 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <20201120022233.25498-1-yongxin.liu@windriver.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH v4] usertools/devbind: fix binding for built-in kernel drivers X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 > --- > > 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