perf/x86/intel/pt: Export cpu frequency ratios needed by PT decoders
Subsystems (2)
Alexander Shishkin
reviewerPATCH 1/1 perf/x86/intel/pt: Export cpu frequency ratios needed by PT decoders
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.
--- arch/x86/kernel/cpu/perf_event_intel_pt.c | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
arch/x86/kernel/cpu/perf_event_intel_pt.c +40 -0
@@ -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 , };
Signature · 1 line
2.5.0
arch/x86/kernel/cpu/perf_event_intel_pt.c static struct attribute_group pt_format_group = { · line 144
Quoted 3 lines · Alexander Shishkin
arch/x86/kernel/cpu/perf_event_intel_pt.c +3
-0+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
Signature · 1 line
[email protected] -- Speaking for myself only
Alexander Shishkin
reviewerQuoted 7 lines · Andi Kleen
arch/x86/kernel/cpu/perf_event_intel_pt.c static struct attribute_group pt_format_group = { · line 144
Quoted 3 lines · Alexander Shishkin
arch/x86/kernel/cpu/perf_event_intel_pt.c +3
-0+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
Quoted 10 lines · Alexander Shishkin
Quoted 7 lines · Andi Kleen
arch/x86/kernel/cpu/perf_event_intel_pt.c static struct attribute_group pt_format_group = { · line 144
Quoted 3 lines · Alexander Shishkin
arch/x86/kernel/cpu/perf_event_intel_pt.c +3
-0+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.
Quoted 4 lines
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