All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] perf tools: Add support for pinned modifier
@ 2013-08-06 13:28 Michael Ellerman
  2013-08-06 13:28 ` [PATCH v2 2/2] perf tests: Add tests of new " Michael Ellerman
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Michael Ellerman @ 2013-08-06 13:28 UTC (permalink / raw)
  To: linux-kernel; +Cc: acme, a.p.zijlstra, jolsa

This commit adds support for a new modifier "D", which requests that the
event, or group of events, be pinned to the PMU.

The "p" modifier is already taken for precise, and "P" may be used in
future to mean "fully precise".

So we use "D", which stands for pinneD - and looks like a padlock, or if
you're using the ":D" syntax perf smiles at you.

This is an oft-requested feature from our HW folks, who want to be able
to run a large number of events, but also want 100% accurate results for
instructions per cycle.

Comparison of results with and without pinning:

$ perf stat -e '{cycles,instructions}:D' -e cycles,instructions,...

  79,590,480,683 cycles         #  0.000 GHz
 166,123,716,524 instructions   #  2.09  insns per cycle
                                #  0.11  stalled cycles per insn

  79,352,134,463 cycles         #  0.000 GHz                     [11.11%]
 165,178,301,818 instructions   #  2.08  insns per cycle
                                #  0.11  stalled cycles per insn [11.13%]

As you can see although perf does a very good job of scaling the values
in the non-pinned case, there is some small discrepancy.

The patch is fairly straight forward, the one detail is that we need to
make sure we only request pinning for the group leader when we have a
group.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
v2: Use "D" instead of "P" as discussed on the list.

 tools/perf/Documentation/perf-list.txt |  1 +
 tools/perf/util/parse-events.c         | 11 ++++++++++-
 tools/perf/util/parse-events.l         |  3 ++-
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/tools/perf/Documentation/perf-list.txt b/tools/perf/Documentation/perf-list.txt
index eb03f06..6fce6a6 100644
--- a/tools/perf/Documentation/perf-list.txt
+++ b/tools/perf/Documentation/perf-list.txt
@@ -30,6 +30,7 @@ counted. The following modifiers exist:
  H - host counting (not in KVM guests)
  p - precise level
  S - read sample value (PERF_SAMPLE_READ)
+ D - pin the event to the PMU
 
 The 'p' modifier can be used for specifying how precise the instruction
 address should be. The 'p' modifier can be specified multiple times:
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index dba877d..178c998 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -688,6 +688,7 @@ struct event_modifier {
 	int precise;
 	int exclude_GH;
 	int sample_read;
+	int pinned;
 };
 
 static int get_event_modifier(struct event_modifier *mod, char *str,
@@ -700,6 +701,7 @@ static int get_event_modifier(struct event_modifier *mod, char *str,
 	int eG = evsel ? evsel->attr.exclude_guest : 0;
 	int precise = evsel ? evsel->attr.precise_ip : 0;
 	int sample_read = 0;
+	int pinned = evsel ? evsel->attr.pinned : 0;
 
 	int exclude = eu | ek | eh;
 	int exclude_GH = evsel ? evsel->exclude_GH : 0;
@@ -734,6 +736,8 @@ static int get_event_modifier(struct event_modifier *mod, char *str,
 				eG = 1;
 		} else if (*str == 'S') {
 			sample_read = 1;
+		} else if (*str == 'D') {
+			pinned = 1;
 		} else
 			break;
 
@@ -761,6 +765,8 @@ static int get_event_modifier(struct event_modifier *mod, char *str,
 	mod->precise = precise;
 	mod->exclude_GH = exclude_GH;
 	mod->sample_read = sample_read;
+	mod->pinned = pinned;
+
 	return 0;
 }
 
@@ -773,7 +779,7 @@ static int check_modifier(char *str)
 	char *p = str;
 
 	/* The sizeof includes 0 byte as well. */
-	if (strlen(str) > (sizeof("ukhGHpppS") - 1))
+	if (strlen(str) > (sizeof("ukhGHpppSD") - 1))
 		return -1;
 
 	while (*p) {
@@ -812,6 +818,9 @@ int parse_events__modifier_event(struct list_head *list, char *str, bool add)
 		evsel->attr.exclude_guest  = mod.eG;
 		evsel->exclude_GH          = mod.exclude_GH;
 		evsel->sample_read         = mod.sample_read;
+
+		if (evsel->leader == evsel)
+			evsel->attr.pinned = mod.pinned;
 	}
 
 	return 0;
diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l
index b36115f..0790452 100644
--- a/tools/perf/util/parse-events.l
+++ b/tools/perf/util/parse-events.l
@@ -82,7 +82,8 @@ num_hex		0x[a-fA-F0-9]+
 num_raw_hex	[a-fA-F0-9]+
 name		[a-zA-Z_*?][a-zA-Z0-9_*?]*
 name_minus	[a-zA-Z_*?][a-zA-Z0-9\-_*?]*
-modifier_event	[ukhpGHS]+
+/* If you add a modifier you need to update check_modifier() */
+modifier_event	[ukhpGHSD]+
 modifier_bp	[rwx]{1,3}
 
 %%
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 2/2] perf tests: Add tests of new pinned modifier
  2013-08-06 13:28 [PATCH v2 1/2] perf tools: Add support for pinned modifier Michael Ellerman
@ 2013-08-06 13:28 ` Michael Ellerman
  2013-08-06 13:59   ` Jiri Olsa
                     ` (2 more replies)
  2013-08-06 13:59 ` [PATCH v2 1/2] perf tools: Add support for " Jiri Olsa
                   ` (3 subsequent siblings)
  4 siblings, 3 replies; 12+ messages in thread
