linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v0 0/3] perf, pt: Intel PT updates
@ 2016-04-28 15:35 Alexander Shishkin
  2016-04-28 15:35 ` [PATCH v0 1/3] perf/x86/intel/pt: Convert ACCESS_ONCE()s Alexander Shishkin
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Alexander Shishkin @ 2016-04-28 15:35 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Thomas Gleixner, x86, Borislav Petkov, Ingo Molnar, linux-kernel,
	vince, eranian, Arnaldo Carvalho de Melo, Mathieu Poirier,
	Alexander Shishkin

Hi Peter,

Here are some patches for Intel PT driver, should all be
self-evident. 2/3 has been posted before in a slightly different form,
but it's been quite a while and everybody should have forgotten it by
now.

Alexander Shishkin (3):
  perf/x86/intel/pt: Convert ACCESS_ONCE()s
  perf/x86/intel/pt: Export cpu frequency ratios needed by PT decoders
  perf, x86: Bypass PT vs LBR exclusivity if the core supports it

 arch/x86/events/core.c       |  6 +++++
 arch/x86/events/intel/core.c |  1 +
 arch/x86/events/intel/pt.c   | 60 +++++++++++++++++++++++++++++++++++++++++---
 arch/x86/events/intel/pt.h   |  6 +++++
 arch/x86/events/perf_event.h |  1 +
 5 files changed, 71 insertions(+), 3 deletions(-)

-- 
2.8.0.rc3

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v0 1/3] perf/x86/intel/pt: Convert ACCESS_ONCE()s
  2016-04-28 15:35 [PATCH v0 0/3] perf, pt: Intel PT updates Alexander Shishkin
@ 2016-04-28 15:35 ` Alexander Shishkin
  2016-05-05  9:49   ` [tip:perf/core] " tip-bot for Alexander Shishkin
  2016-04-28 15:35 ` [PATCH v0 2/3] perf/x86/intel/pt: Export cpu frequency ratios needed by PT decoders Alexander Shishkin
  2016-04-28 15:35 ` [PATCH v0 3/3] perf, x86: Bypass PT vs LBR exclusivity if the core supports it Alexander Shishkin
  2 siblings, 1 reply; 9+ messages in thread
From: Alexander Shishkin @ 2016-04-28 15:35 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Thomas Gleixner, x86, Borislav Petkov, Ingo Molnar, linux-kernel,
	vince, eranian, Arnaldo Carvalho de Melo, Mathieu Poirier,
	Alexander Shishkin

This patch converts remaining ACCESS_ONCE() instances into READ_ONCE()
and WRITE_ONCE() as appropriate.

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
---
 arch/x86/events/intel/pt.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/events/intel/pt.c b/arch/x86/events/intel/pt.c
index 05ef87d839..e88915ff98 100644
--- a/arch/x86/events/intel/pt.c
+++ b/arch/x86/events/intel/pt.c
@@ -933,7 +933,7 @@ void intel_pt_interrupt(void)
 	 * after PT has been disabled by pt_event_stop(). Make sure we don't
 	 * do anything (particularly, re-enable) for this event here.
 	 */
-	if (!ACCESS_ONCE(pt->handle_nmi))
+	if (!READ_ONCE(pt->handle_nmi))
 		return;
 
 	/*
@@ -1035,7 +1035,7 @@ static void pt_event_start(struct perf_event *event, int mode)
 			goto fail_end_stop;
 	}
 
-	ACCESS_ONCE(pt->handle_nmi) = 1;
+	WRITE_ONCE(pt->handle_nmi, 1);
 	hwc->state = 0;
 
 	pt_config_buffer(buf->cur->table, buf->cur_idx,
@@ -1058,7 +1058,7 @@ static void pt_event_stop(struct perf_event *event, int mode)
 	 * Protect against the PMI racing with disabling wrmsr,
 	 * see comment in intel_pt_interrupt().
 	 */
-	ACCESS_ONCE(pt->handle_nmi) = 0;
+	WRITE_ONCE(pt->handle_nmi, 0);
 
 	pt_config_stop(event);
 
-- 
2.8.0.rc3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v0 2/3] perf/x86/intel/pt: Export cpu frequency ratios needed by PT decoders
  2016-04-28 15:35 [PATCH v0 0/3] perf, pt: Intel PT updates Alexander Shishkin
  2016-04-28 15:35 ` [PATCH v0 1/3] perf/x86/intel/pt: Convert ACCESS_ONCE()s Alexander Shishkin
