From: linxiulei <linxiulei@gmail.com>
To: yang_oliver@hotmail.com, peterz@infradead.org, mingo@redhat.com,
acme@kernel.org, alexander.shishkin@linux.intel.com,
linux-kernel@vger.kernel.org, tglx@linutronix.de,
eranian@gmail.com, torvalds@linux-foundation.org,
jolsa@redhat.com, linxiulei@gmail.com
Cc: "leilei . lin" <leilei.lin@alibaba-inc.com>
Subject: [PATCH v3] perf/core: Avoid context switch overheads
Date: Wed, 9 Aug 2017 08:40:19 +0800 [thread overview]
Message-ID: <20170809004019.75458-1-linxiulei@gmail.com> (raw)
From: "leilei.lin" <linxiulei@gmail.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
next reply other threads:[~2017-08-09 0:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-09 0:40 linxiulei [this message]
-- strict thread matches above, loose matches on Subject: below --
2017-08-09 0:29 石祤
2017-08-09 16:37 ` Peter Zijlstra
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=20170809004019.75458-1-linxiulei@gmail.com \
--to=linxiulei@gmail.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=eranian@gmail.com \
--cc=jolsa@redhat.com \
--cc=leilei.lin@alibaba-inc.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=yang_oliver@hotmail.com \
/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
all inboxes | Powered by JetHome®