From: Michael Ellerman @ 2013-08-06 13:28 UTC (permalink / raw)
  To: linux-kernel; +Cc: acme, a.p.zijlstra, jolsa

Add a negative test to test__checkevent_pmu_events() to get lots of
coverage of the negative case, ie. when the modifier is not specified.

Add a test of a single event, and of the group case.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 tools/perf/tests/parse-events.c | 53 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index b46379c..48114d1 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -452,6 +452,7 @@ static int test__checkevent_pmu_events(struct perf_evlist *evlist)
 			evsel->attr.exclude_kernel);
 	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
 	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+	TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
 
 	return 0;
 }
@@ -1070,6 +1071,50 @@ static int test__leader_sample2(struct perf_evlist *evlist __maybe_unused)
 	return 0;
 }
 
+static int test__checkevent_pinned_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = perf_evlist__first(evlist);
+
+	TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
+	TEST_ASSERT_VAL("wrong pinned", evsel->attr.pinned);
+
+	return test__checkevent_symbolic_name(evlist);
+}
+
+static int test__pinned_group(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel, *leader;
+
+	TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
+
+	/* cycles - group leader */
+	evsel = leader = perf_evlist__first(evlist);
+	TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong config",
+			PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
+	TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
+	TEST_ASSERT_VAL("wrong pinned", evsel->attr.pinned);
+
+	/* cache-misses - can not be pinned, but will go on with the leader */
+	evsel = perf_evsel__next(evsel);
+	TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong config",
+			PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
+
+	/* branch-misses - ditto */
+	evsel = perf_evsel__next(evsel);
+	TEST_ASSERT_VAL("wrong config",
+			PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
+
+	return 0;
+}
+
 static int count_tracepoints(void)
 {
 	char events_path[PATH_MAX];
@@ -1294,6 +1339,14 @@ static struct evlist_test test__events[] = {
 		.name  = "{instructions,branch-misses}:Su",
 		.check = test__leader_sample2,
 	},
+	[40] = {
+		.name  = "instructions:uDp",
+		.check = test__checkevent_pinned_modifier,
+	},
+	[41] = {
+		.name  = "{cycles,cache-misses,branch-misses}:D",
+		.check = test__pinned_group,
+	},
 };
 
 static struct evlist_test test__events_pmu[] = {
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/2] perf tools: Add support for pinned modifier
  2013-08-06 13:28 [PATCH v2 1/2] perf tools: Add support for pinned modifier Michael Ellerman
  2013-08-06 13:28 ` [PATCH v2 2/2] perf tests: Add tests of new " Michael Ellerman
@ 2013-08-06 13:59 ` Jiri Olsa
  2013-08-07  5:19   ` Michael Ellerman
  2013-08-06 14:02 ` Jiri Olsa
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 12+ messages in thread
From: Jiri Olsa @ 2013-08-06 13:59 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: linux-kernel, acme, a.p.zijlstra

On Tue, Aug 06, 2013 at 11:28:05PM +1000, Michael Ellerman wrote:

SNIP

>  
>  	while (*p) {
> @@ -812,6 +818,9 @@ int parse_events__modifier_event(struct list_head *list, char *str, bool add)
>  		evsel->attr.exclude_guest  = mod.eG;
>  		evsel->exclude_GH          = mod.exclude_GH;
>  		evsel->sample_read         = mod.sample_read;
> +
> +		if (evsel->leader == evsel)
> +			evsel->attr.pinned = mod.pinned;

nitpick, we have perf_evsel__is_group_leader for this check

jirka

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 2/2] perf tests: Add tests of new pinned modifier
  2013-08-06 13:28 ` [PATCH v2 2/2] perf tests: Add tests of new " Michael Ellerman
@ 2013-08-06 13:59   ` Jiri Olsa
  2013-08-07  6:18   ` Namhyung Kim
  2013-08-12 10:24   ` [tip:perf/core] " tip-bot for Michael Ellerman
  2 siblings, 0 replies; 12+ messages in thread
From: Jiri Olsa @ 2013-08-06 13:59 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: linux-kernel, acme, a.p.zijlstra

On Tue, Aug 06, 2013 at 11:28:06PM +1000, Michael Ellerman wrote:
> Add a negative test to test__checkevent_pmu_events() to get lots of
> coverage of the negative case, ie. when the modifier is not specified.
> 
> Add a test of a single event, and of the group case.

nice! :)

