usertools: show valid hugepage sizes if user requests an invalid hugepage size
diff mbox series

Message ID 20201130124719.23434-1-sarosh.arif@emumba.com
State Superseded
Delegated to: Thomas Monjalon
Headers show
Series
  • usertools: show valid hugepage sizes if user requests an invalid hugepage size
Related show

Checks

Context Check Description
ci/travis-robot success Travis build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/checkpatch success coding style OK

Commit Message

Sarosh Arif Nov. 30, 2020, 12:47 p.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>
---
 usertools/dpdk-hugepages.py | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

Comments

Stephen Hemminger Nov. 30, 2020, 4:46 p.m. UTC | #1
On Mon, 30 Nov 2020 17:47:19 +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>
> ---
>  usertools/dpdk-hugepages.py | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)

If the two patches depend on each other, they should be sent in one
email thread with 1/2 2/2 in header.

This patch introduces pylint warning

usertools/dpdk-hugepages.py:52:0: C0116: Missing function or method docstring (missing-function-docstring)
Stephen Hemminger Nov. 30, 2020, 4:47 p.m. UTC | #2
On Mon, 30 Nov 2020 17:47:19 +0500
Sarosh Arif <sarosh.arif@emumba.com> wrote:

> -        sys.exit('{} is not a valid system huge page size'.format(size))
> -
> +        print('{} is not a valid system huge page size'.format(size))
> +        show_valid_page_sizes(path)
> +        sys.exit()

This is not the same. You should change the helper function to return
a string and do:

	sys.exit('Invalid page size. Valid sizes are:', valid_page_sizes())

Patch
diff mbox series

diff --git a/usertools/dpdk-hugepages.py b/usertools/dpdk-hugepages.py
index 1be100ca3..f503ad377 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 show_valid_page_sizes(path):
+    valid_page_sizes = ""
+    hugepage_dir_path = os.path.split(path)[0]
+    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
+    print("valid page sizes: {}".format(valid_page_sizes))
 
 def set_hugepages(path, pages):
     '''Write the number of reserved huge pages'''
@@ -61,8 +69,9 @@  def set_hugepages(path, pages):
     except FileNotFoundError:
         filename = os.path.basename(path)
         size = filename[10:]
-        sys.exit('{} is not a valid system huge page size'.format(size))
-
+        print('{} is not a valid system huge page size'.format(size))
+        show_valid_page_sizes(path)
+        sys.exit()
 
 def show_numa_pages():
     '''Show huge page reservations on Numa system'''