All of lore.kernel.org
 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] perf-tool: get correct format attribute value
Date: Wed, 20 Dec 2017 15:45:49 -0800	[thread overview]
Message-ID: <1513813549-13803-1-git-send-email-megha.dey@linux.intel.com> (raw)

pmu_format_value() does not always return the correct value when the
default format attribute value is overwritten on the perf command line.

This happens because in pmu_format_value(), the default value is not
actually being overwritten by the new value, but only bits either set
in the new or the default value are being set.

for eg:
For example: cat /sys/devices/cpu/events/bus-cycles
event=0x3c,umask=0x01

perf stat -e cpu/bus-cycles/ sleep 1
event->attr.config = 0x13c

perf stat -e cpu/bus-cycles,umask=2/ sleep
event->attr.config = 0x33c (Expected value is 0x23c, we should be 
event->overwriting the umask value)

perf stat -e cpu/bus-cycles,umask=0/ sleep
event->attr.config = 0x13c (expected value is 0x3c)

To ensure we always get the correct value, we should clear the bits
corresponding to the particular format so that only bits set in the new
value are set. In other words, we overwrite the default with new value.

The following test case can be added to test for this failure:

diff --git a/tools/perf/tests/pmu.c b/tools/perf/tests/pmu.c
index 9abca26..0419833 100644
--- a/tools/perf/tests/pmu.c
+++ b/tools/perf/tests/pmu.c
@@ -78,6 +78,12 @@
                .type_val  = PARSE_EVENTS__TERM_TYPE_NUM,
                .type_term = PARSE_EVENTS__TERM_TYPE_USER,
        },
+       {
+                .config    = (char *) "krava13",
+                .val.num   = 5,
+                .type_val  = PARSE_EVENTS__TERM_TYPE_NUM,
+                .type_term = PARSE_EVENTS__TERM_TYPE_USER,
+        },
 };

 /*
@@ -164,7 +170,7 @@ int test__pmu(struct test *test __maybe_unused, int subtest __maybe_unused)

                if (attr.config  != 0xc00000000002a823)
                        break;
-               if (attr.config1 != 0x8000400000000145)
+               if (attr.config1 != 0x8000a00000000145)
                        break;
                if (attr.config2 != 0x0400000020041d07)
                        break;

Signed-off-by: Megha Dey <megha.dey@linux.intel.com>
---
 tools/perf/util/pmu.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index b42011b..7e7e367 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -761,6 +761,8 @@ static void pmu_format_value(unsigned long *format, __u64 value, __u64 *v,
 {
 	unsigned long fbit, vbit;
 
+	*v = *v & (~(*format));
+
 	for (fbit = 0, vbit = 0; fbit < PERF_PMU_FORMAT_BITS; fbit++) {
 
 		if (!test_bit(fbit, format))
-- 
1.9.1

                 reply	other threads:[~2017-12-20 23:29 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=1513813549-13803-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 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.