mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kan Liang <kan.liang@intel.com>
To: peterz@infradead.org
Cc: mingo@kernel.org, acme@infradead.org, eranian@google.com,
	andi@firstfloor.org, linux-kernel@vger.kernel.org,
	Kan Liang <kan.liang@intel.com>
Subject: [PATCH V8 7/8] perf, x86: introduce PERF_RECORD_LOST_SAMPLES
Date: Wed,  6 May 2015 15:33:53 -0400	[thread overview]
Message-ID: <1430940834-8964-8-git-send-email-kan.liang@intel.com> (raw)
In-Reply-To: <1430940834-8964-1-git-send-email-kan.liang@intel.com>

From: Kan Liang <kan.liang@intel.com>

After enlarging the PEBS interrupt threshold, there may be some mixed up
PEBS samples which are discarded by kernel. This patch drives the kernel
to emit a PERF_RECORD_LOST_SAMPLES record with the number of possible
discards when it is impossible to demux the samples. It makes sure the
user is not left in the dark about such discards.

Signed-off-by: Kan Liang <kan.liang@intel.com>
---
 arch/x86/kernel/cpu/perf_event_intel_ds.c | 16 ++++++++++----
 include/linux/perf_event.h                |  3 +++
 include/uapi/linux/perf_event.h           | 12 +++++++++++
 kernel/events/core.c                      | 35 +++++++++++++++++++++++++++++++
 4 files changed, 62 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/cpu/perf_event_intel_ds.c b/arch/x86/kernel/cpu/perf_event_intel_ds.c
index fc03e7a..cdd331f 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_ds.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_ds.c
@@ -1127,6 +1127,7 @@ static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs)
 	void *base, *at, *top;
 	int bit;
 	short counts[MAX_PEBS_EVENTS] = {};
+	short error[MAX_PEBS_EVENTS] = {};
 
 	if (!x86_pmu.pebs_active)
 		return;
@@ -1170,21 +1171,28 @@ static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs)
 			/* slow path */
 			pebs_status = p->status & cpuc->pebs_enabled;
 			pebs_status &= (1ULL << MAX_PEBS_EVENTS) - 1;
-			if (pebs_status != (1 << bit))
+			if (pebs_status != (1 << bit)) {
+				error[bit]++;
 				continue;
+			}
 		}
 		counts[bit]++;
 	}
 
 	for (bit = 0; bit < x86_pmu.max_pebs_events; bit++) {
-		if (counts[bit] == 0)
+		if ((counts[bit] == 0) && (error[bit] == 0))
 			continue;
 		event = cpuc->events[bit];
 		WARN_ON_ONCE(!event);
 		WARN_ON_ONCE(!event->attr.precise_ip);
 
-		__intel_pmu_pebs_event(event, iregs, base,
-				       top, bit, counts[bit]);
+		/* log dropped samples number */
+		if (error[bit])
+			perf_log_lost_samples(event, error[bit]);
+
+		if (counts[bit])
+			__intel_pmu_pebs_event(event, iregs, base,
+					       top, bit, counts[bit]);
 	}
 }
 
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index bed1b6f..d47d792 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -747,6 +747,9 @@ perf_event__output_id_sample(struct perf_event *event,
 			     struct perf_output_handle *handle,
 			     struct perf_sample_data *sample);
 