@ 2016-04-28 15:35 ` Alexander Shishkin
  2016-04-28 15:55   ` Alexander Shishkin
  2016-05-03 13:53   ` [PATCH v0 2/3] perf/x86/intel/pt: Export cpu " Borislav Petkov
  2016-04-28 15:35 ` [PATCH v0 3/3] perf, x86: Bypass PT vs LBR exclusivity if the core supports it Alexander Shishkin
  2 siblings, 2 replies; 9+ messages in thread
From: Alexander Shishkin @ 2016-04-28 15:35 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Thomas Gleixner, x86, Borislav Petkov, Ingo Molnar, linux-kernel,
	vince, eranian, Arnaldo Carvalho de Melo, Mathieu Poirier,
	Alexander Shishkin

In order for Intel PT decoders to infer correct crystal clock and bus
frequencies that are required to correctly decode timing information
from a PT stream (MTC and CBR packets), export them as sysfs attributes:

  * max_nonturbo_ratio: ratio between the invariant TSC and base clock;
  * tsc_art_ratio: TSC to core crystal clock ratio.

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
---
 arch/x86/events/intel/pt.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++
 arch/x86/events/intel/pt.h |  6 ++++++
 2 files changed, 60 insertions(+)

diff --git a/arch/x86/events/intel/pt.c b/arch/x86/events/intel/pt.c
index e88915ff98..bf0b0fe33d 100644
--- a/arch/x86/events/intel/pt.c
+++ b/arch/x86/events/intel/pt.c
@@ -125,9 +125,46 @@ static struct attribute_group pt_format_group = {
 	.attrs	= pt_formats_attr,
 };
 
+static ssize_t
+pt_timing_attr_show(struct device *dev, struct device_attribute *attr,
+		    char *page)
+{
+	struct perf_pmu_events_attr *pmu_attr =
+		container_of(attr, struct perf_pmu_events_attr, attr);
+
+	switch (pmu_attr->id) {
+	case 0:
+		return sprintf(page, "%lu\n", pt_pmu.max_nonturbo_ratio);
+	case 1:
+		return sprintf(page, "%u:%u\n",
+			       pt_pmu.tsc_art_num,
+			       pt_pmu.tsc_art_den);
+	default:
+		break;
+	}
+
+	return -EINVAL;
+}
+
+PMU_EVENT_ATTR(max_nonturbo_ratio, timing_attr_max_nonturbo_ratio, 0,
+	       pt_timing_attr_show);
+PMU_EVENT_ATTR(tsc_art_ratio, timing_attr_tsc_art_ratio, 1,
+	       pt_timing_attr_show);
+
+static struct attribute *pt_timing_attr[] = {
+	&timing_attr_max_nonturbo_ratio.attr.attr,
+	&timing_attr_tsc_art_ratio.attr.attr,
+	NULL,
+};
+
+static struct attribute_group pt_timing_group = {
+	.attrs	= pt_timing_attr,
+};
+
 static const struct attribute_group *pt_attr_groups[] = {
 	&pt_cap_group,
 	&pt_format_group,
+	&pt_timing_group,
 	NULL,
 };
 
@@ -140,6 +177,23 @@ static int __init pt_pmu_hw_init(void)
 	int ret;
 	long i;
 
