mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frederic Weisbecker <fweisbec@gmail.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Ingo Molnar <mingo@elte.hu>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Paul Mackerras <paulus@samba.org>
Subject: [PATCH 2/4] perf: Add exclude_task perf event attribute
Date: Fri, 21 May 2010 16:05:13 +0200	[thread overview]
Message-ID: <1274450715-23955-3-git-send-regression-fweisbec@gmail.com> (raw)
In-Reply-To: <1274450715-23955-1-git-send-regression-fweisbec@gmail.com>

Excluding is useful when you want to trace only hard and softirqs.

For this we use a new generic perf_exclude_event() (the previous
one beeing turned into perf_exclude_swevent) to which you can pass
the preemption offset to which your events trigger.

Computing preempt_count() - offset gives us the preempt_count() of
the context that the event has interrupted, on top of which we
can filter the non-irq contexts.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
---
 include/linux/perf_event.h |    3 ++-
 kernel/perf_event.c        |   41 ++++++++++++++++++++++++++++++++++-------
 2 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index fe50347..d939fc7 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -214,8 +214,9 @@ struct perf_event_attr {
 				 *  See also PERF_RECORD_MISC_EXACT_IP
 				 */
 				precise_ip     :  2, /* skid constraint       */
+				exclude_task   :  1, /* don't count task context */
 
-				__reserved_1   : 47;
+				__reserved_1   : 46;
 
 	union {
 		__u32		wakeup_events;	  /* wakeup every n events */
diff --git a/kernel/perf_event.c b/kernel/perf_event.c
index 45b7aec..ab96411 100644
--- a/kernel/perf_event.c
+++ b/kernel/perf_event.c
@@ -3907,10 +3907,33 @@ static int __perf_event_overflow(struct perf_event *event, int nmi,
 	return ret;
 }
 
+static bool
+perf_exclude_event(struct perf_event *event, int offset)
+{
+	if (!in_interrupt_offset(preempt_count() - offset)) {
+		if (event->attr.exclude_task)
+			return true;
+	}
+
+	return false;
+}
+
 int perf_event_overflow(struct perf_event *event, int nmi,
 			  struct perf_sample_data *data,
 			  struct pt_regs *regs)
 {
+	int offset = HARDIRQ_OFFSET;
+
+	if (nmi)
+		offset += NMI_OFFSET;
+	/*
+	 * Hardware events trigger on NMI or simple hardirq, which offset we
+	 * need to substract to get the preempt_count() of the interrupted
+	 * context.
+	 */
+	if (perf_exclude_event(event, offset))
+		return 0;
+
 	return __perf_event_overflow(event, nmi, 1, data, regs);
 }
 
@@ -4008,8 +4031,8 @@ static void perf_swevent_add(struct perf_event *event, u64 nr,
 static int perf_tp_event_match(struct perf_event *event,
 				struct perf_sample_data *data);
 
-static int perf_exclude_event(struct perf_event *event,
-			      struct pt_regs *regs)
+static int perf_exclude_swevent(struct perf_event *event,
+			      struct pt_regs *regs, int offset)
 {
 	if (regs) {
 		if (event->attr.exclude_user && user_mode(regs))
@@ -4019,7 +4042,7 @@ static int perf_exclude_event(struct perf_event *event,
 			return 1;
 	}
 
-	return 0;
+	return perf_exclude_event(event, offset);
 }
 
 static int perf_swevent_match(struct perf_event *event,
@@ -4034,7 +4057,7 @@ static int perf_swevent_match(struct perf_event *event,
 	if (event->attr.config != event_id)
 		return 0;
 
-	if (perf_exclude_event(event, regs))
+	if (perf_exclude_swevent(event, regs, 0))
 		return 0;
 
 	if (event->attr.type == PERF_TYPE_TRACEPOINT &&
@@ -4230,9 +4253,13 @@ static enum hrtimer_restart perf_swevent_hrtimer(struct hrtimer *hrtimer)
 	data.period = event->hw.last_period;
 	regs = get_irq_regs();
 
-	if (regs && !perf_exclude_event(event, regs)) {
+	/*
+	 * we are in hardirq, so we need to substract our preempt offset
+	 * to retrieve the interrupted one
+	 */
+	if (regs && !perf_exclude_swevent(event, regs, HARDIRQ_OFFSET)) {
 		if (!(event->attr.exclude_idle && current->pid == 0))
-			if (perf_event_overflow(event, 0, &data, regs))
+			if (__perf_event_overflow(event, 0, 1, &data, regs))
 				ret = HRTIMER_NORESTART;
 	}
 
@@ -4624,7 +4651,7 @@ void perf_bp_event(struct perf_event *bp, void *data)
 
 	perf_sample_data_init(&sample, bp->attr.bp_addr);
 
-	if (!perf_exclude_event(bp, regs))
+	if (!perf_exclude_swevent(bp, regs, 0))
 		perf_swevent_add(bp, 1, 1, &sample, regs);
 }
 #else
-- 
1.6.2.3


  parent reply	other threads:[~2010-05-21 14:10 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-21 14:05 [PATCH 0/4] perf: Tasks and irq exclusion Frederic Weisbecker
2010-05-21 14:05 ` [PATCH 1/4] irq: Support to compute context on top of a given preempt_count offset Frederic Weisbecker
2010-05-21 14:05 ` Frederic Weisbecker [this message]
2010-05-25  1:43   ` [PATCH 2/4] perf: Add exclude_task perf event attribute Paul Mackerras
2010-05-25  6:58     ` Peter Zijlstra
2010-05-25 10:06       ` Frederic Weisbecker
2010-06-07  1:38       ` Frederic Weisbecker
2010-06-08 18:59         ` Ingo Molnar
2010-06-08 19:02           ` Frederic Weisbecker
2010-05-21 14:05 ` [PATCH 3/4] perf: Support for irq exclusion Frederic Weisbecker
2010-05-21 14:06   ` Frederic Weisbecker
2010-05-21 14:05 ` [PATCH 4/4] perf: Support for task/softirq/hardirq exclusion on tools Frederic Weisbecker
2010-05-21 15:12 ` [PATCH 0/4] perf: Precise task / softirq / hardirq filtered stats/profiles Ingo Molnar
2010-05-21 16:15   ` Peter Zijlstra
2010-05-21 18:36     ` Ingo Molnar

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=1274450715-23955-3-git-send-regression-fweisbec@gmail.com \
    --to=fweisbec@gmail.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.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

Powered by JetHome