jirka

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/2] perf tools: Add support for pinned modifier
  2013-08-06 13:28 [PATCH v2 1/2] perf tools: Add support for pinned modifier Michael Ellerman
  2013-08-06 13:28 ` [PATCH v2 2/2] perf tests: Add tests of new " Michael Ellerman
  2013-08-06 13:59 ` [PATCH v2 1/2] perf tools: Add support for " Jiri Olsa
@ 2013-08-06 14:02 ` Jiri Olsa
  2013-08-07  6:18 ` Namhyung Kim
  2013-08-12 10:23 ` [tip:perf/core] " tip-bot for Michael Ellerman
  4 siblings, 0 replies; 12+ messages in thread
From: Jiri Olsa @ 2013-08-06 14:02 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: linux-kernel, acme, a.p.zijlstra

On Tue, Aug 06, 2013 at 11:28:05PM +1000, Michael Ellerman wrote:
> This commit adds support for a new modifier "D", which requests that the
> event, or group of events, be pinned to the PMU.
> 
> The "p" modifier is already taken for precise, and "P" may be used in
> future to mean "fully precise".
> 
> So we use "D", which stands for pinneD - and looks like a padlock, or if
> you're using the ":D" syntax perf smiles at you.
> 
> This is an oft-requested feature from our HW folks, who want to be able
> to run a large number of events, but also want 100% accurate results for
> instructions per cycle.
> 
> Comparison of results with and without pinning:
> 
> $ perf stat -e '{cycles,instructions}:D' -e cycles,instructions,...
> 
>   79,590,480,683 cycles         #  0.000 GHz
>  166,123,716,524 instructions   #  2.09  insns per cycle
>                                 #  0.11  stalled cycles per insn
> 
>   79,352,134,463 cycles         #  0.000 GHz                     [11.11%]
>  165,178,301,818 instructions   #  2.08  insns per cycle
>                                 #  0.11  stalled cycles per insn [11.13%]
> 
> As you can see although perf does a very good job of scaling the values
> in the non-pinned case, there is some small discrepancy.
> 
> The patch is fairly straight forward, the one detail is that we need to
> make sure we only request pinning for the group leader when we have a
> group.
> 
> Signed-off-by: Michael Ellerman <michael@ellerman.id.au>

Tested-by/Acked-by: Jiri Olsa <jolsa@redhat.com>

thanks,
jirka

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/2] perf tools: Add support for pinned modifier
  2013-08-06 13:59 ` [PATCH v2 1/2] perf tools: Add support for " Jiri Olsa
