All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andi Kleen <andi@firstfloor.org>
To: mingo@elte.hu
Cc: acme@redhat.com, linux-kernel@vger.kernel.org,
	Andi Kleen <ak@linux.intel.com>
Subject: [PATCH 03/15] perf, x86: Support full width counting v3
Date: Sat, 20 Apr 2013 12:19:11 -0700	[thread overview]
Message-ID: <1366485563-16209-4-git-send-email-andi@firstfloor.org> (raw)
In-Reply-To: <1366485563-16209-1-git-send-email-andi@firstfloor.org>

From: Andi Kleen <ak@linux.intel.com>

Recent Intel CPUs like Haswell and IvyBridge have a new alternative MSR
range for perfctrs that allows writing the full counter width. Enable this
range if the hardware reports it using a new capability bit.

This lowers the overhead of perf stat slightly because it has to do less
interrupts to accumulate the counter value. On Haswell it also avoids some
problems with TSX aborting when the end of the counter range is reached.

v2: Print the feature at boot
v3: Rename field. Add comment.
Reviewed-by: Stephane Eranian <eranian@google.com>
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 arch/x86/include/uapi/asm/msr-index.h  |    3 +++
 arch/x86/kernel/cpu/perf_event.h       |    5 +++++
 arch/x86/kernel/cpu/perf_event_intel.c |    7 +++++++
 3 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/arch/x86/include/uapi/asm/msr-index.h b/arch/x86/include/uapi/asm/msr-index.h
index bf7bb68..dbe5b52 100644
--- a/arch/x86/include/uapi/asm/msr-index.h
+++ b/arch/x86/include/uapi/asm/msr-index.h
@@ -167,6 +167,9 @@
 #define MSR_KNC_EVNTSEL0               0x00000028
 #define MSR_KNC_EVNTSEL1               0x00000029
 
+/* Alternative perfctr range with full access. */
+#define MSR_IA32_PMC0			0x000004c1
+
 /* AMD64 MSRs. Not complete. See the architecture manual for a more
    complete list. */
 
diff --git a/arch/x86/kernel/cpu/perf_event.h b/arch/x86/kernel/cpu/perf_event.h
index 2341d9f..0da5713 100644
--- a/arch/x86/kernel/cpu/perf_event.h
+++ b/arch/x86/kernel/cpu/perf_event.h
@@ -304,6 +304,11 @@ union perf_capabilities {
 		u64	pebs_arch_reg:1;
 		u64	pebs_format:4;
 		u64	smm_freeze:1;
+		/*
+		 * PMU supports separate counter range for writing
+		 * values > 32bit.
+		 */
+		u64	full_width_write:1;
 	};
 	u64	capabilities;
 };
diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
index 5a0d73c..3f2afb2 100644
--- a/arch/x86/kernel/cpu/perf_event_intel.c
+++ b/arch/x86/kernel/cpu/perf_event_intel.c
@@ -2299,5 +2299,12 @@ __init int intel_pmu_init(void)
 		}
 	}
 
+	/* Support full width counters using alternative MSR range */
+	if (x86_pmu.intel_cap.full_width_write) {
+		x86_pmu.max_period = x86_pmu.cntval_mask;
+		x86_pmu.perfctr = MSR_IA32_PMC0;
+		pr_cont("full-width counters, ");
+	}
+
 	return 0;
 }
-- 
1.7.7.6


  parent reply	other threads:[~2013-04-20 19:19 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-20 19:19 perf PMU support for Haswell v8 Andi Kleen
2013-04-20 19:19 ` [PATCH 01/15] perf, x86: Suppress duplicated abort LBR records Andi Kleen
2013-04-20 19:19 ` [PATCH 02/15] perf, x86: Disable software LBR filter for Sandy Bridge/Haswell Andi Kleen
2013-04-20 19:19 ` Andi Kleen [this message]
2013-04-20 19:19 ` [PATCH 04/15] perf, tools: Support sorting by in_tx, abort branch flags v3 Andi Kleen
2013-04-20 19:19 ` [PATCH 05/15] perf, tools: Add abort_tx,no_tx,in_tx branch filter options to perf record -j v3 Andi Kleen
2013-04-20 19:19 ` [PATCH 06/15] perf, x86: Support the TSX intx/intx_cp qualifiers v4 Andi Kleen
2013-04-20 19:19 ` [PATCH 07/15] perf, x86: Avoid checkpointed counters causing excessive TSX aborts v4 Andi Kleen
2013-04-20 19:19 ` [PATCH 08/15] perf, kvm: Support the intx/intx_cp modifiers in KVM arch perfmon emulation v5 Andi Kleen
2013-04-23  8:48   ` Gleb Natapov
2013-04-20 19:19 ` [PATCH 09/15] perf, x86: Support PERF_SAMPLE_ADDR for all PEBS events v3 Andi Kleen
2013-04-20 19:19 ` [PATCH 10/15] perf, core: Add generic transaction flags v3 Andi Kleen
2013-04-20 19:19 ` [PATCH 11/15] perf, x86: Add Haswell specific transaction flag reporting Andi Kleen
2013-04-20 19:19 ` [PATCH 12/15] perf, tools: Add support for record transaction flags v3 Andi Kleen
2013-04-20 19:19 ` [PATCH 13/15] tools, perf: Add a precise event qualifier v2 Andi Kleen
2013-04-20 19:19 ` [PATCH 14/15] perf, x86: Add Haswell TSX event aliases v4 Andi Kleen
2013-04-20 19:19 ` [PATCH 15/15] perf, tools: Add perf stat --transaction v3 Andi Kleen
2013-06-19  8:51   ` Michael Ellerman
2013-06-19 14:46     ` Andi Kleen
2013-06-27  3:18       ` Michael Ellerman
2013-06-27  3:49         ` Andi Kleen

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=1366485563-16209-4-git-send-email-andi@firstfloor.org \
    --to=andi@firstfloor.org \
    --cc=acme@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.