linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] perf: Fix perf_event_attr::exclusive rotation
@ 2020-10-29 16:27 Peter Zijlstra
  2020-10-29 16:27 ` [PATCH v2 1/4] perf: Simplify group_sched_out() Peter Zijlstra
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Peter Zijlstra @ 2020-10-29 16:27 UTC (permalink / raw)
  To: mingo, acme, mark.rutland, alexander.shishkin, jolsa, namhyung
  Cc: linux-kernel, eranian, ak, peterz

Hi,

Andi recently added exclusive event group support to tools/perf:

  https://lkml.kernel.org/r/20201014144255.22699-1-andi@firstfloor.org

and promptly found that they didn't work as specified.

(sorry for the resend, I forgot LKML the first time)


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

* [PATCH v2 1/4] perf: Simplify group_sched_out()
  2020-10-29 16:27 [PATCH v2 0/4] perf: Fix perf_event_attr::exclusive rotation Peter Zijlstra
@ 2020-10-29 16:27 ` Peter Zijlstra
  2020-11-10 12:45   ` [tip: perf/urgent] " tip-bot2 for Peter Zijlstra
  2020-10-29 16:27 ` [PATCH v2 2/4] perf: Simplify group_sched_in() Peter Zijlstra
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Peter Zijlstra @ 2020-10-29 16:27 UTC (permalink / raw)
  To: mingo, acme, mark.rutland, alexander.shishkin, jolsa, namhyung
  Cc: linux-kernel, eranian, ak, peterz

Since event_sched_out() clears cpuctx->exclusive upon removal of an
exclusive event (and only group leaders can be exclusive), there is no
point in group_sched_out() trying to do it too. It is impossible for
cpuctx->exclusive to still be set here.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 kernel/events/core.c |    3 ---
 1 file changed, 3 deletions(-)

--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -2312,9 +2312,6 @@ group_sched_out(struct perf_event *group
 		event_sched_out(event, cpuctx, ctx);
 
 	perf_pmu_enable(ctx->pmu);
-
-	if (group_event->attr.exclusive)
-		cpuctx->exclusive = 0;
 }
 
 #define DETACH_GROUP	0x01UL



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

* [PATCH v2 2/4] perf: Simplify group_sched_in()
  2020-10-29 16:27 [PATCH v2 0/4] perf: Fix perf_event_attr::exclusive rotation Peter Zijlstra
  2020-10-29 16:27 ` [PATCH v2 1/4] perf: Simplify group_sched_out() Peter Zijlstra
@ 2020-10-29 16:27 ` Peter Zijlstra
  2020-11-10 12:45   ` [tip: perf/urgent] " tip-bot2 for Peter Zijlstra
  2020-10-29 16:27 ` [PATCH v2 3/4] perf: Fix event multiplexing for exclusive groups Peter Zijlstra
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Peter Zijlstra @ 2020-10-29 16:27 UTC (permalink / raw)
  To: mingo, acme, mark.rutland, alexander.shishkin, jolsa, namhyung
  Cc: linux-kernel, eranian, ak, peterz

