[dpdk-dev] [v2 PATCH] usertools: show valid hugepage sizes if user requests an invalid hugepage size

Thomas Monjalon thomas at monjalon.net
Fri Feb 5 19:17:52 CET 2021


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 <sarosh.arif at emumba.com>
> ---
> v2:
> pass string in sys.exit() to remove pylint warning

Stephen, is this version OK?

> +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?

> +    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?

> +    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)))





More information about the dev mailing list