perf: Let PMUs provide supplementary information
Subsystems (2)
Adrian Hunter
reviewerRFC PATCH 1/1 perf: Let PMUs provide supplementary information
This is a follow-up to "[RFC PATCH] perf: Provide status of known PMUs" i.e.
https://lkml.kernel.org/r/[email protected]
There are 3 main changes:
- uses debugfs not sysfs
- doesn't require a PMU to be on the list of known PMU's
- renamed from 'known_pmus' to 'pmu_supplementary_info'
The purpose of the changes is to make optional whether or not PMU supplementary information is provided for a PMU, thus easing the maintenance burden. Maintenance is also eased by having all the code in a separate file.
Also the status codes have changed as requested:
[PERF_PMU_STATUS_ENABLED] = "Enabled",
[PERF_PMU_STATUS_ERROR] = "Disabled: Driver error",
[PERF_PMU_STATUS_NOT_LOADED] = "Disabled: Driver not loaded",
[PERF_PMU_STATUS_NOT_CONFIG] = "Disabled: Driver not in kernel config",
[PERF_PMU_STATUS_NOT_SUPPORTED] = "Disabled: Not supported by the kernel",
[PERF_PMU_STATUS_WRONG_HW] = "Disabled: Not supported by the hardware",
[PERF_PMU_STATUS_WRONG_VENDOR] = "Disabled: Not supported by the hardware vendor",
[PERF_PMU_STATUS_WRONG_ARCH] = "Disabled: Not supported by the the architecture",
[PERF_PMU_STATUS_UNKNOWN] = "Disabled: Unknown status",
Example:
$ cat /sys/kernel/debug/perf/pmu_supplementary_info/intel_pt Enabled
Last time it wasn't clear that a custom status message can be provided. For example, this code snippet from Intel PT:
if (prior_warn) {
x86_add_exclusive(x86_lbr_exclusive_pt);
status_msg = "PT is enabled at boot time, doing nothing";
ret = -EBUSY;
goto out;
}
...
out:
if (status_msg)
pr_warn("%s\n", status_msg);
perf_pmu_error_status("intel_pt", ret, status_msg);Would result in:
$ cat /sys/kernel/debug/perf/pmu_supplementary_info/intel_pt Disabled: Driver error - PT is enabled at boot time, doing nothing
--- arch/x86/kernel/cpu/perf_event.c | 3 + arch/x86/kernel/cpu/perf_event_intel_bts.c | 20 +- arch/x86/kernel/cpu/perf_event_intel_pt.c | 18 +- include/linux/perf_event.h | 45 ++++ kernel/events/Makefile | 2 +- kernel/events/pmu_supp_info.c | 384 +++++++++++++++++++++++++++++ 6 files changed, 462 insertions(+), 10 deletions(-) create mode 100644 kernel/events/pmu_supp_info.c
arch/x86/kernel/cpu/perf_event.c +3 -0
@@ -1670,12 +1670,15 @@ static int __init init_hw_perf_events(void)switch (boot_cpu_data.x86_vendor) {case X86_VENDOR_INTEL : +perf_pmu_vendor ("Intel" ); err =intel_pmu_init ();break ;case X86_VENDOR_AMD : +perf_pmu_vendor ("AMD" ); err =amd_pmu_init ();break ;default : +perf_pmu_vendor ("Unknown" ); err = -ENOTSUPP ; }if (err !=0 ) {
arch/x86/kernel/cpu/perf_event_intel_bts.c +17 -3
@@ -511,8 +511,19 @@ static void bts_event_read(struct perf_event *event)static __init int bts_init (void ) { -if (!boot_cpu_has (X86_FEATURE_DTES64 ) || !x86_pmu.bts) -return -ENODEV ; +const char *status_msg =NULL ; +int ret; + +if (!x86_pmu.bts) { + ret = -ENODEV ; + goto out; + } + +if (!boot_cpu_has (X86_FEATURE_DTES64 )) { + status_msg ="requires 64-bit kernel" ; + ret = -ENOTSUPP ; + goto out; + } bts_pmu.capabilities =PERF_PMU_CAP_AUX_NO_SG |PERF_PMU_CAP_ITRACE ; bts_pmu.task_ctx_nr = perf_sw_context;
@@ -525,6 +536,9 @@ static __init int bts_init(void) bts_pmu.setup_aux = bts_buffer_setup_aux; bts_pmu.free_aux = bts_buffer_free_aux; -return perf_pmu_register (&bts_pmu,"intel_bts" ,-1 ); + ret =perf_pmu_register (&bts_pmu,"intel_bts" ,-1 ); +out: +perf_pmu_error_status ("intel_bts" , ret, status_msg); +return ret; }arch_initcall (bts_init);
arch/x86/kernel/cpu/perf_event_intel_pt.c +12 -6
@@ -1122,6 +1122,7 @@ static int pt_event_init(struct perf_event *event)static __init int pt_init (void ) {int ret, cpu, prior_warn =0 ; +const char *status_msg =NULL ;BUILD_BUG_ON (sizeof (struct topa ) >PAGE_SIZE );get_online_cpus ();
@@ -1136,18 +1137,19 @@ static __init int pt_init(void)if (prior_warn) {x86_add_exclusive (x86_lbr_exclusive_pt); -pr_warn ("PT is enabled at boot time, doing nothing\n" ); - -return -EBUSY ; + status_msg ="PT is enabled at boot time, doing nothing" ; + ret = -EBUSY ; + goto out; } ret =pt_pmu_hw_init ();if (ret) -return ret; + goto out;if (!pt_cap_get (PT_CAP_topa_output)) { -pr_warn ("ToPA output is not supported on this CPU\n" ); -return -ENODEV ; + status_msg ="ToPA output is not supported on this CPU" ; + ret = -ENODEV ; + goto out; }if (!pt_cap_get (PT_CAP_topa_multiple_entries))
@@ -1166,6 +1168,10 @@ static __init int pt_init(void) pt_pmu.pmu.setup_aux = pt_buffer_setup_aux; pt_pmu.pmu.free_aux = pt_buffer_free_aux; ret =perf_pmu_register (&pt_pmu.pmu,"intel_pt" ,-1 ); +out: +if (status_msg) +pr_warn ("%s\n" , status_msg); +perf_pmu_error_status ("intel_pt" , ret, status_msg);return ret; }
include/linux/perf_event.h +45 -0
57 lines not on this page · raw message
kernel/events/Makefile +1 -1
@@ -6,4 +6,4 @@ obj-y := core.o ring_buffer.o callchain.o obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o obj-$(CONFIG_UPROBES) += uprobes.o - +obj-$(CONFIG_DEBUG_FS) += pmu_supp_info.o
kernel/events/pmu_supp_info.c new file +384 -0
384 lines not on this page · raw message
Signature · 1 line
1.9.1
Quoted 8 lines · Adrian Hunter
This is a follow-up to "[RFC PATCH] perf: Provide status of known PMUs" i.e.
https://lkml.kernel.org/r/[email protected]There are 3 main changes:
- uses debugfs not sysfs
- doesn't require a PMU to be on the list of known PMU's
- renamed from 'known_pmus' to 'pmu_supplementary_info'
do you plan any perf tool related change?
'perf list' could display this info
tested..
[root@ibm-x3650m4-01 pmu_supplementary_info]# pwd /sys/kernel/debug/perf/pmu_supplementary_info [root@ibm-x3650m4-01 pmu_supplementary_info]# ll total 0
-r--r--r--. 1 root root 0 Jul 26 18:22 intel_bts -r--r--r--. 1 root root 0 Jul 26 18:22 intel_pt [root@ibm-x3650m4-01 pmu_supplementary_info]# cat * Enabled
Disabled: Not supported by the hardware
jirka