DPDK patches and discussions
 help / color / mirror / Atom feed
From: gowrishankar muthukrishnan <gowrishankar.m@linux.vnet.ibm.com>
To: Thomas Monjalon <thomas@monjalon.net>,
	Andriy Berestovskyy <andriy.berestovskyy@caviumnetworks.com>
Cc: dev@dpdk.org
Subject: Re: [dpdk-dev] [PATCH] usertools: fix CPU layout with python 3
Date: Mon, 1 May 2017 11:59:01 +0530	[thread overview]
Message-ID: <1234535c-4633-8556-47ba-f4b8219c7f55@linux.vnet.ibm.com> (raw)
In-Reply-To: <20170430141140.7865-1-thomas@monjalon.net>

On Sunday 30 April 2017 07:41 PM, Thomas Monjalon wrote:
> These differences in Python 3 were causing errors:
> - xrange is replaced by range
> - dict values are a view (instead of list)
> - has_key is removed
Thanks Thomas.

Please include minor correction in your patch as below.
> Fixes: deb87e6777c0 ("usertools: use sysfs for CPU layout")
> Fixes: 63985c5f104e ("usertools: fix CPU layout for more than 2 threads")
>
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> ---
>   usertools/cpu_layout.py | 8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/usertools/cpu_layout.py b/usertools/cpu_layout.py
> index 99152a2ec..74da928df 100755
> --- a/usertools/cpu_layout.py
> +++ b/usertools/cpu_layout.py
> @@ -35,6 +35,10 @@
>   #
>   from __future__ import print_function
>   import sys
> +try:
> +    xrange # Python 2
> +except NameError:
> +    xrange = range # Python 3
>
>   sockets = []
>   cores = []
> @@ -72,7 +76,7 @@
>   print("")
>
>   max_processor_len = len(str(len(cores) * len(sockets) * 2 - 1))
> -max_thread_count = len(core_map.values()[0])
> +max_thread_count = len(core_map)

We need to retain thread count calculated from any of core_map values 
(index 0 as in patch),
hence keeping ljust() in output same as w/o this change. So,

max_thread_count = len(list(core_map.values())[0])

Above list() ensures return values are in list always irrespective of 
python 2x / 3x.

Regards,
Gowrishankar

>   max_core_map_len = (max_processor_len * max_thread_count)  \
>                         + len(", ") * (max_thread_count - 1) \
>                         + len('[]') + len('Socket ')
> @@ -92,7 +96,7 @@
>   for c in cores:
>       output = "Core %s" % str(c).ljust(max_core_id_len)
>       for s in sockets:
> -        if core_map.has_key((s,c)):
> +        if (s,c) in core_map:
>               output += " " + str(core_map[(s, c)]).ljust(max_core_map_len)
>           else:
>               output += " " * (max_core_map_len + 1)

  reply	other threads:[~2017-05-01  6:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-30 14:11 Thomas Monjalon
2017-05-01  6:29 ` gowrishankar muthukrishnan [this message]
2017-05-01 22:17   ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1234535c-4633-8556-47ba-f4b8219c7f55@linux.vnet.ibm.com \
    --to=gowrishankar.m@linux.vnet.ibm.com \
    --cc=andriy.berestovskyy@caviumnetworks.com \
    --cc=dev@dpdk.org \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).