@ 2013-08-07  5:19   ` Michael Ellerman
  2013-08-07 20:16     ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 12+ messages in thread
From: Michael Ellerman @ 2013-08-07  5:19 UTC (permalink / raw)
  To: Jiri Olsa; +Cc: linux-kernel, acme, a.p.zijlstra

On Tue, Aug 06, 2013 at 03:59:37PM +0200, Jiri Olsa wrote:
> On Tue, Aug 06, 2013 at 11:28:05PM +1000, Michael Ellerman wrote:
> 
> SNIP
> 
> >  
> >  	while (*p) {
> > @@ -812,6 +818,9 @@ int parse_events__modifier_event(struct list_head *list, char *str, bool add)
> >  		evsel->attr.exclude_guest  = mod.eG;
> >  		evsel->exclude_GH          = mod.exclude_GH;
> >  		evsel->sample_read         = mod.sample_read;
> > +
> > +		if (evsel->leader == evsel)
> > +			evsel->attr.pinned = mod.pinned;
> 
> nitpick, we have perf_evsel__is_group_leader for this check

Ah darn, missed it.

Should I do a respin?

cheers

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/2] perf tools: Add support for pinned modifier
  2013-08-06 13:28 [PATCH v2 1/2] perf tools: Add support for pinned modifier Michael Ellerman
                   ` (2 preceding siblings ...)
  2013-08-06 14:02 ` Jiri Olsa
@ 2013-08-07  6:18 ` Namhyung Kim
  2013-08-12 10:23 ` [tip:perf/core] " tip-bot for Michael Ellerman
  4 siblings, 0 replies; 12+ messages in thread
From: Namhyung Kim @ 2013-08-07  6:18 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: linux-kernel, acme, a.p.zijlstra, jolsa

Hi Michael,

On Tue,  6 Aug 2013 23:28:05 +1000, Michael Ellerman wrote:
> This commit adds support for a new modifier "D", which requests that the
> event, or group of events, be pinned to the PMU.
>
> The "p" modifier is already taken for precise, and "P" may be used in
> future to mean "fully precise".
>
> So we use "D", which stands for pinneD - and looks like a padlock, or if
> you're using the ":D" syntax perf smiles at you.
>
> This is an oft-requested feature from our HW folks, who want to be able
> to run a large number of events, but also want 100% accurate results for
> instructions per cycle.
>
> Comparison of results with and without pinning:
>
> $ perf stat -e '{cycles,instructions}:D' -e cycles,instructions,...
>
>   79,590,480,683 cycles         #  0.000 GHz
>  166,123,716,524 instructions   #  2.09  insns per cycle
>                                 #  0.11  stalled cycles per insn
>
>   79,352,134,463 cycles         #  0.000 GHz                     [11.11%]
>  165,178,301,818 instructions   #  2.08  insns per cycle
>                                 #  0.11  stalled cycles per insn [11.13%]
>
> As you can see although perf does a very good job of scaling the values
> in the non-pinned case, there is some small discrepancy.
>
> The patch is fairly straight forward, the one detail is that we need to
> make sure we only request pinning for the group leader when we have a
> group.

Acked-by: Namhyung Kim <namhyung@kernel.org>

Thanks,
Namhyung

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 2/2] perf tests: Add tests of new pinned modifier
  2013-08-06 13:28 ` [PATCH v2 2/2] perf tests: Add tests of new " Michael Ellerman
  2013-08-06 13:59   ` Jiri Olsa
@ 2013-08-07  6:18   ` Namhyung Kim
  2013-08-12 10:24   ` [tip:perf/core] " tip-bot for Michael Ellerman
  2 siblings, 0 replies; 12+ messages in thread
From: Namhyung Kim @ 2013-08-07  6:18 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: linux-kernel, acme, a.p.zijlstra, jolsa

On Tue,  6 Aug 2013 23:28:06 +1000, Michael Ellerman wrote:
> Add a negative test to test__checkevent_pmu_events() to get lots of
> coverage of the negative case, ie. when the modifier is not specified.
>
> Add a test of a single event, and of the group case.

Acked-by: Namhyung Kim <namhyung@kernel.org>

Thanks,
Namhyung

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/2] perf tools: Add support for pinned modifier
  2013-08-07  5:19   ` Michael Ellerman
