mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Megha Dey <megha.dey@linux.intel.com>
To: linux-kernel@vger.kernel.org
Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
	alexander.shishkin@linux.intel.com, jolsa@redhat.com,
	namhyung@kernel.org, yu-cheng.yu@intel.com, megha.dey@intel.com,
	Megha Dey <megha.dey@linux.intel.com>
Subject: [PATCH V1] perf tools: Get correct max value of format attribute
Date: Wed, 20 Dec 2017 15:46:23 -0800	[thread overview]
Message-ID: <1513813583-13847-1-git-send-email-megha.dey@linux.intel.com> (raw)

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

                 reply	other threads:[~2017-12-20 23:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1513813583-13847-1-git-send-email-megha.dey@linux.intel.com \
    --to=megha.dey@linux.intel.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=megha.dey@intel.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=yu-cheng.yu@intel.com \
    /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

Powered by JetHome