Skip to content

Commit

Permalink
perf: Optimize perf_pmu_migrate_context()
Browse files Browse the repository at this point in the history
Thomas reported that offlining CPUs spends a lot of time in
synchronize_rcu() as called from perf_pmu_migrate_context() even though
he's not actually using uncore events.

Turns out, the thing is unconditionally waiting for RCU, even if there's
no actual events to migrate.

Fixes: 0cda4c0 ("perf: Introduce perf_pmu_migrate_context()")
Reported-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Paul E. McKenney <paulmck@kernel.org>
Link: https://lkml.kernel.org/r/20230403090858.GT4253@hirez.programming.kicks-ass.net
  • Loading branch information
Peter Zijlstra committed Apr 5, 2023
1 parent 197b6b6 commit b168098
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions kernel/events/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -12893,12 +12893,14 @@ void perf_pmu_migrate_context(struct pmu *pmu, int src_cpu, int dst_cpu)
__perf_pmu_remove(src_ctx, src_cpu, pmu, &src_ctx->pinned_groups, &events);
__perf_pmu_remove(src_ctx, src_cpu, pmu, &src_ctx->flexible_groups, &events);

/*
* Wait for the events to quiesce before re-instating them.
*/
synchronize_rcu();
if (!list_empty(&events)) {
/*
* Wait for the events to quiesce before re-instating them.
*/
synchronize_rcu();

__perf_pmu_install(dst_ctx, dst_cpu, pmu, &events);
__perf_pmu_install(dst_ctx, dst_cpu, pmu, &events);
}

mutex_unlock(&dst_ctx->mutex);
mutex_unlock(&src_ctx->mutex);
Expand Down

0 comments on commit b168098

Please sign in to comment.