@ 2013-08-07 20:16     ` Arnaldo Carvalho de Melo
  2013-08-07 21:33       ` Michael Ellerman
  0 siblings, 1 reply; 12+ messages in thread
From: Arnaldo Carvalho de Melo @ 2013-08-07 20:16 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: Jiri Olsa, linux-kernel, a.p.zijlstra

Em Wed, Aug 07, 2013 at 03:19:57PM +1000, Michael Ellerman escreveu:
> On Tue, Aug 06, 2013 at 03:59:37PM +0200, Jiri Olsa wrote:
> > On Tue, Aug 06, 2013 at 11:28:05PM +1000, Michael Ellerman wrote:
> > > +		if (evsel->leader == evsel)
> > > +			evsel->attr.pinned = mod.pinned;

> > nitpick, we have perf_evsel__is_group_leader for this check
 
> Ah darn, missed it.

> Should I do a respin?

No need, I did it.

- Arnaldo

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/2] perf tools: Add support for pinned modifier
  2013-08-07 20:16     ` Arnaldo Carvalho de Melo
@ 2013-08-07 21:33       ` Michael Ellerman
  0 siblings, 0 replies; 12+ messages in thread
From: Michael Ellerman @ 2013-08-07 21:33 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel, a.p.zijlstra



Arnaldo Carvalho de Melo <acme@ghostprotocols.net> wrote:
>Em Wed, Aug 07, 2013 at 03:19:57PM +1000, Michael Ellerman escreveu:
>> On Tue, Aug 06, 2013 at 03:59:37PM +0200, Jiri Olsa wrote:
>> > On Tue, Aug 06, 2013 at 11:28:05PM +1000, Michael Ellerman wrote:
>> > > +		if (evsel->leader == evsel)
>> > > +			evsel->attr.pinned = mod.pinned;
>
>> > nitpick, we have perf_evsel__is_group_leader for this check
> 
>> Ah darn, missed it.
>
>> Should I do a respin?
>
>No need, I did it.

Thanks.

cheers

-- 
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [tip:perf/core] perf tools: Add support for pinned modifier
  2013-08-06 13:28 [PATCH v2 1/2] perf tools: Add support for pinned modifier Michael Ellerman
                   ` (3 preceding siblings ...)
  2013-08-07  6:18 ` Namhyung Kim
