Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1706975 > unrolled thread

[PATCH v3] perf/core: Avoid context switch overheads

Started by"石祤" <linxiulei@gmail.com>
First post2017-08-09 02:30 +0200
Last post2017-08-10 14:10 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH v3] perf/core: Avoid context switch overheads "石祤" <linxiulei@gmail.com> - 2017-08-09 02:30 +0200
    Re: [PATCH v3] perf/core: Avoid context switch overheads Peter Zijlstra <peterz@infradead.org> - 2017-08-09 18:40 +0200
    [tip:perf/core] perf/core: Reduce context switch overhead "tip-bot for leilei.lin" <tipbot@zytor.com> - 2017-08-10 14:10 +0200

#1706975 — [PATCH v3] perf/core: Avoid context switch overheads

From"石祤" <linxiulei@gmail.com>
Date2017-08-09 02:30 +0200
Subject[PATCH v3] perf/core: Avoid context switch overheads
Message-ID<ucn2N-7Ls-7@gated-at.bofh.it>
From: "leilei.lin" <leilei.lin@alibaba-inc.com>

A performance issue caused by less strickly check in task
sched when these tasks were once attached by per-task perf_event.

A task will alloc task->perf_event_ctxp[ctxn] when it was called
by perf_event_open, and task->perf_event_ctxp[ctxn] would not
ever be freed to NULL.

__perf_event_task_sched_in()
        if (task->perf_event_ctxp[ctxn]) //  here is always true
                perf_event_context_sched_in() // operate pmu

50% at most performance overhead was observed under some extreme
test case. Therefore, add a more strick check as to ctx->nr_events,
when ctx->nr_events == 0, it's no need to continue.

Signed-off-by: leilei.lin <leilei.lin@alibaba-inc.com>
---
 kernel/events/core.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 426c2ff..3d86695 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3180,6 +3180,13 @@ static void perf_event_context_sched_in(struct perf_event_context *ctx,
 		return;
 
 	perf_ctx_lock(cpuctx, ctx);
+	/*
+	 * We must check ctx->nr_events while holding ctx->lock, such
+	 * that we serialize against perf_install_in_context().
+	 */
+	if (!ctx->nr_events)
+		goto unlock;
+
 	perf_pmu_disable(ctx->pmu);
 	/*
 	 * We want to keep the following priority order:
@@ -3193,6 +3200,8 @@ static void perf_event_context_sched_in(struct perf_event_context *ctx,
 		cpu_ctx_sched_out(cpuctx, EVENT_FLEXIBLE);
 	perf_event_sched_in(cpuctx, ctx, task);
 	perf_pmu_enable(ctx->pmu);
+
+unlock:
 	perf_ctx_unlock(cpuctx, ctx);
 }
 
-- 
2.8.4.31.g9ed660f

[toc] | [next] | [standalone]


#1707470

FromPeter Zijlstra <peterz@infradead.org>
Date2017-08-09 18:40 +0200
Message-ID<ucCbv-1mZ-3@gated-at.bofh.it>
In reply to#1706975
On Wed, Aug 09, 2017 at 08:29:21AM +0800, 石祤 wrote:
> From: "leilei.lin" <leilei.lin@alibaba-inc.com>
> 
> A performance issue caused by less strickly check in task
> sched when these tasks were once attached by per-task perf_event.
> 
> A task will alloc task->perf_event_ctxp[ctxn] when it was called
> by perf_event_open, and task->perf_event_ctxp[ctxn] would not
> ever be freed to NULL.
> 
> __perf_event_task_sched_in()
>         if (task->perf_event_ctxp[ctxn]) //  here is always true
>                 perf_event_context_sched_in() // operate pmu
> 
> 50% at most performance overhead was observed under some extreme
> test case. Therefore, add a more strick check as to ctx->nr_events,
> when ctx->nr_events == 0, it's no need to continue.
> 
> Signed-off-by: leilei.lin <leilei.lin@alibaba-inc.com>

Thanks!

[toc] | [prev] | [next] | [standalone]


#1708502 — [tip:perf/core] perf/core: Reduce context switch overhead

From"tip-bot for leilei.lin" <tipbot@zytor.com>
Date2017-08-10 14:10 +0200
Subject[tip:perf/core] perf/core: Reduce context switch overhead
Message-ID<ucUrN-5pA-31@gated-at.bofh.it>
In reply to#1706975
Commit-ID:  fdccc3fb7a42ea4e4cd77d2fb8fa3a45c66ec0bf
Gitweb:     http://git.kernel.org/tip/fdccc3fb7a42ea4e4cd77d2fb8fa3a45c66ec0bf
Author:     leilei.lin <leilei.lin@alibaba-inc.com>
AuthorDate: Wed, 9 Aug 2017 08:29:21 +0800
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 10 Aug 2017 12:08:40 +0200

perf/core: Reduce context switch overhead

Skip most of the PMU context switching overhead when ctx->nr_events is 0.

50% performance overhead was observed under an extreme testcase.

Signed-off-by: leilei.lin <leilei.lin@alibaba-inc.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: acme@kernel.org
Cc: alexander.shishkin@linux.intel.com
Cc: eranian@gmail.com
Cc: jolsa@redhat.com
Cc: linxiulei@gmail.com
Cc: yang_oliver@hotmail.com
Link: http://lkml.kernel.org/r/20170809002921.69813-1-leilei.lin@alibaba-inc.com
[ Rewrote the changelog. ]
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/events/core.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index ee20d4c..d704e23 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3211,6 +3211,13 @@ static void perf_event_context_sched_in(struct perf_event_context *ctx,
 		return;
 
 	perf_ctx_lock(cpuctx, ctx);
+	/*
+	 * We must check ctx->nr_events while holding ctx->lock, such
+	 * that we serialize against perf_install_in_context().
+	 */
+	if (!ctx->nr_events)
+		goto unlock;
+
 	perf_pmu_disable(ctx->pmu);
 	/*
 	 * We want to keep the following priority order:
@@ -3224,6 +3231,8 @@ static void perf_event_context_sched_in(struct perf_event_context *ctx,
 		cpu_ctx_sched_out(cpuctx, EVENT_FLEXIBLE);
 	perf_event_sched_in(cpuctx, ctx, task);
 	perf_pmu_enable(ctx->pmu);
+
+unlock:
 	perf_ctx_unlock(cpuctx, ctx);
 }
 

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web