+	rdmsrl(MSR_PLATFORM_INFO, reg);
+	pt_pmu.max_nonturbo_ratio = (reg & 0xff00) >> 8;
+
+	/*
+	 * if available, read in TSC to core crystal clock ratio,
+	 * otherwise, zero for numerator stands for "not enumerated"
+	 * as per SDM
+	 */
+	if (boot_cpu_data.cpuid_level >= CPUID_TSC_LEAF) {
+		u32 eax, ebx, ecx, edx;
+
+		cpuid(CPUID_TSC_LEAF, &eax, &ebx, &ecx, &edx);
+
+		pt_pmu.tsc_art_num = ebx;
+		pt_pmu.tsc_art_den = eax;
+	}
+
 	if (boot_cpu_has(X86_FEATURE_VMX)) {
 		/*
 		 * Intel SDM, 36.5 "Tracing post-VMXON" says that
diff --git a/arch/x86/events/intel/pt.h b/arch/x86/events/intel/pt.h
index 3abb5f5ccc..e5385b1fa0 100644
--- a/arch/x86/events/intel/pt.h
+++ b/arch/x86/events/intel/pt.h
@@ -48,6 +48,9 @@ struct topa_entry {
 #define PT_CPUID_LEAVES		2
 #define PT_CPUID_REGS_NUM	4 /* number of regsters (eax, ebx, ecx, edx) */
 
+/* TSC to Core Crystal Clock Ratio */
+#define CPUID_TSC_LEAF		0x15
+
 enum pt_capabilities {
 	PT_CAP_max_subleaf = 0,
 	PT_CAP_cr3_filtering,
@@ -66,6 +69,9 @@ struct pt_pmu {
 	struct pmu		pmu;
 	u32			caps[PT_CPUID_REGS_NUM * PT_CPUID_LEAVES];
 	bool			vmx;
+	unsigned long		max_nonturbo_ratio;
+	unsigned int		tsc_art_num;
+	unsigned int		tsc_art_den;
 };
 
 /**
-- 
2.8.0.rc3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v0 3/3] perf, x86: Bypass PT vs LBR exclusivity if the core supports it
  2016-04-28 15:35 [PATCH v0 0/3] perf, pt: Intel PT updates Alexander Shishkin
  2016-04-28 15:35 ` [PATCH v0 1/3] perf/x86/intel/pt: Convert ACCESS_ONCE()s Alexander Shishkin
  2016-04-28 15:35 ` [PATCH v0 2/3] perf/x86/intel/pt: Export cpu frequency ratios needed by PT decoders Alexander Shishkin
@ 2016-04-28 15:35 ` Alexander Shishkin
  2016-05-05  9:48   ` [tip:perf/core] perf/x86/intel/pt: Bypass PT vs. " tip-bot for Alexander Shishkin
  2 siblings, 1 reply; 9+ messages in thread
From: Alexander Shishkin @ 2016-04-28 15:35 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Thomas Gleixner, x86, Borislav Petkov, Ingo Molnar, linux-kernel,
	vince, eranian, Arnaldo Carvalho de Melo, Mathieu Poirier,
	Alexander Shishkin

Not all cores prevent using Intel PT and LBRs simultaneously, although
most of them still do as of today. This patch adds an opt-in flag for
such cores to disable mutual exclusivity between PT and LBR; also flip
it on for Goldmont.

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
---
 arch/x86/events/core.c       | 6 ++++++
 arch/x86/events/intel/core.c | 1 +
 arch/x86/events/perf_event.h | 1 +
 3 files changed, 8 insertions(+)

diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index 41d93d0e97..5e5e76a52f 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -360,6 +360,9 @@ int x86_add_exclusive(unsigned int what)
 {
 	int i;
 
+	if (x86_pmu.lbr_pt_coexist)
+		return 0;
+
 	if (!atomic_inc_not_zero(&x86_pmu.lbr_exclusive[what])) {
 		mutex_lock(&pmc_reserve_mutex);
 		for (i = 0; i < ARRAY_SIZE(x86_pmu.lbr_exclusive); i++) {
@@ -380,6 +383,9 @@ fail_unlock:
 
 void x86_del_exclusive(unsigned int what)
 {
+	if (x86_pmu.lbr_pt_coexist)
+		return;
+
 	atomic_dec(&x86_pmu.lbr_exclusive[what]);
 	atomic_dec(&active_events);
 }
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 79b59437f5..e36422c687 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -3609,6 +3609,7 @@ __init int intel_pmu_init(void)
 		 */
 		x86_pmu.pebs_aliases = NULL;
 		x86_pmu.pebs_prec_dist = true;
+		x86_pmu.lbr_pt_coexist = true;
 		x86_pmu.flags |= PMU_FL_HAS_RSP_1;
 		pr_cont("Goldmont events, ");
 		break;
diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
index 7d62a02f49..8bd764df81 100644
--- a/arch/x86/events/perf_event.h
+++ b/arch/x86/events/perf_event.h
@@ -601,6 +601,7 @@ struct x86_pmu {
 	u64		lbr_sel_mask;		   /* LBR_SELECT valid bits */
 	const int	*lbr_sel_map;		   /* lbr_select mappings */
 	bool		lbr_double_abort;	   /* duplicated lbr aborts */
+	bool		lbr_pt_coexist;		   /* LBR may coexist with PT */
 
 	/*
 	 * Intel PT/LBR/BTS are exclusive
-- 
2.8.0.rc3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v0 2/3] perf/x86/intel/pt: Export cpu frequency ratios needed by PT decoders
  2016-04-28 15:35 ` [PATCH v0 2/3] perf/x86/intel/pt: Export cpu frequency ratios needed by PT decoders Alexander Shishkin
@ 2016-04-28 15:55   ` Alexander Shishkin
  2016-05-05  9:48     ` [tip:perf/core] perf/x86/intel/pt: Export CPU " tip-bot for Alexander Shishkin
  2016-05-03 13:53   ` [PATCH v0 2/3] perf/x86/intel/pt: Export cpu " Borislav Petkov
  1 sibling, 1 reply; 9+ messages in thread
From: Alexander Shishkin @ 2016-04-28 15:55 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Thomas Gleixner, x86, Borislav Petkov, Ingo Molnar, linux-kernel,
	vince, eranian, Arnaldo Carvalho de Melo, Mathieu Poirier

Alexander Shishkin <alexander.shishkin@linux.intel.com> writes:

> In order for Intel PT decoders to infer correct crystal clock and bus
> frequencies that are required to correctly decode timing information
> from a PT stream (MTC and CBR packets), export them as sysfs attributes:
>
>   * max_nonturbo_ratio: ratio between the invariant TSC and base clock;
>   * tsc_art_ratio: TSC to core crystal clock ratio.
>
> Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>

With a slightly better changelog:

>From d0fbc4e45fb633e464cbbd61d6aacd5a476fd50d Mon Sep 17 00:00:00 2001
From: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Date: Wed, 19 Aug 2015 17:02:10 +0300
Subject: [PATCH] perf/x86/intel/pt: Export cpu frequency ratios needed by PT
 decoders

Intel PT decoders need access to various bits of timing related
information to be able to correctly decode timing packets from a PT
stream (MTC and CBR packets). This patch exports all the necessary
bits as sysfs attributes for the sake of consistency:

  * max_nonturbo_ratio: ratio between the invariant TSC and base clock;
  * tsc_art_ratio: TSC to core crystal clock ratio (also available as
    CPUID.15H).

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
---
 arch/x86/events/intel/pt.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++
 arch/x86/events/intel/pt.h |  6 ++++++
 2 files changed, 60 insertions(+)

diff --git a/arch/x86/events/intel/pt.c b/arch/x86/events/intel/pt.c
index e88915ff98..bf0b0fe33d 100644
--- a/arch/x86/events/intel/pt.c
+++ b/arch/x86/events/intel/pt.c
@@ -125,9 +125,46 @@ static struct attribute_group pt_format_group = {
 	.attrs	= pt_formats_attr,
 };
 
+static ssize_t
+pt_timing_attr_show(struct device *dev, struct device_attribute *attr,
+		    char *page)
+{
+	struct perf_pmu_events_attr *pmu_attr =
+		container_of(attr, struct perf_pmu_events_attr, attr);
+
+	switch (pmu_attr->id) {
+	case 0:
+		return sprintf(page, "%lu\n", pt_pmu.max_nonturbo_ratio);
+	case 1:
+		return sprintf(page, "%u:%u\n",
+			       pt_pmu.tsc_art_num,
+			       pt_pmu.tsc_art_den);
+	default:
+		break;
+	}
+
+	return -EINVAL;
+}
+
+PMU_EVENT_ATTR(max_nonturbo_ratio, timing_attr_max_nonturbo_ratio, 0,
+	       pt_timing_attr_show);
+PMU_EVENT_ATTR(tsc_art_ratio, timing_attr_tsc_art_ratio, 1,
+	       pt_timing_attr_show);
+
+static struct attribute *pt_timing_attr[] = {
+	&timing_attr_max_nonturbo_ratio.attr.attr,
+	&timing_attr_tsc_art_ratio.attr.attr,
+	NULL,
+};
+
+static struct attribute_group pt_timing_group = {
+	.attrs	= pt_timing_attr,
+};
+
 static const struct attribute_group *pt_attr_groups[] = {
 	&pt_cap_group,
 	&pt_format_group,
+	&pt_timing_group,
 	NULL,
 };
 
@@ -140,6 +177,23 @@ static int __init pt_pmu_hw_init(void)
 	int ret;
 	long i;
 
+	rdmsrl(MSR_PLATFORM_INFO, reg);
+	pt_pmu.max_nonturbo_ratio = (reg & 0xff00) >> 8;
+
+	/*
+	 * if available, read in TSC to core crystal clock ratio,
+	 * otherwise, zero for numerator stands for "not enumerated"
+	 * as per SDM
+	 */
+	if (boot_cpu_data.cpuid_level >= CPUID_TSC_LEAF) {
+		u32 eax, ebx, ecx, edx;
+
+		cpuid(CPUID_TSC_LEAF, &eax, &ebx, &ecx, &edx);
+
+		pt_pmu.tsc_art_num = ebx;
+		pt_pmu.tsc_art_den = eax;
+	}
+
 	if (boot_cpu_has(X86_FEATURE_VMX)) {
 		/*
 		 * Intel SDM, 36.5 "Tracing post-VMXON" says that
diff --git a/arch/x86/events/intel/pt.h b/arch/x86/events/intel/pt.h
index 3abb5f5ccc..e5385b1fa0 100644
--- a/arch/x86/events/intel/pt.h
+++ b/arch/x86/events/intel/pt.h
@@ -48,6 +48,9 @@ struct topa_entry {
 #define PT_CPUID_LEAVES		2
 #define PT_CPUID_REGS_NUM	4 /* number of regsters (eax, ebx, ecx, edx) */
 
+/* TSC to Core Crystal Clock Ratio */
+#define CPUID_TSC_LEAF		0x15
+
 enum pt_capabilities {
 	PT_CAP_max_subleaf = 0,
 	PT_CAP_cr3_filtering,
@@ -66,6 +69,9 @@ struct pt_pmu {
 	struct pmu		pmu;
 	u32			caps[PT_CPUID_REGS_NUM * PT_CPUID_LEAVES];
 	bool			vmx;
+	unsigned long		max_nonturbo_ratio;
+	unsigned int		tsc_art_num;
+	unsigned int		tsc_art_den;
 };
 
 /**
-- 
2.8.0.rc3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v0 2/3] perf/x86/intel/pt: Export cpu frequency ratios needed by PT decoders
  2016-04-28 15:35 ` [PATCH v0 2/3] perf/x86/intel/pt: Export cpu frequency ratios needed by PT decoders Alexander Shishkin
  2016-04-28 15:55   ` Alexander Shishkin
@ 2016-05-03 13:53   ` Borislav Petkov
  1 sibling, 0 replies; 9+ messages in thread
From: Borislav Petkov @ 2016-05-03 13:53 UTC (permalink / raw)
  To: Alexander Shishkin
  Cc: Peter Zijlstra, Thomas Gleixner, x86, Ingo Molnar, linux-kernel,
	vince, eranian, Arnaldo Carvalho de Melo, Mathieu Poirier

On Thu, Apr 28, 2016 at 06:35:45PM +0300, Alexander Shishkin wrote:
> In order for Intel PT decoders to infer correct crystal clock and bus
> frequencies that are required to correctly decode timing information
> from a PT stream (MTC and CBR packets), export them as sysfs attributes:
> 
>   * max_nonturbo_ratio: ratio between the invariant TSC and base clock;
>   * tsc_art_ratio: TSC to core crystal clock ratio.

I guess new sysfs nodes need to be documented:

Documentation/ABI/...

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [tip:perf/core] perf/x86/intel/pt: Bypass PT vs. LBR exclusivity if the core supports it
  2016-04-28 15:35 ` [PATCH v0 3/3] perf, x86: Bypass PT vs LBR exclusivity if the core supports it Alexander Shishkin
@ 2016-05-05  9:48   ` tip-bot for Alexander Shishkin
  0 siblings, 0 replies; 9+ messages in thread
From: tip-bot for Alexander Shishkin @ 2016-05-05  9:48 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, peterz, eranian, mathieu.poirier, bp,
	vincent.weaver, acme, alexander.shishkin, torvalds, hpa, tglx,
	mingo, acme, jolsa

Commit-ID:  ccbebba4c6bfda8e3ef9e431ce2c3d91c5fc5a63
Gitweb:     http://git.kernel.org/tip/ccbebba4c6bfda8e3ef9e431ce2c3d91c5fc5a63
Author:     Alexander Shishkin <alexander.shishkin@linux.intel.com>
AuthorDate: Thu, 28 Apr 2016 18:35:46 +0300
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 5 May 2016 10:16:28 +0200

perf/x86/intel/pt: Bypass PT vs. LBR exclusivity if the core supports it

Not all cores prevent using Intel PT and LBRs simultaneously, although
most of them still do as of today. This patch adds an opt-in flag for
such cores to disable mutual exclusivity between PT and LBR; also flip
it on for Goldmont.

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: vince@deater.net
Link: http://lkml.kernel.org/r/1461857746-31346-4-git-send-email-alexander.shishkin@linux.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/events/core.c       | 6 ++++++
 arch/x86/events/intel/core.c | 1 +
 arch/x86/events/perf_event.h | 1 +
 3 files changed, 8 insertions(+)

diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index 41d93d0..5e5e76a 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -360,6 +360,9 @@ int x86_add_exclusive(unsigned int what)
 {
 	int i;
 
+	if (x86_pmu.lbr_pt_coexist)
+		return 0;
+
 	if (!atomic_inc_not_zero(&x86_pmu.lbr_exclusive[what])) {
 		mutex_lock(&pmc_reserve_mutex);
 		for (i = 0; i < ARRAY_SIZE(x86_pmu.lbr_exclusive); i++) {
@@ -380,6 +383,9 @@ fail_unlock:
 
 void x86_del_exclusive(unsigned int what)
 {
+	if (x86_pmu.lbr_pt_coexist)
+		return;
+
 	atomic_dec(&x86_pmu.lbr_exclusive[what]);
 	atomic_dec(&active_events);
 }
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 90ba3ae..cd31940 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -3609,6 +3609,7 @@ __init int intel_pmu_init(void)
 		 */
 		x86_pmu.pebs_aliases = NULL;
 		x86_pmu.pebs_prec_dist = true;
+		x86_pmu.lbr_pt_coexist = true;
 		x86_pmu.flags |= PMU_FL_HAS_RSP_1;
 		pr_cont("Goldmont events, ");
 		break;
diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
index 7d62a02..8bd764d 100644
--- a/arch/x86/events/perf_event.h
+++ b/arch/x86/events/perf_event.h
@@ -601,6 +601,7 @@ struct x86_pmu {
 	u64		lbr_sel_mask;		   /* LBR_SELECT valid bits */
 	const int	*lbr_sel_map;		   /* lbr_select mappings */
 	bool		lbr_double_abort;	   /* duplicated lbr aborts */
+	bool		lbr_pt_coexist;		   /* LBR may coexist with PT */
 
 	/*
 	 * Intel PT/LBR/BTS are exclusive

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [tip:perf/core] perf/x86/intel/pt: Export CPU frequency ratios needed by PT decoders
  2016-04-28 15:55   ` Alexander Shishkin
@ 2016-05-05  9:48     ` tip-bot for Alexander Shishkin
  0 siblings, 0 replies; 9+ messages in thread
From: tip-bot for Alexander Shishkin @ 2016-05-05  9:48 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: bp, alexander.shishkin, jolsa, hpa, tglx, mathieu.poirier,
	eranian, torvalds, linux-kernel, acme, vincent.weaver, peterz,
	mingo, acme

Commit-ID:  65c7e6f1c4810e9bce935520f44f6d2613cd1b40
Gitweb:     http://git.kernel.org/tip/65c7e6f1c4810e9bce935520f44f6d2613cd1b40
Author:     Alexander Shishkin <alexander.shishkin@linux.intel.com>
AuthorDate: Wed, 19 Aug 2015 17:02:10 +0300
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 5 May 2016 10:16:28 +0200

perf/x86/intel/pt: Export CPU frequency ratios needed by PT decoders

Intel PT decoders need access to various bits of timing related
information to be able to correctly decode timing packets from a PT
stream (MTC and CBR packets). This patch exports all the necessary
bits as sysfs attributes for the sake of consistency:

  * max_nonturbo_ratio: ratio between the invariant TSC and base clock;

  * tsc_art_ratio: TSC to core crystal clock ratio (also available as CPUID.15H).

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: vince@deater.net
Link: http://lkml.kernel.org/r/87zisdvibe.fsf@ashishki-desk.ger.corp.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/events/intel/pt.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++
 arch/x86/events/intel/pt.h |  6 ++++++
 2 files changed, 60 insertions(+)

diff --git a/arch/x86/events/intel/pt.c b/arch/x86/events/intel/pt.c
index 2d1ce2c..c3a359c 100644
--- a/arch/x86/events/intel/pt.c
+++ b/arch/x86/events/intel/pt.c
@@ -127,9 +127,46 @@ static struct attribute_group pt_format_group = {
 	.attrs	= pt_formats_attr,
 };
 
+static ssize_t
+pt_timing_attr_show(struct device *dev, struct device_attribute *attr,
+		    char *page)
+{
+	struct perf_pmu_events_attr *pmu_attr =
+		container_of(attr, struct perf_pmu_events_attr, attr);
+
+	switch (pmu_attr->id) {
+	case 0:
+		return sprintf(page, "%lu\n", pt_pmu.max_nonturbo_ratio);
+	case 1:
+		return sprintf(page, "%u:%u\n",
+			       pt_pmu.tsc_art_num,
+			       pt_pmu.tsc_art_den);
+	default:
+		break;
+	}
+
+	return -EINVAL;
+}
+
+PMU_EVENT_ATTR(max_nonturbo_ratio, timing_attr_max_nonturbo_ratio, 0,
+	       pt_timing_attr_show);
+PMU_EVENT_ATTR(tsc_art_ratio, timing_attr_tsc_art_ratio, 1,
+	       pt_timing_attr_show);
+
+static struct attribute *pt_timing_attr[] = {
+	&timing_attr_max_nonturbo_ratio.attr.attr,
+	&timing_attr_tsc_art_ratio.attr.attr,
+	NULL,
+};
+
+static struct attribute_group pt_timing_group = {
+	.attrs	= pt_timing_attr,
+};
+
 static const struct attribute_group *pt_attr_groups[] = {
 	&pt_cap_group,
 	&pt_format_group,
+	&pt_timing_group,
 	NULL,
 };
 
@@ -142,6 +179,23 @@ static int __init pt_pmu_hw_init(void)
 	int ret;
 	long i;
 
+	rdmsrl(MSR_PLATFORM_INFO, reg);
+	pt_pmu.max_nonturbo_ratio = (reg & 0xff00) >> 8;
+
+	/*
+	 * if available, read in TSC to core crystal clock ratio,
+	 * otherwise, zero for numerator stands for "not enumerated"
+	 * as per SDM
+	 */
+	if (boot_cpu_data.cpuid_level >= CPUID_TSC_LEAF) {
+		u32 eax, ebx, ecx, edx;
+
+		cpuid(CPUID_TSC_LEAF, &eax, &ebx, &ecx, &edx);
+
+		pt_pmu.tsc_art_num = ebx;
+		pt_pmu.tsc_art_den = eax;
+	}
+
 	if (boot_cpu_has(X86_FEATURE_VMX)) {
 		/*
 		 * Intel SDM, 36.5 "Tracing post-VMXON" says that
diff --git a/arch/x86/events/intel/pt.h b/arch/x86/events/intel/pt.h
index ca64599..efffa4a 100644
--- a/arch/x86/events/intel/pt.h
+++ b/arch/x86/events/intel/pt.h
@@ -82,6 +82,9 @@ struct topa_entry {
 #define PT_CPUID_LEAVES		2
 #define PT_CPUID_REGS_NUM	4 /* number of regsters (eax, ebx, ecx, edx) */
 
+/* TSC to Core Crystal Clock Ratio */
+#define CPUID_TSC_LEAF		0x15
+
 enum pt_capabilities {
 	PT_CAP_max_subleaf = 0,
 	PT_CAP_cr3_filtering,
@@ -102,6 +105,9 @@ struct pt_pmu {
 	struct pmu		pmu;
 	u32			caps[PT_CPUID_REGS_NUM * PT_CPUID_LEAVES];
 	bool			vmx;
+	unsigned long		max_nonturbo_ratio;
+	unsigned int		tsc_art_num;
+	unsigned int		tsc_art_den;
 };
 
 /**

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [tip:perf/core] perf/x86/intel/pt: Convert ACCESS_ONCE()s
  2016-04-28 15:35 ` [PATCH v0 1/3] perf/x86/intel/pt: Convert ACCESS_ONCE()s Alexander Shishkin
@ 2016-05-05  9:49   ` tip-bot for Alexander Shishkin
  0 siblings, 0 replies; 9+ messages in thread
From: tip-bot for Alexander Shishkin @ 2016-05-05  9:49 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, mathieu.poirier, peterz, jolsa, eranian, acme,
	linux-kernel, vincent.weaver, hpa, tglx, bp, alexander.shishkin,
	torvalds, mingo

Commit-ID:  1b6de5917172967acd8db4d222df4225d23a8a60
Gitweb:     http://git.kernel.org/tip/1b6de5917172967acd8db4d222df4225d23a8a60
Author:     Alexander Shishkin <alexander.shishkin@linux.intel.com>
AuthorDate: Thu, 28 Apr 2016 18:35:44 +0300
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 5 May 2016 10:16:29 +0200

perf/x86/intel/pt: Convert ACCESS_ONCE()s

This patch converts remaining ACCESS_ONCE() instances into READ_ONCE()
and WRITE_ONCE() as appropriate.

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: vince@deater.net
Link: http://lkml.kernel.org/r/1461857746-31346-2-git-send-email-alexander.shishkin@linux.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/events/intel/pt.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/events/intel/pt.c b/arch/x86/events/intel/pt.c
index c3a359c..54fa238 100644
--- a/arch/x86/events/intel/pt.c
+++ b/arch/x86/events/intel/pt.c
@@ -1135,7 +1135,7 @@ void intel_pt_interrupt(void)
 	 * after PT has been disabled by pt_event_stop(). Make sure we don't
 	 * do anything (particularly, re-enable) for this event here.
 	 */
-	if (!ACCESS_ONCE(pt->handle_nmi))
+	if (!READ_ONCE(pt->handle_nmi))
 		return;
 
 	/*
@@ -1237,7 +1237,7 @@ static void pt_event_start(struct perf_event *event, int mode)
 			goto fail_end_stop;
 	}
 
-	ACCESS_ONCE(pt->handle_nmi) = 1;
+	WRITE_ONCE(pt->handle_nmi, 1);
 	hwc->state = 0;
 
 	pt_config_buffer(buf->cur->table, buf->cur_idx,
@@ -1260,7 +1260,7 @@ static void pt_event_stop(struct perf_event *event, int mode)
 	 * Protect against the PMI racing with disabling wrmsr,
 	 * see comment in intel_pt_interrupt().
 	 */
-	ACCESS_ONCE(pt->handle_nmi) = 0;
+	WRITE_ONCE(pt->handle_nmi, 0);
 
 	pt_config_stop(event);
 

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-05-05  9:50 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-28 15:35 [PATCH v0 0/3] perf, pt: Intel PT updates Alexander Shishkin
2016-04-28 15:35 ` [PATCH v0 1/3] perf/x86/intel/pt: Convert ACCESS_ONCE()s Alexander Shishkin
2016-05-05  9:49   ` [tip:perf/core] " tip-bot for Alexander Shishkin
2016-04-28 15:35 ` [PATCH v0 2/3] perf/x86/intel/pt: Export cpu frequency ratios needed by PT decoders Alexander Shishkin
2016-04-28 15:55   ` Alexander Shishkin
2016-05-05  9:48     ` [tip:perf/core] perf/x86/intel/pt: Export CPU " tip-bot for Alexander Shishkin
2016-05-03 13:53   ` [PATCH v0 2/3] perf/x86/intel/pt: Export cpu " Borislav Petkov
2016-04-28 15:35 ` [PATCH v0 3/3] perf, x86: Bypass PT vs LBR exclusivity if the core supports it Alexander Shishkin
2016-05-05  9:48   ` [tip:perf/core] perf/x86/intel/pt: Bypass PT vs. " tip-bot for Alexander Shishkin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).