Skip to contentSkip to conversation

perf tools: fix format max value calculation

PATCH In review [email protected] 3 participants 3 messages Mar 31, 2016 – Apr 6, 2016 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf tools: fix format max value calculation

From: Kan Liang <[email protected]>

Currently the max value of format is calculated by the bits number. It relies on the continuity of the format.
However, uncore event format is not continuous. E.g. uncore qpi event format can be 0-7,21.
If bit 21 is set, there is parsing issues as below.
perf stat -a -e uncore_qpi_0/event=0x200002,umask=0x8/
event syntax error: '..pi_0/event=0x200002,umask=0x8/'
\___ value too big for format, maximum
is 511

This patch return the real max value by setting all possible bit to 1.

---
 tools/perf/util/pmu.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
tools/perf/util/pmu.c +6 -7
index adef23b..bf34468 100644
@@ -602,14 +602,13 @@ static void pmu_format_value(unsigned long *format, __u64 value, __u64 *v,
 
 static __u64 pmu_format_max_value(const unsigned long *format)
 {
-	int w;
+	__u64 w = 0;
+	int fbit;
 
-	w = bitmap_weight(format, PERF_PMU_FORMAT_BITS);
-	if (!w)
-		return 0;
-	if (w < 64)
-		return (1ULL << w) - 1;
-	return -1;
+	for_each_set_bit(fbit, format, PERF_PMU_FORMAT_BITS)
+		w |= (1ULL << fbit);
+
+	return w;
 }
 
 /*
Signature · 1 line
2.5.0
#1 lore raw

Em Wed, Mar 30, 2016 at 12:16:15PM -0700, [email protected] escreveu:

Quoted 12 lines

From: Kan Liang <[email protected]>

Currently the max value of format is calculated by the bits number. It relies on the continuity of the format.
However, uncore event format is not continuous. E.g. uncore qpi event format can be 0-7,21.
If bit 21 is set, there is parsing issues as below.
perf stat -a -e uncore_qpi_0/event=0x200002,umask=0x8/
event syntax error: '..pi_0/event=0x200002,umask=0x8/'
\___ value too big for format, maximum
is 511

Quoted 1 line

This patch return the real max value by setting all possible bit to 1.

Looks good, applied.

- Arnaldo

#2 lore raw

[tip:perf/core] perf tools: Fix PMU term format max value calculation

In reply to [email protected]
perf tools: Fix PMU term format max value calculation
Commit-ID:  ac0e2cd555373ae6f8f3a3ad3fbbf5b6d1e7aaaa
Gitweb:     http://git.kernel.org/tip/ac0e2cd555373ae6f8f3a3ad3fbbf5b6d1e7aaaa
Author:     Kan Liang <[email protected]>
AuthorDate: Wed, 30 Mar 2016 12:16:15 -0700
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 1 Apr 2016 18:46:24 -0300

perf tools: Fix PMU term format max value calculation

Currently the max value of format is calculated by the bits number. It relies on the continuity of the format.

However, uncore event format is not continuous. E.g. uncore qpi event format can be 0-7,21.

If bit 21 is set, there is parsing issues as below.

  $ perf stat -a -e uncore_qpi_0/event=0x200002,umask=0x8/
  event syntax error: '..pi_0/event=0x200002,umask=0x8/'
                                    \___ value too big for format, maximum is 511

This patch return the real max value by setting all possible bits to 1.

---
 tools/perf/util/pmu.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
tools/perf/util/pmu.c +6 -7
index adef23b..bf34468 100644
@@ -602,14 +602,13 @@ static void pmu_format_value(unsigned long *format, __u64 value, __u64 *v,
 
 static __u64 pmu_format_max_value(const unsigned long *format)
 {
-	int w;
+	__u64 w = 0;
+	int fbit;
 
-	w = bitmap_weight(format, PERF_PMU_FORMAT_BITS);
-	if (!w)
-		return 0;
-	if (w < 64)
-		return (1ULL << w) - 1;
-	return -1;
+	for_each_set_bit(fbit, format, PERF_PMU_FORMAT_BITS)
+		w |= (1ULL << fbit);
+
+	return w;
 }
 
 /*