public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "tip-bot for Yan, Zheng" <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: zheng.z.yan@intel.com, akpm@linux-foundation.org,
	peterz@infradead.org, kan.liang@intel.com, mingo@kernel.org,
	torvalds@linux-foundation.org, hpa@zytor.com,
	linux-kernel@vger.kernel.org, tglx@linutronix.de
Subject: [tip:perf/core] perf/x86/intel: Use the PEBS auto reload mechanism when possible
Date: Sun, 7 Jun 2015 10:49:03 -0700	[thread overview]
Message-ID: <tip-851559e35fd5ab637783ba395e55edd50f761229@git.kernel.org> (raw)
In-Reply-To: <1430940834-8964-2-git-send-email-kan.liang@intel.com>

Commit-ID:  851559e35fd5ab637783ba395e55edd50f761229
Gitweb:     http://git.kernel.org/tip/851559e35fd5ab637783ba395e55edd50f761229
Author:     Yan, Zheng <zheng.z.yan@intel.com>
AuthorDate: Wed, 6 May 2015 15:33:47 -0400
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Sun, 7 Jun 2015 16:08:35 +0200

perf/x86/intel: Use the PEBS auto reload mechanism when possible

When a fixed period is specified, this patch makes perf use the PEBS
auto reload mechanism. This makes normal profiling faster, because
it avoids one costly MSR write in the PMI handler.

However, the reset value will be loaded by hardware assist. There is a
small delay compared to the previous non-auto-reload mechanism. The
delay time is arbitrary, but very small. The assist cost is 400-800
cycles, assuming common cases with everything cached. The minimum period
the patch currently uses is 10000. In that extreme case it can be ~10%
if cycles are used.

Signed-off-by: Yan, Zheng <zheng.z.yan@intel.com>
Signed-off-by: Kan Liang <kan.liang@intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: acme@infradead.org
Cc: eranian@google.com
Link: http://lkml.kernel.org/r/1430940834-8964-2-git-send-email-kan.liang@intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/kernel/cpu/perf_event.c          | 15 +++++++++------
 arch/x86/kernel/cpu/perf_event.h          |  1 +
 arch/x86/kernel/cpu/perf_event_intel.c    |  8 ++++++--
 arch/x86/kernel/cpu/perf_event_intel_ds.c |  7 +++++++
 4 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index dbe3328..9560d0f 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -1094,13 +1094,16 @@ int x86_perf_event_set_period(struct perf_event *event)
 
 	per_cpu(pmc_prev_left[idx], smp_processor_id()) = left;
 
-	/*
-	 * The hw event starts counting from this event offset,
-	 * mark it to be able to extra future deltas:
-	 */
-	local64_set(&hwc->prev_count, (u64)-left);
+	if (!(hwc->flags & PERF_X86_EVENT_AUTO_RELOAD) ||
+	    local64_read(&hwc->prev_count) != (u64)-left) {
+		/*
+		 * The hw event starts counting from this event offset,
+		 * mark it to be able to extra future deltas:
+		 */
+		local64_set(&hwc->prev_count, (u64)-left);
 
-	wrmsrl(hwc->event_base, (u64)(-left) & x86_pmu.cntval_mask);
+		wrmsrl(hwc->event_base, (u64)(-left) & x86_pmu.cntval_mask);
+	}
 
 	/*
 	 * Due to erratum on certan cpu we need
diff --git a/arch/x86/kernel/cpu/perf_event.h b/arch/x86/kernel/cpu/perf_event.h
index 89e6cd6..7a3f0fd 100644
--- a/arch/x86/kernel/cpu/perf_event.h
+++ b/arch/x86/kernel/cpu/perf_event.h
@@ -75,6 +75,7 @@ struct event_constraint {
 #define PERF_X86_EVENT_DYNAMIC		0x0080 /* dynamic alloc'd constraint */
 #define PERF_X86_EVENT_RDPMC_ALLOWED	0x0100 /* grant rdpmc permission */
 #define PERF_X86_EVENT_EXCL_ACCT	0x0200 /* accounted EXCL event */
+#define PERF_X86_EVENT_AUTO_RELOAD	0x0400 /* use PEBS auto-reload */
 
 
 struct amd_nb {
diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
index 74f19d9..1762893 100644
--- a/arch/x86/kernel/cpu/perf_event_intel.c
+++ b/arch/x86/kernel/cpu/perf_event_intel.c
@@ -2260,8 +2260,12 @@ static int intel_pmu_hw_config(struct perf_event *event)
 	if (ret)
 		return ret;
 
-	if (event->attr.precise_ip && x86_pmu.pebs_aliases)
-		x86_pmu.pebs_aliases(event);
+	if (event->attr.precise_ip) {
+		if (!event->attr.freq)
+			event->hw.flags |= PERF_X86_EVENT_AUTO_RELOAD;
+		if (x86_pmu.pebs_aliases)
+			x86_pmu.pebs_aliases(event);
+	}
 
 	if (needs_branch_stack(event)) {
 		ret = intel_pmu_setup_lbr_filter(event);
diff --git a/arch/x86/kernel/cpu/perf_event_intel_ds.c b/arch/x86/kernel/cpu/perf_event_intel_ds.c
index 7f73b35..4802d5d 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_ds.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_ds.c
@@ -688,6 +688,7 @@ void intel_pmu_pebs_enable(struct perf_event *event)
 {
 	struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
 	struct hw_perf_event *hwc = &event->hw;
+	struct debug_store *ds = cpuc->ds;
 
 	hwc->config &= ~ARCH_PERFMON_EVENTSEL_INT;
 
@@ -697,6 +698,12 @@ void intel_pmu_pebs_enable(struct perf_event *event)
 		cpuc->pebs_enabled |= 1ULL << (hwc->idx + 32);
 	else if (event->hw.flags & PERF_X86_EVENT_PEBS_ST)
 		cpuc->pebs_enabled |= 1ULL << 63;
+
+	/* Use auto-reload if possible to save a MSR write in the PMI */
+	if (hwc->flags & PERF_X86_EVENT_AUTO_RELOAD) {
+		ds->pebs_event_reset[hwc->idx] =
+			(u64)(-hwc->sample_period) & x86_pmu.cntval_mask;
+	}
 }
 
 void intel_pmu_pebs_disable(struct perf_event *event)

  reply	other threads:[~2015-06-07 17:49 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-bot for Yan, Zheng [this message]
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 ` [PATCH V8 7/8] perf, x86: introduce PERF_RECORD_LOST_SAMPLES Kan Liang
2015-05-07 11:35   ` 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=tip-851559e35fd5ab637783ba395e55edd50f761229@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=akpm@linux-foundation.org \
    --cc=hpa@zytor.com \
    --cc=kan.liang@intel.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 \
    --cc=zheng.z.yan@intel.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