perf/x86: Rework msr probe interface
Subsystems (2)
Jiri Olsa
reviewerv3 cover perf/x86: Rework msr probe interface
hi,
following up on [1], [2] and [3], this patchset adds update attribute groups to pmu, factors out the MSR probe code and use it in msr,cstate* and rapl PMUs.
The functionality stays the same with one exception:
for msr PMU: the event is not exported if the rdmsr return zero on event's msr, cstate* and rapl pmu functionality stays.
And also: ;-)
Quoted 2 lines
Somewhere along the line you lost the explanation of _why_ we're doing this; namely: virt sucks.
Also available in:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/msr
Tested on snb and skylake servers.
v3 changes:
- rebase on latest perf changes for Icelake models
v2 changes:
- checking zero rdmsr only for rapl PMU events, cstate* and msr pmu functionality stays unchanged
thanks,
jirka
[1] https://lore.kernel.org/lkml/20190301114250.GA23459@krava/
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/lkml/[email protected]/
---
Jiri Olsa (8):
perf/x86: Add msr probe interface
perf/x86/msr: Use new probe function
perf/x86/cstate: Use new probe function
perf/x86/rapl: Use new msr detection interface perf/x86/rapl: Get rapl_cntr_mask from new probe framework perf/x86/rapl: Get msr values from new probe framework perf/x86/rapl: Get attributes from new probe framework perf/x86/rapl: Get quirk state from new probe framework
arch/x86/events/Makefile | 2 +- arch/x86/events/intel/cstate.c | 152 +++++++++++++++++++++++++++--------------------- arch/x86/events/intel/rapl.c | 380 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------ arch/x86/events/msr.c | 110 +++++++++++++++++++---------------- arch/x86/events/probe.c | 45 +++++++++++++++ arch/x86/events/probe.h | 29 ++++++++++ 6 files changed, 392 insertions(+), 326 deletions(-) create mode 100644 arch/x86/events/probe.c create mode 100644 arch/x86/events/probe.h
Jiri Olsa
reviewerPATCH v3 1/8 perf/x86: Add msr probe interface
Adding perf_msr_probe function to provide interface for checking up on MSR register and set the related attribute group visibility.
User defines following struct for each MSR register:
struct perf_msr {
u64 msr;
struct attribute_group *grp;
bool (*test)(int idx, void *data);
bool no_check;
};Where:
msr - is the MSR address attrs - is attribute groups array to add if the check passed test - is test function pointer
no_check - is bool that bypass the check and adds the
attribute without any test
The array of struct perf_msr is passed into:
perf_msr_probe(struct perf_msr *msr, int cnt, bool zero, void *data)
Together with:
cnt - which is the number of struct msr array elements data - which is user pointer passed to the test function zero - allow counters that returns zero on rdmsr
The perf_msr_probe will executed test code, read the MSR and check the value is != 0. If all these tests pass, related attribute group is kept visible.
Also adding PMU_EVENT_GROUP macro helper to define attribute group for single attribute. It will be used in following patches.
--- arch/x86/events/Makefile | 2 +- arch/x86/events/probe.c | 45 ++++++++++++++++++++++++++++++++++++++++ arch/x86/events/probe.h | 29 ++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 arch/x86/events/probe.c create mode 100644 arch/x86/events/probe.h
arch/x86/events/Makefile +1 -1
@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-y += core.o +obj-y += core.o probe.o obj-y += amd/ obj-$(CONFIG_X86_LOCAL_APIC) += msr.o obj-$(CONFIG_CPU_SUP_INTEL) += intel/
arch/x86/events/probe.c new file +45 -0
45 lines not on this page · raw message
arch/x86/events/probe.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ARCH_X86_EVENTS_PROBE_H__ +#define __ARCH_X86_EVENTS_PROBE_H__ +#include <linux/sysfs.h> + +struct perf_msr { +u64 msr; +struct attribute_group *grp; +bool (*test)(int idx,void *data); +bool no_check; +}; + +unsigned long +perf_msr_probe (struct perf_msr *msr,int cnt,bool no_zero,void *data); + +#define __PMU_EVENT_GROUP (_name) \ +static struct attribute *attrs_##_name[] = { \ + &attr_##_name.attr.attr, \ + NULL, \ +} + +#define PMU_EVENT_GROUP (_grp, _name) \ +__PMU_EVENT_GROUP(_name); \ +static struct attribute_group group_##_name = { \ + .name = #_grp, \ + .attrs = attrs_##_name, \ +} + +#endif /* __ARCH_X86_EVENTS_PROBE_H__ */
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH v3 2/8 perf/x86/msr: Use new probe function
In reply to Jiri OlsaUsing perf_msr_probe function to probe for msr events.
The functionality is the same, with one exception, that perf_msr_probe checks for rdmsr to return value != 0 for given MSR register.
Using the new attribute groups and adding the events via pmu::attr_update.
--- arch/x86/events/msr.c | 110 +++++++++++++++++++++++------------------- 1 file changed, 60 insertions(+), 50 deletions(-)
arch/x86/events/msr.c +60 -50
@@ -1,7 +1,9 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/perf_event.h> +#include <linux/sysfs.h> #include <linux/nospec.h> #include <asm/intel-family.h> +#include "probe.h" enum perf_msr_id {PERF_MSR_TSC =0 ,
@@ -12,32 +14,30 @@ enum perf_msr_id {PERF_MSR_PTSC =5 ,PERF_MSR_IRPERF =6 ,PERF_MSR_THERM =7 , -PERF_MSR_THERM_SNAP =8 , -PERF_MSR_THERM_UNIT =9 , PERF_MSR_EVENT_MAX, }; -static bool test_aperfmperf (int idx) +static bool test_aperfmperf (int idx,void *data) {return boot_cpu_has (X86_FEATURE_APERFMPERF ); } -static bool test_ptsc (int idx) +static bool test_ptsc (int idx,void *data) {return boot_cpu_has (X86_FEATURE_PTSC ); } -static bool test_irperf (int idx) +static bool test_irperf (int idx,void *data) {return boot_cpu_has (X86_FEATURE_IRPERF ); } -static bool test_therm_status (int idx) +static bool test_therm_status (int idx,void *data) {return boot_cpu_has (X86_FEATURE_DTHERM ); } -static bool test_intel (int idx) +static bool test_intel (int idx,void *data) {if (boot_cpu_data.x86_vendor !=X86_VENDOR_INTEL || boot_cpu_data.x86 !=6 )
@@ -98,37 +98,51 @@ static bool test_intel(int idx)return false; } -struct perf_msr { -u64 msr; -struct perf_pmu_events_attr *attr; -bool (*test)(int idx); +PMU_EVENT_ATTR_STRING (tsc, attr_tsc,"event=0x00" ); +PMU_EVENT_ATTR_STRING (aperf, attr_aperf,"event=0x01" ); +PMU_EVENT_ATTR_STRING (mperf, attr_mperf,"event=0x02" ); +PMU_EVENT_ATTR_STRING (pperf, attr_pperf,"event=0x03" ); +PMU_EVENT_ATTR_STRING (smi, attr_smi,"event=0x04" ); +PMU_EVENT_ATTR_STRING (ptsc, attr_ptsc,"event=0x05" ); +PMU_EVENT_ATTR_STRING (irperf, attr_irperf,"event=0x06" ); +PMU_EVENT_ATTR_STRING (cpu_thermal_margin, attr_therm,"event=0x07" ); +PMU_EVENT_ATTR_STRING (cpu_thermal_margin.snapshot, attr_therm_snap,"1" ); +PMU_EVENT_ATTR_STRING (cpu_thermal_margin.unit, attr_therm_unit,"C" ); + +static unsigned long msr_mask; + +PMU_EVENT_GROUP (events, aperf); +PMU_EVENT_GROUP (events, mperf); +PMU_EVENT_GROUP (events, pperf); +PMU_EVENT_GROUP (events, smi); +PMU_EVENT_GROUP (events, ptsc); +PMU_EVENT_GROUP (events, irperf); + +static struct attribute *attrs_therm[] = { + &attr_therm.attr.attr, + &attr_therm_snap.attr.attr, + &attr_therm_unit.attr.attr, +NULL , }; -PMU_EVENT_ATTR_STRING (tsc, evattr_tsc,"event=0x00" ); -PMU_EVENT_ATTR_STRING (aperf, evattr_aperf,"event=0x01" ); -PMU_EVENT_ATTR_STRING (mperf, evattr_mperf,"event=0x02" ); -PMU_EVENT_ATTR_STRING (pperf, evattr_pperf,"event=0x03" ); -PMU_EVENT_ATTR_STRING (smi, evattr_smi,"event=0x04" ); -PMU_EVENT_ATTR_STRING (ptsc, evattr_ptsc,"event=0x05" ); -PMU_EVENT_ATTR_STRING (irperf, evattr_irperf,"event=0x06" ); -PMU_EVENT_ATTR_STRING (cpu_thermal_margin, evattr_therm,"event=0x07" ); -PMU_EVENT_ATTR_STRING (cpu_thermal_margin.snapshot, evattr_therm_snap,"1" ); -PMU_EVENT_ATTR_STRING (cpu_thermal_margin.unit, evattr_therm_unit,"C" ); +static struct attribute_group group_therm = { + .name ="events" , + .attrs = attrs_therm, +};static struct perf_msr msr[] = { - [PERF_MSR_TSC ] = {0 , &evattr_tsc,NULL , }, - [PERF_MSR_APERF ] = {MSR_IA32_APERF , &evattr_aperf, test_aperfmperf, }, - [PERF_MSR_MPERF ] = {MSR_IA32_MPERF , &evattr_mperf, test_aperfmperf, }, - [PERF_MSR_PPERF ] = {MSR_PPERF , &evattr_pperf, test_intel, }, - [PERF_MSR_SMI ] = {MSR_SMI_COUNT , &evattr_smi, test_intel, }, - [PERF_MSR_PTSC ] = {MSR_F15H_PTSC , &evattr_ptsc, test_ptsc, }, - [PERF_MSR_IRPERF ] = {MSR_F17H_IRPERF , &evattr_irperf, test_irperf, }, - [PERF_MSR_THERM ] = {MSR_IA32_THERM_STATUS , &evattr_therm, test_therm_status, }, - [PERF_MSR_THERM_SNAP ] = {MSR_IA32_THERM_STATUS , &evattr_therm_snap, test_therm_status, }, - [PERF_MSR_THERM_UNIT ] = {MSR_IA32_THERM_STATUS , &evattr_therm_unit, test_therm_status, }, + [PERF_MSR_TSC ] = { .no_check = true, }, + [PERF_MSR_APERF ] = {MSR_IA32_APERF , &group_aperf, test_aperfmperf, }, + [PERF_MSR_MPERF ] = {MSR_IA32_MPERF , &group_mperf, test_aperfmperf, }, + [PERF_MSR_PPERF ] = {MSR_PPERF , &group_pperf, test_intel, }, + [PERF_MSR_SMI ] = {MSR_SMI_COUNT , &group_smi, test_intel, }, + [PERF_MSR_PTSC ] = {MSR_F15H_PTSC , &group_ptsc, test_ptsc, }, + [PERF_MSR_IRPERF ] = {MSR_F17H_IRPERF , &group_irperf, test_irperf, }, + [PERF_MSR_THERM ] = {MSR_IA32_THERM_STATUS , &group_therm, test_therm_status, }, }; -static struct attribute *events_attrs[PERF_MSR_EVENT_MAX +1 ] = { +static struct attribute *events_attrs[] = { + &attr_tsc.attr.attr,NULL , };
@@ -153,6 +167,17 @@ static const struct attribute_group *attr_groups[] = { NULL, }; +const struct attribute_group *attr_update[] = { + &group_aperf, + &group_mperf, + &group_pperf, + &group_smi, + &group_ptsc, + &group_irperf, + &group_therm, +NULL , +}; +static int msr_event_init (struct perf_event *event) {u64 cfg = event->attr.config;
@@ -169,7 +194,7 @@ static int msr_event_init(struct perf_event *event) cfg =array_index_nospec ((unsigned long )cfg,PERF_MSR_EVENT_MAX ); -if (!msr[cfg].attr) +if (!(msr_mask & (1 << cfg)))return -EINVAL ; event->hw.idx =-1 ;
@@ -252,32 +277,17 @@ static struct pmu pmu_msr = { .stop = msr_event_stop, .read = msr_event_update, .capabilities = PERF_PMU_CAP_NO_INTERRUPT | PERF_PMU_CAP_NO_EXCLUDE, + .attr_update = attr_update, };static int __init msr_init (void ) { -int i, j =0 ; -if (!boot_cpu_has (X86_FEATURE_TSC )) {pr_cont ("no MSR PMU driver.\n" );return 0 ; } -/* Probe the MSRs. */ -for (i =PERF_MSR_TSC +1 ; i <PERF_MSR_EVENT_MAX ; i++) { -u64 val; - -/* Virt sucks; you cannot tell if a R/O MSR is present :/ */ -if (!msr[i].test (i) ||rdmsrl_safe (msr[i].msr, &val)) - msr[i].attr =NULL ; - } - -/* List remaining MSRs in the sysfs attrs. */ -for (i =0 ; i <PERF_MSR_EVENT_MAX ; i++) { -if (msr[i].attr) - events_attrs[j++] = &msr[i].attr->attr.attr; - } - events_attrs[j] =NULL ; + msr_mask =perf_msr_probe (msr,PERF_MSR_EVENT_MAX , true,NULL );perf_pmu_register (&pmu_msr,"msr" ,-1 );
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH v3 3/8 perf/x86/cstate: Use new probe function
In reply to Jiri OlsaUsing perf_msr_probe function to probe for cstate events.
The functionality is the same, with one exception, that perf_msr_probe checks for rdmsr to return value != 0 for given MSR register.
Using the new attribute groups and adding the events via pmu::attr_update.
--- arch/x86/events/intel/cstate.c | 152 +++++++++++++++++++-------------- 1 file changed, 87 insertions(+), 65 deletions(-)
arch/x86/events/intel/cstate.c +87 -65
@@ -96,6 +96,7 @@#include <asm/cpu_device_id.h> #include <asm/intel-family.h> #include "../perf_event.h" +#include "../probe.h" MODULE_LICENSE ("GPL" );
@@ -144,25 +145,42 @@ enum perf_cstate_core_events {PERF_CSTATE_CORE_EVENT_MAX , }; -PMU_EVENT_ATTR_STRING (c1-residency, evattr_cstate_core_c1,"event=0x00" ); -PMU_EVENT_ATTR_STRING (c3-residency, evattr_cstate_core_c3,"event=0x01" ); -PMU_EVENT_ATTR_STRING (c6-residency, evattr_cstate_core_c6,"event=0x02" ); -PMU_EVENT_ATTR_STRING (c7-residency, evattr_cstate_core_c7,"event=0x03" ); +PMU_EVENT_ATTR_STRING (c1-residency, attr_cstate_core_c1,"event=0x00" ); +PMU_EVENT_ATTR_STRING (c3-residency, attr_cstate_core_c3,"event=0x01" ); +PMU_EVENT_ATTR_STRING (c6-residency, attr_cstate_core_c6,"event=0x02" ); +PMU_EVENT_ATTR_STRING (c7-residency, attr_cstate_core_c7,"event=0x03" ); -static struct perf_cstate_msr core_msr[] = { - [PERF_CSTATE_CORE_C1_RES ] = {MSR_CORE_C1_RES , &evattr_cstate_core_c1 }, - [PERF_CSTATE_CORE_C3_RES ] = {MSR_CORE_C3_RESIDENCY , &evattr_cstate_core_c3 }, - [PERF_CSTATE_CORE_C6_RES ] = {MSR_CORE_C6_RESIDENCY , &evattr_cstate_core_c6 }, - [PERF_CSTATE_CORE_C7_RES ] = {MSR_CORE_C7_RESIDENCY , &evattr_cstate_core_c7 }, +static unsigned long core_msr_mask; + +PMU_EVENT_GROUP (events, cstate_core_c1); +PMU_EVENT_GROUP (events, cstate_core_c3); +PMU_EVENT_GROUP (events, cstate_core_c6); +PMU_EVENT_GROUP (events, cstate_core_c7); + +static bool test_msr (int idx,void *data) +{ +return test_bit (idx, (unsigned long *) data); +} + +static struct perf_msr core_msr[] = { + [PERF_CSTATE_CORE_C1_RES ] = {MSR_CORE_C1_RES , &group_cstate_core_c1, test_msr }, + [PERF_CSTATE_CORE_C3_RES ] = {MSR_CORE_C3_RESIDENCY , &group_cstate_core_c3, test_msr }, + [PERF_CSTATE_CORE_C6_RES ] = {MSR_CORE_C6_RESIDENCY , &group_cstate_core_c6, test_msr }, + [PERF_CSTATE_CORE_C7_RES ] = {MSR_CORE_C7_RESIDENCY , &group_cstate_core_c7, test_msr }, }; -static struct attribute *core_events_attrs[PERF_CSTATE_CORE_EVENT_MAX +1 ] = { +static struct attribute *attrs_empty[] = {NULL , }; +/* +* There are no default events, but we need to create +* "events" group (with empty attrs) before updating +* it with detected events. +*/ static struct attribute_group core_events_attr_group = { .name ="events" , - .attrs = core_events_attrs, + .attrs = attrs_empty, };DEFINE_CSTATE_FORMAT_ATTR (core_event, event,"config:0-63" );
@@ -211,31 +229,37 @@ enum perf_cstate_pkg_events {PERF_CSTATE_PKG_EVENT_MAX , }; -PMU_EVENT_ATTR_STRING (c2-residency, evattr_cstate_pkg_c2,"event=0x00" ); -PMU_EVENT_ATTR_STRING (c3-residency, evattr_cstate_pkg_c3,"event=0x01" ); -PMU_EVENT_ATTR_STRING (c6-residency, evattr_cstate_pkg_c6,"event=0x02" ); -PMU_EVENT_ATTR_STRING (c7-residency, evattr_cstate_pkg_c7,"event=0x03" ); -PMU_EVENT_ATTR_STRING (c8-residency, evattr_cstate_pkg_c8,"event=0x04" ); -PMU_EVENT_ATTR_STRING (c9-residency, evattr_cstate_pkg_c9,"event=0x05" ); -PMU_EVENT_ATTR_STRING (c10-residency, evattr_cstate_pkg_c10,"event=0x06" ); - -static struct perf_cstate_msr pkg_msr[] = { - [PERF_CSTATE_PKG_C2_RES ] = {MSR_PKG_C2_RESIDENCY , &evattr_cstate_pkg_c2 }, - [PERF_CSTATE_PKG_C3_RES ] = {MSR_PKG_C3_RESIDENCY , &evattr_cstate_pkg_c3 }, - [PERF_CSTATE_PKG_C6_RES ] = {MSR_PKG_C6_RESIDENCY , &evattr_cstate_pkg_c6 }, - [PERF_CSTATE_PKG_C7_RES ] = {MSR_PKG_C7_RESIDENCY , &evattr_cstate_pkg_c7 }, - [PERF_CSTATE_PKG_C8_RES ] = {MSR_PKG_C8_RESIDENCY , &evattr_cstate_pkg_c8 }, - [PERF_CSTATE_PKG_C9_RES ] = {MSR_PKG_C9_RESIDENCY , &evattr_cstate_pkg_c9 }, - [PERF_CSTATE_PKG_C10_RES ] = {MSR_PKG_C10_RESIDENCY , &evattr_cstate_pkg_c10 }, -}; - -static struct attribute *pkg_events_attrs[PERF_CSTATE_PKG_EVENT_MAX +1 ] = { -NULL , +PMU_EVENT_ATTR_STRING (c2-residency, attr_cstate_pkg_c2,"event=0x00" ); +PMU_EVENT_ATTR_STRING (c3-residency, attr_cstate_pkg_c3,"event=0x01" ); +PMU_EVENT_ATTR_STRING (c6-residency, attr_cstate_pkg_c6,"event=0x02" ); +PMU_EVENT_ATTR_STRING (c7-residency, attr_cstate_pkg_c7,"event=0x03" ); +PMU_EVENT_ATTR_STRING (c8-residency, attr_cstate_pkg_c8,"event=0x04" ); +PMU_EVENT_ATTR_STRING (c9-residency, attr_cstate_pkg_c9,"event=0x05" ); +PMU_EVENT_ATTR_STRING (c10-residency, attr_cstate_pkg_c10,"event=0x06" ); + +static unsigned long pkg_msr_mask; + +PMU_EVENT_GROUP (events, cstate_pkg_c2); +PMU_EVENT_GROUP (events, cstate_pkg_c3); +PMU_EVENT_GROUP (events, cstate_pkg_c6); +PMU_EVENT_GROUP (events, cstate_pkg_c7); +PMU_EVENT_GROUP (events, cstate_pkg_c8); +PMU_EVENT_GROUP (events, cstate_pkg_c9); +PMU_EVENT_GROUP (events, cstate_pkg_c10); + +static struct perf_msr pkg_msr[] = { + [PERF_CSTATE_PKG_C2_RES ] = {MSR_PKG_C2_RESIDENCY , &group_cstate_pkg_c2, test_msr }, + [PERF_CSTATE_PKG_C3_RES ] = {MSR_PKG_C3_RESIDENCY , &group_cstate_pkg_c3, test_msr }, + [PERF_CSTATE_PKG_C6_RES ] = {MSR_PKG_C6_RESIDENCY , &group_cstate_pkg_c6, test_msr }, + [PERF_CSTATE_PKG_C7_RES ] = {MSR_PKG_C7_RESIDENCY , &group_cstate_pkg_c7, test_msr }, + [PERF_CSTATE_PKG_C8_RES ] = {MSR_PKG_C8_RESIDENCY , &group_cstate_pkg_c8, test_msr }, + [PERF_CSTATE_PKG_C9_RES ] = {MSR_PKG_C9_RESIDENCY , &group_cstate_pkg_c9, test_msr }, + [PERF_CSTATE_PKG_C10_RES ] = {MSR_PKG_C10_RESIDENCY , &group_cstate_pkg_c10, test_msr }, };static struct attribute_group pkg_events_attr_group = { .name ="events" , - .attrs = pkg_events_attrs, + .attrs = attrs_empty, };DEFINE_CSTATE_FORMAT_ATTR (pkg_event, event,"config:0-63" );
@@ -289,7 +313,8 @@ static int cstate_pmu_event_init(struct perf_event *event)if (event->pmu == &cstate_core_pmu) {if (cfg >=PERF_CSTATE_CORE_EVENT_MAX )return -EINVAL ; -if (!core_msr[cfg].attr) + cfg =array_index_nospec ((unsigned long )cfg,PERF_CSTATE_CORE_EVENT_MAX ); +if (!(core_msr_mask & (1 << cfg)))return -EINVAL ; event->hw.event_base = core_msr[cfg].msr; cpu = cpumask_any_and(&cstate_core_cpu_mask,
@@ -298,7 +323,7 @@ static int cstate_pmu_event_init(struct perf_event *event)if (cfg >=PERF_CSTATE_PKG_EVENT_MAX )return -EINVAL ; cfg =array_index_nospec ((unsigned long )cfg,PERF_CSTATE_PKG_EVENT_MAX ); -if (!pkg_msr[cfg].attr) +if (!(pkg_msr_mask & (1 << cfg)))return -EINVAL ; event->hw.event_base = pkg_msr[cfg].msr; cpu = cpumask_any_and(&cstate_pkg_cpu_mask,
@@ -421,8 +446,28 @@ static int cstate_cpu_init(unsigned int cpu)return 0 ; } +const struct attribute_group *core_attr_update[] = { + &group_cstate_core_c1, + &group_cstate_core_c3, + &group_cstate_core_c6, + &group_cstate_core_c7, +NULL , +}; + +const struct attribute_group *pkg_attr_update[] = { + &group_cstate_pkg_c2, + &group_cstate_pkg_c3, + &group_cstate_pkg_c6, + &group_cstate_pkg_c7, + &group_cstate_pkg_c8, + &group_cstate_pkg_c9, + &group_cstate_pkg_c10, +NULL , +}; +static struct pmu cstate_core_pmu = { .attr_groups = core_attr_groups, + .attr_update = core_attr_update, .name ="cstate_core" , .task_ctx_nr = perf_invalid_context, .event_init = cstate_pmu_event_init,
@@ -437,6 +482,7 @@ static struct pmu cstate_core_pmu = {static struct pmu cstate_pkg_pmu = { .attr_groups = pkg_attr_groups, + .attr_update = pkg_attr_update, .name ="cstate_pkg" , .task_ctx_nr = perf_invalid_context, .event_init = cstate_pmu_event_init,
@@ -585,31 +631,6 @@ static const struct x86_cpu_id intel_cstates_match[] __initconst = { };MODULE_DEVICE_TABLE (x86cpu, intel_cstates_match); -/* -* Probe the cstate events and insert the available one into sysfs attrs -* Return false if there are no available events. -*/ -static bool __init cstate_probe_msr (const unsigned long evmsk,int max, -struct perf_cstate_msr *msr, -struct attribute **attrs) -{ -bool found = false; -unsigned int bit; -u64 val; - -for (bit =0 ; bit < max; bit++) { -if (test_bit (bit, &evmsk) && !rdmsrl_safe (msr[bit].msr, &val)) { - *attrs++ = &msr[bit].attr->attr.attr; - found = true; - }else { - msr[bit].attr =NULL ; - } - } - *attrs =NULL ; - -return found; -} -static int __init cstate_probe (const struct cstate_model *cm) {/* SLM has different MSR for PKG C6 */
@@ -621,13 +642,14 @@ static int __init cstate_probe(const struct cstate_model *cm) pkg_msr[PERF_CSTATE_CORE_C6_RES ].msr =MSR_KNL_CORE_C6_RESIDENCY ; - has_cstate_core =cstate_probe_msr (cm->core_events, -PERF_CSTATE_CORE_EVENT_MAX , - core_msr, core_events_attrs); + core_msr_mask =perf_msr_probe (core_msr,PERF_CSTATE_CORE_EVENT_MAX , + true, (void *) &cm->core_events); + + pkg_msr_mask =perf_msr_probe (pkg_msr,PERF_CSTATE_PKG_EVENT_MAX , + true, (void *) &cm->pkg_events); - has_cstate_pkg =cstate_probe_msr (cm->pkg_events, -PERF_CSTATE_PKG_EVENT_MAX , - pkg_msr, pkg_events_attrs); + has_cstate_core = !!core_msr_mask; + has_cstate_pkg = !!pkg_msr_mask;return (has_cstate_core || has_cstate_pkg) ?0 : -ENODEV ; }
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH v3 4/8 perf/x86/rapl: Use new msr detection interface
In reply to Jiri OlsaUsing perf_msr_probe function to probe for rapl msrs.
Adding new rapl_model_match device table, that gathers events info for given model, following the msr and cstate module design.
It will replace the current rapl_cpu_match device table and detection code in following patches.
--- arch/x86/events/intel/rapl.c | 192 ++++++++++++++++++++++++++++++++++- 1 file changed, 191 insertions(+), 1 deletion(-)
arch/x86/events/intel/rapl.c +191 -1
@@ -58,6 +58,7 @@#include <asm/cpu_device_id.h> #include <asm/intel-family.h> #include "../perf_event.h" +#include "../probe.h" MODULE_LICENSE ("GPL" );
@@ -76,6 +77,17 @@ MODULE_LICENSE("GPL");#define INTEL_RAPL_PSYS 0x5/* pseudo-encoding */ #define NR_RAPL_DOMAINS 0x5 + +enum perf_rapl_events { +PERF_RAPL_PP0 =0 ,/* all cores */ +PERF_RAPL_PKG ,/* entire package */ +PERF_RAPL_RAM ,/* DRAM */ +PERF_RAPL_PP1 ,/* gpu */ +PERF_RAPL_PSYS ,/* psys */ + +PERF_RAPL_MAX , +}; +static const char *const rapl_domain_names[NR_RAPL_DOMAINS ]__initconst = {"pp0-core" ,"package" ,
@@ -153,6 +165,11 @@ struct rapl_pmus {struct rapl_pmu *pmus[]; }; +struct rapl_model { +unsigned long events; +bool apply_quirk; +}; +/* 1/2^hw_unit Joule */ static int rapl_hw_unit[NR_RAPL_DOMAINS ]__read_mostly ;static struct rapl_pmus *rapl_pmus;
@@ -538,9 +555,18 @@ static struct attribute *rapl_events_knl_attr[] = { NULL, }; +/* +* There are no default events, but we need to create +* "events" group (with empty attrs) before updating +* it with detected events. +*/ +static struct attribute *attrs_empty[] = { +NULL , +}; +static struct attribute_group rapl_pmu_events_group = { .name ="events" , - .attrs =NULL ,/* patched at runtime */ + .attrs = attrs_empty, };DEFINE_RAPL_FORMAT_ATTR (event, event,"config:0-7" );
@@ -561,6 +587,79 @@ static const struct attribute_group *rapl_attr_groups[] = { NULL, }; +static struct attribute *rapl_events_cores[] = { +EVENT_PTR (rapl_cores), +EVENT_PTR (rapl_cores_unit), +EVENT_PTR (rapl_cores_scale), +NULL , +}; + +static struct attribute_group rapl_events_cores_group = { + .name ="events" , + .attrs = rapl_events_cores, +}; + +static struct attribute *rapl_events_pkg[] = { +EVENT_PTR (rapl_pkg), +EVENT_PTR (rapl_pkg_unit), +EVENT_PTR (rapl_pkg_scale), +NULL , +}; + +static struct attribute_group rapl_events_pkg_group = { + .name ="events" , + .attrs = rapl_events_pkg, +}; + +static struct attribute *rapl_events_ram[] = { +EVENT_PTR (rapl_ram), +EVENT_PTR (rapl_ram_unit), +EVENT_PTR (rapl_ram_scale), +NULL , +}; + +static struct attribute_group rapl_events_ram_group = { + .name ="events" , + .attrs = rapl_events_ram, +}; + +static struct attribute *rapl_events_gpu[] = { +EVENT_PTR (rapl_gpu), +EVENT_PTR (rapl_gpu_unit), +EVENT_PTR (rapl_gpu_scale), +NULL , +}; + +static struct attribute_group rapl_events_gpu_group = { + .name ="events" , + .attrs = rapl_events_gpu, +}; + +static struct attribute *rapl_events_psys[] = { +EVENT_PTR (rapl_psys), +EVENT_PTR (rapl_psys_unit), +EVENT_PTR (rapl_psys_scale), +NULL , +}; + +static struct attribute_group rapl_events_psys_group = { + .name ="events" , + .attrs = rapl_events_psys, +}; + +static bool test_msr (int idx,void *data) +{ +return test_bit (idx, (unsigned long *) data); +} + +static struct perf_msr rapl_msrs[] = { + [PERF_RAPL_PP0 ] = {MSR_PP0_ENERGY_STATUS , &rapl_events_cores_group, test_msr }, + [PERF_RAPL_PKG ] = {MSR_PKG_ENERGY_STATUS , &rapl_events_pkg_group, test_msr }, + [PERF_RAPL_RAM ] = {MSR_DRAM_ENERGY_STATUS , &rapl_events_ram_group, test_msr }, + [PERF_RAPL_PP1 ] = {MSR_PP1_ENERGY_STATUS , &rapl_events_gpu_group, test_msr }, + [PERF_RAPL_PSYS ] = {MSR_PLATFORM_ENERGY_STATUS , &rapl_events_psys_group, test_msr }, +}; +static int rapl_cpu_offline (unsigned int cpu) {struct rapl_pmu *pmu =cpu_to_rapl_pmu (cpu);
@@ -674,6 +773,15 @@ static void cleanup_rapl_pmus(void)kfree (rapl_pmus); } +const struct attribute_group *rapl_attr_update[] = { + &rapl_events_cores_group, + &rapl_events_pkg_group, + &rapl_events_ram_group, + &rapl_events_gpu_group, + &rapl_events_gpu_group, +NULL , +}; +static int __init init_rapl_pmus (void ) {int maxdie =topology_max_packages () *topology_max_die_per_package ();
@@ -686,6 +794,7 @@ static int __init init_rapl_pmus(void) rapl_pmus->maxdie = maxdie; rapl_pmus->pmu.attr_groups = rapl_attr_groups; + rapl_pmus->pmu.attr_update = rapl_attr_update; rapl_pmus->pmu.task_ctx_nr = perf_invalid_context; rapl_pmus->pmu.event_init = rapl_pmu_event_init; rapl_pmus->pmu.add = rapl_pmu_event_add;
@@ -784,13 +893,94 @@ static const struct x86_cpu_id rapl_cpu_match[] __initconst = {MODULE_DEVICE_TABLE (x86cpu, rapl_cpu_match); +static struct rapl_model model_snb = { + .events =BIT (PERF_RAPL_PP0 ) | +BIT (PERF_RAPL_PKG ) | +BIT (PERF_RAPL_PP1 ), + .apply_quirk = false, +}; + +static struct rapl_model model_snbep = { + .events =BIT (PERF_RAPL_PP0 ) | +BIT (PERF_RAPL_PKG ) | +BIT (PERF_RAPL_RAM ), + .apply_quirk = false, +}; + +static struct rapl_model model_hsw = { + .events =BIT (PERF_RAPL_PP0 ) | +BIT (PERF_RAPL_PKG ) | +BIT (PERF_RAPL_RAM ) | +BIT (PERF_RAPL_PP1 ), + .apply_quirk = false, +}; + +static struct rapl_model model_hsx = { + .events =BIT (PERF_RAPL_PP0 ) | +BIT (PERF_RAPL_PKG ) | +BIT (PERF_RAPL_RAM ), + .apply_quirk = true, +}; + +static struct rapl_model model_knl = { + .events =BIT (PERF_RAPL_PKG ) | +BIT (PERF_RAPL_RAM ), + .apply_quirk = true, +}; + +static struct rapl_model model_skl = { + .events =BIT (PERF_RAPL_PP0 ) | +BIT (PERF_RAPL_PKG ) | +BIT (PERF_RAPL_RAM ) | +BIT (PERF_RAPL_PP1 ) | +BIT (PERF_RAPL_PSYS ), + .apply_quirk = false, +}; + +static const struct x86_cpu_id rapl_model_match[]__initconst = { +X86_RAPL_MODEL_MATCH (INTEL_FAM6_SANDYBRIDGE , model_snb), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_SANDYBRIDGE_X , model_snbep), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_IVYBRIDGE , model_snb), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_IVYBRIDGE_X , model_snbep), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_HASWELL_CORE , model_hsw), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_HASWELL_X , model_hsx), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_HASWELL_ULT , model_hsw), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_HASWELL_GT3E , model_hsw), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_BROADWELL_CORE , model_hsw), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_BROADWELL_GT3E , model_hsw), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_BROADWELL_X , model_hsx), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_BROADWELL_XEON_D , model_hsx), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_XEON_PHI_KNL , model_knl), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_XEON_PHI_KNM , model_knl), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_SKYLAKE_MOBILE , model_skl), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_SKYLAKE_DESKTOP , model_skl), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_SKYLAKE_X , model_hsx), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_KABYLAKE_MOBILE , model_skl), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_KABYLAKE_DESKTOP , model_skl), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_CANNONLAKE_MOBILE , model_skl), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_ATOM_GOLDMONT , model_hsw), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_ATOM_GOLDMONT_X , model_hsw), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_ATOM_GOLDMONT_PLUS , model_hsw), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_ICELAKE_MOBILE , model_skl), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_ICELAKE_DESKTOP , model_skl), + {}, +}; +static int __init rapl_pmu_init (void ) {const struct x86_cpu_id *id;struct intel_rapl_init_fun *rapl_init; +struct rapl_model *rm;bool apply_quirk;int ret; + id =x86_match_cpu (rapl_model_match); +if (!id) +return -ENODEV ; + + rm = (struct rapl_model *) id->driver_data; +perf_msr_probe (rapl_msrs,PERF_RAPL_MAX , false, (void *) &rm->events); + id =x86_match_cpu (rapl_cpu_match);if (!id)return -ENODEV ;
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH v3 5/8 perf/x86/rapl: Get rapl_cntr_mask from new probe framework
In reply to Jiri OlsaWe get rapl_cntr_mask from perf_msr_probe call, as a replacement for current intel_rapl_init_fun::cntr_mask value for each model.
--- arch/x86/events/intel/rapl.c | 38 ++---------------------------------- 1 file changed, 2 insertions(+), 36 deletions(-)
arch/x86/events/intel/rapl.c +2 -36
@@ -96,33 +96,6 @@ static const char *const rapl_domain_names[NR_RAPL_DOMAINS] __initconst = { "psys", }; -/* Clients have PP0, PKG */ -#define RAPL_IDX_CLN (1<<RAPL_IDX_PP0_NRG_STAT|\ - 1<<RAPL_IDX_PKG_NRG_STAT|\ - 1<<RAPL_IDX_PP1_NRG_STAT) - -/* Servers have PP0, PKG, RAM */ -#define RAPL_IDX_SRV (1<<RAPL_IDX_PP0_NRG_STAT|\ - 1<<RAPL_IDX_PKG_NRG_STAT|\ - 1<<RAPL_IDX_RAM_NRG_STAT) - -/* Servers have PP0, PKG, RAM, PP1 */ -#define RAPL_IDX_HSW (1<<RAPL_IDX_PP0_NRG_STAT|\ - 1<<RAPL_IDX_PKG_NRG_STAT|\ - 1<<RAPL_IDX_RAM_NRG_STAT|\ - 1<<RAPL_IDX_PP1_NRG_STAT) - -/* SKL clients have PP0, PKG, RAM, PP1, PSYS */ -#define RAPL_IDX_SKL_CLN (1<<RAPL_IDX_PP0_NRG_STAT|\ - 1<<RAPL_IDX_PKG_NRG_STAT|\ - 1<<RAPL_IDX_RAM_NRG_STAT|\ - 1<<RAPL_IDX_PP1_NRG_STAT|\ - 1<<RAPL_IDX_PSYS_NRG_STAT) - -/* Knights Landing has PKG, RAM */ -#define RAPL_IDX_KNL (1<<RAPL_IDX_PKG_NRG_STAT|\ - 1<<RAPL_IDX_RAM_NRG_STAT) -/* * event code: LSB 8 bits, passed in attr->config * any other bit is reserved
@@ -812,43 +785,36 @@ static int __init init_rapl_pmus(void)struct intel_rapl_init_fun {bool apply_quirk; -int cntr_mask;struct attribute **attrs; };static const struct intel_rapl_init_fun snb_rapl_init__initconst = { .apply_quirk = false, - .cntr_mask =RAPL_IDX_CLN , .attrs = rapl_events_cln_attr, };static const struct intel_rapl_init_fun hsx_rapl_init__initconst = { .apply_quirk = true, - .cntr_mask =RAPL_IDX_SRV , .attrs = rapl_events_srv_attr, };static const struct intel_rapl_init_fun hsw_rapl_init__initconst = { .apply_quirk = false, - .cntr_mask =RAPL_IDX_HSW , .attrs = rapl_events_hsw_attr, };static const struct intel_rapl_init_fun snbep_rapl_init__initconst = { .apply_quirk = false, - .cntr_mask =RAPL_IDX_SRV , .attrs = rapl_events_srv_attr, };static const struct intel_rapl_init_fun knl_rapl_init__initconst = { .apply_quirk = true, - .cntr_mask =RAPL_IDX_KNL , .attrs = rapl_events_knl_attr, };static const struct intel_rapl_init_fun skl_rapl_init__initconst = { .apply_quirk = false, - .cntr_mask =RAPL_IDX_SKL_CLN , .attrs = rapl_events_skl_attr, };
@@ -979,7 +945,8 @@ static int __init rapl_pmu_init(void)return -ENODEV ; rm = (struct rapl_model *) id->driver_data; -perf_msr_probe (rapl_msrs,PERF_RAPL_MAX , false, (void *) &rm->events); + rapl_cntr_mask =perf_msr_probe (rapl_msrs,PERF_RAPL_MAX , + false, (void *) &rm->events); id =x86_match_cpu (rapl_cpu_match);if (!id)
@@ -987,7 +954,6 @@ static int __init rapl_pmu_init(void) rapl_init = (struct intel_rapl_init_fun *)id->driver_data; apply_quirk = rapl_init->apply_quirk; - rapl_cntr_mask = rapl_init->cntr_mask; rapl_pmu_events_group.attrs = rapl_init->attrs; ret =rapl_check_hw_unit (apply_quirk);
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH v3 6/8 perf/x86/rapl: Get msr values from new probe framework
In reply to Jiri OlsaThere's no need to have special code for getting the bit and msr value for given event. We can now easily get it from rapl_msrs array.
Also getting rid of RAPL_IDX_*, which is no longer needed and replacing INTEL_RAPL* with PERF_RAPL* enums.
--- arch/x86/events/intel/rapl.c | 53 ++++++++---------------------------- 1 file changed, 11 insertions(+), 42 deletions(-)
arch/x86/events/intel/rapl.c +11 -42
@@ -55,6 +55,7 @@#include <linux/module.h> #include <linux/slab.h> #include <linux/perf_event.h> +#include <linux/nospec.h> #include <asm/cpu_device_id.h> #include <asm/intel-family.h> #include "../perf_event.h"
@@ -65,19 +66,6 @@ MODULE_LICENSE("GPL");/* * RAPL energy status counters */ -#define RAPL_IDX_PP0_NRG_STAT 0/* all cores */ -#define INTEL_RAPL_PP0 0x1/* pseudo-encoding */ -#define RAPL_IDX_PKG_NRG_STAT 1/* entire package */ -#define INTEL_RAPL_PKG 0x2/* pseudo-encoding */ -#define RAPL_IDX_RAM_NRG_STAT 2/* DRAM */ -#define INTEL_RAPL_RAM 0x3/* pseudo-encoding */ -#define RAPL_IDX_PP1_NRG_STAT 3/* gpu */ -#define INTEL_RAPL_PP1 0x4/* pseudo-encoding */ -#define RAPL_IDX_PSYS_NRG_STAT 4/* psys */ -#define INTEL_RAPL_PSYS 0x5/* pseudo-encoding */ - -#define NR_RAPL_DOMAINS 0x5 -enum perf_rapl_events {PERF_RAPL_PP0 =0 ,/* all cores */ PERF_RAPL_PKG ,/* entire package */
@@ -86,6 +74,7 @@ enum perf_rapl_events {PERF_RAPL_PSYS ,/* psys */ PERF_RAPL_MAX , + NR_RAPL_DOMAINS = PERF_RAPL_MAX, }; static const char *const rapl_domain_names[NR_RAPL_DOMAINS] __initconst = {
@@ -149,6 +138,7 @@ static struct rapl_pmus *rapl_pmus;static cpumask_t rapl_cpu_mask;static unsigned int rapl_cntr_mask;static u64 rapl_timer_ms; +static struct perf_msr rapl_msrs[];static inline struct rapl_pmu *cpu_to_rapl_pmu (unsigned int cpu) {
@@ -340,7 +330,7 @@ static void rapl_pmu_event_del(struct perf_event *event, int flags)static int rapl_pmu_event_init (struct perf_event *event) {u64 cfg = event->attr.config &RAPL_EVENT_MASK ; -int bit, msr, ret =0 ; +int bit, ret =0 ;struct rapl_pmu *pmu;/* only look at RAPL events */
@@ -356,33 +346,12 @@ static int rapl_pmu_event_init(struct perf_event *event) event->event_caps |=PERF_EV_CAP_READ_ACTIVE_PKG ; -/* -* check event is known (determines counter) -*/ -switch (cfg) { -case INTEL_RAPL_PP0 : - bit =RAPL_IDX_PP0_NRG_STAT ; - msr =MSR_PP0_ENERGY_STATUS ; -break ; -case INTEL_RAPL_PKG : - bit =RAPL_IDX_PKG_NRG_STAT ; - msr =MSR_PKG_ENERGY_STATUS ; -break ; -case INTEL_RAPL_RAM : - bit =RAPL_IDX_RAM_NRG_STAT ; - msr =MSR_DRAM_ENERGY_STATUS ; -break ; -case INTEL_RAPL_PP1 : - bit =RAPL_IDX_PP1_NRG_STAT ; - msr =MSR_PP1_ENERGY_STATUS ; -break ; -case INTEL_RAPL_PSYS : - bit =RAPL_IDX_PSYS_NRG_STAT ; - msr =MSR_PLATFORM_ENERGY_STATUS ; -break ; -default : +if (!cfg || cfg >=NR_RAPL_DOMAINS +1 )return -EINVAL ; - } + + cfg =array_index_nospec (cfg,NR_RAPL_DOMAINS +1 ); + bit = cfg -1 ; +/* check event supported */ if (!(rapl_cntr_mask & (1 << bit)))return -EINVAL ;
@@ -397,7 +366,7 @@ static int rapl_pmu_event_init(struct perf_event *event)return -EINVAL ; event->cpu = pmu->cpu; event->pmu_private = pmu; - event->hw.event_base = msr; + event->hw.event_base = rapl_msrs[bit].msr; event->hw.config = cfg; event->hw.idx = bit;
@@ -705,7 +674,7 @@ static int rapl_check_hw_unit(bool apply_quirk)* of 2. Datasheet, September 2014, Reference Number: 330784-001 " */ if (apply_quirk) - rapl_hw_unit[RAPL_IDX_RAM_NRG_STAT ] =16 ; + rapl_hw_unit[PERF_RAPL_RAM ] =16 ;/* * Calculate the timer rate:
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH v3 7/8 perf/x86/rapl: Get attributes from new probe framework
In reply to Jiri OlsaWe no longer need model specific attribute arrays, because we get all this detected in rapl_events_attrs.
--- arch/x86/events/intel/rapl.c | 89 ------------------------------------ 1 file changed, 89 deletions(-)
arch/x86/events/intel/rapl.c +0 -89
@@ -416,87 +416,6 @@ RAPL_EVENT_ATTR_STR(energy-ram.scale, rapl_ram_scale, "2.3283064365386962890RAPL_EVENT_ATTR_STR (energy-gpu.scale, rapl_gpu_scale,"2.3283064365386962890625e-10" );RAPL_EVENT_ATTR_STR (energy-psys.scale, rapl_psys_scale,"2.3283064365386962890625e-10" ); -static struct attribute *rapl_events_srv_attr[] = { -EVENT_PTR (rapl_cores), -EVENT_PTR (rapl_pkg), -EVENT_PTR (rapl_ram), - -EVENT_PTR (rapl_cores_unit), -EVENT_PTR (rapl_pkg_unit), -EVENT_PTR (rapl_ram_unit), - -EVENT_PTR (rapl_cores_scale), -EVENT_PTR (rapl_pkg_scale), -EVENT_PTR (rapl_ram_scale), -NULL , -}; - -static struct attribute *rapl_events_cln_attr[] = { -EVENT_PTR (rapl_cores), -EVENT_PTR (rapl_pkg), -EVENT_PTR (rapl_gpu), - -EVENT_PTR (rapl_cores_unit), -EVENT_PTR (rapl_pkg_unit), -EVENT_PTR (rapl_gpu_unit), - -EVENT_PTR (rapl_cores_scale), -EVENT_PTR (rapl_pkg_scale), -EVENT_PTR (rapl_gpu_scale), -NULL , -}; - -static struct attribute *rapl_events_hsw_attr[] = { -EVENT_PTR (rapl_cores), -EVENT_PTR (rapl_pkg), -EVENT_PTR (rapl_gpu), -EVENT_PTR (rapl_ram), - -EVENT_PTR (rapl_cores_unit), -EVENT_PTR (rapl_pkg_unit), -EVENT_PTR (rapl_gpu_unit), -EVENT_PTR (rapl_ram_unit), - -EVENT_PTR (rapl_cores_scale), -EVENT_PTR (rapl_pkg_scale), -EVENT_PTR (rapl_gpu_scale), -EVENT_PTR (rapl_ram_scale), -NULL , -}; - -static struct attribute *rapl_events_skl_attr[] = { -EVENT_PTR (rapl_cores), -EVENT_PTR (rapl_pkg), -EVENT_PTR (rapl_gpu), -EVENT_PTR (rapl_ram), -EVENT_PTR (rapl_psys), - -EVENT_PTR (rapl_cores_unit), -EVENT_PTR (rapl_pkg_unit), -EVENT_PTR (rapl_gpu_unit), -EVENT_PTR (rapl_ram_unit), -EVENT_PTR (rapl_psys_unit), - -EVENT_PTR (rapl_cores_scale), -EVENT_PTR (rapl_pkg_scale), -EVENT_PTR (rapl_gpu_scale), -EVENT_PTR (rapl_ram_scale), -EVENT_PTR (rapl_psys_scale), -NULL , -}; - -static struct attribute *rapl_events_knl_attr[] = { -EVENT_PTR (rapl_pkg), -EVENT_PTR (rapl_ram), - -EVENT_PTR (rapl_pkg_unit), -EVENT_PTR (rapl_ram_unit), - -EVENT_PTR (rapl_pkg_scale), -EVENT_PTR (rapl_ram_scale), -NULL , -}; -/* * There are no default events, but we need to create * "events" group (with empty attrs) before updating
@@ -754,37 +673,30 @@ static int __init init_rapl_pmus(void)struct intel_rapl_init_fun {bool apply_quirk; -struct attribute **attrs; };static const struct intel_rapl_init_fun snb_rapl_init__initconst = { .apply_quirk = false, - .attrs = rapl_events_cln_attr, };static const struct intel_rapl_init_fun hsx_rapl_init__initconst = { .apply_quirk = true, - .attrs = rapl_events_srv_attr, };static const struct intel_rapl_init_fun hsw_rapl_init__initconst = { .apply_quirk = false, - .attrs = rapl_events_hsw_attr, };static const struct intel_rapl_init_fun snbep_rapl_init__initconst = { .apply_quirk = false, - .attrs = rapl_events_srv_attr, };static const struct intel_rapl_init_fun knl_rapl_init__initconst = { .apply_quirk = true, - .attrs = rapl_events_knl_attr, };static const struct intel_rapl_init_fun skl_rapl_init__initconst = { .apply_quirk = false, - .attrs = rapl_events_skl_attr, };static const struct x86_cpu_id rapl_cpu_match[]__initconst = {
@@ -923,7 +835,6 @@ static int __init rapl_pmu_init(void) rapl_init = (struct intel_rapl_init_fun *)id->driver_data; apply_quirk = rapl_init->apply_quirk; - rapl_pmu_events_group.attrs = rapl_init->attrs; ret =rapl_check_hw_unit (apply_quirk);if (ret)
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH v3 8/8 perf/x86/rapl: Get quirk state from new probe framework
In reply to Jiri OlsaGetting the apply_quirk bool from new rapl_model_match array.
And because apply_quirk was the last remaining piece of data in rapl_cpu_match, replacing it with rapl_model_match as device table.
The switch to new perf_msr_probe detection API is done.
--- arch/x86/events/intel/rapl.c | 82 ++---------------------------------- 1 file changed, 3 insertions(+), 79 deletions(-)
arch/x86/events/intel/rapl.c +3 -79
@@ -671,75 +671,6 @@ static int __init init_rapl_pmus(void)#define X86_RAPL_MODEL_MATCH (model, init) \ { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, (unsigned long)&init } -struct intel_rapl_init_fun { -bool apply_quirk; -}; - -static const struct intel_rapl_init_fun snb_rapl_init__initconst = { - .apply_quirk = false, -}; - -static const struct intel_rapl_init_fun hsx_rapl_init__initconst = { - .apply_quirk = true, -}; - -static const struct intel_rapl_init_fun hsw_rapl_init__initconst = { - .apply_quirk = false, -}; - -static const struct intel_rapl_init_fun snbep_rapl_init__initconst = { - .apply_quirk = false, -}; - -static const struct intel_rapl_init_fun knl_rapl_init__initconst = { - .apply_quirk = true, -}; - -static const struct intel_rapl_init_fun skl_rapl_init__initconst = { - .apply_quirk = false, -}; - -static const struct x86_cpu_id rapl_cpu_match[]__initconst = { -X86_RAPL_MODEL_MATCH (INTEL_FAM6_SANDYBRIDGE , snb_rapl_init), -X86_RAPL_MODEL_MATCH (INTEL_FAM6_SANDYBRIDGE_X , snbep_rapl_init), - -X86_RAPL_MODEL_MATCH (INTEL_FAM6_IVYBRIDGE , snb_rapl_init), -X86_RAPL_MODEL_MATCH (INTEL_FAM6_IVYBRIDGE_X , snbep_rapl_init), - -X86_RAPL_MODEL_MATCH (INTEL_FAM6_HASWELL_CORE , hsw_rapl_init), -X86_RAPL_MODEL_MATCH (INTEL_FAM6_HASWELL_X , hsx_rapl_init), -X86_RAPL_MODEL_MATCH (INTEL_FAM6_HASWELL_ULT , hsw_rapl_init), -X86_RAPL_MODEL_MATCH (INTEL_FAM6_HASWELL_GT3E , hsw_rapl_init), - -X86_RAPL_MODEL_MATCH (INTEL_FAM6_BROADWELL_CORE , hsw_rapl_init), -X86_RAPL_MODEL_MATCH (INTEL_FAM6_BROADWELL_GT3E , hsw_rapl_init), -X86_RAPL_MODEL_MATCH (INTEL_FAM6_BROADWELL_X , hsx_rapl_init), -X86_RAPL_MODEL_MATCH (INTEL_FAM6_BROADWELL_XEON_D , hsx_rapl_init), - -X86_RAPL_MODEL_MATCH (INTEL_FAM6_XEON_PHI_KNL , knl_rapl_init), -X86_RAPL_MODEL_MATCH (INTEL_FAM6_XEON_PHI_KNM , knl_rapl_init), - -X86_RAPL_MODEL_MATCH (INTEL_FAM6_SKYLAKE_MOBILE , skl_rapl_init), -X86_RAPL_MODEL_MATCH (INTEL_FAM6_SKYLAKE_DESKTOP , skl_rapl_init), -X86_RAPL_MODEL_MATCH (INTEL_FAM6_SKYLAKE_X , hsx_rapl_init), - -X86_RAPL_MODEL_MATCH (INTEL_FAM6_KABYLAKE_MOBILE , skl_rapl_init), -X86_RAPL_MODEL_MATCH (INTEL_FAM6_KABYLAKE_DESKTOP , skl_rapl_init), - -X86_RAPL_MODEL_MATCH (INTEL_FAM6_CANNONLAKE_MOBILE , skl_rapl_init), - -X86_RAPL_MODEL_MATCH (INTEL_FAM6_ATOM_GOLDMONT , hsw_rapl_init), -X86_RAPL_MODEL_MATCH (INTEL_FAM6_ATOM_GOLDMONT_X , hsw_rapl_init), - -X86_RAPL_MODEL_MATCH (INTEL_FAM6_ATOM_GOLDMONT_PLUS , hsw_rapl_init), - -X86_RAPL_MODEL_MATCH (INTEL_FAM6_ICELAKE_MOBILE , skl_rapl_init), -X86_RAPL_MODEL_MATCH (INTEL_FAM6_ICELAKE_DESKTOP , skl_rapl_init), - {}, -}; - -MODULE_DEVICE_TABLE (x86cpu, rapl_cpu_match); -static struct rapl_model model_snb = { .events =BIT (PERF_RAPL_PP0 ) | BIT(PERF_RAPL_PKG) |
@@ -813,12 +744,12 @@ static const struct x86_cpu_id rapl_model_match[] __initconst = { {}, }; +MODULE_DEVICE_TABLE (x86cpu, rapl_model_match); +static int __init rapl_pmu_init (void ) {const struct x86_cpu_id *id; -struct intel_rapl_init_fun *rapl_init;struct rapl_model *rm; -bool apply_quirk;int ret; id =x86_match_cpu (rapl_model_match);
@@ -829,14 +760,7 @@ static int __init rapl_pmu_init(void) rapl_cntr_mask =perf_msr_probe (rapl_msrs,PERF_RAPL_MAX , false, (void *) &rm->events); - id =x86_match_cpu (rapl_cpu_match); -if (!id) -return -ENODEV ; - - rapl_init = (struct intel_rapl_init_fun *)id->driver_data; - apply_quirk = rapl_init->apply_quirk; - - ret =rapl_check_hw_unit (apply_quirk); + ret =rapl_check_hw_unit (rm->apply_quirk);if (ret)return ret;
Signature · 1 line
2.21.0
Peter Zijlstra
maintainerRe: [PATCH 6/8] perf/x86/rapl: Get msr values from new probe framework
In reply to Jiri OlsaReview
Quoted 1 line · Jiri Olsa
(quoted diff) +1
-0+ cfg = array_index_nospec(cfg, NR_RAPL_DOMAINS + 1);
This one fails to build on i386. Istr we had issues like that before. This makes it build.
arch/x86/events/intel/rapl.c +1 -1
@@ -349,7 +349,7 @@ static int rapl_pmu_event_init(struct perf_event *event)if (!cfg || cfg >=NR_RAPL_DOMAINS +1 )return -EINVAL ; - cfg =array_index_nospec (cfg,NR_RAPL_DOMAINS +1 ); + cfg =array_index_nospec ((long )cfg,NR_RAPL_DOMAINS +1 ); bit = cfg -1 ;/* check event supported */
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf/x86: Add MSR probe interface
In reply to Jiri Olsaperf/x86: Add MSR probe interface
Commit-ID: 98253a546a468d88b7e782ab67cdf447d3c7bbe2 Gitweb: https://git.kernel.org/tip/98253a546a468d88b7e782ab67cdf447d3c7bbe2 Author: Jiri Olsa <[email protected]> AuthorDate: Sun, 16 Jun 2019 16:03:51 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Mon, 24 Jun 2019 19:28:31 +0200
perf/x86: Add MSR probe interface
Adding perf_msr_probe function to provide interface for checking up on MSR register and set the related attribute group visibility.
User defines following struct for each MSR register:
struct perf_msr {
u64 msr;
struct attribute_group *grp;
bool (*test)(int idx, void *data);
bool no_check;
};Where:
msr - is the MSR address attrs - is attribute groups array to add if the check passed test - is test function pointer
no_check - is bool that bypass the check and adds the
attribute without any test
The array of struct perf_msr is passed into:
perf_msr_probe(struct perf_msr *msr, int cnt, bool zero, void *data)
Together with:
cnt - which is the number of struct msr array elements data - which is user pointer passed to the test function zero - allow counters that returns zero on rdmsr
The perf_msr_probe will executed test code, read the MSR and check the value is != 0. If all these tests pass, related attribute group is kept visible.
Also adding PMU_EVENT_GROUP macro helper to define attribute group for single attribute. It will be used in following patches.
--- arch/x86/events/Makefile | 2 +- arch/x86/events/probe.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ arch/x86/events/probe.h | 29 +++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-)
arch/x86/events/Makefile +1 -1
@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-y += core.o +obj-y += core.o probe.o obj-y += amd/ obj-$(CONFIG_X86_LOCAL_APIC) += msr.o obj-$(CONFIG_CPU_SUP_INTEL) += intel/
arch/x86/events/probe.c new file +45 -0
45 lines not on this page · raw message
arch/x86/events/probe.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ARCH_X86_EVENTS_PROBE_H__ +#define __ARCH_X86_EVENTS_PROBE_H__ +#include <linux/sysfs.h> + +struct perf_msr { +u64 msr; +struct attribute_group *grp; +bool (*test)(int idx,void *data); +bool no_check; +}; + +unsigned long +perf_msr_probe (struct perf_msr *msr,int cnt,bool no_zero,void *data); + +#define __PMU_EVENT_GROUP (_name) \ +static struct attribute *attrs_##_name[] = { \ + &attr_##_name.attr.attr, \ + NULL, \ +} + +#define PMU_EVENT_GROUP (_grp, _name) \ +__PMU_EVENT_GROUP(_name); \ +static struct attribute_group group_##_name = { \ + .name = #_grp, \ + .attrs = attrs_##_name, \ +} + +#endif /* __ARCH_X86_EVENTS_PROBE_H__ */
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf/x86/msr: Use new probe function
In reply to Jiri Olsaperf/x86/msr: Use new probe function
Commit-ID: dde5e72068cd0cd8237f7c2589ec8f587563a390 Gitweb: https://git.kernel.org/tip/dde5e72068cd0cd8237f7c2589ec8f587563a390 Author: Jiri Olsa <[email protected]> AuthorDate: Sun, 16 Jun 2019 16:03:52 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Mon, 24 Jun 2019 19:28:32 +0200
perf/x86/msr: Use new probe function
Using perf_msr_probe function to probe for msr events.
The functionality is the same, with one exception, that perf_msr_probe checks for rdmsr to return value != 0 for given MSR register.
Using the new attribute groups and adding the events via pmu::attr_update.
--- arch/x86/events/msr.c | 110 +++++++++++++++++++++++++++----------------------- 1 file changed, 60 insertions(+), 50 deletions(-)
arch/x86/events/msr.c +60 -50
@@ -1,7 +1,9 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/perf_event.h> +#include <linux/sysfs.h> #include <linux/nospec.h> #include <asm/intel-family.h> +#include "probe.h" enum perf_msr_id {PERF_MSR_TSC =0 ,
@@ -12,32 +14,30 @@ enum perf_msr_id {PERF_MSR_PTSC =5 ,PERF_MSR_IRPERF =6 ,PERF_MSR_THERM =7 , -PERF_MSR_THERM_SNAP =8 , -PERF_MSR_THERM_UNIT =9 , PERF_MSR_EVENT_MAX, }; -static bool test_aperfmperf (int idx) +static bool test_aperfmperf (int idx,void *data) {return boot_cpu_has (X86_FEATURE_APERFMPERF ); } -static bool test_ptsc (int idx) +static bool test_ptsc (int idx,void *data) {return boot_cpu_has (X86_FEATURE_PTSC ); } -static bool test_irperf (int idx) +static bool test_irperf (int idx,void *data) {return boot_cpu_has (X86_FEATURE_IRPERF ); } -static bool test_therm_status (int idx) +static bool test_therm_status (int idx,void *data) {return boot_cpu_has (X86_FEATURE_DTHERM ); } -static bool test_intel (int idx) +static bool test_intel (int idx,void *data) {if (boot_cpu_data.x86_vendor !=X86_VENDOR_INTEL || boot_cpu_data.x86 !=6 )
@@ -98,37 +98,51 @@ static bool test_intel(int idx)return false; } -struct perf_msr { -u64 msr; -struct perf_pmu_events_attr *attr; -bool (*test)(int idx); +PMU_EVENT_ATTR_STRING (tsc, attr_tsc,"event=0x00" ); +PMU_EVENT_ATTR_STRING (aperf, attr_aperf,"event=0x01" ); +PMU_EVENT_ATTR_STRING (mperf, attr_mperf,"event=0x02" ); +PMU_EVENT_ATTR_STRING (pperf, attr_pperf,"event=0x03" ); +PMU_EVENT_ATTR_STRING (smi, attr_smi,"event=0x04" ); +PMU_EVENT_ATTR_STRING (ptsc, attr_ptsc,"event=0x05" ); +PMU_EVENT_ATTR_STRING (irperf, attr_irperf,"event=0x06" ); +PMU_EVENT_ATTR_STRING (cpu_thermal_margin, attr_therm,"event=0x07" ); +PMU_EVENT_ATTR_STRING (cpu_thermal_margin.snapshot, attr_therm_snap,"1" ); +PMU_EVENT_ATTR_STRING (cpu_thermal_margin.unit, attr_therm_unit,"C" ); + +static unsigned long msr_mask; + +PMU_EVENT_GROUP (events, aperf); +PMU_EVENT_GROUP (events, mperf); +PMU_EVENT_GROUP (events, pperf); +PMU_EVENT_GROUP (events, smi); +PMU_EVENT_GROUP (events, ptsc); +PMU_EVENT_GROUP (events, irperf); + +static struct attribute *attrs_therm[] = { + &attr_therm.attr.attr, + &attr_therm_snap.attr.attr, + &attr_therm_unit.attr.attr, +NULL , }; -PMU_EVENT_ATTR_STRING (tsc, evattr_tsc,"event=0x00" ); -PMU_EVENT_ATTR_STRING (aperf, evattr_aperf,"event=0x01" ); -PMU_EVENT_ATTR_STRING (mperf, evattr_mperf,"event=0x02" ); -PMU_EVENT_ATTR_STRING (pperf, evattr_pperf,"event=0x03" ); -PMU_EVENT_ATTR_STRING (smi, evattr_smi,"event=0x04" ); -PMU_EVENT_ATTR_STRING (ptsc, evattr_ptsc,"event=0x05" ); -PMU_EVENT_ATTR_STRING (irperf, evattr_irperf,"event=0x06" ); -PMU_EVENT_ATTR_STRING (cpu_thermal_margin, evattr_therm,"event=0x07" ); -PMU_EVENT_ATTR_STRING (cpu_thermal_margin.snapshot, evattr_therm_snap,"1" ); -PMU_EVENT_ATTR_STRING (cpu_thermal_margin.unit, evattr_therm_unit,"C" ); +static struct attribute_group group_therm = { + .name ="events" , + .attrs = attrs_therm, +};static struct perf_msr msr[] = { - [PERF_MSR_TSC ] = {0 , &evattr_tsc,NULL , }, - [PERF_MSR_APERF ] = {MSR_IA32_APERF , &evattr_aperf, test_aperfmperf, }, - [PERF_MSR_MPERF ] = {MSR_IA32_MPERF , &evattr_mperf, test_aperfmperf, }, - [PERF_MSR_PPERF ] = {MSR_PPERF , &evattr_pperf, test_intel, }, - [PERF_MSR_SMI ] = {MSR_SMI_COUNT , &evattr_smi, test_intel, }, - [PERF_MSR_PTSC ] = {MSR_F15H_PTSC , &evattr_ptsc, test_ptsc, }, - [PERF_MSR_IRPERF ] = {MSR_F17H_IRPERF , &evattr_irperf, test_irperf, }, - [PERF_MSR_THERM ] = {MSR_IA32_THERM_STATUS , &evattr_therm, test_therm_status, }, - [PERF_MSR_THERM_SNAP ] = {MSR_IA32_THERM_STATUS , &evattr_therm_snap, test_therm_status, }, - [PERF_MSR_THERM_UNIT ] = {MSR_IA32_THERM_STATUS , &evattr_therm_unit, test_therm_status, }, + [PERF_MSR_TSC ] = { .no_check = true, }, + [PERF_MSR_APERF ] = {MSR_IA32_APERF , &group_aperf, test_aperfmperf, }, + [PERF_MSR_MPERF ] = {MSR_IA32_MPERF , &group_mperf, test_aperfmperf, }, + [PERF_MSR_PPERF ] = {MSR_PPERF , &group_pperf, test_intel, }, + [PERF_MSR_SMI ] = {MSR_SMI_COUNT , &group_smi, test_intel, }, + [PERF_MSR_PTSC ] = {MSR_F15H_PTSC , &group_ptsc, test_ptsc, }, + [PERF_MSR_IRPERF ] = {MSR_F17H_IRPERF , &group_irperf, test_irperf, }, + [PERF_MSR_THERM ] = {MSR_IA32_THERM_STATUS , &group_therm, test_therm_status, }, }; -static struct attribute *events_attrs[PERF_MSR_EVENT_MAX +1 ] = { +static struct attribute *events_attrs[] = { + &attr_tsc.attr.attr,NULL , };
@@ -153,6 +167,17 @@ static const struct attribute_group *attr_groups[] = { NULL, }; +const struct attribute_group *attr_update[] = { + &group_aperf, + &group_mperf, + &group_pperf, + &group_smi, + &group_ptsc, + &group_irperf, + &group_therm, +NULL , +}; +static int msr_event_init (struct perf_event *event) {u64 cfg = event->attr.config;
@@ -169,7 +194,7 @@ static int msr_event_init(struct perf_event *event) cfg =array_index_nospec ((unsigned long )cfg,PERF_MSR_EVENT_MAX ); -if (!msr[cfg].attr) +if (!(msr_mask & (1 << cfg)))return -EINVAL ; event->hw.idx =-1 ;
@@ -252,32 +277,17 @@ static struct pmu pmu_msr = { .stop = msr_event_stop, .read = msr_event_update, .capabilities = PERF_PMU_CAP_NO_INTERRUPT | PERF_PMU_CAP_NO_EXCLUDE, + .attr_update = attr_update, };static int __init msr_init (void ) { -int i, j =0 ; -if (!boot_cpu_has (X86_FEATURE_TSC )) {pr_cont ("no MSR PMU driver.\n" );return 0 ; } -/* Probe the MSRs. */ -for (i =PERF_MSR_TSC +1 ; i <PERF_MSR_EVENT_MAX ; i++) { -u64 val; - -/* Virt sucks; you cannot tell if a R/O MSR is present :/ */ -if (!msr[i].test (i) ||rdmsrl_safe (msr[i].msr, &val)) - msr[i].attr =NULL ; - } - -/* List remaining MSRs in the sysfs attrs. */ -for (i =0 ; i <PERF_MSR_EVENT_MAX ; i++) { -if (msr[i].attr) - events_attrs[j++] = &msr[i].attr->attr.attr; - } - events_attrs[j] =NULL ; + msr_mask =perf_msr_probe (msr,PERF_MSR_EVENT_MAX , true,NULL );perf_pmu_register (&pmu_msr,"msr" ,-1 );
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf/x86/cstate: Use new probe function
In reply to Jiri Olsaperf/x86/cstate: Use new probe function
Commit-ID: 8f2a28c5859ba33519d90b66bf7f820e36640c98 Gitweb: https://git.kernel.org/tip/8f2a28c5859ba33519d90b66bf7f820e36640c98 Author: Jiri Olsa <[email protected]> AuthorDate: Sun, 16 Jun 2019 16:03:53 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Mon, 24 Jun 2019 19:28:33 +0200
perf/x86/cstate: Use new probe function
Using perf_msr_probe function to probe for cstate events.
The functionality is the same, with one exception, that perf_msr_probe checks for rdmsr to return value != 0 for given MSR register.
Using the new attribute groups and adding the events via pmu::attr_update.
--- arch/x86/events/intel/cstate.c | 152 +++++++++++++++++++++++------------------ 1 file changed, 87 insertions(+), 65 deletions(-)
arch/x86/events/intel/cstate.c +87 -65
@@ -96,6 +96,7 @@#include <asm/cpu_device_id.h> #include <asm/intel-family.h> #include "../perf_event.h" +#include "../probe.h" MODULE_LICENSE ("GPL" );
@@ -144,25 +145,42 @@ enum perf_cstate_core_events {PERF_CSTATE_CORE_EVENT_MAX , }; -PMU_EVENT_ATTR_STRING (c1-residency, evattr_cstate_core_c1,"event=0x00" ); -PMU_EVENT_ATTR_STRING (c3-residency, evattr_cstate_core_c3,"event=0x01" ); -PMU_EVENT_ATTR_STRING (c6-residency, evattr_cstate_core_c6,"event=0x02" ); -PMU_EVENT_ATTR_STRING (c7-residency, evattr_cstate_core_c7,"event=0x03" ); +PMU_EVENT_ATTR_STRING (c1-residency, attr_cstate_core_c1,"event=0x00" ); +PMU_EVENT_ATTR_STRING (c3-residency, attr_cstate_core_c3,"event=0x01" ); +PMU_EVENT_ATTR_STRING (c6-residency, attr_cstate_core_c6,"event=0x02" ); +PMU_EVENT_ATTR_STRING (c7-residency, attr_cstate_core_c7,"event=0x03" ); -static struct perf_cstate_msr core_msr[] = { - [PERF_CSTATE_CORE_C1_RES ] = {MSR_CORE_C1_RES , &evattr_cstate_core_c1 }, - [PERF_CSTATE_CORE_C3_RES ] = {MSR_CORE_C3_RESIDENCY , &evattr_cstate_core_c3 }, - [PERF_CSTATE_CORE_C6_RES ] = {MSR_CORE_C6_RESIDENCY , &evattr_cstate_core_c6 }, - [PERF_CSTATE_CORE_C7_RES ] = {MSR_CORE_C7_RESIDENCY , &evattr_cstate_core_c7 }, +static unsigned long core_msr_mask; + +PMU_EVENT_GROUP (events, cstate_core_c1); +PMU_EVENT_GROUP (events, cstate_core_c3); +PMU_EVENT_GROUP (events, cstate_core_c6); +PMU_EVENT_GROUP (events, cstate_core_c7); + +static bool test_msr (int idx,void *data) +{ +return test_bit (idx, (unsigned long *) data); +} + +static struct perf_msr core_msr[] = { + [PERF_CSTATE_CORE_C1_RES ] = {MSR_CORE_C1_RES , &group_cstate_core_c1, test_msr }, + [PERF_CSTATE_CORE_C3_RES ] = {MSR_CORE_C3_RESIDENCY , &group_cstate_core_c3, test_msr }, + [PERF_CSTATE_CORE_C6_RES ] = {MSR_CORE_C6_RESIDENCY , &group_cstate_core_c6, test_msr }, + [PERF_CSTATE_CORE_C7_RES ] = {MSR_CORE_C7_RESIDENCY , &group_cstate_core_c7, test_msr }, }; -static struct attribute *core_events_attrs[PERF_CSTATE_CORE_EVENT_MAX +1 ] = { +static struct attribute *attrs_empty[] = {NULL , }; +/* +* There are no default events, but we need to create +* "events" group (with empty attrs) before updating +* it with detected events. +*/ static struct attribute_group core_events_attr_group = { .name ="events" , - .attrs = core_events_attrs, + .attrs = attrs_empty, };DEFINE_CSTATE_FORMAT_ATTR (core_event, event,"config:0-63" );
@@ -211,31 +229,37 @@ enum perf_cstate_pkg_events {PERF_CSTATE_PKG_EVENT_MAX , }; -PMU_EVENT_ATTR_STRING (c2-residency, evattr_cstate_pkg_c2,"event=0x00" ); -PMU_EVENT_ATTR_STRING (c3-residency, evattr_cstate_pkg_c3,"event=0x01" ); -PMU_EVENT_ATTR_STRING (c6-residency, evattr_cstate_pkg_c6,"event=0x02" ); -PMU_EVENT_ATTR_STRING (c7-residency, evattr_cstate_pkg_c7,"event=0x03" ); -PMU_EVENT_ATTR_STRING (c8-residency, evattr_cstate_pkg_c8,"event=0x04" ); -PMU_EVENT_ATTR_STRING (c9-residency, evattr_cstate_pkg_c9,"event=0x05" ); -PMU_EVENT_ATTR_STRING (c10-residency, evattr_cstate_pkg_c10,"event=0x06" ); - -static struct perf_cstate_msr pkg_msr[] = { - [PERF_CSTATE_PKG_C2_RES ] = {MSR_PKG_C2_RESIDENCY , &evattr_cstate_pkg_c2 }, - [PERF_CSTATE_PKG_C3_RES ] = {MSR_PKG_C3_RESIDENCY , &evattr_cstate_pkg_c3 }, - [PERF_CSTATE_PKG_C6_RES ] = {MSR_PKG_C6_RESIDENCY , &evattr_cstate_pkg_c6 }, - [PERF_CSTATE_PKG_C7_RES ] = {MSR_PKG_C7_RESIDENCY , &evattr_cstate_pkg_c7 }, - [PERF_CSTATE_PKG_C8_RES ] = {MSR_PKG_C8_RESIDENCY , &evattr_cstate_pkg_c8 }, - [PERF_CSTATE_PKG_C9_RES ] = {MSR_PKG_C9_RESIDENCY , &evattr_cstate_pkg_c9 }, - [PERF_CSTATE_PKG_C10_RES ] = {MSR_PKG_C10_RESIDENCY , &evattr_cstate_pkg_c10 }, -}; - -static struct attribute *pkg_events_attrs[PERF_CSTATE_PKG_EVENT_MAX +1 ] = { -NULL , +PMU_EVENT_ATTR_STRING (c2-residency, attr_cstate_pkg_c2,"event=0x00" ); +PMU_EVENT_ATTR_STRING (c3-residency, attr_cstate_pkg_c3,"event=0x01" ); +PMU_EVENT_ATTR_STRING (c6-residency, attr_cstate_pkg_c6,"event=0x02" ); +PMU_EVENT_ATTR_STRING (c7-residency, attr_cstate_pkg_c7,"event=0x03" ); +PMU_EVENT_ATTR_STRING (c8-residency, attr_cstate_pkg_c8,"event=0x04" ); +PMU_EVENT_ATTR_STRING (c9-residency, attr_cstate_pkg_c9,"event=0x05" ); +PMU_EVENT_ATTR_STRING (c10-residency, attr_cstate_pkg_c10,"event=0x06" ); + +static unsigned long pkg_msr_mask; + +PMU_EVENT_GROUP (events, cstate_pkg_c2); +PMU_EVENT_GROUP (events, cstate_pkg_c3); +PMU_EVENT_GROUP (events, cstate_pkg_c6); +PMU_EVENT_GROUP (events, cstate_pkg_c7); +PMU_EVENT_GROUP (events, cstate_pkg_c8); +PMU_EVENT_GROUP (events, cstate_pkg_c9); +PMU_EVENT_GROUP (events, cstate_pkg_c10); + +static struct perf_msr pkg_msr[] = { + [PERF_CSTATE_PKG_C2_RES ] = {MSR_PKG_C2_RESIDENCY , &group_cstate_pkg_c2, test_msr }, + [PERF_CSTATE_PKG_C3_RES ] = {MSR_PKG_C3_RESIDENCY , &group_cstate_pkg_c3, test_msr }, + [PERF_CSTATE_PKG_C6_RES ] = {MSR_PKG_C6_RESIDENCY , &group_cstate_pkg_c6, test_msr }, + [PERF_CSTATE_PKG_C7_RES ] = {MSR_PKG_C7_RESIDENCY , &group_cstate_pkg_c7, test_msr }, + [PERF_CSTATE_PKG_C8_RES ] = {MSR_PKG_C8_RESIDENCY , &group_cstate_pkg_c8, test_msr }, + [PERF_CSTATE_PKG_C9_RES ] = {MSR_PKG_C9_RESIDENCY , &group_cstate_pkg_c9, test_msr }, + [PERF_CSTATE_PKG_C10_RES ] = {MSR_PKG_C10_RESIDENCY , &group_cstate_pkg_c10, test_msr }, };static struct attribute_group pkg_events_attr_group = { .name ="events" , - .attrs = pkg_events_attrs, + .attrs = attrs_empty, };DEFINE_CSTATE_FORMAT_ATTR (pkg_event, event,"config:0-63" );
@@ -289,7 +313,8 @@ static int cstate_pmu_event_init(struct perf_event *event)if (event->pmu == &cstate_core_pmu) {if (cfg >=PERF_CSTATE_CORE_EVENT_MAX )return -EINVAL ; -if (!core_msr[cfg].attr) + cfg =array_index_nospec ((unsigned long )cfg,PERF_CSTATE_CORE_EVENT_MAX ); +if (!(core_msr_mask & (1 << cfg)))return -EINVAL ; event->hw.event_base = core_msr[cfg].msr; cpu = cpumask_any_and(&cstate_core_cpu_mask,
@@ -298,7 +323,7 @@ static int cstate_pmu_event_init(struct perf_event *event)if (cfg >=PERF_CSTATE_PKG_EVENT_MAX )return -EINVAL ; cfg =array_index_nospec ((unsigned long )cfg,PERF_CSTATE_PKG_EVENT_MAX ); -if (!pkg_msr[cfg].attr) +if (!(pkg_msr_mask & (1 << cfg)))return -EINVAL ; event->hw.event_base = pkg_msr[cfg].msr; cpu = cpumask_any_and(&cstate_pkg_cpu_mask,
@@ -421,8 +446,28 @@ static int cstate_cpu_init(unsigned int cpu)return 0 ; } +const struct attribute_group *core_attr_update[] = { + &group_cstate_core_c1, + &group_cstate_core_c3, + &group_cstate_core_c6, + &group_cstate_core_c7, +NULL , +}; + +const struct attribute_group *pkg_attr_update[] = { + &group_cstate_pkg_c2, + &group_cstate_pkg_c3, + &group_cstate_pkg_c6, + &group_cstate_pkg_c7, + &group_cstate_pkg_c8, + &group_cstate_pkg_c9, + &group_cstate_pkg_c10, +NULL , +}; +static struct pmu cstate_core_pmu = { .attr_groups = core_attr_groups, + .attr_update = core_attr_update, .name ="cstate_core" , .task_ctx_nr = perf_invalid_context, .event_init = cstate_pmu_event_init,
@@ -437,6 +482,7 @@ static struct pmu cstate_core_pmu = {static struct pmu cstate_pkg_pmu = { .attr_groups = pkg_attr_groups, + .attr_update = pkg_attr_update, .name ="cstate_pkg" , .task_ctx_nr = perf_invalid_context, .event_init = cstate_pmu_event_init,
@@ -585,31 +631,6 @@ static const struct x86_cpu_id intel_cstates_match[] __initconst = { };MODULE_DEVICE_TABLE (x86cpu, intel_cstates_match); -/* -* Probe the cstate events and insert the available one into sysfs attrs -* Return false if there are no available events. -*/ -static bool __init cstate_probe_msr (const unsigned long evmsk,int max, -struct perf_cstate_msr *msr, -struct attribute **attrs) -{ -bool found = false; -unsigned int bit; -u64 val; - -for (bit =0 ; bit < max; bit++) { -if (test_bit (bit, &evmsk) && !rdmsrl_safe (msr[bit].msr, &val)) { - *attrs++ = &msr[bit].attr->attr.attr; - found = true; - }else { - msr[bit].attr =NULL ; - } - } - *attrs =NULL ; - -return found; -} -static int __init cstate_probe (const struct cstate_model *cm) {/* SLM has different MSR for PKG C6 */
@@ -621,13 +642,14 @@ static int __init cstate_probe(const struct cstate_model *cm) pkg_msr[PERF_CSTATE_CORE_C6_RES ].msr =MSR_KNL_CORE_C6_RESIDENCY ; - has_cstate_core =cstate_probe_msr (cm->core_events, -PERF_CSTATE_CORE_EVENT_MAX , - core_msr, core_events_attrs); + core_msr_mask =perf_msr_probe (core_msr,PERF_CSTATE_CORE_EVENT_MAX , + true, (void *) &cm->core_events); + + pkg_msr_mask =perf_msr_probe (pkg_msr,PERF_CSTATE_PKG_EVENT_MAX , + true, (void *) &cm->pkg_events); - has_cstate_pkg =cstate_probe_msr (cm->pkg_events, -PERF_CSTATE_PKG_EVENT_MAX , - pkg_msr, pkg_events_attrs); + has_cstate_core = !!core_msr_mask; + has_cstate_pkg = !!pkg_msr_mask;return (has_cstate_core || has_cstate_pkg) ?0 : -ENODEV ; }
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf/x86/rapl: Use new MSR detection interface
In reply to Jiri Olsaperf/x86/rapl: Use new MSR detection interface
Commit-ID: 5fb5273a905ca4cba7aae16e61c26127cadbac5c Gitweb: https://git.kernel.org/tip/5fb5273a905ca4cba7aae16e61c26127cadbac5c Author: Jiri Olsa <[email protected]> AuthorDate: Sun, 16 Jun 2019 16:03:54 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Mon, 24 Jun 2019 19:28:33 +0200
perf/x86/rapl: Use new MSR detection interface
Using perf_msr_probe function to probe for RAPL MSRs.
Adding new rapl_model_match device table, that
gathers events info for given model, following
the MSR and cstate module design.
It will replace the current rapl_cpu_match device
table and detection code in following patches.
--- arch/x86/events/intel/rapl.c | 192 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 191 insertions(+), 1 deletion(-)
arch/x86/events/intel/rapl.c +191 -1
@@ -58,6 +58,7 @@#include <asm/cpu_device_id.h> #include <asm/intel-family.h> #include "../perf_event.h" +#include "../probe.h" MODULE_LICENSE ("GPL" );
@@ -76,6 +77,17 @@ MODULE_LICENSE("GPL");#define INTEL_RAPL_PSYS 0x5/* pseudo-encoding */ #define NR_RAPL_DOMAINS 0x5 + +enum perf_rapl_events { +PERF_RAPL_PP0 =0 ,/* all cores */ +PERF_RAPL_PKG ,/* entire package */ +PERF_RAPL_RAM ,/* DRAM */ +PERF_RAPL_PP1 ,/* gpu */ +PERF_RAPL_PSYS ,/* psys */ + +PERF_RAPL_MAX , +}; +static const char *const rapl_domain_names[NR_RAPL_DOMAINS ]__initconst = {"pp0-core" ,"package" ,
@@ -153,6 +165,11 @@ struct rapl_pmus {struct rapl_pmu *pmus[]; }; +struct rapl_model { +unsigned long events; +bool apply_quirk; +}; +/* 1/2^hw_unit Joule */ static int rapl_hw_unit[NR_RAPL_DOMAINS ]__read_mostly ;static struct rapl_pmus *rapl_pmus;
@@ -538,9 +555,18 @@ static struct attribute *rapl_events_knl_attr[] = { NULL, }; +/* +* There are no default events, but we need to create +* "events" group (with empty attrs) before updating +* it with detected events. +*/ +static struct attribute *attrs_empty[] = { +NULL , +}; +static struct attribute_group rapl_pmu_events_group = { .name ="events" , - .attrs =NULL ,/* patched at runtime */ + .attrs = attrs_empty, };DEFINE_RAPL_FORMAT_ATTR (event, event,"config:0-7" );
@@ -561,6 +587,79 @@ static const struct attribute_group *rapl_attr_groups[] = { NULL, }; +static struct attribute *rapl_events_cores[] = { +EVENT_PTR (rapl_cores), +EVENT_PTR (rapl_cores_unit), +EVENT_PTR (rapl_cores_scale), +NULL , +}; + +static struct attribute_group rapl_events_cores_group = { + .name ="events" , + .attrs = rapl_events_cores, +}; + +static struct attribute *rapl_events_pkg[] = { +EVENT_PTR (rapl_pkg), +EVENT_PTR (rapl_pkg_unit), +EVENT_PTR (rapl_pkg_scale), +NULL , +}; + +static struct attribute_group rapl_events_pkg_group = { + .name ="events" , + .attrs = rapl_events_pkg, +}; + +static struct attribute *rapl_events_ram[] = { +EVENT_PTR (rapl_ram), +EVENT_PTR (rapl_ram_unit), +EVENT_PTR (rapl_ram_scale), +NULL , +}; + +static struct attribute_group rapl_events_ram_group = { + .name ="events" , + .attrs = rapl_events_ram, +}; + +static struct attribute *rapl_events_gpu[] = { +EVENT_PTR (rapl_gpu), +EVENT_PTR (rapl_gpu_unit), +EVENT_PTR (rapl_gpu_scale), +NULL , +}; + +static struct attribute_group rapl_events_gpu_group = { + .name ="events" , + .attrs = rapl_events_gpu, +}; + +static struct attribute *rapl_events_psys[] = { +EVENT_PTR (rapl_psys), +EVENT_PTR (rapl_psys_unit), +EVENT_PTR (rapl_psys_scale), +NULL , +}; + +static struct attribute_group rapl_events_psys_group = { + .name ="events" , + .attrs = rapl_events_psys, +}; + +static bool test_msr (int idx,void *data) +{ +return test_bit (idx, (unsigned long *) data); +} + +static struct perf_msr rapl_msrs[] = { + [PERF_RAPL_PP0 ] = {MSR_PP0_ENERGY_STATUS , &rapl_events_cores_group, test_msr }, + [PERF_RAPL_PKG ] = {MSR_PKG_ENERGY_STATUS , &rapl_events_pkg_group, test_msr }, + [PERF_RAPL_RAM ] = {MSR_DRAM_ENERGY_STATUS , &rapl_events_ram_group, test_msr }, + [PERF_RAPL_PP1 ] = {MSR_PP1_ENERGY_STATUS , &rapl_events_gpu_group, test_msr }, + [PERF_RAPL_PSYS ] = {MSR_PLATFORM_ENERGY_STATUS , &rapl_events_psys_group, test_msr }, +}; +static int rapl_cpu_offline (unsigned int cpu) {struct rapl_pmu *pmu =cpu_to_rapl_pmu (cpu);
@@ -674,6 +773,15 @@ static void cleanup_rapl_pmus(void)kfree (rapl_pmus); } +const struct attribute_group *rapl_attr_update[] = { + &rapl_events_cores_group, + &rapl_events_pkg_group, + &rapl_events_ram_group, + &rapl_events_gpu_group, + &rapl_events_gpu_group, +NULL , +}; +static int __init init_rapl_pmus (void ) {int maxdie =topology_max_packages () *topology_max_die_per_package ();
@@ -686,6 +794,7 @@ static int __init init_rapl_pmus(void) rapl_pmus->maxdie = maxdie; rapl_pmus->pmu.attr_groups = rapl_attr_groups; + rapl_pmus->pmu.attr_update = rapl_attr_update; rapl_pmus->pmu.task_ctx_nr = perf_invalid_context; rapl_pmus->pmu.event_init = rapl_pmu_event_init; rapl_pmus->pmu.add = rapl_pmu_event_add;
@@ -784,13 +893,94 @@ static const struct x86_cpu_id rapl_cpu_match[] __initconst = {MODULE_DEVICE_TABLE (x86cpu, rapl_cpu_match); +static struct rapl_model model_snb = { + .events =BIT (PERF_RAPL_PP0 ) | +BIT (PERF_RAPL_PKG ) | +BIT (PERF_RAPL_PP1 ), + .apply_quirk = false, +}; + +static struct rapl_model model_snbep = { + .events =BIT (PERF_RAPL_PP0 ) | +BIT (PERF_RAPL_PKG ) | +BIT (PERF_RAPL_RAM ), + .apply_quirk = false, +}; + +static struct rapl_model model_hsw = { + .events =BIT (PERF_RAPL_PP0 ) | +BIT (PERF_RAPL_PKG ) | +BIT (PERF_RAPL_RAM ) | +BIT (PERF_RAPL_PP1 ), + .apply_quirk = false, +}; + +static struct rapl_model model_hsx = { + .events =BIT (PERF_RAPL_PP0 ) | +BIT (PERF_RAPL_PKG ) | +BIT (PERF_RAPL_RAM ), + .apply_quirk = true, +}; + +static struct rapl_model model_knl = { + .events =BIT (PERF_RAPL_PKG ) | +BIT (PERF_RAPL_RAM ), + .apply_quirk = true, +}; + +static struct rapl_model model_skl = { + .events =BIT (PERF_RAPL_PP0 ) | +BIT (PERF_RAPL_PKG ) | +BIT (PERF_RAPL_RAM ) | +BIT (PERF_RAPL_PP1 ) | +BIT (PERF_RAPL_PSYS ), + .apply_quirk = false, +}; + +static const struct x86_cpu_id rapl_model_match[]__initconst = { +X86_RAPL_MODEL_MATCH (INTEL_FAM6_SANDYBRIDGE , model_snb), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_SANDYBRIDGE_X , model_snbep), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_IVYBRIDGE , model_snb), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_IVYBRIDGE_X , model_snbep), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_HASWELL_CORE , model_hsw), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_HASWELL_X , model_hsx), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_HASWELL_ULT , model_hsw), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_HASWELL_GT3E , model_hsw), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_BROADWELL_CORE , model_hsw), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_BROADWELL_GT3E , model_hsw), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_BROADWELL_X , model_hsx), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_BROADWELL_XEON_D , model_hsx), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_XEON_PHI_KNL , model_knl), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_XEON_PHI_KNM , model_knl), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_SKYLAKE_MOBILE , model_skl), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_SKYLAKE_DESKTOP , model_skl), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_SKYLAKE_X , model_hsx), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_KABYLAKE_MOBILE , model_skl), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_KABYLAKE_DESKTOP , model_skl), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_CANNONLAKE_MOBILE , model_skl), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_ATOM_GOLDMONT , model_hsw), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_ATOM_GOLDMONT_X , model_hsw), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_ATOM_GOLDMONT_PLUS , model_hsw), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_ICELAKE_MOBILE , model_skl), +X86_RAPL_MODEL_MATCH (INTEL_FAM6_ICELAKE_DESKTOP , model_skl), + {}, +}; +static int __init rapl_pmu_init (void ) {const struct x86_cpu_id *id;struct intel_rapl_init_fun *rapl_init; +struct rapl_model *rm;bool apply_quirk;int ret; + id =x86_match_cpu (rapl_model_match); +if (!id) +return -ENODEV ; + + rm = (struct rapl_model *) id->driver_data; +perf_msr_probe (rapl_msrs,PERF_RAPL_MAX , false, (void *) &rm->events); + id =x86_match_cpu (rapl_cpu_match);if (!id)return -ENODEV ;
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf/x86/rapl: Get rapl_cntr_mask from new probe framework
In reply to Jiri Olsaperf/x86/rapl: Get rapl_cntr_mask from new probe framework
Commit-ID: cd105aed1a9954605d693948efad86cd8e57cb1a Gitweb: https://git.kernel.org/tip/cd105aed1a9954605d693948efad86cd8e57cb1a Author: Jiri Olsa <[email protected]> AuthorDate: Sun, 16 Jun 2019 16:03:55 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Mon, 24 Jun 2019 19:28:34 +0200
perf/x86/rapl: Get rapl_cntr_mask from new probe framework
We get rapl_cntr_mask from perf_msr_probe call, as a replacement for current intel_rapl_init_fun::cntr_mask value for each model.
--- arch/x86/events/intel/rapl.c | 38 ++------------------------------------ 1 file changed, 2 insertions(+), 36 deletions(-)
arch/x86/events/intel/rapl.c +2 -36
@@ -96,33 +96,6 @@ static const char *const rapl_domain_names[NR_RAPL_DOMAINS] __initconst = { "psys", }; -/* Clients have PP0, PKG */ -#define RAPL_IDX_CLN (1<<RAPL_IDX_PP0_NRG_STAT|\ - 1<<RAPL_IDX_PKG_NRG_STAT|\ - 1<<RAPL_IDX_PP1_NRG_STAT) - -/* Servers have PP0, PKG, RAM */ -#define RAPL_IDX_SRV (1<<RAPL_IDX_PP0_NRG_STAT|\ - 1<<RAPL_IDX_PKG_NRG_STAT|\ - 1<<RAPL_IDX_RAM_NRG_STAT) - -/* Servers have PP0, PKG, RAM, PP1 */ -#define RAPL_IDX_HSW (1<<RAPL_IDX_PP0_NRG_STAT|\ - 1<<RAPL_IDX_PKG_NRG_STAT|\ - 1<<RAPL_IDX_RAM_NRG_STAT|\ - 1<<RAPL_IDX_PP1_NRG_STAT) - -/* SKL clients have PP0, PKG, RAM, PP1, PSYS */ -#define RAPL_IDX_SKL_CLN (1<<RAPL_IDX_PP0_NRG_STAT|\ - 1<<RAPL_IDX_PKG_NRG_STAT|\ - 1<<RAPL_IDX_RAM_NRG_STAT|\ - 1<<RAPL_IDX_PP1_NRG_STAT|\ - 1<<RAPL_IDX_PSYS_NRG_STAT) - -/* Knights Landing has PKG, RAM */ -#define RAPL_IDX_KNL (1<<RAPL_IDX_PKG_NRG_STAT|\ - 1<<RAPL_IDX_RAM_NRG_STAT) -/* * event code: LSB 8 bits, passed in attr->config * any other bit is reserved
@@ -812,43 +785,36 @@ static int __init init_rapl_pmus(void)struct intel_rapl_init_fun {bool apply_quirk; -int cntr_mask;struct attribute **attrs; };static const struct intel_rapl_init_fun snb_rapl_init__initconst = { .apply_quirk = false, - .cntr_mask =RAPL_IDX_CLN , .attrs = rapl_events_cln_attr, };static const struct intel_rapl_init_fun hsx_rapl_init__initconst = { .apply_quirk = true, - .cntr_mask =RAPL_IDX_SRV , .attrs = rapl_events_srv_attr, };static const struct intel_rapl_init_fun hsw_rapl_init__initconst = { .apply_quirk = false, - .cntr_mask =RAPL_IDX_HSW , .attrs = rapl_events_hsw_attr, };static const struct intel_rapl_init_fun snbep_rapl_init__initconst = { .apply_quirk = false, - .cntr_mask =RAPL_IDX_SRV , .attrs = rapl_events_srv_attr, };static const struct intel_rapl_init_fun knl_rapl_init__initconst = { .apply_quirk = true, - .cntr_mask =RAPL_IDX_KNL , .attrs = rapl_events_knl_attr, };static const struct intel_rapl_init_fun skl_rapl_init__initconst = { .apply_quirk = false, - .cntr_mask =RAPL_IDX_SKL_CLN , .attrs = rapl_events_skl_attr, };
@@ -979,7 +945,8 @@ static int __init rapl_pmu_init(void)return -ENODEV ; rm = (struct rapl_model *) id->driver_data; -perf_msr_probe (rapl_msrs,PERF_RAPL_MAX , false, (void *) &rm->events); + rapl_cntr_mask =perf_msr_probe (rapl_msrs,PERF_RAPL_MAX , + false, (void *) &rm->events); id =x86_match_cpu (rapl_cpu_match);if (!id)
@@ -987,7 +954,6 @@ static int __init rapl_pmu_init(void) rapl_init = (struct intel_rapl_init_fun *)id->driver_data; apply_quirk = rapl_init->apply_quirk; - rapl_cntr_mask = rapl_init->cntr_mask; rapl_pmu_events_group.attrs = rapl_init->attrs; ret =rapl_check_hw_unit (apply_quirk);
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf/x86/rapl: Get MSR values from new probe framework
In reply to Jiri Olsaperf/x86/rapl: Get MSR values from new probe framework
Commit-ID: 122f1c51b11a9e572263c4965d772381fcef06c5 Gitweb: https://git.kernel.org/tip/122f1c51b11a9e572263c4965d772381fcef06c5 Author: Jiri Olsa <[email protected]> AuthorDate: Sun, 16 Jun 2019 16:03:56 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Mon, 24 Jun 2019 19:28:34 +0200
perf/x86/rapl: Get MSR values from new probe framework
There's no need to have special code for getting
the bit and MSR value for given event. We can
now easily get it from rapl_msrs array.
Also getting rid of RAPL_IDX_*, which is no longer needed and replacing INTEL_RAPL* with PERF_RAPL* enums.
--- arch/x86/events/intel/rapl.c | 53 +++++++++----------------------------------- 1 file changed, 11 insertions(+), 42 deletions(-)
arch/x86/events/intel/rapl.c +11 -42
@@ -55,6 +55,7 @@#include <linux/module.h> #include <linux/slab.h> #include <linux/perf_event.h> +#include <linux/nospec.h> #include <asm/cpu_device_id.h> #include <asm/intel-family.h> #include "../perf_event.h"
@@ -65,19 +66,6 @@ MODULE_LICENSE("GPL");/* * RAPL energy status counters */ -#define RAPL_IDX_PP0_NRG_STAT 0/* all cores */ -#define INTEL_RAPL_PP0 0x1/* pseudo-encoding */ -#define RAPL_IDX_PKG_NRG_STAT 1/* entire package */ -#define INTEL_RAPL_PKG 0x2/* pseudo-encoding */ -#define RAPL_IDX_RAM_NRG_STAT 2/* DRAM */ -#define INTEL_RAPL_RAM 0x3/* pseudo-encoding */ -#define RAPL_IDX_PP1_NRG_STAT 3/* gpu */ -#define INTEL_RAPL_PP1 0x4/* pseudo-encoding */ -#define RAPL_IDX_PSYS_NRG_STAT 4/* psys */ -#define INTEL_RAPL_PSYS 0x5/* pseudo-encoding */ - -#define NR_RAPL_DOMAINS 0x5 -enum perf_rapl_events {PERF_RAPL_PP0 =0 ,/* all cores */ PERF_RAPL_PKG ,/* entire package */
@@ -86,6 +74,7 @@ enum perf_rapl_events {PERF_RAPL_PSYS ,/* psys */ PERF_RAPL_MAX , + NR_RAPL_DOMAINS = PERF_RAPL_MAX, }; static const char *const rapl_domain_names[NR_RAPL_DOMAINS] __initconst = {
@@ -149,6 +138,7 @@ static struct rapl_pmus *rapl_pmus;static cpumask_t rapl_cpu_mask;static unsigned int rapl_cntr_mask;static u64 rapl_timer_ms; +static struct perf_msr rapl_msrs[];static inline struct rapl_pmu *cpu_to_rapl_pmu (unsigned int cpu) {
@@ -340,7 +330,7 @@ static void rapl_pmu_event_del(struct perf_event *event, int flags)static int rapl_pmu_event_init (struct perf_event *event) {u64 cfg = event->attr.config &RAPL_EVENT_MASK ; -int bit, msr, ret =0 ; +int bit, ret =0 ;struct rapl_pmu *pmu;/* only look at RAPL events */
@@ -356,33 +346,12 @@ static int rapl_pmu_event_init(struct perf_event *event) event->event_caps |=PERF_EV_CAP_READ_ACTIVE_PKG ; -/* -* check event is known (determines counter) -*/ -switch (cfg) { -case INTEL_RAPL_PP0 : - bit =RAPL_IDX_PP0_NRG_STAT ; - msr =MSR_PP0_ENERGY_STATUS ; -break ; -case INTEL_RAPL_PKG : - bit =RAPL_IDX_PKG_NRG_STAT ; - msr =MSR_PKG_ENERGY_STATUS ; -break ; -case INTEL_RAPL_RAM : - bit =RAPL_IDX_RAM_NRG_STAT ; - msr =MSR_DRAM_ENERGY_STATUS ; -break ; -case INTEL_RAPL_PP1 : - bit =RAPL_IDX_PP1_NRG_STAT ; - msr =MSR_PP1_ENERGY_STATUS ; -break ; -case INTEL_RAPL_PSYS : - bit =RAPL_IDX_PSYS_NRG_STAT ; - msr =MSR_PLATFORM_ENERGY_STATUS ; -break ; -default : +if (!cfg || cfg >=NR_RAPL_DOMAINS +1 )return -EINVAL ; - } + + cfg =array_index_nospec ((long )cfg,NR_RAPL_DOMAINS +1 ); + bit = cfg -1 ; +/* check event supported */ if (!(rapl_cntr_mask & (1 << bit)))return -EINVAL ;
@@ -397,7 +366,7 @@ static int rapl_pmu_event_init(struct perf_event *event)return -EINVAL ; event->cpu = pmu->cpu; event->pmu_private = pmu; - event->hw.event_base = msr; + event->hw.event_base = rapl_msrs[bit].msr; event->hw.config = cfg; event->hw.idx = bit;
@@ -705,7 +674,7 @@ static int rapl_check_hw_unit(bool apply_quirk)* of 2. Datasheet, September 2014, Reference Number: 330784-001 " */ if (apply_quirk) - rapl_hw_unit[RAPL_IDX_RAM_NRG_STAT ] =16 ; + rapl_hw_unit[PERF_RAPL_RAM ] =16 ;/* * Calculate the timer rate:
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf/x86/rapl: Get quirk state from new probe framework
In reply to Jiri Olsaperf/x86/rapl: Get quirk state from new probe framework
Commit-ID: 637d97b53cdded02da55d0a25cda6fd6af3bd042 Gitweb: https://git.kernel.org/tip/637d97b53cdded02da55d0a25cda6fd6af3bd042 Author: Jiri Olsa <[email protected]> AuthorDate: Sun, 16 Jun 2019 16:03:58 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Mon, 24 Jun 2019 19:28:36 +0200
perf/x86/rapl: Get quirk state from new probe framework
Getting the apply_quirk bool from new rapl_model_match array.
And because apply_quirk was the last remaining piece of data in rapl_cpu_match, replacing it with rapl_model_match as device table.
The switch to new perf_msr_probe detection API is done.
--- arch/x86/events/intel/rapl.c | 82 ++------------------------------------------ 1 file changed, 3 insertions(+), 79 deletions(-)
arch/x86/events/intel/rapl.c +3 -79
@@ -671,75 +671,6 @@ static int __init init_rapl_pmus(void)#define X86_RAPL_MODEL_MATCH (model, init) \ { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, (unsigned long)&init } -struct intel_rapl_init_fun { -bool apply_quirk; -}; - -static const struct intel_rapl_init_fun snb_rapl_init__initconst = { - .apply_quirk = false, -}; - -static const struct intel_rapl_init_fun hsx_rapl_init__initconst = { - .apply_quirk = true, -}; - -static const struct intel_rapl_init_fun hsw_rapl_init__initconst = { - .apply_quirk = false, -}; - -static const struct intel_rapl_init_fun snbep_rapl_init__initconst = { - .apply_quirk = false, -}; - -static const struct intel_rapl_init_fun knl_rapl_init__initconst = { - .apply_quirk = true, -}; - -static const struct intel_rapl_init_fun skl_rapl_init__initconst = { - .apply_quirk = false, -}; - -static const struct x86_cpu_id rapl_cpu_match[]__initconst = { -X86_RAPL_MODEL_MATCH (INTEL_FAM6_SANDYBRIDGE , snb_rapl_init), -X86_RAPL_MODEL_MATCH (INTEL_FAM6_SANDYBRIDGE_X , snbep_rapl_init), - -X86_RAPL_MODEL_MATCH (INTEL_FAM6_IVYBRIDGE , snb_rapl_init), -X86_RAPL_MODEL_MATCH (INTEL_FAM6_IVYBRIDGE_X , snbep_rapl_init), - -X86_RAPL_MODEL_MATCH (INTEL_FAM6_HASWELL_CORE , hsw_rapl_init), -X86_RAPL_MODEL_MATCH (INTEL_FAM6_HASWELL_X , hsx_rapl_init), -X86_RAPL_MODEL_MATCH (INTEL_FAM6_HASWELL_ULT , hsw_rapl_init), -X86_RAPL_MODEL_MATCH (INTEL_FAM6_HASWELL_GT3E , hsw_rapl_init), - -X86_RAPL_MODEL_MATCH (INTEL_FAM6_BROADWELL_CORE , hsw_rapl_init), -X86_RAPL_MODEL_MATCH (INTEL_FAM6_BROADWELL_GT3E , hsw_rapl_init), -X86_RAPL_MODEL_MATCH (INTEL_FAM6_BROADWELL_X , hsx_rapl_init), -X86_RAPL_MODEL_MATCH (INTEL_FAM6_BROADWELL_XEON_D , hsx_rapl_init), - -X86_RAPL_MODEL_MATCH (INTEL_FAM6_XEON_PHI_KNL , knl_rapl_init), -X86_RAPL_MODEL_MATCH (INTEL_FAM6_XEON_PHI_KNM , knl_rapl_init), - -X86_RAPL_MODEL_MATCH (INTEL_FAM6_SKYLAKE_MOBILE , skl_rapl_init), -X86_RAPL_MODEL_MATCH (INTEL_FAM6_SKYLAKE_DESKTOP , skl_rapl_init), -X86_RAPL_MODEL_MATCH (INTEL_FAM6_SKYLAKE_X , hsx_rapl_init), - -X86_RAPL_MODEL_MATCH (INTEL_FAM6_KABYLAKE_MOBILE , skl_rapl_init), -X86_RAPL_MODEL_MATCH (INTEL_FAM6_KABYLAKE_DESKTOP , skl_rapl_init), - -X86_RAPL_MODEL_MATCH (INTEL_FAM6_CANNONLAKE_MOBILE , skl_rapl_init), - -X86_RAPL_MODEL_MATCH (INTEL_FAM6_ATOM_GOLDMONT , hsw_rapl_init), -X86_RAPL_MODEL_MATCH (INTEL_FAM6_ATOM_GOLDMONT_X , hsw_rapl_init), - -X86_RAPL_MODEL_MATCH (INTEL_FAM6_ATOM_GOLDMONT_PLUS , hsw_rapl_init), - -X86_RAPL_MODEL_MATCH (INTEL_FAM6_ICELAKE_MOBILE , skl_rapl_init), -X86_RAPL_MODEL_MATCH (INTEL_FAM6_ICELAKE_DESKTOP , skl_rapl_init), - {}, -}; - -MODULE_DEVICE_TABLE (x86cpu, rapl_cpu_match); -static struct rapl_model model_snb = { .events =BIT (PERF_RAPL_PP0 ) | BIT(PERF_RAPL_PKG) |
@@ -813,12 +744,12 @@ static const struct x86_cpu_id rapl_model_match[] __initconst = { {}, }; +MODULE_DEVICE_TABLE (x86cpu, rapl_model_match); +static int __init rapl_pmu_init (void ) {const struct x86_cpu_id *id; -struct intel_rapl_init_fun *rapl_init;struct rapl_model *rm; -bool apply_quirk;int ret; id =x86_match_cpu (rapl_model_match);
@@ -829,14 +760,7 @@ static int __init rapl_pmu_init(void) rapl_cntr_mask =perf_msr_probe (rapl_msrs,PERF_RAPL_MAX , false, (void *) &rm->events); - id =x86_match_cpu (rapl_cpu_match); -if (!id) -return -ENODEV ; - - rapl_init = (struct intel_rapl_init_fun *)id->driver_data; - apply_quirk = rapl_init->apply_quirk; - - ret =rapl_check_hw_unit (apply_quirk); + ret =rapl_check_hw_unit (rm->apply_quirk);if (ret)return ret;
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf/x86/rapl: Get attributes from new probe framework
In reply to Jiri Olsaperf/x86/rapl: Get attributes from new probe framework
Commit-ID: 5fc1bd84664a5152dcbdba0962c40a6a07fbd78b Gitweb: https://git.kernel.org/tip/5fc1bd84664a5152dcbdba0962c40a6a07fbd78b Author: Jiri Olsa <[email protected]> AuthorDate: Sun, 16 Jun 2019 16:03:57 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Mon, 24 Jun 2019 19:28:35 +0200
perf/x86/rapl: Get attributes from new probe framework
We no longer need model specific attribute arrays, because we get all this detected in rapl_events_attrs.
--- arch/x86/events/intel/rapl.c | 89 -------------------------------------------- 1 file changed, 89 deletions(-)
arch/x86/events/intel/rapl.c +0 -89
@@ -416,87 +416,6 @@ RAPL_EVENT_ATTR_STR(energy-ram.scale, rapl_ram_scale, "2.3283064365386962890RAPL_EVENT_ATTR_STR (energy-gpu.scale, rapl_gpu_scale,"2.3283064365386962890625e-10" );RAPL_EVENT_ATTR_STR (energy-psys.scale, rapl_psys_scale,"2.3283064365386962890625e-10" ); -static struct attribute *rapl_events_srv_attr[] = { -EVENT_PTR (rapl_cores), -EVENT_PTR (rapl_pkg), -EVENT_PTR (rapl_ram), - -EVENT_PTR (rapl_cores_unit), -EVENT_PTR (rapl_pkg_unit), -EVENT_PTR (rapl_ram_unit), - -EVENT_PTR (rapl_cores_scale), -EVENT_PTR (rapl_pkg_scale), -EVENT_PTR (rapl_ram_scale), -NULL , -}; - -static struct attribute *rapl_events_cln_attr[] = { -EVENT_PTR (rapl_cores), -EVENT_PTR (rapl_pkg), -EVENT_PTR (rapl_gpu), - -EVENT_PTR (rapl_cores_unit), -EVENT_PTR (rapl_pkg_unit), -EVENT_PTR (rapl_gpu_unit), - -EVENT_PTR (rapl_cores_scale), -EVENT_PTR (rapl_pkg_scale), -EVENT_PTR (rapl_gpu_scale), -NULL , -}; - -static struct attribute *rapl_events_hsw_attr[] = { -EVENT_PTR (rapl_cores), -EVENT_PTR (rapl_pkg), -EVENT_PTR (rapl_gpu), -EVENT_PTR (rapl_ram), - -EVENT_PTR (rapl_cores_unit), -EVENT_PTR (rapl_pkg_unit), -EVENT_PTR (rapl_gpu_unit), -EVENT_PTR (rapl_ram_unit), - -EVENT_PTR (rapl_cores_scale), -EVENT_PTR (rapl_pkg_scale), -EVENT_PTR (rapl_gpu_scale), -EVENT_PTR (rapl_ram_scale), -NULL , -}; - -static struct attribute *rapl_events_skl_attr[] = { -EVENT_PTR (rapl_cores), -EVENT_PTR (rapl_pkg), -EVENT_PTR (rapl_gpu), -EVENT_PTR (rapl_ram), -EVENT_PTR (rapl_psys), - -EVENT_PTR (rapl_cores_unit), -EVENT_PTR (rapl_pkg_unit), -EVENT_PTR (rapl_gpu_unit), -EVENT_PTR (rapl_ram_unit), -EVENT_PTR (rapl_psys_unit), - -EVENT_PTR (rapl_cores_scale), -EVENT_PTR (rapl_pkg_scale), -EVENT_PTR (rapl_gpu_scale), -EVENT_PTR (rapl_ram_scale), -EVENT_PTR (rapl_psys_scale), -NULL , -}; - -static struct attribute *rapl_events_knl_attr[] = { -EVENT_PTR (rapl_pkg), -EVENT_PTR (rapl_ram), - -EVENT_PTR (rapl_pkg_unit), -EVENT_PTR (rapl_ram_unit), - -EVENT_PTR (rapl_pkg_scale), -EVENT_PTR (rapl_ram_scale), -NULL , -}; -/* * There are no default events, but we need to create * "events" group (with empty attrs) before updating
@@ -754,37 +673,30 @@ static int __init init_rapl_pmus(void)struct intel_rapl_init_fun {bool apply_quirk; -struct attribute **attrs; };static const struct intel_rapl_init_fun snb_rapl_init__initconst = { .apply_quirk = false, - .attrs = rapl_events_cln_attr, };static const struct intel_rapl_init_fun hsx_rapl_init__initconst = { .apply_quirk = true, - .attrs = rapl_events_srv_attr, };static const struct intel_rapl_init_fun hsw_rapl_init__initconst = { .apply_quirk = false, - .attrs = rapl_events_hsw_attr, };static const struct intel_rapl_init_fun snbep_rapl_init__initconst = { .apply_quirk = false, - .attrs = rapl_events_srv_attr, };static const struct intel_rapl_init_fun knl_rapl_init__initconst = { .apply_quirk = true, - .attrs = rapl_events_knl_attr, };static const struct intel_rapl_init_fun skl_rapl_init__initconst = { .apply_quirk = false, - .attrs = rapl_events_skl_attr, };static const struct x86_cpu_id rapl_cpu_match[]__initconst = {
@@ -923,7 +835,6 @@ static int __init rapl_pmu_init(void) rapl_init = (struct intel_rapl_init_fun *)id->driver_data; apply_quirk = rapl_init->apply_quirk; - rapl_pmu_events_group.attrs = rapl_init->attrs; ret =rapl_check_hw_unit (apply_quirk);if (ret)