All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V1] perf tools: Get correct max value of format attribute
@ 2017-12-20 23:46 Megha Dey
  0 siblings, 0 replies; only message in thread
From: Megha Dey @ 2017-12-20 23:46 UTC (permalink / raw)
  To: linux-kernel
  Cc: peterz, mingo, acme, alexander.shishkin, jolsa, namhyung,
	yu-cheng.yu, megha.dey, Megha Dey

Currently, the maximum value of every format attribute is not being
correctly set.

For eg:
cat /sys/devices/cpu/format/umask
config:8-15

This implies the max_value of umask should be 0xff

./perf stat –e cpu/umask=0x100/ sleep 1
Performance counter stats for '../rets-128.bin':

                 0      cpu/umask=0x100/

       0.109157272 seconds time elapsed

works just fine(0x100 > 0xff). Whereas,

./perf stat –e cpu/umask=0xff01/ sleep 1
event syntax error: 'cpu/umask=0xff01/'
                               \___ value too big for format, maximum is
65280(0xff00)

The maximum value is set to 0xff00 instead of 0xff.

This patch fixes the pmu_format_max_value() function to return the
correct maximum value.

Acked-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Megha Dey <megha.dey@linux.intel.com>
---
 tools/perf/util/pmu.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 2fffc3a..2bf7a7d 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -777,13 +777,7 @@ static void pmu_format_value(unsigned long *format, __u64 value, __u64 *v,
 
 static __u64 pmu_format_max_value(const unsigned long *format)
 {
-	__u64 w = 0;
-	int fbit;
-
-	for_each_set_bit(fbit, format, PERF_PMU_FORMAT_BITS)
-		w |= (1ULL << fbit);
-
-	return w;
+	return (1ULL << bitmap_weight(format, PERF_PMU_FORMAT_BITS)) - 1;
 }
 
 /*
-- 
1.9.1

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2017-12-20 23:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-20 23:46 [PATCH V1] perf tools: Get correct max value of format attribute Megha Dey

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.