+extern void
+perf_log_lost_samples(struct perf_event *event, u64 lost);
+
 static inline bool is_sampling_event(struct perf_event *event)
 {
 	return event->attr.sample_period != 0;
diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index 309211b..2c1ae5c 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -800,6 +800,18 @@ enum perf_event_type {
 	 */
 	PERF_RECORD_ITRACE_START		= 12,
 
+	/*
+	 * Records the dropped/lost sample number.
+	 *
+	 * struct {
+	 *	struct perf_event_header	header;
+	 *	u64				id;
+	 *	u64				lost;
+	 *	struct sample_id		sample_id;
+	 * };
+	 */
+	PERF_RECORD_LOST_SAMPLES		= 13,
+
 	PERF_RECORD_MAX,			/* non-ABI */
 };
 
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 4d221a4..1337fe3 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -5927,6 +5927,41 @@ void perf_event_aux_event(struct perf_event *event, unsigned long head,
 }
 
 /*
+ * Lost/dropped samples logging
+ */
+void perf_log_lost_samples(struct perf_event *event, u64 lost)
+{
+	struct perf_output_handle handle;
+	struct perf_sample_data sample;
+	int ret;
+
+	struct {
+		struct perf_event_header	header;
+		u64				id;
+		u64				lost;
+	} lost_samples_event = {
+		.header = {
+			.type = PERF_RECORD_LOST_SAMPLES,
+			.misc = 0,
+			.size = sizeof(lost_samples_event),
+		},
+		.id		= event->id,
+		.lost		= lost,
+	};
+
+	perf_event_header__init_id(&lost_samples_event.header, &sample, event);
+
+	ret = perf_output_begin(&handle, event,
+				lost_samples_event.header.size);
+	if (ret)
+		return;
+
+	perf_output_put(&handle, lost_samples_event);
+	perf_event__output_id_sample(event, &handle, &sample);
+	perf_output_end(&handle);
+}
+
+/*
  * IRQ throttle logging
  */
 
-- 
1.8.3.1


  parent reply	other threads:[~2015-05-07  2:47 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-06 19:33 [PATCH V8 0/8] large PEBS interrupt threshold Kan Liang
2015-05-06 19:33 ` [PATCH V8 1/8] perf, x86: use the PEBS auto reload mechanism when possible Kan Liang
2015-06-07 17:49   ` [tip:perf/core] perf/x86/intel: Use " tip-bot for Yan, Zheng
2015-05-06 19:33 ` [PATCH V8 2/8] perf, x86: introduce setup_pebs_sample_data() Kan Liang
2015-06-07 17:49   ` [tip:perf/core] perf/x86/intel: Introduce setup_pebs_sample_data( ) tip-bot for Yan, Zheng
2015-05-06 19:33 ` [PATCH V8 3/8] perf, x86: handle multiple records in PEBS buffer Kan Liang
2015-05-08 11:05   ` Andi Kleen
2015-05-08 11:29     ` Peter Zijlstra
2015-06-07 17:49   ` [tip:perf/core] perf/x86/intel: Handle multiple records in the " tip-bot for Yan, Zheng
2015-05-06 19:33 ` [PATCH V8 4/8] perf, x86: large PEBS interrupt threshold Kan Liang
2015-06-07 17:49   ` [tip:perf/core] perf/x86/intel: Implement batched PEBS interrupt handling (large PEBS interrupt threshold ) tip-bot for Yan, Zheng
2015-05-06 19:33 ` [PATCH V8 5/8] perf, x86: drain PEBS buffer during context switch Kan Liang
2015-06-07 17:50   ` [tip:perf/core] perf/x86/intel: Drain the PEBS buffer during context switches tip-bot for Yan, Zheng
2015-05-06 19:33 ` [PATCH V8 6/8] perf, x86: enlarge PEBS buffer Kan Liang
2015-06-07 17:50   ` [tip:perf/core] perf/intel/x86: Enlarge the " tip-bot for Yan, Zheng
2015-05-06 19:33 ` Kan Liang [this message]
2015-05-07 11:35   ` [PATCH V8 7/8] perf, x86: introduce PERF_RECORD_LOST_SAMPLES Peter Zijlstra
2015-05-07 11:54     ` Peter Zijlstra
2015-05-07 14:15       ` Arnaldo Carvalho de Melo
2015-05-07 14:21         ` Arnaldo Carvalho de Melo
2015-05-07 14:39         ` Peter Zijlstra
2015-05-07 16:22           ` Arnaldo Carvalho de Melo
2015-05-07 17:37             ` Peter Zijlstra
2015-05-07 20:01               ` Arnaldo Carvalho de Melo
2015-05-07 13:56     ` Liang, Kan
2015-05-07 13:58       ` Peter Zijlstra
2015-05-06 19:33 ` [PATCH V8 8/8] perf tools: handle PERF_RECORD_LOST_SAMPLES Kan Liang
2015-05-07 10:33   ` Andi Kleen
2015-05-07 14:17     ` Liang, Kan

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=1430940834-8964-8-git-send-email-kan.liang@intel.com \
    --to=kan.liang@intel.com \
    --cc=acme@infradead.org \
    --cc=andi@firstfloor.org \
    --cc=eranian@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.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