From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CC186A0547; Tue, 9 Feb 2021 12:34:20 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 462E71606FD; Tue, 9 Feb 2021 12:34:20 +0100 (CET) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mails.dpdk.org (Postfix) with ESMTP id 26C8240147 for ; Tue, 9 Feb 2021 12:34:18 +0100 (CET) IronPort-SDR: ogWBm4+WeWYgQb6CZh+tmgptmbUq59o230qphLyGTCjWSCwgPBF3qmXqQJ1iAqsnZPATUSHtbl ygyPideHDsdw== X-IronPort-AV: E=McAfee;i="6000,8403,9889"; a="161017548" X-IronPort-AV: E=Sophos;i="5.81,164,1610438400"; d="scan'208";a="161017548" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2021 03:34:17 -0800 IronPort-SDR: OvjHBEcaUbpYwQ0ftwCzB17sXzUswvrxNeVYpOTh/ZnpYdtihBDa2i3tDJYA58vnxAOKgkPnL6 vMNf8Qol3X3w== X-IronPort-AV: E=Sophos;i="5.81,164,1610438400"; d="scan'208";a="378875832" Received: from aburakov-mobl.ger.corp.intel.com (HELO [10.213.229.136]) ([10.213.229.136]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2021 03:34:16 -0800 To: Sarosh Arif , sthemmin@microsoft.com Cc: dev@dpdk.org References: <20201130124719.23434-1-sarosh.arif@emumba.com> <20201202110654.20923-1-sarosh.arif@emumba.com> From: "Burakov, Anatoly" Message-ID: Date: Tue, 9 Feb 2021 11:34:15 +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: <20201202110654.20923-1-sarosh.arif@emumba.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [v2 PATCH] usertools: show valid hugepage sizes if user requests an invalid hugepage size X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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 02-Dec-20 11:06 AM, Sarosh Arif wrote: > If user requests a hugepage size which is not supported by the system, > currently user gets an error message saying that the requested size > is not a valid system huge page size. In addition to this if we display > the valid hugepage sizes it will be convenient for the user to request > the right size next time. > > Signed-off-by: Sarosh Arif > --- > v2: > pass string in sys.exit() to remove pylint warning > --- > usertools/dpdk-hugepages.py | 14 ++++++++++---- > 1 file changed, 10 insertions(+), 4 deletions(-) > > diff --git a/usertools/dpdk-hugepages.py b/usertools/dpdk-hugepages.py > index 1be100ca3..09d35bf55 100755 > --- a/usertools/dpdk-hugepages.py > +++ b/usertools/dpdk-hugepages.py > @@ -49,6 +49,14 @@ def get_hugepages(path): > return int(nr_hugepages.read()) > return 0 > > +def get_valid_page_sizes(path): > + valid_page_sizes = "" > + hugepage_dir_path = os.path.split(path)[0] os.path.dirname() ? > + hugepage_dirs = os.listdir(hugepage_dir_path) > + for each_dir in hugepage_dirs: > + hugepage_size = each_dir.split("-")[1] > + valid_page_sizes = valid_page_sizes + " " + hugepage_size You could rewrite this to be clearer and more concise: def get_valid_page_sizes(path): dir = os.path.dirname(path) pg_sizes = (d.split("-")[1] for d in os.listdir(dir)) return " ".join(pg_sizes) > + return valid_page_sizes > > def set_hugepages(path, pages): > '''Write the number of reserved huge pages''' > @@ -59,10 +67,8 @@ def set_hugepages(path, pages): > except PermissionError: > sys.exit('Permission denied: need to be root!') > except FileNotFoundError: > - filename = os.path.basename(path) > - size = filename[10:] > - sys.exit('{} is not a valid system huge page size'.format(size)) > - > + sys.exit("Invalid page size. Valid page sizes: {}".format( > + get_valid_page_sizes(path))) > > def show_numa_pages(): > '''Show huge page reservations on Numa system''' > -- Thanks, Anatoly