[v4] usertools: show valid hugepage sizes if user requests an invalid hugepage size

Message ID 20210211082004.23626-1-sarosh.arif@emumba.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v4] usertools: show valid hugepage sizes if user requests an invalid hugepage size |

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/iol-broadcom-Functional success Functional Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-testing warning Testing issues
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-mellanox-Functional success Functional Testing PASS
ci/checkpatch success coding style OK

Commit Message

Sarosh Arif Feb. 11, 2021, 8:20 a.m. UTC
  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 <sarosh.arif@emumba.com>
---
v2:
pass string in sys.exit() to remove pylint warning
v3:
modify get_valid_page_sizes()
v4:
fix indentation
---
 usertools/dpdk-hugepages.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
  

Comments

Stephen Hemminger Feb. 11, 2021, 4:26 p.m. UTC | #1
On Thu, 11 Feb 2021 13:20:04 +0500
Sarosh Arif <sarosh.arif@emumba.com> 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 <sarosh.arif@emumba.com>

Looks good, thanks for following up.

Acked-by: Stephen Hemminger <stephen@networkplumber.org>
  
Thomas Monjalon Feb. 11, 2021, 9:44 p.m. UTC | #2
11/02/2021 09:20, 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 <sarosh.arif@emumba.com>
> ---
> --- a/usertools/dpdk-hugepages.py
> +++ b/usertools/dpdk-hugepages.py
> @@ -43,6 +43,12 @@ def is_numa():
>      return os.path.exists('/sys/devices/system/node')
>  
>  
> +def get_valid_page_sizes(path):
> +    '''Extract valid hugepage sizes'''
> +    dir = os.path.dirname(path)
> +    pg_sizes = (d.split("-")[1] for d in os.listdir(dir))
> +    return " ".join(pg_sizes)
> +

A second blank line is required here.

>  def get_hugepages(path):
>      '''Read number of reserved pages'''
>      with open(path + '/nr_hugepages') as nr_hugepages:
> @@ -59,9 +65,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)))

Alignment needs a small fixup.

After these small changes, flake8 is OK.

Applied, thanks.
  
Stephen Hemminger Feb. 11, 2021, 11:16 p.m. UTC | #3
On Thu, 11 Feb 2021 22:44:03 +0100
Thomas Monjalon <thomas@monjalon.net> wrote:

> 11/02/2021 09:20, 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 <sarosh.arif@emumba.com>
> > ---
> > --- a/usertools/dpdk-hugepages.py
> > +++ b/usertools/dpdk-hugepages.py
> > @@ -43,6 +43,12 @@ def is_numa():
> >      return os.path.exists('/sys/devices/system/node')
> >  
> >  
> > +def get_valid_page_sizes(path):
> > +    '''Extract valid hugepage sizes'''
> > +    dir = os.path.dirname(path)
> > +    pg_sizes = (d.split("-")[1] for d in os.listdir(dir))
> > +    return " ".join(pg_sizes)
> > +  
> 
> A second blank line is required here.
> 
> >  def get_hugepages(path):
> >      '''Read number of reserved pages'''
> >      with open(path + '/nr_hugepages') as nr_hugepages:
> > @@ -59,9 +65,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)))  
> 
> Alignment needs a small fixup.
> 
> After these small changes, flake8 is OK.
> 
> Applied, thanks.

I used Yet-Another-Python-Formmatter originally (yapf).
Its preferred style for that would be:
diff --git a/usertools/dpdk-hugepages.py b/usertools/dpdk-hugepages.py
index fb368b693399..28eba86641f7 100755
--- a/usertools/dpdk-hugepages.py
+++ b/usertools/dpdk-hugepages.py
@@ -67,7 +67,7 @@ def set_hugepages(path, pages):
         sys.exit('Permission denied: need to be root!')
     except FileNotFoundError:
         sys.exit("Invalid page size. Valid page sizes: {}".format(
-                 get_valid_page_sizes(path)))
+            get_valid_page_sizes(path)))
     if get_hugepages(path) != pages:
         sys.exit('Unable to reserve required pages.')
  

Patch

diff --git a/usertools/dpdk-hugepages.py b/usertools/dpdk-hugepages.py
index 70432f9cd..e68bae5a4 100755
--- a/usertools/dpdk-hugepages.py
+++ b/usertools/dpdk-hugepages.py
@@ -43,6 +43,12 @@  def is_numa():
     return os.path.exists('/sys/devices/system/node')
 
 
+def get_valid_page_sizes(path):
+    '''Extract valid hugepage sizes'''
+    dir = os.path.dirname(path)
+    pg_sizes = (d.split("-")[1] for d in os.listdir(dir))
+    return " ".join(pg_sizes)
+
 def get_hugepages(path):
     '''Read number of reserved pages'''
     with open(path + '/nr_hugepages') as nr_hugepages:
@@ -59,9 +65,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)))
     if get_hugepages(path) != pages:
         sys.exit('Unable to reserve required pages.')