@ 2013-08-12 10:23 ` tip-bot for Michael Ellerman
  4 siblings, 0 replies; 12+ messages in thread
From: tip-bot for Michael Ellerman @ 2013-08-12 10:23 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, linux-kernel, hpa, mingo, a.p.zijlstra, michael, namhyung,
	jolsa, tglx

Commit-ID:  e9a7c414477d20c3cc56f90f29c35b06f0f15e25
Gitweb:     http://git.kernel.org/tip/e9a7c414477d20c3cc56f90f29c35b06f0f15e25
Author:     Michael Ellerman <michael@ellerman.id.au>
AuthorDate: Tue, 6 Aug 2013 23:28:05 +1000
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 7 Aug 2013 17:35:40 -0300

perf tools: Add support for pinned modifier

This commit adds support for a new modifier "D", which requests that the
event, or group of events, be pinned to the PMU.

The "p" modifier is already taken for precise, and "P" may be used in
future to mean "fully precise".

So we use "D", which stands for pinneD - and looks like a padlock, or if
you're using the ":D" syntax perf smiles at you.

This is an oft-requested feature from our HW folks, who want to be able
to run a large number of events, but also want 100% accurate results for
instructions per cycle.

Comparison of results with and without pinning:

$ perf stat -e '{cycles,instructions}:D' -e cycles,instructions,...

  79,590,480,683 cycles         #  0.000 GHz
 166,123,716,524 instructions   #  2.09  insns per cycle
                                #  0.11  stalled cycles per insn

  79,352,134,463 cycles         #  0.000 GHz                     [11.11%]
 165,178,301,818 instructions   #  2.08  insns per cycle
                                #  0.11  stalled cycles per insn [11.13%]

As you can see although perf does a very good job of scaling the values
in the non-pinned case, there is some small discrepancy.

The patch is fairly straight forward, the one detail is that we need to
make sure we only request pinning for the group leader when we have a
group.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Tested-by: Jiri Olsa <jolsa@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1375795686-4226-1-git-send-email-michael@ellerman.id.au
[ Use perf_evsel__is_group_leader instead of open coded equivalent, as
  suggested by Jiri Olsa ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-list.txt |  1 +
 tools/perf/util/parse-events.c         | 11 ++++++++++-
 tools/perf/util/parse-events.l         |  3 ++-
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/tools/perf/Documentation/perf-list.txt b/tools/perf/Documentation/perf-list.txt
index eb03f06..6fce6a6 100644
--- a/tools/perf/Documentation/perf-list.txt
+++ b/tools/perf/Documentation/perf-list.txt
@@ -30,6 +30,7 @@ counted. The following modifiers exist:
  H - host counting (not in KVM guests)
  p - precise level
  S - read sample value (PERF_SAMPLE_READ)
+ D - pin the event to the PMU
 
 The 'p' modifier can be used for specifying how precise the instruction
 address should be. The 'p' modifier can be specified multiple times:
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index dba877d..9cba923 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -688,6 +688,7 @@ struct event_modifier {
 	int precise;
 	int exclude_GH;
 	int sample_read;
+	int pinned;
 };
 
 static int get_event_modifier(struct event_modifier *mod, char *str,
@@ -700,6 +701,7 @@ static int get_event_modifier(struct event_modifier *mod, char *str,
 	int eG = evsel ? evsel->attr.exclude_guest : 0;
 	int precise = evsel ? evsel->attr.precise_ip : 0;
 	int sample_read = 0;
+	int pinned = evsel ? evsel->attr.pinned : 0;
 
 	int exclude = eu | ek | eh;
 	int exclude_GH = evsel ? evsel->exclude_GH : 0;
@@ -734,6 +736,8 @@ static int get_event_modifier(struct event_modifier *mod, char *str,
 				eG = 1;
 		} else if (*str == 'S') {
 			sample_read = 1;
+		} else if (*str == 'D') {
+			pinned = 1;
 		} else
 			break;
 
@@ -761,6 +765,8 @@ static int get_event_modifier(struct event_modifier *mod, char *str,
 	mod->precise = precise;
 	mod->exclude_GH = exclude_GH;
 	mod->sample_read = sample_read;
+	mod->pinned = pinned;
+
 	return 0;
 }
 
@@ -773,7 +779,7 @@ static int check_modifier(char *str)
 	char *p = str;
 
 	/* The sizeof includes 0 byte as well. */
-	if (strlen(str) > (sizeof("ukhGHpppS") - 1))
+	if (strlen(str) > (sizeof("ukhGHpppSD") - 1))
 		return -1;
 
 	while (*p) {
@@ -812,6 +818,9 @@ int parse_events__modifier_event(struct list_head *list, char *str, bool add)
 		evsel->attr.exclude_guest  = mod.eG;
 		evsel->exclude_GH          = mod.exclude_GH;
 		evsel->sample_read         = mod.sample_read;
+
+		if (perf_evsel__is_group_leader(evsel))
+			evsel->attr.pinned = mod.pinned;
 	}
 
 	return 0;
diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l
index b36115f..0790452 100644
--- a/tools/perf/util/parse-events.l
+++ b/tools/perf/util/parse-events.l
@@ -82,7 +82,8 @@ num_hex		0x[a-fA-F0-9]+
 num_raw_hex	[a-fA-F0-9]+
 name		[a-zA-Z_*?][a-zA-Z0-9_*?]*
 name_minus	[a-zA-Z_*?][a-zA-Z0-9\-_*?]*
-modifier_event	[ukhpGHS]+
+/* If you add a modifier you need to update check_modifier() */
+modifier_event	[ukhpGHSD]+
 modifier_bp	[rwx]{1,3}
 
 %%

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [tip:perf/core] perf tests: Add tests of new pinned modifier
  2013-08-06 13:28 ` [PATCH v2 2/2] perf tests: Add tests of new " Michael Ellerman
  2013-08-06 13:59   ` Jiri Olsa
  2013-08-07  6:18   ` Namhyung Kim
