Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1214635 > unrolled thread

[PATCH] perf/x86/intel/pt: Export cpu frequency ratios needed by PT decoders

Started byAlexander Shishkin <alexander.shishkin@linux.intel.com>
First post2015-08-27 17:10 +0200
Last post2015-08-31 22:10 +0200
Articles 4 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] perf/x86/intel/pt: Export cpu frequency ratios needed by PT decoders Alexander Shishkin <alexander.shishkin@linux.intel.com> - 2015-08-27 17:10 +0200
    Re: [PATCH] perf/x86/intel/pt: Export cpu frequency ratios needed by PT decoders Andi Kleen <andi@firstfloor.org> - 2015-08-28 21:40 +0200
      Re: [PATCH] perf/x86/intel/pt: Export cpu frequency ratios needed by PT decoders Alexander Shishkin <alexander.shishkin@linux.intel.com> - 2015-08-31 15:00 +0200
        Re: [PATCH] perf/x86/intel/pt: Export cpu frequency ratios needed by  PT decoders Andi Kleen <andi@firstfloor.org> - 2015-08-31 22:10 +0200

#1214635 — [PATCH] perf/x86/intel/pt: Export cpu frequency ratios needed by PT decoders

FromAlexander Shishkin <alexander.shishkin@linux.intel.com>
Date2015-08-27 17:10 +0200
Subject[PATCH] perf/x86/intel/pt: Export cpu frequency ratios needed by PT decoders
Message-ID<q26Yq-828-17@gated-at.bofh.it>
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/kernel/cpu/perf_event_intel_pt.c | 40 +++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/arch/x86/kernel/cpu/perf_event_intel_pt.c b/arch/x86/kernel/cpu/perf_event_intel_pt.c
index c534261068..e76aa5a30c 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_pt.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_pt.c
@@ -126,9 +126,49 @@ 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);
+	u32 eax, ebx, ecx, edx;
+	unsigned long val;
+
+	switch (pmu_attr->id) {
+	case 0:
+		rdmsrl(MSR_PLATFORM_INFO, val);
+		val = (val & 0xff00) >> 8;
+		return sprintf(page, "%lu\n", val);
+	case 1:
+		cpuid(0x15, &eax, &ebx, &ecx, &edx);
+		return sprintf(page, "%u:%u\n", ebx, eax);
+	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,
 };
 
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1215532

FromAndi Kleen <andi@firstfloor.org>
Date2015-08-28 21:40 +0200
Message-ID<q2xFg-4lL-13@gated-at.bofh.it>
In reply to#1214635
Alexander Shishkin <alexander.shishkin@linux.intel.com> writes:
> +		return sprintf(page, "%lu\n", val);
> +	case 1:
> +		cpuid(0x15, &eax, &ebx, &ecx, &edx);

Surely this needs to be protected by a cpuid level check?
Broadwell for once doesn't have CPUID 0x15.

-Andi

-- 
ak@linux.intel.com -- Speaking for myself only
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1216168

FromAlexander Shishkin <alexander.shishkin@linux.intel.com>
Date2015-08-31 15:00 +0200
Message-ID<q3wQO-89h-13@gated-at.bofh.it>
In reply to#1215532
Andi Kleen <andi@firstfloor.org> writes:

> Alexander Shishkin <alexander.shishkin@linux.intel.com> writes:
>> +		return sprintf(page, "%lu\n", val);
>> +	case 1:
>> +		cpuid(0x15, &eax, &ebx, &ecx, &edx);
>
> Surely this needs to be protected by a cpuid level check?
> Broadwell for once doesn't have CPUID 0x15.

I couldn't find where this is explicitly said in the SDM. However, the
leaf description says that CPUID.0x15.EBX[31:0]==0 means that the ratio
is not enumerated. I don't see how to better communicate this to
userspace though than to simply have 0 there.

Regards,
--
Alex
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1216413 — Re: [PATCH] perf/x86/intel/pt: Export cpu frequency ratios needed by PT decoders

FromAndi Kleen <andi@firstfloor.org>
Date2015-08-31 22:10 +0200
SubjectRe: [PATCH] perf/x86/intel/pt: Export cpu frequency ratios needed by PT decoders
Message-ID<q3DyX-1dj-31@gated-at.bofh.it>
In reply to#1216168
On Mon, Aug 31, 2015 at 03:59:08PM +0300, Alexander Shishkin wrote:
> Andi Kleen <andi@firstfloor.org> writes:
> 
> > Alexander Shishkin <alexander.shishkin@linux.intel.com> writes:
> >> +		return sprintf(page, "%lu\n", val);
> >> +	case 1:
> >> +		cpuid(0x15, &eax, &ebx, &ecx, &edx);
> >
> > Surely this needs to be protected by a cpuid level check?
> > Broadwell for once doesn't have CPUID 0x15.
> 
> I couldn't find where this is explicitly said in the SDM. However, the
> leaf description says that CPUID.0x15.EBX[31:0]==0 means that the ratio
> is not enumerated. I don't see how to better communicate this to
> userspace though than to simply have 0 there.

What I meant is -- the kernel may crash on a older CPU that does
not support CPUID 0x15. For example Broadwell doesn't have it.
For CPUID you always need to check the level.

-Andi
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web