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 D2855A0548; Mon, 8 Feb 2021 23:12:16 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4BBB0160722; Mon, 8 Feb 2021 23:12:16 +0100 (CET) Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by mails.dpdk.org (Postfix) with ESMTP id 759FD16071D for ; Mon, 8 Feb 2021 23:12:15 +0100 (CET) Received: by mail-pg1-f173.google.com with SMTP id n10so11144321pgl.10 for ; Mon, 08 Feb 2021 14:12:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rB8/vDYgY97ArU8z7W+8nHV9FjCoIjlKvfQV30OyU7Y=; b=NnqlgGpz3fe1/klmk1Fm2Y14afuwUt8hZrzOqIawpQMLQPS5En6szytWv7ZZtodGUk gJV9FHqsbgXJcI+zMN+tRsLhAdEyNWyxekKDOcRfgf0zoDa0t9gMu4llq3VYg6Abf7M8 IHi9Qb6Wt2+fdf3spYAUxfEa7YD3mf5mfMKdJ6FY6M/2zwonue8Gt1wncdUSAup0mAy8 K5Ef806hG2WbH3DmsPF+MGes/7XiFjaUpDmzSqyVg5DzzGI9KsjhM+ANdKtKkpHMXgbO ZzaeZrkR2ulI0VWj+Cl44vY/uf5/GbvO5U1Sj4xvnu9EGzOnxpuh3tQM93PQpH3tSFY/ hFoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rB8/vDYgY97ArU8z7W+8nHV9FjCoIjlKvfQV30OyU7Y=; b=Pbi7ylVy4dS7zibnsr5LBsRResPKDum1mjlxuxZ0K+Mnd/ZZQ7x1Xkc7RXx15CrWUd nr4LZX0/M6IHZBzul8Fz7rkkuDwz/0eRqcFqAjaqkXtWkmpGPtbJP1kc9za3BUFYxZzG wykLMSYyXWcJzFojROTwHL/JmdJJ0drBcNoS2n/y4IOrJo4oUpzlR7cQDiW0A+nbQX+C bEokBlWJgt0vc72GcQxENjtAIJmiSaKc9OSITmfJ9QHtdRrCstgUzgfaJAJbj07o6WRo 6FpR4QAwwWX2PS+FQ3LYFFWjl8ieQO7+CNWADER+3N/DmysnmJgxtSDGhvgYKuUpk2Bx nzBg== X-Gm-Message-State: AOAM530BptCb51aGNIZ4/1DnY2Dmjfd251BP6Mhg+6Ayu5FDGhSXj3NN GADPU7kl9mGaYtTdf/YP3fCHLQ== X-Google-Smtp-Source: ABdhPJzCgN6q9FJNNukbFPi2yiYJs3I6ZiFirjSEYM7a4Xgq/vd3oC03kq+9T55loV2g+NZoqKZPwQ== X-Received: by 2002:a62:2785:0:b029:1d2:7de2:c56f with SMTP id n127-20020a6227850000b02901d27de2c56fmr20200192pfn.59.1612822334382; Mon, 08 Feb 2021 14:12:14 -0800 (PST) Received: from hermes.local (76-14-222-244.or.wavecable.com. [76.14.222.244]) by smtp.gmail.com with ESMTPSA id a78sm4104188pfa.10.2021.02.08.14.12.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Feb 2021 14:12:13 -0800 (PST) Date: Mon, 8 Feb 2021 14:12:09 -0800 From: Stephen Hemminger To: Thomas Monjalon Cc: Sarosh Arif , sthemmin@microsoft.com, dev@dpdk.org Message-ID: <20210208141209.73f194b3@hermes.local> In-Reply-To: <2159847.9U2c7sIdO1@thomas> References: <20201130124719.23434-1-sarosh.arif@emumba.com> <20201202110654.20923-1-sarosh.arif@emumba.com> <2159847.9U2c7sIdO1@thomas> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII 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 Fri, 05 Feb 2021 19:17:52 +0100 Thomas Monjalon wrote: > 02/12/2020 12:06, Sarosh Arif: > > 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 > > Stephen, is this version OK? This looks good. > > > +def get_valid_page_sizes(path): > > + valid_page_sizes = "" > > + hugepage_dir_path = os.path.split(path)[0] > > Sorry for not following. Why this split? > Maybe add a comment? Guess the code here is using split ad equivalent of dirname() on the path. The path is the string which holds the full filename of the attempted write to sysfs. So this is to get the directory part which could be numa or non-numa. > > > + 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 > > Why not using += here? Should work. Overall, this reads a bit like C code here. A python wizard would use list comprehensions here https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions > > > + 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))) > > >