perf/amd/uncore: Support user core/thread and slice specification
Subsystems (2)
cover perf/amd/uncore: Support user core/thread and slice specification
Add support for AMD's uncore L3 PMUs to count events by core/thread and/or by L3 slice.
The first patch rewrites most of the initial F17h support to enhance readability and to prepare for the new upcoming attributes.
The second patch adds support for F17h's threadmask and slicemask.
The third patch adds support for F19h's threadmask, coreid, sliceid, enallcores, and enallslices. F19h hardware can only count one core or slice, or all of them at one time.
The last patch makes the driver's dmesg output more useful.
Kim Phillips (4):
perf/amd/uncore: Prepare to scale for more attributes that vary per
family
perf/amd/uncore: Allow F17h user threadmask and slicemask
specification
perf/amd/uncore: Allow F19h user coreid, threadmask, and sliceid
specification
perf/amd/uncore: Inform the user how many counters each uncore PMU has
arch/x86/events/amd/uncore.c | 174 ++++++++++++++++++++++------------- 1 file changed, 111 insertions(+), 63 deletions(-)
Signature · 1 line
2.27.0
PATCH 1/4 perf/amd/uncore: Prepare to scale for more attributes that vary per family
Replace AMD_FORMAT_ATTR with the more apropos DEFINE_UNCORE_FORMAT_ATTR stolen from arch/x86/events/intel/uncore.h. This way we can clearly see the bit-variants of each of the attributes that want to have the same name across families.
Also unroll AMD_ATTRIBUTE because we are going to separately add new attributes that differ between DF and L3.
Also clean up the if-Family 17h-else logic in amd_uncore_init.
This is basically a rewrite of commit da6adaea2b7e ("perf/x86/amd/uncore: Update sysfs attributes for Family17h processors").
No functional changes.
Tested F17h+ /sys/bus/event_source/devices/amd_{l3,df}/format/* content remains unchanged:
/sys/bus/event_source/devices/amd_l3/format/event:config:0-7 /sys/bus/event_source/devices/amd_l3/format/umask:config:8-15 /sys/bus/event_source/devices/amd_df/format/event:config:0-7,32-35,59-60 /sys/bus/event_source/devices/amd_df/format/umask:config:8-15
--- arch/x86/events/amd/uncore.c | 111 +++++++++++++++++++---------------- 1 file changed, 61 insertions(+), 50 deletions(-)
arch/x86/events/amd/uncore.c +61 -50
@@ -262,47 +262,60 @@ static struct attribute_group amd_uncore_attr_group = { .attrs = amd_uncore_attrs, }; -/* -* Similar to PMU_FORMAT_ATTR but allowing for format_attr to be assigned based -* on family -*/ -#define AMD_FORMAT_ATTR (_dev, _name, _format) \ -static ssize_t \ -_dev##_show##_name(struct device *dev, \ - struct device_attribute *attr, \ - char *page) \ -{ \ - BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \ - return sprintf(page, _format "\n"); \ -} \ -static struct device_attribute format_attr_##_dev##_name = __ATTR_RO(_dev); - -/* Used for each uncore counter type */ -#define AMD_ATTRIBUTE (_name) \ -static struct attribute *amd_uncore_format_attr_##_name[] = { \ - &format_attr_event_##_name.attr, \ - &format_attr_umask.attr, \ - NULL, \ -}; \ -static struct attribute_group amd_uncore_format_group_##_name = { \ - .name = "format", \ - .attrs = amd_uncore_format_attr_##_name, \ -}; \ -static const struct attribute_group *amd_uncore_attr_groups_##_name[] = { \ - &amd_uncore_attr_group, \ - &amd_uncore_format_group_##_name, \ - NULL, \ +#define DEFINE_UNCORE_FORMAT_ATTR (_var, _name, _format) \ +static ssize_t __uncore_##_var##_show(struct kobject *kobj, \ + struct kobj_attribute *attr, \ + char *page) \ +{ \ + BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \ + return sprintf(page, _format "\n"); \ +} \ +static struct kobj_attribute format_attr_##_var = \ + __ATTR(_name, 0444, __uncore_##_var##_show, NULL) + +DEFINE_UNCORE_FORMAT_ATTR (event12, event,"config:0-7,32-35" ); +DEFINE_UNCORE_FORMAT_ATTR (event14, event,"config:0-7,32-35,59-60" );/* F17h+ DF */ +DEFINE_UNCORE_FORMAT_ATTR (event8, event,"config:0-7" );/* F17h+ L3 */ +DEFINE_UNCORE_FORMAT_ATTR (umask, umask,"config:8-15" ); + +static struct attribute *amd_uncore_df_format_attr[] = { + &format_attr_event12.attr,/* event14 if F17h+ */ + &format_attr_umask.attr, +NULL , +}; + +static struct attribute *amd_uncore_l3_format_attr[] = { + &format_attr_event12.attr,/* event8 if F17h+ */ + &format_attr_umask.attr, +NULL , +}; + +static struct attribute_group amd_uncore_df_format_group = { + .name ="format" , + .attrs = amd_uncore_df_format_attr, +}; + +static struct attribute_group amd_uncore_l3_format_group = { + .name ="format" , + .attrs = amd_uncore_l3_format_attr, }; -AMD_FORMAT_ATTR(event, , "config:0-7,32-35"); -AMD_FORMAT_ATTR(umask, , "config:8-15"); -AMD_FORMAT_ATTR (event, _df,"config:0-7,32-35,59-60" ); -AMD_FORMAT_ATTR (event, _l3,"config:0-7" ); -AMD_ATTRIBUTE (df); -AMD_ATTRIBUTE (l3); +static const struct attribute_group *amd_uncore_df_attr_groups[] = { + &amd_uncore_attr_group, + &amd_uncore_df_format_group, +NULL , +}; + +static const struct attribute_group *amd_uncore_l3_attr_groups[] = { + &amd_uncore_attr_group, + &amd_uncore_l3_format_group, +NULL , +};static struct pmu amd_nb_pmu = { .task_ctx_nr = perf_invalid_context, + .attr_groups = amd_uncore_df_attr_groups, + .name ="amd_nb" , .event_init = amd_uncore_event_init, .add = amd_uncore_add, .del = amd_uncore_del,
@@ -314,6 +327,8 @@ static struct pmu amd_nb_pmu = {static struct pmu amd_llc_pmu = { .task_ctx_nr = perf_invalid_context, + .attr_groups = amd_uncore_l3_attr_groups, + .name ="amd_l2" , .event_init = amd_uncore_event_init, .add = amd_uncore_add, .del = amd_uncore_del,
@@ -517,6 +532,8 @@ static int amd_uncore_cpu_dead(unsigned int cpu)static int __init amd_uncore_init (void ) { +struct attribute **df_attr = amd_uncore_df_format_attr; +struct attribute **l3_attr = amd_uncore_l3_format_attr;int ret = -ENODEV ; if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD &&
@@ -526,6 +543,8 @@ static int __init amd_uncore_init(void)if (!boot_cpu_has (X86_FEATURE_TOPOEXT ))return -ENODEV ; + num_counters_nb =NUM_COUNTERS_NB ; + num_counters_llc =NUM_COUNTERS_L2 ;if (boot_cpu_data.x86 >=0x17 ) {/* * For F17h and above, the Northbridge counters are
@@ -533,27 +552,16 @@ static int __init amd_uncore_init(void)* counters are supported too. The PMUs are exported * based on family as either L2 or L3 and NB or DF. */ - num_counters_nb =NUM_COUNTERS_NB ; num_counters_llc =NUM_COUNTERS_L3 ; amd_nb_pmu.name ="amd_df" ; amd_llc_pmu.name ="amd_l3" ; - format_attr_event_df.show = &event_show_df; - format_attr_event_l3.show = &event_show_l3; l3_mask = true; - }else { - num_counters_nb =NUM_COUNTERS_NB ; - num_counters_llc =NUM_COUNTERS_L2 ; - amd_nb_pmu.name ="amd_nb" ; - amd_llc_pmu.name ="amd_l2" ; - format_attr_event_df = format_attr_event; - format_attr_event_l3 = format_attr_event; - l3_mask = false; } - amd_nb_pmu.attr_groups = amd_uncore_attr_groups_df; - amd_llc_pmu.attr_groups = amd_uncore_attr_groups_l3; -if (boot_cpu_has (X86_FEATURE_PERFCTR_NB )) { +if (boot_cpu_data.x86 >=0x17 ) + *df_attr = &format_attr_event14.attr; + amd_uncore_nb = alloc_percpu(struct amd_uncore *);if (!amd_uncore_nb) { ret = -ENOMEM ;
@@ -570,6 +578,9 @@ static int __init amd_uncore_init(void) }if (boot_cpu_has (X86_FEATURE_PERFCTR_LLC )) { +if (boot_cpu_data.x86 >=0x17 ) + *l3_attr = &format_attr_event8.attr; + amd_uncore_llc = alloc_percpu(struct amd_uncore *);if (!amd_uncore_llc) { ret = -ENOMEM ;
Signature · 1 line
2.27.0
[tip: perf/core] perf/amd/uncore: Prepare to scale for more attributes that vary per family
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 06f2c24584f31bc16129643bfb8239a1af82a17f Gitweb: https://git.kernel.org/tip/06f2c24584f31bc16129643bfb8239a1af82a17f Author: Kim Phillips <[email protected]> AuthorDate: Mon, 21 Sep 2020 09:43:27 -05:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Thu, 24 Sep 2020 15:55:49 +02:00
perf/amd/uncore: Prepare to scale for more attributes that vary per family
Replace AMD_FORMAT_ATTR with the more apropos DEFINE_UNCORE_FORMAT_ATTR stolen from arch/x86/events/intel/uncore.h. This way we can clearly see the bit-variants of each of the attributes that want to have the same name across families.
Also unroll AMD_ATTRIBUTE because we are going to separately add new attributes that differ between DF and L3.
Also clean up the if-Family 17h-else logic in amd_uncore_init.
This is basically a rewrite of commit da6adaea2b7e ("perf/x86/amd/uncore: Update sysfs attributes for Family17h processors").
No functional changes.
Tested F17h+ /sys/bus/event_source/devices/amd_{l3,df}/format/* content remains unchanged:
/sys/bus/event_source/devices/amd_l3/format/event:config:0-7 /sys/bus/event_source/devices/amd_l3/format/umask:config:8-15 /sys/bus/event_source/devices/amd_df/format/event:config:0-7,32-35,59-60 /sys/bus/event_source/devices/amd_df/format/umask:config:8-15
--- arch/x86/events/amd/uncore.c | 111 ++++++++++++++++++---------------- 1 file changed, 61 insertions(+), 50 deletions(-)
arch/x86/events/amd/uncore.c +61 -50
@@ -262,47 +262,60 @@ static struct attribute_group amd_uncore_attr_group = { .attrs = amd_uncore_attrs, }; -/* -* Similar to PMU_FORMAT_ATTR but allowing for format_attr to be assigned based -* on family -*/ -#define AMD_FORMAT_ATTR (_dev, _name, _format) \ -static ssize_t \ -_dev##_show##_name(struct device *dev, \ - struct device_attribute *attr, \ - char *page) \ -{ \ - BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \ - return sprintf(page, _format "\n"); \ -} \ -static struct device_attribute format_attr_##_dev##_name = __ATTR_RO(_dev); - -/* Used for each uncore counter type */ -#define AMD_ATTRIBUTE (_name) \ -static struct attribute *amd_uncore_format_attr_##_name[] = { \ - &format_attr_event_##_name.attr, \ - &format_attr_umask.attr, \ - NULL, \ -}; \ -static struct attribute_group amd_uncore_format_group_##_name = { \ - .name = "format", \ - .attrs = amd_uncore_format_attr_##_name, \ -}; \ -static const struct attribute_group *amd_uncore_attr_groups_##_name[] = { \ - &amd_uncore_attr_group, \ - &amd_uncore_format_group_##_name, \ - NULL, \ +#define DEFINE_UNCORE_FORMAT_ATTR (_var, _name, _format) \ +static ssize_t __uncore_##_var##_show(struct kobject *kobj, \ + struct kobj_attribute *attr, \ + char *page) \ +{ \ + BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \ + return sprintf(page, _format "\n"); \ +} \ +static struct kobj_attribute format_attr_##_var = \ + __ATTR(_name, 0444, __uncore_##_var##_show, NULL) + +DEFINE_UNCORE_FORMAT_ATTR (event12, event,"config:0-7,32-35" ); +DEFINE_UNCORE_FORMAT_ATTR (event14, event,"config:0-7,32-35,59-60" );/* F17h+ DF */ +DEFINE_UNCORE_FORMAT_ATTR (event8, event,"config:0-7" );/* F17h+ L3 */ +DEFINE_UNCORE_FORMAT_ATTR (umask, umask,"config:8-15" ); + +static struct attribute *amd_uncore_df_format_attr[] = { + &format_attr_event12.attr,/* event14 if F17h+ */ + &format_attr_umask.attr, +NULL , +}; + +static struct attribute *amd_uncore_l3_format_attr[] = { + &format_attr_event12.attr,/* event8 if F17h+ */ + &format_attr_umask.attr, +NULL , +}; + +static struct attribute_group amd_uncore_df_format_group = { + .name ="format" , + .attrs = amd_uncore_df_format_attr, +}; + +static struct attribute_group amd_uncore_l3_format_group = { + .name ="format" , + .attrs = amd_uncore_l3_format_attr, }; -AMD_FORMAT_ATTR(event, , "config:0-7,32-35"); -AMD_FORMAT_ATTR(umask, , "config:8-15"); -AMD_FORMAT_ATTR (event, _df,"config:0-7,32-35,59-60" ); -AMD_FORMAT_ATTR (event, _l3,"config:0-7" ); -AMD_ATTRIBUTE (df); -AMD_ATTRIBUTE (l3); +static const struct attribute_group *amd_uncore_df_attr_groups[] = { + &amd_uncore_attr_group, + &amd_uncore_df_format_group, +NULL , +}; + +static const struct attribute_group *amd_uncore_l3_attr_groups[] = { + &amd_uncore_attr_group, + &amd_uncore_l3_format_group, +NULL , +};static struct pmu amd_nb_pmu = { .task_ctx_nr = perf_invalid_context, + .attr_groups = amd_uncore_df_attr_groups, + .name ="amd_nb" , .event_init = amd_uncore_event_init, .add = amd_uncore_add, .del = amd_uncore_del,
@@ -314,6 +327,8 @@ static struct pmu amd_nb_pmu = {static struct pmu amd_llc_pmu = { .task_ctx_nr = perf_invalid_context, + .attr_groups = amd_uncore_l3_attr_groups, + .name ="amd_l2" , .event_init = amd_uncore_event_init, .add = amd_uncore_add, .del = amd_uncore_del,
@@ -517,6 +532,8 @@ static int amd_uncore_cpu_dead(unsigned int cpu)static int __init amd_uncore_init (void ) { +struct attribute **df_attr = amd_uncore_df_format_attr; +struct attribute **l3_attr = amd_uncore_l3_format_attr;int ret = -ENODEV ; if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD &&
@@ -526,6 +543,8 @@ static int __init amd_uncore_init(void)if (!boot_cpu_has (X86_FEATURE_TOPOEXT ))return -ENODEV ; + num_counters_nb =NUM_COUNTERS_NB ; + num_counters_llc =NUM_COUNTERS_L2 ;if (boot_cpu_data.x86 >=0x17 ) {/* * For F17h and above, the Northbridge counters are
@@ -533,27 +552,16 @@ static int __init amd_uncore_init(void)* counters are supported too. The PMUs are exported * based on family as either L2 or L3 and NB or DF. */ - num_counters_nb =NUM_COUNTERS_NB ; num_counters_llc =NUM_COUNTERS_L3 ; amd_nb_pmu.name ="amd_df" ; amd_llc_pmu.name ="amd_l3" ; - format_attr_event_df.show = &event_show_df; - format_attr_event_l3.show = &event_show_l3; l3_mask = true; - }else { - num_counters_nb =NUM_COUNTERS_NB ; - num_counters_llc =NUM_COUNTERS_L2 ; - amd_nb_pmu.name ="amd_nb" ; - amd_llc_pmu.name ="amd_l2" ; - format_attr_event_df = format_attr_event; - format_attr_event_l3 = format_attr_event; - l3_mask = false; } - amd_nb_pmu.attr_groups = amd_uncore_attr_groups_df; - amd_llc_pmu.attr_groups = amd_uncore_attr_groups_l3; -if (boot_cpu_has (X86_FEATURE_PERFCTR_NB )) { +if (boot_cpu_data.x86 >=0x17 ) + *df_attr = &format_attr_event14.attr; + amd_uncore_nb = alloc_percpu(struct amd_uncore *);if (!amd_uncore_nb) { ret = -ENOMEM ;
@@ -570,6 +578,9 @@ static int __init amd_uncore_init(void) }if (boot_cpu_has (X86_FEATURE_PERFCTR_LLC )) { +if (boot_cpu_data.x86 >=0x17 ) + *l3_attr = &format_attr_event8.attr; + amd_uncore_llc = alloc_percpu(struct amd_uncore *);if (!amd_uncore_llc) { ret = -ENOMEM ;
PATCH 2/4 perf/amd/uncore: Allow F17h user threadmask and slicemask specification
In reply to Kim PhillipsContinue to fully populate either one of threadmask or slicemask if the user doesn't.
--- arch/x86/events/amd/uncore.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)
arch/x86/events/amd/uncore.c +16 -7
@@ -181,13 +181,14 @@ static void amd_uncore_del(struct perf_event *event, int flags) }/* -* Return a full thread and slice mask until per-CPU is -* properly supported. +* Return a full thread and slice mask unless user +* has provided them */ -static u64 l3_thread_slice_mask (void ) +static u64 l3_thread_slice_mask (u64 config) {if (boot_cpu_data.x86 <=0x18 ) -return AMD64_L3_SLICE_MASK |AMD64_L3_THREAD_MASK ; +return ((config &AMD64_L3_SLICE_MASK ) ? :AMD64_L3_SLICE_MASK ) | + ((config &AMD64_L3_THREAD_MASK ) ? :AMD64_L3_THREAD_MASK );return AMD64_L3_EN_ALL_SLICES |AMD64_L3_EN_ALL_CORES |AMD64_L3_F19H_THREAD_MASK ;
@@ -220,7 +221,7 @@ static int amd_uncore_event_init(struct perf_event *event)* For other events, the two fields do not affect the count. */ if (l3_mask &&is_llc_event (event)) - hwc->config |=l3_thread_slice_mask (); + hwc->config |=l3_thread_slice_mask (event->attr.config); uncore =event_to_amd_uncore (event);if (!uncore)
@@ -277,6 +278,8 @@ DEFINE_UNCORE_FORMAT_ATTR(event12, event, "config:0-7,32-35");DEFINE_UNCORE_FORMAT_ATTR (event14, event,"config:0-7,32-35,59-60" );/* F17h+ DF */ DEFINE_UNCORE_FORMAT_ATTR (event8, event,"config:0-7" );/* F17h+ L3 */ DEFINE_UNCORE_FORMAT_ATTR (umask, umask,"config:8-15" ); +DEFINE_UNCORE_FORMAT_ATTR (slicemask, slicemask,"config:48-51" );/* F17h L3 */ +DEFINE_UNCORE_FORMAT_ATTR (threadmask8, threadmask,"config:56-63" );/* F17h L3 */ static struct attribute *amd_uncore_df_format_attr[] = { &format_attr_event12.attr,/* event14 if F17h+ */
@@ -287,6 +290,8 @@ static struct attribute *amd_uncore_df_format_attr[] = {static struct attribute *amd_uncore_l3_format_attr[] = { &format_attr_event12.attr,/* event8 if F17h+ */ &format_attr_umask.attr, +NULL ,/* slicemask if F17h */ +NULL ,/* threadmask8 if F17h */ NULL , };
@@ -578,8 +583,12 @@ static int __init amd_uncore_init(void) }if (boot_cpu_has (X86_FEATURE_PERFCTR_LLC )) { -if (boot_cpu_data.x86 >=0x17 ) - *l3_attr = &format_attr_event8.attr; +if (boot_cpu_data.x86 >=0x17 ) { + *l3_attr++ = &format_attr_event8.attr; + *l3_attr++ = &format_attr_umask.attr; + *l3_attr++ = &format_attr_slicemask.attr; + *l3_attr++ = &format_attr_threadmask8.attr; + } amd_uncore_llc = alloc_percpu(struct amd_uncore *);if (!amd_uncore_llc) {
Signature · 1 line
2.27.0
[tip: perf/core] perf/amd/uncore: Allow F17h user threadmask and slicemask specification
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 8170f386f19ca7120393c957d4bfbdc07f964ab6 Gitweb: https://git.kernel.org/tip/8170f386f19ca7120393c957d4bfbdc07f964ab6 Author: Kim Phillips <[email protected]> AuthorDate: Mon, 21 Sep 2020 09:43:28 -05:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Thu, 24 Sep 2020 15:55:49 +02:00
perf/amd/uncore: Allow F17h user threadmask and slicemask specification
Continue to fully populate either one of threadmask or slicemask if the user doesn't.
--- arch/x86/events/amd/uncore.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)
arch/x86/events/amd/uncore.c +16 -7
@@ -181,13 +181,14 @@ static void amd_uncore_del(struct perf_event *event, int flags) }/* -* Return a full thread and slice mask until per-CPU is -* properly supported. +* Return a full thread and slice mask unless user +* has provided them */ -static u64 l3_thread_slice_mask (void ) +static u64 l3_thread_slice_mask (u64 config) {if (boot_cpu_data.x86 <=0x18 ) -return AMD64_L3_SLICE_MASK |AMD64_L3_THREAD_MASK ; +return ((config &AMD64_L3_SLICE_MASK ) ? :AMD64_L3_SLICE_MASK ) | + ((config &AMD64_L3_THREAD_MASK ) ? :AMD64_L3_THREAD_MASK );return AMD64_L3_EN_ALL_SLICES |AMD64_L3_EN_ALL_CORES |AMD64_L3_F19H_THREAD_MASK ;
@@ -220,7 +221,7 @@ static int amd_uncore_event_init(struct perf_event *event)* For other events, the two fields do not affect the count. */ if (l3_mask &&is_llc_event (event)) - hwc->config |=l3_thread_slice_mask (); + hwc->config |=l3_thread_slice_mask (event->attr.config); uncore =event_to_amd_uncore (event);if (!uncore)
@@ -277,6 +278,8 @@ DEFINE_UNCORE_FORMAT_ATTR(event12, event, "config:0-7,32-35");DEFINE_UNCORE_FORMAT_ATTR (event14, event,"config:0-7,32-35,59-60" );/* F17h+ DF */ DEFINE_UNCORE_FORMAT_ATTR (event8, event,"config:0-7" );/* F17h+ L3 */ DEFINE_UNCORE_FORMAT_ATTR (umask, umask,"config:8-15" ); +DEFINE_UNCORE_FORMAT_ATTR (slicemask, slicemask,"config:48-51" );/* F17h L3 */ +DEFINE_UNCORE_FORMAT_ATTR (threadmask8, threadmask,"config:56-63" );/* F17h L3 */ static struct attribute *amd_uncore_df_format_attr[] = { &format_attr_event12.attr,/* event14 if F17h+ */
@@ -287,6 +290,8 @@ static struct attribute *amd_uncore_df_format_attr[] = {static struct attribute *amd_uncore_l3_format_attr[] = { &format_attr_event12.attr,/* event8 if F17h+ */ &format_attr_umask.attr, +NULL ,/* slicemask if F17h */ +NULL ,/* threadmask8 if F17h */ NULL , };
@@ -578,8 +583,12 @@ static int __init amd_uncore_init(void) }if (boot_cpu_has (X86_FEATURE_PERFCTR_LLC )) { -if (boot_cpu_data.x86 >=0x17 ) - *l3_attr = &format_attr_event8.attr; +if (boot_cpu_data.x86 >=0x17 ) { + *l3_attr++ = &format_attr_event8.attr; + *l3_attr++ = &format_attr_umask.attr; + *l3_attr++ = &format_attr_slicemask.attr; + *l3_attr++ = &format_attr_threadmask8.attr; + } amd_uncore_llc = alloc_percpu(struct amd_uncore *);if (!amd_uncore_llc) {
PATCH 3/4 perf/amd/uncore: Allow F19h user coreid, threadmask, and sliceid specification
In reply to Kim PhillipsOn Family 19h, the driver checks for a populated 2-bit threadmask in order to establish that the user wants to measure individual slices, individual cores (only one can be measured at a time), and lets the user also directly specify enallcores and/or enallslices if desired.
Example F19h invocation to measure L3 accesses (event 4, umask 0xff) by the first thread (id 0 -> mask 0x1) of the first core (id 0) on the first slice (id 0):
perf stat -a -e instructions,amd_l3/umask=0xff,event=0x4,coreid=0,threadmask=1,sliceid=0,enallcores=0,enallslices=0/ <workload>
--- arch/x86/events/amd/uncore.c | 37 +++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-)
arch/x86/events/amd/uncore.c +32 -5
@@ -190,8 +190,19 @@ static u64 l3_thread_slice_mask(u64 config)return ((config &AMD64_L3_SLICE_MASK ) ? :AMD64_L3_SLICE_MASK ) | ((config &AMD64_L3_THREAD_MASK ) ? :AMD64_L3_THREAD_MASK ); -return AMD64_L3_EN_ALL_SLICES |AMD64_L3_EN_ALL_CORES | -AMD64_L3_F19H_THREAD_MASK ; +/* +* If the user doesn't specify a threadmask, they're not trying to +* count core 0, so we enable all cores & threads. +* We'll also assume that they want to count slice 0 if they specify +* a threadmask and leave sliceid and enallslices unpopulated. +*/ +if (!(config &AMD64_L3_F19H_THREAD_MASK )) +return AMD64_L3_F19H_THREAD_MASK |AMD64_L3_EN_ALL_SLICES | +AMD64_L3_EN_ALL_CORES ; + +return config & (AMD64_L3_F19H_THREAD_MASK |AMD64_L3_SLICEID_MASK | +AMD64_L3_EN_ALL_CORES |AMD64_L3_EN_ALL_SLICES | +AMD64_L3_COREID_MASK ); }static int amd_uncore_event_init (struct perf_event *event)
@@ -278,8 +289,13 @@ DEFINE_UNCORE_FORMAT_ATTR(event12, event, "config:0-7,32-35");DEFINE_UNCORE_FORMAT_ATTR (event14, event,"config:0-7,32-35,59-60" );/* F17h+ DF */ DEFINE_UNCORE_FORMAT_ATTR (event8, event,"config:0-7" );/* F17h+ L3 */ DEFINE_UNCORE_FORMAT_ATTR (umask, umask,"config:8-15" ); +DEFINE_UNCORE_FORMAT_ATTR (coreid, coreid,"config:42-44" );/* F19h L3 */ DEFINE_UNCORE_FORMAT_ATTR (slicemask, slicemask,"config:48-51" );/* F17h L3 */ DEFINE_UNCORE_FORMAT_ATTR (threadmask8, threadmask,"config:56-63" );/* F17h L3 */ +DEFINE_UNCORE_FORMAT_ATTR (threadmask2, threadmask,"config:56-57" );/* F19h L3 */ +DEFINE_UNCORE_FORMAT_ATTR (enallslices, enallslices,"config:46" );/* F19h L3 */ +DEFINE_UNCORE_FORMAT_ATTR (enallcores, enallcores,"config:47" );/* F19h L3 */ +DEFINE_UNCORE_FORMAT_ATTR (sliceid, sliceid,"config:48-50" );/* F19h L3 */ static struct attribute *amd_uncore_df_format_attr[] = { &format_attr_event12.attr,/* event14 if F17h+ */
@@ -290,8 +306,11 @@ static struct attribute *amd_uncore_df_format_attr[] = {static struct attribute *amd_uncore_l3_format_attr[] = { &format_attr_event12.attr,/* event8 if F17h+ */ &format_attr_umask.attr, -NULL ,/* slicemask if F17h */ -NULL ,/* threadmask8 if F17h */ +NULL ,/* slicemask if F17h, coreid if F19h */ +NULL ,/* threadmask8 if F17h, enallslices if F19h */ +NULL ,/* enallcores if F19h */ +NULL ,/* sliceid if F19h */ +NULL ,/* threadmask2 if F19h */ NULL , };
@@ -583,7 +602,15 @@ static int __init amd_uncore_init(void) }if (boot_cpu_has (X86_FEATURE_PERFCTR_LLC )) { -if (boot_cpu_data.x86 >=0x17 ) { +if (boot_cpu_data.x86 >=0x19 ) { + *l3_attr++ = &format_attr_event8.attr; + *l3_attr++ = &format_attr_umask.attr; + *l3_attr++ = &format_attr_coreid.attr; + *l3_attr++ = &format_attr_enallslices.attr; + *l3_attr++ = &format_attr_enallcores.attr; + *l3_attr++ = &format_attr_sliceid.attr; + *l3_attr++ = &format_attr_threadmask2.attr; + }else if (boot_cpu_data.x86 >=0x17 ) { *l3_attr++ = &format_attr_event8.attr; *l3_attr++ = &format_attr_umask.attr; *l3_attr++ = &format_attr_slicemask.attr;
Signature · 1 line
2.27.0
[tip: perf/core] perf/amd/uncore: Allow F19h user coreid, threadmask, and sliceid specification
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 87a54a1fd525f2af8d82becf583c7e836918cf22 Gitweb: https://git.kernel.org/tip/87a54a1fd525f2af8d82becf583c7e836918cf22 Author: Kim Phillips <[email protected]> AuthorDate: Mon, 21 Sep 2020 09:43:29 -05:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Thu, 24 Sep 2020 15:55:50 +02:00
perf/amd/uncore: Allow F19h user coreid, threadmask, and sliceid specification
On Family 19h, the driver checks for a populated 2-bit threadmask in order to establish that the user wants to measure individual slices, individual cores (only one can be measured at a time), and lets the user also directly specify enallcores and/or enallslices if desired.
Example F19h invocation to measure L3 accesses (event 4, umask 0xff) by the first thread (id 0 -> mask 0x1) of the first core (id 0) on the first slice (id 0):
perf stat -a -e instructions,amd_l3/umask=0xff,event=0x4,coreid=0,threadmask=1,sliceid=0,enallcores=0,enallslices=0/ <workload>
--- arch/x86/events/amd/uncore.c | 37 ++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-)
arch/x86/events/amd/uncore.c +32 -5
@@ -190,8 +190,19 @@ static u64 l3_thread_slice_mask(u64 config)return ((config &AMD64_L3_SLICE_MASK ) ? :AMD64_L3_SLICE_MASK ) | ((config &AMD64_L3_THREAD_MASK ) ? :AMD64_L3_THREAD_MASK ); -return AMD64_L3_EN_ALL_SLICES |AMD64_L3_EN_ALL_CORES | -AMD64_L3_F19H_THREAD_MASK ; +/* +* If the user doesn't specify a threadmask, they're not trying to +* count core 0, so we enable all cores & threads. +* We'll also assume that they want to count slice 0 if they specify +* a threadmask and leave sliceid and enallslices unpopulated. +*/ +if (!(config &AMD64_L3_F19H_THREAD_MASK )) +return AMD64_L3_F19H_THREAD_MASK |AMD64_L3_EN_ALL_SLICES | +AMD64_L3_EN_ALL_CORES ; + +return config & (AMD64_L3_F19H_THREAD_MASK |AMD64_L3_SLICEID_MASK | +AMD64_L3_EN_ALL_CORES |AMD64_L3_EN_ALL_SLICES | +AMD64_L3_COREID_MASK ); }static int amd_uncore_event_init (struct perf_event *event)
@@ -278,8 +289,13 @@ DEFINE_UNCORE_FORMAT_ATTR(event12, event, "config:0-7,32-35");DEFINE_UNCORE_FORMAT_ATTR (event14, event,"config:0-7,32-35,59-60" );/* F17h+ DF */ DEFINE_UNCORE_FORMAT_ATTR (event8, event,"config:0-7" );/* F17h+ L3 */ DEFINE_UNCORE_FORMAT_ATTR (umask, umask,"config:8-15" ); +DEFINE_UNCORE_FORMAT_ATTR (coreid, coreid,"config:42-44" );/* F19h L3 */ DEFINE_UNCORE_FORMAT_ATTR (slicemask, slicemask,"config:48-51" );/* F17h L3 */ DEFINE_UNCORE_FORMAT_ATTR (threadmask8, threadmask,"config:56-63" );/* F17h L3 */ +DEFINE_UNCORE_FORMAT_ATTR (threadmask2, threadmask,"config:56-57" );/* F19h L3 */ +DEFINE_UNCORE_FORMAT_ATTR (enallslices, enallslices,"config:46" );/* F19h L3 */ +DEFINE_UNCORE_FORMAT_ATTR (enallcores, enallcores,"config:47" );/* F19h L3 */ +DEFINE_UNCORE_FORMAT_ATTR (sliceid, sliceid,"config:48-50" );/* F19h L3 */ static struct attribute *amd_uncore_df_format_attr[] = { &format_attr_event12.attr,/* event14 if F17h+ */
@@ -290,8 +306,11 @@ static struct attribute *amd_uncore_df_format_attr[] = {static struct attribute *amd_uncore_l3_format_attr[] = { &format_attr_event12.attr,/* event8 if F17h+ */ &format_attr_umask.attr, -NULL ,/* slicemask if F17h */ -NULL ,/* threadmask8 if F17h */ +NULL ,/* slicemask if F17h, coreid if F19h */ +NULL ,/* threadmask8 if F17h, enallslices if F19h */ +NULL ,/* enallcores if F19h */ +NULL ,/* sliceid if F19h */ +NULL ,/* threadmask2 if F19h */ NULL , };
@@ -583,7 +602,15 @@ static int __init amd_uncore_init(void) }if (boot_cpu_has (X86_FEATURE_PERFCTR_LLC )) { -if (boot_cpu_data.x86 >=0x17 ) { +if (boot_cpu_data.x86 >=0x19 ) { + *l3_attr++ = &format_attr_event8.attr; + *l3_attr++ = &format_attr_umask.attr; + *l3_attr++ = &format_attr_coreid.attr; + *l3_attr++ = &format_attr_enallslices.attr; + *l3_attr++ = &format_attr_enallcores.attr; + *l3_attr++ = &format_attr_sliceid.attr; + *l3_attr++ = &format_attr_threadmask2.attr; + }else if (boot_cpu_data.x86 >=0x17 ) { *l3_attr++ = &format_attr_event8.attr; *l3_attr++ = &format_attr_umask.attr; *l3_attr++ = &format_attr_slicemask.attr;
PATCH 4/4 perf/amd/uncore: Inform the user how many counters each uncore PMU has
In reply to Kim PhillipsPreviously, the uncore driver would say "NB counters detected" on F17h machines, which don't have NorthBridge (NB) counters. They have Data Fabric (DF) counters. Just use the pmu.name to inform users which pmu to use and its associated counter count.
F17h dmesg BEFORE:
amd_uncore: AMD NB counters detectedamd_uncore: AMD LLC counters detected
F17h dmesg AFTER:
amd_uncore: 4 amd_df counters detectedamd_uncore: 6 amd_l3 counters detected
--- arch/x86/events/amd/uncore.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
arch/x86/events/amd/uncore.c +7 -6
@@ -595,9 +595,10 @@ static int __init amd_uncore_init(void)if (ret) goto fail_nb; -pr_info ("%s NB counters detected\n" , - boot_cpu_data.x86_vendor ==X86_VENDOR_HYGON ? -"HYGON" :"AMD" ); +pr_info ("%d %s %s counters detected\n" , num_counters_nb, + boot_cpu_data.x86_vendor ==X86_VENDOR_HYGON ?"HYGON" :"" , + amd_nb_pmu.name); + ret =0 ; }
@@ -626,9 +627,9 @@ static int __init amd_uncore_init(void)if (ret) goto fail_llc; -pr_info ("%s LLC counters detected\n" , - boot_cpu_data.x86_vendor ==X86_VENDOR_HYGON ? -"HYGON" :"AMD" ); +pr_info ("%d %s %s counters detected\n" , num_counters_llc, + boot_cpu_data.x86_vendor ==X86_VENDOR_HYGON ?"HYGON" :"" , + amd_llc_pmu.name); ret =0 ; }
Signature · 1 line
2.27.0
[tip: perf/core] perf/amd/uncore: Inform the user how many counters each uncore PMU has
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 9ed9647dc0671486f9e998b7258f75167a9c4697 Gitweb: https://git.kernel.org/tip/9ed9647dc0671486f9e998b7258f75167a9c4697 Author: Kim Phillips <[email protected]> AuthorDate: Mon, 21 Sep 2020 09:43:30 -05:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Thu, 24 Sep 2020 15:55:50 +02:00
perf/amd/uncore: Inform the user how many counters each uncore PMU has
Previously, the uncore driver would say "NB counters detected" on F17h machines, which don't have NorthBridge (NB) counters. They have Data Fabric (DF) counters. Just use the pmu.name to inform users which pmu to use and its associated counter count.
F17h dmesg BEFORE:
amd_uncore: AMD NB counters detectedamd_uncore: AMD LLC counters detected
F17h dmesg AFTER:
amd_uncore: 4 amd_df counters detectedamd_uncore: 6 amd_l3 counters detected
--- arch/x86/events/amd/uncore.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
arch/x86/events/amd/uncore.c +7 -6
@@ -595,9 +595,10 @@ static int __init amd_uncore_init(void)if (ret) goto fail_nb; -pr_info ("%s NB counters detected\n" , - boot_cpu_data.x86_vendor ==X86_VENDOR_HYGON ? -"HYGON" :"AMD" ); +pr_info ("%d %s %s counters detected\n" , num_counters_nb, + boot_cpu_data.x86_vendor ==X86_VENDOR_HYGON ?"HYGON" :"" , + amd_nb_pmu.name); + ret =0 ; }
@@ -626,9 +627,9 @@ static int __init amd_uncore_init(void)if (ret) goto fail_llc; -pr_info ("%s LLC counters detected\n" , - boot_cpu_data.x86_vendor ==X86_VENDOR_HYGON ? -"HYGON" :"AMD" ); +pr_info ("%d %s %s counters detected\n" , num_counters_llc, + boot_cpu_data.x86_vendor ==X86_VENDOR_HYGON ?"HYGON" :"" , + amd_llc_pmu.name); ret =0 ; }