perf, pt: Intel PT updates
Subsystems (2)
Alexander Shishkin
reviewercover perf, pt: Intel PT updates
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(-)
Signature · 1 line
2.8.0.rc3
Alexander Shishkin
reviewerPATCH 1/3 perf/x86/intel/pt: Convert ACCESS_ONCE()s
This patch converts remaining ACCESS_ONCE() instances into READ_ONCE() and WRITE_ONCE() as appropriate.
--- arch/x86/events/intel/pt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/events/intel/pt.c +3 -3
@@ -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);
Signature · 1 line
2.8.0.rc3
tip-bot for Alexander Shishkin
merge bot[tip:perf/core] perf/x86/intel/pt: Convert ACCESS_ONCE()s
perf/x86/intel/pt: Convert ACCESS_ONCE()s
Commit-ID: 1b6de5917172967acd8db4d222df4225d23a8a60 Gitweb: http://git.kernel.org/tip/1b6de5917172967acd8db4d222df4225d23a8a60 Author: Alexander Shishkin <[email protected]> AuthorDate: Thu, 28 Apr 2016 18:35:44 +0300 Committer: Ingo Molnar <[email protected]> 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.
--- arch/x86/events/intel/pt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/events/intel/pt.c +3 -3
@@ -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);
Alexander Shishkin
reviewerPATCH 2/3 perf/x86/intel/pt: Export cpu frequency ratios needed by PT decoders
In reply to Alexander ShishkinIn 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/events/intel/pt.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++ arch/x86/events/intel/pt.h | 6 ++++++ 2 files changed, 60 insertions(+)
arch/x86/events/intel/pt.c +54 -0
@@ -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
arch/x86/events/intel/pt.h +6 -0
@@ -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; };/**
Signature · 1 line
2.8.0.rc3
Alexander Shishkin
reviewerRe: [PATCH v0 2/3] perf/x86/intel/pt: Export cpu frequency ratios needed by PT decoders
Quoted 8 lines · 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 <[email protected]>
With a slightly better changelog:
Quoted 1 line
From
d0fbc4e45fb633e464cbbd61d6aacd5a476fd50dMon Sep 17 00:00:00 2001
From: Alexander Shishkin <[email protected]>
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).
--- arch/x86/events/intel/pt.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++ arch/x86/events/intel/pt.h | 6 ++++++ 2 files changed, 60 insertions(+)
arch/x86/events/intel/pt.c +54 -0
@@ -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
arch/x86/events/intel/pt.h +6 -0
@@ -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; };/**
Signature · 1 line
2.8.0.rc3
tip-bot for Alexander Shishkin
merge bot[tip:perf/core] perf/x86/intel/pt: Export CPU frequency ratios needed by PT decoders
perf/x86/intel/pt: Export CPU frequency ratios needed by PT decoders
Commit-ID: 65c7e6f1c4810e9bce935520f44f6d2613cd1b40 Gitweb: http://git.kernel.org/tip/65c7e6f1c4810e9bce935520f44f6d2613cd1b40 Author: Alexander Shishkin <[email protected]> AuthorDate: Wed, 19 Aug 2015 17:02:10 +0300 Committer: Ingo Molnar <[email protected]> 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).
--- arch/x86/events/intel/pt.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++ arch/x86/events/intel/pt.h | 6 ++++++ 2 files changed, 60 insertions(+)
arch/x86/events/intel/pt.c +54 -0
@@ -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
arch/x86/events/intel/pt.h +6 -0
@@ -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; };/**
Borislav Petkov
maintainerRe: [PATCH v0 2/3] perf/x86/intel/pt: Export cpu frequency ratios needed by PT decoders
In reply to Alexander ShishkinQuoted 6 lines · 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.
I guess new sysfs nodes need to be documented:
Documentation/ABI/...
Signature · 4 lines
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.Alexander Shishkin
reviewerPATCH 3/3 perf, x86: Bypass PT vs LBR exclusivity if the core supports it
In reply to Alexander ShishkinNot 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.
--- 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(+)
arch/x86/events/core.c +6 -0
@@ -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); }
arch/x86/events/intel/core.c +1 -0
@@ -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 ;
arch/x86/events/perf_event.h +1 -0
@@ -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
Signature · 1 line
2.8.0.rc3
tip-bot for Alexander Shishkin
merge bot[tip:perf/core] perf/x86/intel/pt: Bypass PT vs. LBR exclusivity if the core supports it
perf/x86/intel/pt: Bypass PT vs. LBR exclusivity if the core supports it
Commit-ID: ccbebba4c6bfda8e3ef9e431ce2c3d91c5fc5a63 Gitweb: http://git.kernel.org/tip/ccbebba4c6bfda8e3ef9e431ce2c3d91c5fc5a63 Author: Alexander Shishkin <[email protected]> AuthorDate: Thu, 28 Apr 2016 18:35:46 +0300 Committer: Ingo Molnar <[email protected]> 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.
--- 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(+)
arch/x86/events/core.c +6 -0
@@ -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); }
arch/x86/events/intel/core.c +1 -0
@@ -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 ;
arch/x86/events/perf_event.h +1 -0
@@ -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