From: "tip-bot for leilei.lin" <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: hpa@zytor.com, mingo@kernel.org, leilei.lin@alibaba-inc.com,
tglx@linutronix.de, linux-kernel@vger.kernel.org,
torvalds@linux-foundation.org, peterz@infradead.org
Subject: [tip:perf/core] perf/core: Reduce context switch overhead
Date: Thu, 10 Aug 2017 05:03:19 -0700 [thread overview]
Message-ID: <tip-fdccc3fb7a42ea4e4cd77d2fb8fa3a45c66ec0bf@git.kernel.org> (raw)
In-Reply-To: <20170809002921.69813-1-leilei.lin@alibaba-inc.com>
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);
}
prev parent reply other threads:[~2017-08-10 12:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-09 0:29 [PATCH v3] perf/core: Avoid context switch overheads 石祤
2017-08-09 16:37 ` Peter Zijlstra
2017-08-10 12:03 ` tip-bot for leilei.lin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tip-fdccc3fb7a42ea4e4cd77d2fb8fa3a45c66ec0bf@git.kernel.org \
--to=tipbot@zytor.com \
--cc=hpa@zytor.com \
--cc=leilei.lin@alibaba-inc.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox