Skip to content

Commit 90c91df

Browse files
author
Peter Zijlstra
committed
perf/core: Fix endless multiplex timer
Kan and Andi reported that we fail to kill rotation when the flexible events go empty, but the context does not. XXX moar Fixes: fd7d551 ("perf/cgroups: Don't rotate events for cgroups unnecessarily") Reported-by: Andi Kleen <[email protected]> Reported-by: Kan Liang <[email protected]> Tested-by: Kan Liang <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent d8a7386 commit 90c91df

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

kernel/events/core.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2291,6 +2291,7 @@ __perf_remove_from_context(struct perf_event *event,
22912291

22922292
if (!ctx->nr_events && ctx->is_active) {
22932293
ctx->is_active = 0;
2294+
ctx->rotate_necessary = 0;
22942295
if (ctx->task) {
22952296
WARN_ON_ONCE(cpuctx->task_ctx != ctx);
22962297
cpuctx->task_ctx = NULL;
@@ -3188,12 +3189,6 @@ static void ctx_sched_out(struct perf_event_context *ctx,
31883189
if (!ctx->nr_active || !(is_active & EVENT_ALL))
31893190
return;
31903191

3191-
/*
3192-
* If we had been multiplexing, no rotations are necessary, now no events
3193-
* are active.
3194-
*/
3195-
ctx->rotate_necessary = 0;
3196-
31973192
perf_pmu_disable(ctx->pmu);
31983193
if (is_active & EVENT_PINNED) {
31993194
list_for_each_entry_safe(event, tmp, &ctx->pinned_active, active_list)
@@ -3203,6 +3198,13 @@ static void ctx_sched_out(struct perf_event_context *ctx,
32033198
if (is_active & EVENT_FLEXIBLE) {
32043199
list_for_each_entry_safe(event, tmp, &ctx->flexible_active, active_list)
32053200
group_sched_out(event, cpuctx, ctx);
3201+
3202+
/*
3203+
* Since we cleared EVENT_FLEXIBLE, also clear
3204+
* rotate_necessary, is will be reset by
3205+
* ctx_flexible_sched_in() when needed.
3206+
*/
3207+
ctx->rotate_necessary = 0;
32063208
}
32073209
perf_pmu_enable(ctx->pmu);
32083210
}
@@ -3985,6 +3987,12 @@ ctx_event_to_rotate(struct perf_event_context *ctx)
39853987
typeof(*event), group_node);
39863988
}
39873989

3990+
/*
3991+
* Unconditionally clear rotate_necessary; if ctx_flexible_sched_in()
3992+
* finds there are unschedulable events, it will set it again.
3993+
*/
3994+
ctx->rotate_necessary = 0;
3995+
39883996
return event;
39893997
}
39903998

0 commit comments

Comments
 (0)