Collate the error paths. Code duplication only leads to divergence and
extra bugs.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 kernel/events/core.c |   10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -2580,11 +2580,8 @@ group_sched_in(struct perf_event *group_
 
 	pmu->start_txn(pmu, PERF_PMU_TXN_ADD);
 
-	if (event_sched_in(group_event, cpuctx, ctx)) {
-		pmu->cancel_txn(pmu);
-		perf_mux_hrtimer_restart(cpuctx);
-		return -EAGAIN;
-	}
+	if (event_sched_in(group_event, cpuctx, ctx))
+		goto error;
 
 	/*
 	 * Schedule in siblings as one group (if any):
@@ -2613,10 +2610,9 @@ group_sched_in(struct perf_event *group_
 	}
 	event_sched_out(group_event, cpuctx, ctx);
 
+error:
 	pmu->cancel_txn(pmu);
-
 	perf_mux_hrtimer_restart(cpuctx);
-
 	return -EAGAIN;
 }
 



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

* [PATCH v2 3/4] perf: Fix event multiplexing for exclusive groups
  2020-10-29 16:27 [PATCH v2 0/4] perf: Fix perf_event_attr::exclusive rotation Peter Zijlstra
  2020-10-29 16:27 ` [PATCH v2 1/4] perf: Simplify group_sched_out() Peter Zijlstra
  2020-10-29 16:27 ` [PATCH v2 2/4] perf: Simplify group_sched_in() Peter Zijlstra
@ 2020-10-29 16:27 ` Peter Zijlstra
  2020-11-10 12:45   ` [tip: perf/urgent] " tip-bot2 for Peter Zijlstra
  2020-10-29 16:27 ` [PATCH v2 4/4] perf: Tweak perf_event_attr::exclusive semantics Peter Zijlstra
  2020-10-31 23:44 ` [PATCH v2 0/4] perf: Fix perf_event_attr::exclusive rotation Jiri Olsa
  4 siblings, 1 reply; 14+ messages in thread
From: Peter Zijlstra @ 2020-10-29 16:27 UTC (permalink / raw)
  To: mingo, acme, mark.rutland, alexander.shishkin, jolsa, namhyung
  Cc: linux-kernel, eranian, ak, peterz

Commit 9e6302056f80 ("perf: Use hrtimers for event multiplexing")
placed the hrtimer (re)start call in the wrong place.  Instead of
capturing all scheduling failures, it only considered the PMU failure.

The result is that groups using perf_event_attr::exclusive are no
longer rotated.

Fixes: 9e6302056f80 ("perf: Use hrtimers for event multiplexing")
Reported-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 kernel/events/core.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -2612,7 +2612,6 @@ group_sched_in(struct perf_event *group_
 
 error:
 	pmu->cancel_txn(pmu);
-	perf_mux_hrtimer_restart(cpuctx);
 	return -EAGAIN;
 }
 
@@ -3672,6 +3671,7 @@ static int merge_sched_in(struct perf_ev
 
 		*can_add_hw = 0;
 		ctx->rotate_necessary = 1;
+		perf_mux_hrtimer_restart(cpuctx);
 	}
 
 	return 0;



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

* [PATCH v2 4/4] perf: Tweak perf_event_attr::exclusive semantics
  2020-10-29 16:27 [PATCH v2 0/4] perf: Fix perf_event_attr::exclusive rotation Peter Zijlstra
                   ` (2 preceding siblings ...)
  2020-10-29 16:27 ` [PATCH v2 3/4] perf: Fix event multiplexing for exclusive groups Peter Zijlstra
@ 2020-10-29 16:27 ` Peter Zijlstra
  2020-11-10 12:45   ` [tip: perf/urgent] " tip-bot2 for Peter Zijlstra
  2020-10-31 23:44 ` [PATCH v2 0/4] perf: Fix perf_event_attr::exclusive rotation Jiri Olsa
  4 siblings, 1 reply; 14+ messages in thread
From: Peter Zijlstra @ 2020-10-29 16:27 UTC (permalink / raw)
  To: mingo, acme, mark.rutland, alexander.shishkin, jolsa, namhyung
  Cc: linux-kernel, eranian, ak, peterz

Currently perf_event_attr::exclusive can be used to ensure an
event(group) is the sole group scheduled on the PMU. One consequence
is that when you have a pinned event (say the watchdog) you can no
longer have regular exclusive event(group)s.

Inspired by the fact that !pinned events are considered less strict,
allow !pinned,exclusive events to share the PMU with pinned,!exclusive
events.

Pinned,exclusive is still fully exclusive.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 kernel/events/core.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -2637,7 +2637,7 @@ static int group_can_go_on(struct perf_e
 	 * If this group is exclusive and there are already
 	 * events on the CPU, it can't go on.
 	 */
-	if (event->attr.exclusive && cpuctx->active_oncpu)
+	if (event->attr.exclusive && !list_empty(get_event_list(event)))
 		return 0;
 	/*
 	 * Otherwise, try to add it if all previous groups were able



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

* Re: [PATCH v2 0/4] perf: Fix perf_event_attr::exclusive rotation
  2020-10-29 16:27 [PATCH v2 0/4] perf: Fix perf_event_attr::exclusive rotation Peter Zijlstra
                   ` (3 preceding siblings ...)
  2020-10-29 16:27 ` [PATCH v2 4/4] perf: Tweak perf_event_attr::exclusive semantics Peter Zijlstra
@ 2020-10-31 23:44 ` Jiri Olsa
  2020-11-02  3:52   ` Andi Kleen
  4 siblings, 1 reply; 14+ messages in thread
From: Jiri Olsa @ 2020-10-31 23:44 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: mingo, acme, mark.rutland, alexander.shishkin, namhyung,
	linux-kernel, eranian, ak

On Thu, Oct 29, 2020 at 05:27:19PM +0100, Peter Zijlstra wrote:
> Hi,
> 
> Andi recently added exclusive event group support to tools/perf:
> 
>   https://lkml.kernel.org/r/20201014144255.22699-1-andi@firstfloor.org
> 
> and promptly found that they didn't work as specified.
> 
> (sorry for the resend, I forgot LKML the first time)

hm, it's too late for me to check ;-) but should I be able to do
this with exclusive event.. running both command at the same time:

	$ sudo ./perf stat -e cycles:e -I 1000
	#           time             counts unit events
	     1.002430650         33,946,849      cycles:e                                                    
	     2.004920725        502,399,986      cycles:e                                                      (67.57%)
	     3.007087631        859,745,048      cycles:e                                                      (50.00%)
	     4.009078254        845,860,723      cycles:e                                                      (50.00%)
	     5.011086104        838,457,275      cycles:e                                                      (50.00%)

	$ sudo ./perf stat -e cycles:e  -I 1000
	#           time             counts unit events
	     1.001665466        848,973,404      cycles:e                                                      (50.01%)
	     2.003658048        856,505,255      cycles:e                                                      (50.00%)
	     3.005658022        842,737,973      cycles:e                                                      (50.00%)
	     4.007657797        844,800,598      cycles:e                                                      (50.00%)

jirka


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

* Re: [PATCH v2 0/4] perf: Fix perf_event_attr::exclusive rotation
  2020-10-31 23:44 ` [PATCH v2 0/4] perf: Fix perf_event_attr::exclusive rotation Jiri Olsa
@ 2020-11-02  3:52   ` Andi Kleen
  2020-11-02 14:16     ` Peter Zijlstra
  0 siblings, 1 reply; 14+ messages in thread
From: Andi Kleen @ 2020-11-02  3:52 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Peter Zijlstra, mingo, acme, mark.rutland, alexander.shishkin,
	namhyung, linux-kernel, eranian

> hm, it's too late for me to check ;-) but should I be able to do
> this with exclusive event.. running both command at the same time:

Yes. The exclusive part only applies during a given context,
but the two commands are different contexts.

You would only see a difference when in the same context,
and you have multiple groups (or events) that could in theory schedule
in parallel

e.g. something like

perf stat -e '{cycles,cycles},{cycles,cycles}'  ...

The main motivation is actually that the "multiple groups" algorithm
in perf doesn't work all that great: it has quite a few cases where it
starves groups or makes the wrong decisions. That is because it is very
difficult (likely NP complete) problem and the kernel takes a lot
of short cuts to avoid spending too much time on it.

With exclusive it will be possible for a tool to generate "perfect groups"
in user space and assume the kernel schedules it dumbly, but at least
without any starvation.

-Andi

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

* Re: [PATCH v2 0/4] perf: Fix perf_event_attr::exclusive rotation
  2020-11-02  3:52   ` Andi Kleen
@ 2020-11-02 14:16     ` Peter Zijlstra
  2020-11-03  2:41       ` Andi Kleen
  0 siblings, 1 reply; 14+ messages in thread
From: Peter Zijlstra @ 2020-11-02 14:16 UTC (permalink / raw)
  To: Andi Kleen
  Cc: Jiri Olsa, mingo, acme, mark.rutland, alexander.shishkin,
	namhyung, linux-kernel, eranian

On Sun, Nov 01, 2020 at 07:52:38PM -0800, Andi Kleen wrote:
> The main motivation is actually that the "multiple groups" algorithm
> in perf doesn't work all that great: it has quite a few cases where it
> starves groups or makes the wrong decisions. That is because it is very
> difficult (likely NP complete) problem and the kernel takes a lot
> of short cuts to avoid spending too much time on it.

The event scheduling should be starvation free, except in the presence
of pinned events.

If you can show starvation without pinned events, it's a bug.

It will also always do equal or better than exclusive mode wrt PMU
utilization. Again, if it doesn't it's a bug.

Please provide concrete examples for these two cases, or stop spreading
FUD like this.

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

* Re: [PATCH v2 0/4] perf: Fix perf_event_attr::exclusive rotation
  2020-11-02 14:16     ` Peter Zijlstra
@ 2020-11-03  2:41       ` Andi Kleen
  2020-11-09 11:48         ` Peter Zijlstra
  0 siblings, 1 reply; 14+ messages in thread
From: Andi Kleen @ 2020-11-03  2:41 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Jiri Olsa, mingo, acme, mark.rutland, alexander.shishkin,
	namhyung, linux-kernel, eranian

On Mon, Nov 02, 2020 at 03:16:25PM +0100, Peter Zijlstra wrote:
> On Sun, Nov 01, 2020 at 07:52:38PM -0800, Andi Kleen wrote:
> > The main motivation is actually that the "multiple groups" algorithm
> > in perf doesn't work all that great: it has quite a few cases where it
> > starves groups or makes the wrong decisions. That is because it is very
> > difficult (likely NP complete) problem and the kernel takes a lot
> > of short cuts to avoid spending too much time on it.
> 
> The event scheduling should be starvation free, except in the presence
> of pinned events.
> 
> If you can show starvation without pinned events, it's a bug.
> 
> It will also always do equal or better than exclusive mode wrt PMU
> utilization. Again, if it doesn't it's a bug.

Simple example (I think we've shown that one before):

(on skylake)
$ cat /proc/sys/kernel/nmi_watchdog
0
$ perf stat -e instructions,cycles,frontend_retired.latency_ge_2,frontend_retired.latency_ge_16 -a sleep 2

 Performance counter stats for 'system wide':

       654,514,990      instructions              #    0.34  insn per cycle           (50.67%)
     1,924,297,028      cycles                                                        (74.28%)
        21,708,935      frontend_retired.latency_ge_2                                     (75.01%)
         1,769,952      frontend_retired.latency_ge_16                                     (24.99%)

       2.002426541 seconds time elapsed

The second frontend_retired should be both getting 50% and the fixed events should be getting
100%. So several events are starved.

Another similar example is trying to schedule the topdown events on Icelake in parallel to other
groups. It works with one extra group, but breaks with two.

(on icelake)
$ cat /proc/sys/kernel/nmi_watchdog
0
$ perf stat -e '{slots,topdown-bad-spec,topdown-be-bound,topdown-fe-bound,topdown-retiring},{branches,branches,branches,branches,branches,branches,branches,branches},{branches,branches,branches,branches,branches,branches,branches,branches}' -a sleep 1

 Performance counter stats for 'system wide':

        71,229,087      slots                                                         (60.65%)
         5,066,320      topdown-bad-spec          #      7.1% bad speculation         (60.65%)
        35,080,387      topdown-be-bound          #     49.2% backend bound           (60.65%)
        22,769,750      topdown-fe-bound          #     32.0% frontend bound          (60.65%)
         8,336,760      topdown-retiring          #     11.7% retiring                (60.65%)
           424,584      branches                                                      (70.00%)
           424,584      branches                                                      (70.00%)
           424,584      branches                                                      (70.00%)
           424,584      branches                                                      (70.00%)
           424,584      branches                                                      (70.00%)
           424,584      branches                                                      (70.00%)
           424,584      branches                                                      (70.00%)
           424,584      branches                                                      (70.00%)
         3,634,075      branches                                                      (30.00%)
         3,634,075      branches                                                      (30.00%)
         3,634,075      branches                                                      (30.00%)
         3,634,075      branches                                                      (30.00%)
         3,634,075      branches                                                      (30.00%)
         3,634,075      branches                                                      (30.00%)
         3,634,075      branches                                                      (30.00%)
         3,634,075      branches                                                      (30.00%)

       1.001312511 seconds time elapsed

A tool using exclusive hopefully will be able to do better than this.

-Andi

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

* Re: [PATCH v2 0/4] perf: Fix perf_event_attr::exclusive rotation
  2020-11-03  2:41       ` Andi Kleen
@ 2020-11-09 11:48         ` Peter Zijlstra
  0 siblings, 0 replies; 14+ messages in thread
From: Peter Zijlstra @ 2020-11-09 11:48 UTC (permalink / raw)
  To: Andi Kleen
  Cc: Jiri Olsa, mingo, acme, mark.rutland, alexander.shishkin,
	namhyung, linux-kernel, eranian

On Mon, Nov 02, 2020 at 06:41:43PM -0800, Andi Kleen wrote:
> On Mon, Nov 02, 2020 at 03:16:25PM +0100, Peter Zijlstra wrote:
> > On Sun, Nov 01, 2020 at 07:52:38PM -0800, Andi Kleen wrote:
> > > The main motivation is actually that the "multiple groups" algorithm
> > > in perf doesn't work all that great: it has quite a few cases where it
> > > starves groups or makes the wrong decisions. That is because it is very
> > > difficult (likely NP complete) problem and the kernel takes a lot
> > > of short cuts to avoid spending too much time on it.
> > 
> > The event scheduling should be starvation free, except in the presence
> > of pinned events.
> > 
> > If you can show starvation without pinned events, it's a bug.
> > 
> > It will also always do equal or better than exclusive mode wrt PMU
> > utilization. Again, if it doesn't it's a bug.
> 
> Simple example (I think we've shown that one before):
> 
> (on skylake)
> $ cat /proc/sys/kernel/nmi_watchdog
> 0
> $ perf stat -e instructions,cycles,frontend_retired.latency_ge_2,frontend_retired.latency_ge_16 -a sleep 2
> 
>  Performance counter stats for 'system wide':
> 
>        654,514,990      instructions              #    0.34  insn per cycle           (50.67%)
>      1,924,297,028      cycles                                                        (74.28%)
>         21,708,935      frontend_retired.latency_ge_2                                     (75.01%)
>          1,769,952      frontend_retired.latency_ge_16                                     (24.99%)
> 
>        2.002426541 seconds time elapsed
> 
> The second frontend_retired should be both getting 50% and the fixed events should be getting
> 100%. So several events are starved.

*should* how? Also, nothing is 0% so nothing is getting starved.

> Another similar example is trying to schedule the topdown events on Icelake in parallel to other
> groups. It works with one extra group, but breaks with two.
> 
> (on icelake)
> $ cat /proc/sys/kernel/nmi_watchdog
> 0
> $ perf stat -e '{slots,topdown-bad-spec,topdown-be-bound,topdown-fe-bound,topdown-retiring},{branches,branches,branches,branches,branches,branches,branches,branches},{branches,branches,branches,branches,branches,branches,branches,branches}' -a sleep 1
> 
>  Performance counter stats for 'system wide':
> 
>         71,229,087      slots                                                         (60.65%)
>          5,066,320      topdown-bad-spec          #      7.1% bad speculation         (60.65%)
>         35,080,387      topdown-be-bound          #     49.2% backend bound           (60.65%)
>         22,769,750      topdown-fe-bound          #     32.0% frontend bound          (60.65%)
>          8,336,760      topdown-retiring          #     11.7% retiring                (60.65%)
>            424,584      branches                                                      (70.00%)
>            424,584      branches                                                      (70.00%)
>            424,584      branches                                                      (70.00%)
>            424,584      branches                                                      (70.00%)
>            424,584      branches                                                      (70.00%)
>            424,584      branches                                                      (70.00%)
>            424,584      branches                                                      (70.00%)
>            424,584      branches                                                      (70.00%)
>          3,634,075      branches                                                      (30.00%)
>          3,634,075      branches                                                      (30.00%)
>          3,634,075      branches                                                      (30.00%)
>          3,634,075      branches                                                      (30.00%)
>          3,634,075      branches                                                      (30.00%)
>          3,634,075      branches                                                      (30.00%)
>          3,634,075      branches                                                      (30.00%)
>          3,634,075      branches                                                      (30.00%)
> 
>        1.001312511 seconds time elapsed
> 
> A tool using exclusive hopefully will be able to do better than this.

I don't see how, exclusive will always result in equal or worse PMU
utilization, never better.

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

* [tip: perf/urgent] perf: Tweak perf_event_attr::exclusive semantics
  2020-10-29 16:27 ` [PATCH v2 4/4] perf: Tweak perf_event_attr::exclusive semantics Peter Zijlstra
@ 2020-11-10 12:45   ` tip-bot2 for Peter Zijlstra
  0 siblings, 0 replies; 14+ messages in thread
From: tip-bot2 for Peter Zijlstra @ 2020-11-10 12:45 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Peter Zijlstra (Intel), x86, linux-kernel

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     1908dc911792067287458fdb0800f036f4f4e0f6
Gitweb:        https://git.kernel.org/tip/1908dc911792067287458fdb0800f036f4f4e0f6
Author:        Peter Zijlstra <peterz@infradead.org>
AuthorDate:    Thu, 29 Oct 2020 16:32:22 +01:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Mon, 09 Nov 2020 18:12:36 +01:00

perf: Tweak perf_event_attr::exclusive semantics

Currently perf_event_attr::exclusive can be used to ensure an
event(group) is the sole group scheduled on the PMU. One consequence
is that when you have a pinned event (say the watchdog) you can no
longer have regular exclusive event(group)s.

Inspired by the fact that !pinned events are considered less strict,
allow !pinned,exclusive events to share the PMU with pinned,!exclusive
events.

Pinned,exclusive is still fully exclusive.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20201029162902.105962225@infradead.org
---
 kernel/events/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 00be48a..dc568ca 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -2637,7 +2637,7 @@ static int group_can_go_on(struct perf_event *event,
 	 * If this group is exclusive and there are already
 	 * events on the CPU, it can't go on.
 	 */
-	if (event->attr.exclusive && cpuctx->active_oncpu)
+	if (event->attr.exclusive && !list_empty(get_event_list(event)))
 		return 0;
 	/*
 	 * Otherwise, try to add it if all previous groups were able

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

* [tip: perf/urgent] perf: Simplify group_sched_in()
  2020-10-29 16:27 ` [PATCH v2 2/4] perf: Simplify group_sched_in() Peter Zijlstra
@ 2020-11-10 12:45   ` tip-bot2 for Peter Zijlstra
  0 siblings, 0 replies; 14+ messages in thread
From: tip-bot2 for Peter Zijlstra @ 2020-11-10 12:45 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Peter Zijlstra (Intel), x86, linux-kernel

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     251ff2d49347793d348babcff745289b11910e96
Gitweb:        https://git.kernel.org/tip/251ff2d49347793d348babcff745289b11910e96
Author:        Peter Zijlstra <peterz@infradead.org>
AuthorDate:    Thu, 29 Oct 2020 16:29:15 +01:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Mon, 09 Nov 2020 18:12:35 +01:00

perf: Simplify group_sched_in()

Collate the error paths. Code duplication only leads to divergence and
extra bugs.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20201029162901.972161394@infradead.org
---
 kernel/events/core.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 9a57366..f0e5268 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -2580,11 +2580,8 @@ group_sched_in(struct perf_event *group_event,
 
 	pmu->start_txn(pmu, PERF_PMU_TXN_ADD);
 
-	if (event_sched_in(group_event, cpuctx, ctx)) {
-		pmu->cancel_txn(pmu);
-		perf_mux_hrtimer_restart(cpuctx);
-		return -EAGAIN;
-	}
+	if (event_sched_in(group_event, cpuctx, ctx))
+		goto error;
 
 	/*
 	 * Schedule in siblings as one group (if any):
@@ -2613,10 +2610,9 @@ group_error:
 	}
 	event_sched_out(group_event, cpuctx, ctx);
 
+error:
 	pmu->cancel_txn(pmu);
-
 	perf_mux_hrtimer_restart(cpuctx);
-
 	return -EAGAIN;
 }
 

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

* [tip: perf/urgent] perf: Fix event multiplexing for exclusive groups
  2020-10-29 16:27 ` [PATCH v2 3/4] perf: Fix event multiplexing for exclusive groups Peter Zijlstra
@ 2020-11-10 12:45   ` tip-bot2 for Peter Zijlstra
  0 siblings, 0 replies; 14+ messages in thread
From: tip-bot2 for Peter Zijlstra @ 2020-11-10 12:45 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Andi Kleen, Peter Zijlstra (Intel), x86, linux-kernel

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     2714c3962f304d031d5016c963c4b459337b0749
Gitweb:        https://git.kernel.org/tip/2714c3962f304d031d5016c963c4b459337b0749
Author:        Peter Zijlstra <peterz@infradead.org>
AuthorDate:    Thu, 29 Oct 2020 16:29:53 +01:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Mon, 09 Nov 2020 18:12:36 +01:00

perf: Fix event multiplexing for exclusive groups

Commit 9e6302056f80 ("perf: Use hrtimers for event multiplexing")
placed the hrtimer (re)start call in the wrong place.  Instead of
capturing all scheduling failures, it only considered the PMU failure.

The result is that groups using perf_event_attr::exclusive are no
longer rotated.

Fixes: 9e6302056f80 ("perf: Use hrtimers for event multiplexing")
Reported-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20201029162902.038667689@infradead.org
---
 kernel/events/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index f0e5268..00be48a 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -2612,7 +2612,6 @@ group_error:
 
 error:
 	pmu->cancel_txn(pmu);
-	perf_mux_hrtimer_restart(cpuctx);
 	return -EAGAIN;
 }
 
@@ -3672,6 +3671,7 @@ static int merge_sched_in(struct perf_event *event, void *data)
 
 		*can_add_hw = 0;
 		ctx->rotate_necessary = 1;
+		perf_mux_hrtimer_restart(cpuctx);
 	}
 
 	return 0;

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

* [tip: perf/urgent] perf: Simplify group_sched_out()
  2020-10-29 16:27 ` [PATCH v2 1/4] perf: Simplify group_sched_out() Peter Zijlstra
@ 2020-11-10 12:45   ` tip-bot2 for Peter Zijlstra
  0 siblings, 0 replies; 14+ messages in thread
From: tip-bot2 for Peter Zijlstra @ 2020-11-10 12:45 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Peter Zijlstra (Intel), x86, linux-kernel

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     8c7855d82933bab7fa5e96f0e568fc125c2e1ab4
Gitweb:        https://git.kernel.org/tip/8c7855d82933bab7fa5e96f0e568fc125c2e1ab4
Author:        Peter Zijlstra <peterz@infradead.org>
AuthorDate:    Thu, 29 Oct 2020 16:28:25 +01:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Mon, 09 Nov 2020 18:12:35 +01:00

perf: Simplify group_sched_out()

Since event_sched_out() clears cpuctx->exclusive upon removal of an
exclusive event (and only group leaders can be exclusive), there is no
point in group_sched_out() trying to do it too. It is impossible for
cpuctx->exclusive to still be set here.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20201029162901.904060564@infradead.org
---
 kernel/events/core.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index d67c9cb..9a57366 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -2312,9 +2312,6 @@ group_sched_out(struct perf_event *group_event,
 		event_sched_out(event, cpuctx, ctx);
 
 	perf_pmu_enable(ctx->pmu);
-
-	if (group_event->attr.exclusive)
-		cpuctx->exclusive = 0;
 }
 
 #define DETACH_GROUP	0x01UL

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

end of thread, other threads:[~2020-11-10 12:46 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-29 16:27 [PATCH v2 0/4] perf: Fix perf_event_attr::exclusive rotation Peter Zijlstra
2020-10-29 16:27 ` [PATCH v2 1/4] perf: Simplify group_sched_out() Peter Zijlstra
2020-11-10 12:45   ` [tip: perf/urgent] " tip-bot2 for Peter Zijlstra
2020-10-29 16:27 ` [PATCH v2 2/4] perf: Simplify group_sched_in() Peter Zijlstra
2020-11-10 12:45   ` [tip: perf/urgent] " tip-bot2 for Peter Zijlstra
2020-10-29 16:27 ` [PATCH v2 3/4] perf: Fix event multiplexing for exclusive groups Peter Zijlstra
2020-11-10 12:45   ` [tip: perf/urgent] " tip-bot2 for Peter Zijlstra
2020-10-29 16:27 ` [PATCH v2 4/4] perf: Tweak perf_event_attr::exclusive semantics Peter Zijlstra
2020-11-10 12:45   ` [tip: perf/urgent] " tip-bot2 for Peter Zijlstra
2020-10-31 23:44 ` [PATCH v2 0/4] perf: Fix perf_event_attr::exclusive rotation Jiri Olsa
2020-11-02  3:52   ` Andi Kleen
2020-11-02 14:16     ` Peter Zijlstra
2020-11-03  2:41       ` Andi Kleen
2020-11-09 11:48         ` Peter Zijlstra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).