From: Arnaldo Carvalho de Melo <[email protected]>

3.4.112-rc1 review patch.  If anyone has any objections, please let me know.

------------------


commit caa470475d9b59eeff093ae650800d34612c4379 upstream.

The original patch introducing this header wrote the number of CPUs available
and online in one order and then swapped those values when reading, fix it.

Before:

  # perf record usleep 1
  # perf report --header-only | grep 'nrcpus \(online\|avail\)'
  # nrcpus online : 4
  # nrcpus avail : 4
  # echo 0 > /sys/devices/system/cpu/cpu2/online
  # perf record usleep 1
  # perf report --header-only | grep 'nrcpus \(online\|avail\)'
  # nrcpus online : 4
  # nrcpus avail : 3
  # echo 0 > /sys/devices/system/cpu/cpu1/online
  # perf record usleep 1
  # perf report --header-only | grep 'nrcpus \(online\|avail\)'
  # nrcpus online : 4
  # nrcpus avail : 2

After the fix, bringing back the CPUs online:

  # perf report --header-only | grep 'nrcpus \(online\|avail\)'
  # nrcpus online : 2
  # nrcpus avail : 4
  # echo 1 > /sys/devices/system/cpu/cpu2/online
  # perf record usleep 1
  # perf report --header-only | grep 'nrcpus \(online\|avail\)'
  # nrcpus online : 3
  # nrcpus avail : 4
  # echo 1 > /sys/devices/system/cpu/cpu1/online
  # perf record usleep 1
  # perf report --header-only | grep 'nrcpus \(online\|avail\)'
  # nrcpus online : 4
  # nrcpus avail : 4

Acked-by: Namhyung Kim <[email protected]>
Cc: Adrian Hunter <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Kan Liang <[email protected]>
Cc: Stephane Eranian <[email protected]>
Cc: Wang Nan <[email protected]>
Fixes: fbe96f29ce4b ("perf tools: Make perf.data more self-descriptive (v8)")
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
[lizf: Backported to 3.4: fix it by saving values in an array and then print
 it in reverse order]
Signed-off-by: Zefan Li <[email protected]>
---
 tools/perf/util/header.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index c0b70c6..5a4482c 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1060,25 +1060,19 @@ static void print_cpudesc(struct perf_header *ph, int 
fd, FILE *fp)
 static void print_nrcpus(struct perf_header *ph, int fd, FILE *fp)
 {
        ssize_t ret;
-       u32 nr;
+       u32 nr[2];
 
        ret = read(fd, &nr, sizeof(nr));
        if (ret != (ssize_t)sizeof(nr))
-               nr = -1; /* interpreted as error */
+               nr[0] = nr[1] = -1; /* interpreted as error */
 
-       if (ph->needs_swap)
-               nr = bswap_32(nr);
-
-       fprintf(fp, "# nrcpus online : %u\n", nr);
-
-       ret = read(fd, &nr, sizeof(nr));
-       if (ret != (ssize_t)sizeof(nr))
-               nr = -1; /* interpreted as error */
-
-       if (ph->needs_swap)
-               nr = bswap_32(nr);
+       if (ph->needs_swap) {
+               nr[0] = bswap_32(nr[0]);
+               nr[1] = bswap_32(nr[1]);
+       }
 
-       fprintf(fp, "# nrcpus avail : %u\n", nr);
+       fprintf(fp, "# nrcpus online : %u\n", nr[1]);
+       fprintf(fp, "# nrcpus avail : %u\n", nr[0]);
 }
 
 static void print_version(struct perf_header *ph, int fd, FILE *fp)
-- 
1.9.1

Reply via email to