mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: tip-bot for Peter Zijlstra <a.p.zijlstra@chello.nl>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@redhat.com,
	fweisbec@gmail.com, a.p.zijlstra@chello.nl, tglx@linutronix.de,
	mingo@elte.hu
Subject: [tip:perf/core] perf: Use jump_labels to optimize the scheduler hooks
Date: Mon, 18 Oct 2010 19:21:48 GMT	[thread overview]
Message-ID: <tip-82cd6def9806dcb6a325fb6abbc1d61388a15f6a@git.kernel.org> (raw)
In-Reply-To: <20101014203625.501657727@chello.nl>

Commit-ID:  82cd6def9806dcb6a325fb6abbc1d61388a15f6a
Gitweb:     http://git.kernel.org/tip/82cd6def9806dcb6a325fb6abbc1d61388a15f6a
Author:     Peter Zijlstra <a.p.zijlstra@chello.nl>
AuthorDate: Thu, 14 Oct 2010 17:57:23 +0200
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Mon, 18 Oct 2010 19:58:58 +0200

perf: Use jump_labels to optimize the scheduler hooks

Trades a call + conditional + ret for an unconditional jmp.

Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <20101014203625.501657727@chello.nl>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 include/linux/perf_event.h |   27 +++++++++++++++++++++++++--
 kernel/perf_event.c        |   24 +++++++++---------------
 2 files changed, 34 insertions(+), 17 deletions(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 97965fa..7f0e7f5 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -487,6 +487,7 @@ struct perf_guest_info_callbacks {
 #include <linux/ftrace.h>
 #include <linux/cpu.h>
 #include <linux/irq_work.h>
+#include <linux/jump_label_ref.h>
 #include <asm/atomic.h>
 #include <asm/local.h>
 
@@ -895,8 +896,30 @@ extern void perf_pmu_unregister(struct pmu *pmu);
 
 extern int perf_num_counters(void);
 extern const char *perf_pmu_name(void);
-extern void perf_event_task_sched_in(struct task_struct *task);
-extern void perf_event_task_sched_out(struct task_struct *task, struct task_struct *next);
+extern void __perf_event_task_sched_in(struct task_struct *task);
+extern void __perf_event_task_sched_out(struct task_struct *task, struct task_struct *next);
+
+extern atomic_t perf_task_events;
+
+static inline void perf_event_task_sched_in(struct task_struct *task)
+{
+	JUMP_LABEL(&perf_task_events, have_events);
+	return;
+
+have_events:
+	__perf_event_task_sched_in(task);
+}
+
+static inline
+void perf_event_task_sched_out(struct task_struct *task, struct task_struct *next)
+{
+	JUMP_LABEL(&perf_task_events, have_events);
+	return;
+
+have_events:
+	__perf_event_task_sched_out(task, next);
+}
+
 extern int perf_event_init_task(struct task_struct *child);
 extern void perf_event_exit_task(struct task_struct *child);
 extern void perf_event_free_task(struct task_struct *task);
diff --git a/kernel/perf_event.c b/kernel/perf_event.c
index 856e20b..f7febb0 100644
--- a/kernel/perf_event.c
+++ b/kernel/perf_event.c
@@ -34,7 +34,7 @@
 
 #include <asm/irq_regs.h>
 
-static atomic_t nr_events __read_mostly;
+atomic_t perf_task_events __read_mostly;
 static atomic_t nr_mmap_events __read_mostly;
 static atomic_t nr_comm_events __read_mostly;
 static atomic_t nr_task_events __read_mostly;
@@ -1311,8 +1311,8 @@ void perf_event_context_sched_out(struct task_struct *task, int ctxn,
  * accessing the event control register. If a NMI hits, then it will
  * not restart the event.
  */
-void perf_event_task_sched_out(struct task_struct *task,
-			       struct task_struct *next)
+void __perf_event_task_sched_out(struct task_struct *task,
+				 struct task_struct *next)
 {
 	int ctxn;
 
@@ -1340,14 +1340,6 @@ static void task_ctx_sched_out(struct perf_event_context *ctx,
 /*
  * Called with IRQs disabled
  */
-static void __perf_event_task_sched_out(struct perf_event_context *ctx)
-{
-	task_ctx_sched_out(ctx, EVENT_ALL);
-}
-
-/*
- * Called with IRQs disabled
- */
 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
 			      enum event_type_t event_type)
 {
@@ -1494,7 +1486,7 @@ void perf_event_context_sched_in(struct perf_event_context *ctx)
  * accessing the event control register. If a NMI hits, then it will
  * keep the event running.
  */
-void perf_event_task_sched_in(struct task_struct *task)
+void __perf_event_task_sched_in(struct task_struct *task)
 {
 	struct perf_event_context *ctx;
 	int ctxn;
@@ -2216,7 +2208,8 @@ static void free_event(struct perf_event *event)
 	irq_work_sync(&event->pending);
 
 	if (!event->parent) {
-		atomic_dec(&nr_events);
+		if (event->attach_state & PERF_ATTACH_TASK)
+			jump_label_dec(&perf_task_events);
 		if (event->attr.mmap || event->attr.mmap_data)
 			atomic_dec(&nr_mmap_events);
 		if (event->attr.comm)
@@ -5354,7 +5347,8 @@ done:
 	event->pmu = pmu;
 
 	if (!event->parent) {
-		atomic_inc(&nr_events);
+		if (event->attach_state & PERF_ATTACH_TASK)
+			jump_label_inc(&perf_task_events);
 		if (event->attr.mmap || event->attr.mmap_data)
 			atomic_inc(&nr_mmap_events);
 		if (event->attr.comm)
@@ -5849,7 +5843,7 @@ static void perf_event_exit_task_context(struct task_struct *child, int ctxn)
 	 * our context.
 	 */
 	child_ctx = child->perf_event_ctxp[ctxn];
-	__perf_event_task_sched_out(child_ctx);
+	task_ctx_sched_out(child_ctx, EVENT_ALL);
 
 	/*
 	 * Take the context lock here so that if find_get_context is

  parent reply	other threads:[~2010-10-18 19:22 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-14 20:34 [RFC][PATCH 0/7] perf and jump_label bits Peter Zijlstra
2010-10-14 20:34 ` [RFC][PATCH 1/7] perf: Fix task refcount issues Peter Zijlstra
2010-10-15 18:14   ` Frederic Weisbecker
2010-10-15 20:02   ` Matt Helsley
2010-10-18 19:19   ` [tip:perf/core] perf: Fix task refcount bugs tip-bot for Peter Zijlstra
2010-10-14 20:34 ` [RFC][PATCH 2/7] perf: Find task before event alloc Peter Zijlstra
2010-10-18 19:20   ` [tip:perf/core] " tip-bot for Peter Zijlstra
2010-10-14 20:34 ` [RFC][PATCH 3/7] perf, hw_breakpoint: Fix crash in hw_breakpoint creation Peter Zijlstra
2010-10-15 13:47   ` Frederic Weisbecker
2010-10-15 13:52     ` Peter Zijlstra
2010-10-18 19:20   ` [tip:perf/core] " tip-bot for Peter Zijlstra
2010-10-14 20:34 ` [RFC][PATCH 4/7] jump_label: More consitent naming Peter Zijlstra
2010-10-18 19:21   ` [tip:perf/core] jump_label: Use more consistent naming tip-bot for Peter Zijlstra
2010-10-14 20:34 ` [RFC][PATCH 5/7] jump_label: atomic_t interface Peter Zijlstra
2010-10-15 14:01   ` Frederic Weisbecker
2010-10-18 19:21   ` [tip:perf/core] jump_label: Add " tip-bot for Peter Zijlstra
2010-10-18 19:21   ` tip-bot for Peter Zijlstra [this message]
2010-10-14 20:34 ` [RFC][PATCH 6/7] perf: use jump_label to optimize the scheduler hooks Peter Zijlstra
2010-10-15 13:59   ` Frederic Weisbecker
2010-10-17  9:52   ` Peter Zijlstra
2010-10-17 10:16     ` Peter Zijlstra
2010-10-14 20:34 ` [RFC][PATCH 7/7] perf: Optimize sw events Peter Zijlstra
2010-10-15  9:14   ` Peter Zijlstra
2010-10-15 14:18     ` Jason Baron
2010-10-15 14:57     ` Peter Zijlstra
2010-10-15 15:02       ` Jason Baron
2010-10-15 19:32       ` Steven Rostedt
2010-10-15 19:54         ` Peter Zijlstra
2010-10-16  6:27       ` Ingo Molnar
2010-10-15 14:04   ` Frederic Weisbecker
2010-10-15 14:08     ` Peter Zijlstra
2010-10-15 14:11       ` Frederic Weisbecker

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-82cd6def9806dcb6a325fb6abbc1d61388a15f6a@git.kernel.org \
    --to=a.p.zijlstra@chello.nl \
    --cc=fweisbec@gmail.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    /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

Powered by JetHome