@ 2013-08-12 10:24   ` tip-bot for Michael Ellerman
  2 siblings, 0 replies; 12+ messages in thread
From: tip-bot for Michael Ellerman @ 2013-08-12 10:24 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, linux-kernel, hpa, mingo, a.p.zijlstra, michael, namhyung,
	jolsa, tglx

Commit-ID:  c9ee780f2736b7a149658b0cd8c8389da23e190a
Gitweb:     http://git.kernel.org/tip/c9ee780f2736b7a149658b0cd8c8389da23e190a
Author:     Michael Ellerman <michael@ellerman.id.au>
AuthorDate: Tue, 6 Aug 2013 23:28:06 +1000
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 7 Aug 2013 17:35:40 -0300

perf tests: Add tests of new pinned modifier

Add a negative test to test__checkevent_pmu_events() to get lots of
coverage of the negative case, ie. when the modifier is not specified.

Add a test of a single event, and of the group case.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1375795686-4226-2-git-send-email-michael@ellerman.id.au
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/tests/parse-events.c | 53 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index b46379c..48114d1 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -452,6 +452,7 @@ static int test__checkevent_pmu_events(struct perf_evlist *evlist)
 			evsel->attr.exclude_kernel);
 	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
 	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+	TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
 
 	return 0;
 }
@@ -1070,6 +1071,50 @@ static int test__leader_sample2(struct perf_evlist *evlist __maybe_unused)
 	return 0;
 }
 
+static int test__checkevent_pinned_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = perf_evlist__first(evlist);
+
+	TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
+	TEST_ASSERT_VAL("wrong pinned", evsel->attr.pinned);
+
+	return test__checkevent_symbolic_name(evlist);
+}
+
+static int test__pinned_group(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel, *leader;
+
+	TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
+
+	/* cycles - group leader */
+	evsel = leader = perf_evlist__first(evlist);
+	TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong config",
+			PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
+	TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
+	TEST_ASSERT_VAL("wrong pinned", evsel->attr.pinned);
+
+	/* cache-misses - can not be pinned, but will go on with the leader */
+	evsel = perf_evsel__next(evsel);
+	TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong config",
+			PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
+
+	/* branch-misses - ditto */
+	evsel = perf_evsel__next(evsel);
+	TEST_ASSERT_VAL("wrong config",
+			PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
+
+	return 0;
+}
+
 static int count_tracepoints(void)
 {
 	char events_path[PATH_MAX];
@@ -1294,6 +1339,14 @@ static struct evlist_test test__events[] = {
 		.name  = "{instructions,branch-misses}:Su",
 		.check = test__leader_sample2,
 	},
+	[40] = {
+		.name  = "instructions:uDp",
+		.check = test__checkevent_pinned_modifier,
+	},
+	[41] = {
+		.name  = "{cycles,cache-misses,branch-misses}:D",
+		.check = test__pinned_group,
+	},
 };
 
 static struct evlist_test test__events_pmu[] = {

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2013-08-12 10:24 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-06 13:28 [PATCH v2 1/2] perf tools: Add support for pinned modifier Michael Ellerman
2013-08-06 13:28 ` [PATCH v2 2/2] perf tests: Add tests of new " Michael Ellerman
2013-08-06 13:59   ` Jiri Olsa
2013-08-07  6:18   ` Namhyung Kim
2013-08-12 10:24   ` [tip:perf/core] " tip-bot for Michael Ellerman
2013-08-06 13:59 ` [PATCH v2 1/2] perf tools: Add support for " Jiri Olsa
2013-08-07  5:19   ` Michael Ellerman
2013-08-07 20:16     ` Arnaldo Carvalho de Melo
2013-08-07 21:33       ` Michael Ellerman
2013-08-06 14:02 ` Jiri Olsa
2013-08-07  6:18 ` Namhyung Kim
2013-08-12 10:23 ` [tip:perf/core] " tip-bot for Michael Ellerman

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.