Uncore PMON discovery mechanism support
Subsystems (2)
cover Uncore PMON discovery mechanism support
From: Kan Liang <[email protected]>
A mechanism of self-describing HW for the uncore PMOM has been introduced with the latest Intel platforms. By reading through an MMIO page worth of information, SW can ‘discover’ all the standard uncore PMON registers.
With the discovery mechanism, Perf can
- Retrieve the generic uncore unit information of all standard uncore blocks, e.g., the address of counters, the address of the counter control, the counter width, the access type, etc.
Perf can provide basic uncore support based on this information. For a new platform, perf users will get basic uncore support even if the platform-specific enabling code is not ready yet.
- Retrieve accurate uncore unit information, e.g., the number of uncore boxes. The number of uncore boxes may be different among machines. Current perf hard code the max number of the uncore blocks. On some machines, perf may create a PMU for an unavailable uncore block. Although there is no harm (always return 0 for the unavailable uncore block), it may confuse the users. The discovery mechanism can provide the accurate number of available uncore boxes on a machine.
But, the discovery mechanism has some limits,
- Rely on BIOS's support. If a BIOS doesn't support the discovery mechanism, the uncore driver will exit with -ENODEV. There is nothing changed.
- Only provide the generic uncore unit information. The information for the advanced features, such as fixed counters, filters, and constraints, cannot be retrieved.
- Only support the standard PMON blocks. Non-standard PMON blocks, e.g., free-running counters, are not supported.
- Only provide an ID for an uncore block. No meaningful name is provided. The uncore_type_&typeID_&boxID will be used as the name.
- Enabling the PCI and MMIO type of uncore blocks rely on the NUMA support. These uncore blocks require the mapping information from a BUS to a die. The current discovery table doesn't provide the mapping information. The pcibus_to_node() from NUMA is used to retrieve the information. If NUMA is not supported, some uncore blocks maybe unavailable.
To locate the MMIO page, SW has to find a PCI device with the unique capability ID 0x23 and retrieve its BAR address.
The spec can be found at Snow Ridge or Ice Lake server's uncore document.
https://cdrdv2.intel.com/v1/dl/getContent/611319
Kan Liang (5):
perf/x86/intel/uncore: Parse uncore discovery tables perf/x86/intel/uncore: Generic support for the MSR type of uncore
blocks
perf/x86/intel/uncore: Rename uncore_notifier to
uncore_pci_sub_notifier
perf/x86/intel/uncore: Generic support for the PCI type of uncore
blocks
perf/x86/intel/uncore: Generic support for the MMIO type of uncore
blocks
arch/x86/events/intel/Makefile | 2 +- arch/x86/events/intel/uncore.c | 184 +++++++-- arch/x86/events/intel/uncore.h | 10 +- arch/x86/events/intel/uncore_discovery.c | 626 +++++++++++++++++++++++++++++++ arch/x86/events/intel/uncore_discovery.h | 131 +++++++ 5 files changed, 922 insertions(+), 31 deletions(-) create mode 100644 arch/x86/events/intel/uncore_discovery.c create mode 100644 arch/x86/events/intel/uncore_discovery.h
Signature · 1 line
2.7.4
PATCH 1/5 perf/x86/intel/uncore: Parse uncore discovery tables
From: Kan Liang <[email protected]>
A self-describing mechanism for the uncore PerfMon hardware has been introduced with the latest Intel platforms. By reading through an MMIO page worth of information, perf can 'discover' all the standard uncore PerfMon registers in a machine.
The discovery mechanism relies on BIOS's support. With a proper BIOS, a PCI device with the unique capability ID 0x23 can be found on each die. Perf can retrieve the information of all available uncore PerfMons from the device via MMIO. The information is composed of one global discovery table and several unit discovery tables.
- The global discovery table includes global uncore information of the die, e.g., the address of the global control register, the offset of the global status register, the number of uncore units, the offset of unit discovery tables, etc.
- The unit discovery table includes generic uncore unit information, e.g., the access type, the counter width, the address of counters, the address of the counter control, the unit ID, the unit type, etc. The unit is also called "box" in the code.
Perf can provide basic uncore support based on this information with the following patches.
To locate the PCI device with the discovery tables, check the generic PCI ID first. If it doesn't match, go through the entire PCI device tree and locate the device with the unique capability ID.
The uncore information is similar among dies. To save parsing time and space, only completely parse and store the discovery tables on the first die and the first box of each die. The parsed information is stored in an RB tree structure, intel_uncore_discovery_type. The size of the stored discovery tables varies among platforms. It's around 4KB for a Sapphire Rapids server.
If a BIOS doesn't support the 'discovery' mechanism, there is nothing changed.
--- arch/x86/events/intel/Makefile | 2 +- arch/x86/events/intel/uncore.c | 27 ++- arch/x86/events/intel/uncore_discovery.c | 322 +++++++++++++++++++++++++++++++ arch/x86/events/intel/uncore_discovery.h | 105 ++++++++++ 4 files changed, 448 insertions(+), 8 deletions(-) create mode 100644 arch/x86/events/intel/uncore_discovery.c create mode 100644 arch/x86/events/intel/uncore_discovery.h
arch/x86/events/intel/Makefile +1 -1
@@ -3,6 +3,6 @@ obj-$(CONFIG_CPU_SUP_INTEL) += core.o bts.o obj-$(CONFIG_CPU_SUP_INTEL) += ds.o knc.o obj-$(CONFIG_CPU_SUP_INTEL) += lbr.o p4.o p6.o pt.o obj-$(CONFIG_PERF_EVENTS_INTEL_UNCORE) += intel-uncore.o -intel-uncore-objs := uncore.o uncore_nhmex.o uncore_snb.o uncore_snbep.o +intel-uncore-objs := uncore.o uncore_nhmex.o uncore_snb.o uncore_snbep.o uncore_discovery.o obj-$(CONFIG_PERF_EVENTS_INTEL_CSTATE) += intel-cstate.o intel-cstate-objs := cstate.o
arch/x86/events/intel/uncore.c +20 -7
@@ -4,6 +4,7 @@#include <asm/cpu_device_id.h> #include <asm/intel-family.h> #include "uncore.h" +#include "uncore_discovery.h" static struct intel_uncore_type *empty_uncore[] = {NULL , };struct intel_uncore_type **uncore_msr_uncores = empty_uncore;
@@ -1637,6 +1638,9 @@ static const struct intel_uncore_init_fun snr_uncore_init __initconst = { .mmio_init = snr_uncore_mmio_init, }; +static const struct intel_uncore_init_fun generic_uncore_init__initconst = { +}; +static const struct x86_cpu_id intel_uncore_match[]__initconst = {X86_MATCH_INTEL_FAM6_MODEL (NEHALEM_EP , &nhm_uncore_init),X86_MATCH_INTEL_FAM6_MODEL (NEHALEM , &nhm_uncore_init),
@@ -1684,17 +1688,21 @@ static int __init intel_uncore_init(void)struct intel_uncore_init_fun *uncore_init;int pret =0 , cret =0 , mret =0 , ret; - id =x86_match_cpu (intel_uncore_match); -if (!id) -return -ENODEV ; -if (boot_cpu_has (X86_FEATURE_HYPERVISOR ))return -ENODEV ; __uncore_max_dies =topology_max_packages () *topology_max_die_per_package (); - uncore_init = (struct intel_uncore_init_fun *)id->driver_data; + id =x86_match_cpu (intel_uncore_match); +if (!id) { +if (intel_uncore_has_discovery_tables ()) + uncore_init = (struct intel_uncore_init_fun *)&generic_uncore_init; +else +return -ENODEV ; + }else + uncore_init = (struct intel_uncore_init_fun *)id->driver_data; +if (uncore_init->pci_init) { pret = uncore_init->pci_init ();if (!pret)
@@ -1711,8 +1719,10 @@ static int __init intel_uncore_init(void) mret =uncore_mmio_init (); } -if (cret && pret && mret) -return -ENODEV ; +if (cret && pret && mret) { + ret = -ENODEV ; + goto free_discovery; + }/* Install hotplug callbacks to setup the targets for each package */ ret = cpuhp_setup_state(CPUHP_AP_PERF_X86_UNCORE_ONLINE,
@@ -1727,6 +1737,8 @@ static int __init intel_uncore_init(void)uncore_types_exit (uncore_msr_uncores);uncore_types_exit (uncore_mmio_uncores);uncore_pci_exit (); +free_discovery: +intel_uncore_clear_discovery_tables ();return ret; }module_init (intel_uncore_init);
@@ -1737,5 +1749,6 @@ static void __exit intel_uncore_exit(void)uncore_types_exit (uncore_msr_uncores);uncore_types_exit (uncore_mmio_uncores);uncore_pci_exit (); +intel_uncore_clear_discovery_tables (); }module_exit (intel_uncore_exit);
arch/x86/events/intel/uncore_discovery.c new file +322 -0
322 lines not on this page · raw message
arch/x86/events/intel/uncore_discovery.h new file +105 -0
105 lines not on this page · raw message
Signature · 1 line
2.7.4
Peter Zijlstra
maintainerRe: [PATCH 1/5] perf/x86/intel/uncore: Parse uncore discovery tables
Quoted 55 lines · On Fri, Mar 12, 2021 at 08:34:34AM -0800, [email protected] wrote:
arch/x86/events/intel/uncore_discovery.c new file +55
-0+static struct intel_uncore_discovery_type * +search_uncore_discovery_type (u16 type_id) +{ +struct rb_node *node = discovery_tables.rb_node; +struct intel_uncore_discovery_type *type; + +while (node) { + type = rb_entry(node, struct intel_uncore_discovery_type, node); + +if (type->type > type_id) + node = node->rb_left; +else if (type->type < type_id) + node = node->rb_right; +else +return type; + } + +return NULL ; +} + +static struct intel_uncore_discovery_type * +add_uncore_discovery_type (struct uncore_unit_discovery *unit) +{ +struct intel_uncore_discovery_type *type, *cur; +struct rb_node **node = &discovery_tables.rb_node; +struct rb_node *parent = *node; + +if (unit->access_type >=UNCORE_ACCESS_MAX ) { +pr_warn ("Unsupported access type %d\n" , unit->access_type); +return NULL ; + } + + type =kzalloc (sizeof (struct intel_uncore_discovery_type ),GFP_KERNEL ); +if (!type) +return NULL ; + + type->box_ctrl_die =kcalloc (__uncore_max_dies,sizeof (u64),GFP_KERNEL ); +if (!type->box_ctrl_die) + goto free_type; + + type->access_type = unit->access_type; + num_discovered_types[type->access_type]++; + type->type = unit->box_type; + +while (*node) { + parent = *node; + cur = rb_entry(parent, struct intel_uncore_discovery_type, node); + +if (cur->type > type->type) + node = &parent->rb_left; +else + node = &parent->rb_right; + } + +rb_link_node (&type->node, parent, node);
arch/x86/events/intel/uncore_discovery.c line 125
Quoted 10 lines
arch/x86/events/intel/uncore_discovery.c new file +10
-0+rb_insert_color (&type->node, &discovery_tables); + +return type; + +free_type: +kfree (type); + +return NULL ; + +}
I'm thinking this can use some of this:
2d24dd5798d0 ("rbtree: Add generic add and find helpers")
Re: [PATCH 1/5] perf/x86/intel/uncore: Parse uncore discovery tables
Quoted 69 lines · Peter Zijlstra
Quoted 55 lines · On Fri, Mar 12, 2021 at 08:34:34AM -0800, [email protected] wrote:
arch/x86/events/intel/uncore_discovery.c new file +55
-0+static struct intel_uncore_discovery_type * +search_uncore_discovery_type (u16 type_id) +{ +struct rb_node *node = discovery_tables.rb_node; +struct intel_uncore_discovery_type *type; + +while (node) { + type = rb_entry(node, struct intel_uncore_discovery_type, node); + +if (type->type > type_id) + node = node->rb_left; +else if (type->type < type_id) + node = node->rb_right; +else +return type; + } + +return NULL ; +} + +static struct intel_uncore_discovery_type * +add_uncore_discovery_type (struct uncore_unit_discovery *unit) +{ +struct intel_uncore_discovery_type *type, *cur; +struct rb_node **node = &discovery_tables.rb_node; +struct rb_node *parent = *node; + +if (unit->access_type >=UNCORE_ACCESS_MAX ) { +pr_warn ("Unsupported access type %d\n" , unit->access_type); +return NULL ; + } + + type =kzalloc (sizeof (struct intel_uncore_discovery_type ),GFP_KERNEL ); +if (!type) +return NULL ; + + type->box_ctrl_die =kcalloc (__uncore_max_dies,sizeof (u64),GFP_KERNEL ); +if (!type->box_ctrl_die) + goto free_type; + + type->access_type = unit->access_type; + num_discovered_types[type->access_type]++; + type->type = unit->box_type; + +while (*node) { + parent = *node; + cur = rb_entry(parent, struct intel_uncore_discovery_type, node); + +if (cur->type > type->type) + node = &parent->rb_left; +else + node = &parent->rb_right; + } + +rb_link_node (&type->node, parent, node);arch/x86/events/intel/uncore_discovery.c line 125
Quoted 10 lines
arch/x86/events/intel/uncore_discovery.c new file +10
-0+rb_insert_color (&type->node, &discovery_tables); + +return type; + +free_type: +kfree (type); + +return NULL ; + +}I'm thinking this can use some of this:
Quoted 2 lines
2d24dd5798d0("rbtree: Add generic add and find helpers")
Sure, I will use the generic rbtree framework in V2.
Thanks,
Kan
Peter Zijlstra
maintainerRe: [PATCH 1/5] perf/x86/intel/uncore: Parse uncore discovery tables
In reply to [email protected]Quoted 7 lines · On Fri, Mar 12, 2021 at 08:34:34AM -0800, [email protected] wrote:
From: Kan Liang <[email protected]>
A self-describing mechanism for the uncore PerfMon hardware has been introduced with the latest Intel platforms. By reading through an MMIO page worth of information, perf can 'discover' all the standard uncore PerfMon registers in a machine.
Quoted 8 lines
The discovery mechanism relies on BIOS's support. With a proper BIOS, a PCI device with the unique capability ID
0x23can be found on each die. Perf can retrieve the information of all available uncore PerfMons from the device via MMIO. The information is composed of one global discovery table and several unit discovery tables.If a BIOS doesn't support the 'discovery' mechanism, there is nothing changed.
What if the BIOS got it wrong? Will the driver still get it correct if it is a known platform?
Do we need a chicken flag to kill the discovery? uncore_no_discover?
Re: [PATCH 1/5] perf/x86/intel/uncore: Parse uncore discovery tables
Quoted 14 lines · Peter Zijlstra
Quoted 12 lines · On Fri, Mar 12, 2021 at 08:34:34AM -0800, [email protected] wrote:
From: Kan Liang <[email protected]>
A self-describing mechanism for the uncore PerfMon hardware has been introduced with the latest Intel platforms. By reading through an MMIO page worth of information, perf can 'discover' all the standard uncore PerfMon registers in a machine.
The discovery mechanism relies on BIOS's support. With a proper BIOS, a PCI device with the unique capability ID
0x23can be found on each die. Perf can retrieve the information of all available uncore PerfMons from the device via MMIO. The information is composed of one global discovery table and several unit discovery tables.
Quoted 5 lines
Quoted 2 lines
If a BIOS doesn't support the 'discovery' mechanism, there is nothing changed.
What if the BIOS got it wrong? Will the driver still get it correct if it is a known platform?
Yes, I will submit a platform specific patch to fix this case.
Quoted 3 lines
Do we need a chicken flag to kill the discovery?
uncore_no_discover?
Yes, I plan to introduce a .use_discovery_tables flag to indicate whether to use the discovery tables for the known platform.
The below codes is part of the upcoming SPR uncore patches.
The first SPR uncore patch will still rely on the BIOS discovery tables, because some uncore block information hasn't been published yet. We have to retrieve the information fro the tables. Once all the information is published, we can kill the discovery by removing the ".use_discovery_tables = true".
+static const struct intel_uncore_init_fun spr_uncore_init __initconst = {
+ .cpu_init = spr_uncore_cpu_init, + .pci_init = spr_uncore_pci_init, + .mmio_init = spr_uncore_mmio_init, + .use_discovery_tables = true,
+};
Thanks,
Kan
Peter Zijlstra
maintainerRe: [PATCH 1/5] perf/x86/intel/uncore: Parse uncore discovery tables
Quoted 32 lines · Kan
Quoted 14 lines · Peter Zijlstra
Quoted 12 lines · On Fri, Mar 12, 2021 at 08:34:34AM -0800, [email protected] wrote:
From: Kan Liang <[email protected]>
A self-describing mechanism for the uncore PerfMon hardware has been introduced with the latest Intel platforms. By reading through an MMIO page worth of information, perf can 'discover' all the standard uncore PerfMon registers in a machine.
The discovery mechanism relies on BIOS's support. With a proper BIOS, a PCI device with the unique capability ID
0x23can be found on each die. Perf can retrieve the information of all available uncore PerfMons from the device via MMIO. The information is composed of one global discovery table and several unit discovery tables.Quoted 5 lines
Quoted 2 lines
If a BIOS doesn't support the 'discovery' mechanism, there is nothing changed.
What if the BIOS got it wrong? Will the driver still get it correct if it is a known platform?
Yes, I will submit a platform specific patch to fix this case.
Quoted 3 lines
Do we need a chicken flag to kill the discovery?
uncore_no_discover?Yes, I plan to introduce a .use_discovery_tables flag to indicate whether to use the discovery tables for the known platform.
Quoted 6 lines
The below codes is part of the upcoming SPR uncore patches.
The first SPR uncore patch will still rely on the BIOS discovery tables, because some uncore block information hasn't been published yet. We have to retrieve the information fro the tables. Once all the information is published, we can kill the discovery by removing the ".use_discovery_tables = true".
I was thinking of a module parameter, such that we can tell it to skip discovery on module load time etc.
Re: [PATCH 1/5] perf/x86/intel/uncore: Parse uncore discovery tables
Quoted 40 lines · Peter Zijlstra
Quoted 32 lines · Kan
Quoted 14 lines · Peter Zijlstra
Quoted 12 lines · On Fri, Mar 12, 2021 at 08:34:34AM -0800, [email protected] wrote:
From: Kan Liang <[email protected]>
A self-describing mechanism for the uncore PerfMon hardware has been introduced with the latest Intel platforms. By reading through an MMIO page worth of information, perf can 'discover' all the standard uncore PerfMon registers in a machine.
The discovery mechanism relies on BIOS's support. With a proper BIOS, a PCI device with the unique capability ID
0x23can be found on each die. Perf can retrieve the information of all available uncore PerfMons from the device via MMIO. The information is composed of one global discovery table and several unit discovery tables.Quoted 5 lines
Quoted 2 lines
If a BIOS doesn't support the 'discovery' mechanism, there is nothing changed.
What if the BIOS got it wrong? Will the driver still get it correct if it is a known platform?
Yes, I will submit a platform specific patch to fix this case.
Quoted 3 lines
Do we need a chicken flag to kill the discovery?
uncore_no_discover?Yes, I plan to introduce a .use_discovery_tables flag to indicate whether to use the discovery tables for the known platform.
Quoted 6 lines
The below codes is part of the upcoming SPR uncore patches.
The first SPR uncore patch will still rely on the BIOS discovery tables, because some uncore block information hasn't been published yet. We have to retrieve the information fro the tables. Once all the information is published, we can kill the discovery by removing the ".use_discovery_tables = true".
Quoted 3 lines
I was thinking of a module parameter, such that we can tell it to skip discovery on module load time etc.
Sure, I will add a module parameter, uncore_no_discover.
If users don't want the discovery feature, they can set uncore_no_discover=true.
Thanks,
Kan
PATCH 2/5 perf/x86/intel/uncore: Generic support for the MSR type of uncore blocks
In reply to [email protected]From: Kan Liang <[email protected]>
The discovery table provides the generic uncore block information for the MSR type of uncore blocks, e.g., the counter width, the number of counters, the location of control/counter registers, which is good enough to provide basic uncore support. It can be used as a fallback solution when the kernel doesn't support a platform.
The name of the uncore box cannot be retrieved from the discovery table. uncore_type_&typeID_&boxID will be used as its name. Save the type ID and the box ID information in the struct intel_uncore_type. Factor out uncore_get_pmu_name() to handle different naming methods.
Implement generic support for the MSR type of uncore block.
Some advanced features, such as filters and constraints, cannot be retrieved from discovery tables. Features that rely on that information are not be supported here.
--- arch/x86/events/intel/uncore.c | 45 ++++++++--- arch/x86/events/intel/uncore.h | 3 + arch/x86/events/intel/uncore_discovery.c | 126 +++++++++++++++++++++++++++++++ arch/x86/events/intel/uncore_discovery.h | 18 +++++ 4 files changed, 182 insertions(+), 10 deletions(-)
arch/x86/events/intel/uncore.c +35 -10
@@ -6,7 +6,7 @@#include "uncore.h" #include "uncore_discovery.h" -static struct intel_uncore_type *empty_uncore[] = {NULL , }; +struct intel_uncore_type *empty_uncore[] = {NULL , };struct intel_uncore_type **uncore_msr_uncores = empty_uncore;struct intel_uncore_type **uncore_pci_uncores = empty_uncore;struct intel_uncore_type **uncore_mmio_uncores = empty_uncore;
@@ -830,6 +830,34 @@ static const struct attribute_group uncore_pmu_attr_group = { .attrs = uncore_pmu_attrs, }; +static void uncore_get_pmu_name (struct intel_uncore_pmu *pmu) +{ +struct intel_uncore_type *type = pmu->type; + +/* +* No uncore block name in discovery table. +* Use uncore_type_&typeid_&boxid as name. +*/ +if (!type->name) { +if (type->num_boxes ==1 ) +sprintf (pmu->name,"uncore_type_%u" , type->type_id); +else { +sprintf (pmu->name,"uncore_type_%u_%d" , + type->type_id, type->box_ids[pmu->pmu_idx]); + } +return ; + } + +if (type->num_boxes ==1 ) { +if (strlen (type->name) >0 ) +sprintf (pmu->name,"uncore_%s" , type->name); +else +sprintf (pmu->name,"uncore" ); + }else +sprintf (pmu->name,"uncore_%s_%d" , type->name, pmu->pmu_idx); + +} +static int uncore_pmu_register (struct intel_uncore_pmu *pmu) {int ret;
@@ -856,15 +884,7 @@ static int uncore_pmu_register(struct intel_uncore_pmu *pmu) pmu->pmu.attr_update = pmu->type->attr_update; } -if (pmu->type->num_boxes ==1 ) { -if (strlen (pmu->type->name) >0 ) -sprintf (pmu->name,"uncore_%s" , pmu->type->name); -else -sprintf (pmu->name,"uncore" ); - }else { -sprintf (pmu->name,"uncore_%s_%d" , pmu->type->name, - pmu->pmu_idx); - } +uncore_get_pmu_name (pmu); ret =perf_pmu_register (&pmu->pmu, pmu->name,-1 );if (!ret)
@@ -905,6 +925,10 @@ static void uncore_type_exit(struct intel_uncore_type *type)kfree (type->pmus); type->pmus =NULL ; } +if (type->box_ids) { +kfree (type->box_ids); + type->box_ids =NULL ; + }kfree (type->events_group); type->events_group =NULL ; }
@@ -1639,6 +1663,7 @@ static const struct intel_uncore_init_fun snr_uncore_init __initconst = { };static const struct intel_uncore_init_fun generic_uncore_init__initconst = { + .cpu_init = intel_uncore_generic_uncore_cpu_init, };static const struct x86_cpu_id intel_uncore_match[]__initconst = {
arch/x86/events/intel/uncore.h +3 -0
@@ -50,6 +50,7 @@ struct intel_uncore_type {int perf_ctr_bits;int fixed_ctr_bits;int num_freerunning_types; +int type_id;unsigned perf_ctr;unsigned event_ctl;unsigned event_mask;
@@ -66,6 +67,7 @@ struct intel_uncore_type { unsigned single_fixed:1; unsigned pair_ctr_ctl:1;unsigned *msr_offsets; +unsigned *box_ids;struct event_constraint unconstrainted;struct event_constraint *constraints;struct intel_uncore_pmu *pmus;
@@ -547,6 +549,7 @@ uncore_get_constraint(struct intel_uncore_box *box, struct perf_event *event);void uncore_put_constraint (struct intel_uncore_box *box,struct perf_event *event);u64 uncore_shared_reg_config (struct intel_uncore_box *box,int idx); +extern struct intel_uncore_type *empty_uncore[];extern struct intel_uncore_type **uncore_msr_uncores;extern struct intel_uncore_type **uncore_pci_uncores;extern struct intel_uncore_type **uncore_mmio_uncores;
arch/x86/events/intel/uncore_discovery.c +126 -0
129 lines not on this page · raw message
arch/x86/events/intel/uncore_discovery.h +18 -0
@@ -28,6 +28,23 @@ unit.table1 == -1ULL || unit.ctl == -1ULL || \ unit.table3 == -1ULL) +#define GENERIC_PMON_CTL_EV_SEL_MASK 0x000000ff +#define GENERIC_PMON_CTL_UMASK_MASK 0x0000ff00 +#define GENERIC_PMON_CTL_EDGE_DET (1 << 18) +#define GENERIC_PMON_CTL_INVERT (1 << 23) +#define GENERIC_PMON_CTL_TRESH_MASK 0xff000000 +#define GENERIC_PMON_RAW_EVENT_MASK (GENERIC_PMON_CTL_EV_SEL_MASK | \ + GENERIC_PMON_CTL_UMASK_MASK | \ + GENERIC_PMON_CTL_EDGE_DET | \ + GENERIC_PMON_CTL_INVERT | \ + GENERIC_PMON_CTL_TRESH_MASK) + +#define GENERIC_PMON_BOX_CTL_FRZ (1 << 0) +#define GENERIC_PMON_BOX_CTL_RST_CTRL (1 << 8) +#define GENERIC_PMON_BOX_CTL_RST_CTRS (1 << 9) +#define GENERIC_PMON_BOX_CTL_INT (GENERIC_PMON_BOX_CTL_RST_CTRL | \ + GENERIC_PMON_BOX_CTL_RST_CTRS) +enum uncore_access_type {UNCORE_ACCESS_MSR =0 ,UNCORE_ACCESS_MMIO ,
@@ -103,3 +120,4 @@ struct intel_uncore_discovery_type {bool intel_uncore_has_discovery_tables (void );void intel_uncore_clear_discovery_tables (void ); +void intel_uncore_generic_uncore_cpu_init (void );
Signature · 1 line
2.7.4
PATCH 3/5 perf/x86/intel/uncore: Rename uncore_notifier to uncore_pci_sub_notifier
In reply to [email protected]From: Kan Liang <[email protected]>
Perf will use a similar method to the PCI sub driver to register the PMUs for the PCI type of uncore blocks. The method requires a BUS notifier to support hotplug. The current BUS notifier cannot be reused, because it searches a const id_table for the corresponding registered PMU. The PCI type of uncore blocks in the discovery tables doesn't provide an id_table.
Factor out uncore_bus_notify() and add the pointer of an id_table as a parameter. The uncore_bus_notify() will be reused in the following patch.
The current BUS notifier is only used by the PCI sub driver. Its name is too generic. Rename it to uncore_pci_sub_notifier, which is specific for the PCI sub driver.
--- arch/x86/events/intel/uncore.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
arch/x86/events/intel/uncore.c +14 -6
@@ -1199,7 +1199,8 @@ static void uncore_pci_remove(struct pci_dev *pdev) }static int uncore_bus_notify (struct notifier_block *nb, -unsigned long action,void *data) +unsigned long action,void *data, +const struct pci_device_id *ids) {struct device *dev = data;struct pci_dev *pdev =to_pci_dev (dev);
@@ -1210,7 +1211,7 @@ static int uncore_bus_notify(struct notifier_block *nb,if (action !=BUS_NOTIFY_DEL_DEVICE )return NOTIFY_DONE ; - pmu =uncore_pci_find_dev_pmu (pdev, uncore_pci_sub_driver->id_table); + pmu =uncore_pci_find_dev_pmu (pdev, ids);if (!pmu)return NOTIFY_DONE ;
@@ -1222,8 +1223,15 @@ static int uncore_bus_notify(struct notifier_block *nb,return NOTIFY_OK ; } -static struct notifier_block uncore_notifier = { - .notifier_call = uncore_bus_notify, +static int uncore_pci_sub_bus_notify (struct notifier_block *nb, +unsigned long action,void *data) +{ +return uncore_bus_notify (nb, action, data, + uncore_pci_sub_driver->id_table); +} + +static struct notifier_block uncore_pci_sub_notifier = { + .notifier_call = uncore_pci_sub_bus_notify, };static void uncore_pci_sub_driver_init (void )
@@ -1264,7 +1272,7 @@ static void uncore_pci_sub_driver_init(void) ids++; } -if (notify &&bus_register_notifier (&pci_bus_type, &uncore_notifier)) +if (notify &&bus_register_notifier (&pci_bus_type, &uncore_pci_sub_notifier)) notify = false;if (!notify)
@@ -1315,7 +1323,7 @@ static void uncore_pci_exit(void)if (pcidrv_registered) { pcidrv_registered = false;if (uncore_pci_sub_driver) -bus_unregister_notifier (&pci_bus_type, &uncore_notifier); +bus_unregister_notifier (&pci_bus_type, &uncore_pci_sub_notifier);pci_unregister_driver (uncore_pci_driver);uncore_types_exit (uncore_pci_uncores);kfree (uncore_extra_pci_dev);
Signature · 1 line
2.7.4
PATCH 4/5 perf/x86/intel/uncore: Generic support for the PCI type of uncore blocks
In reply to [email protected]From: Kan Liang <[email protected]>
The discovery table provides the generic uncore block information for the PCI type of uncore blocks, which is good enough to provide basic uncore support.
The PCI BUS and DEVFN information can be retrieved from the box control field. Introduce the uncore_pci_pmus_register() to register all the PCICFG type of uncore blocks. The old PCI probe/remove way is dropped.
The PCI BUS and DEVFN information are different among dies. Add box_ctls to store the box control field of each die.
Add a new BUS notifier for the PCI type of uncore block to support the hotplug. If the device is "hot remove", the corresponding registered PMU has to be unregistered. Perf cannot locate the PMU by searching a const pci_device_id table, because the discovery tables don't provide such information. Introduce uncore_pci_find_dev_pmu_from_types() to search the whole uncore_pci_uncores for the PMU.
Implement generic support for the PCI type of uncore block.
--- arch/x86/events/intel/uncore.c | 91 +++++++++++++++++++++++++++++--- arch/x86/events/intel/uncore.h | 6 ++- arch/x86/events/intel/uncore_discovery.c | 80 ++++++++++++++++++++++++++++ arch/x86/events/intel/uncore_discovery.h | 7 +++ 4 files changed, 177 insertions(+), 7 deletions(-)
arch/x86/events/intel/uncore.c +85 -6
@@ -1028,10 +1028,37 @@ static int uncore_pci_get_dev_die_info(struct pci_dev *pdev, int *die)return 0 ; } +static struct intel_uncore_pmu * +uncore_pci_find_dev_pmu_from_types (struct pci_dev *pdev) +{ +struct intel_uncore_type **types = uncore_pci_uncores; +struct intel_uncore_type *type; +u64 box_ctl; +int i, die; + +for (; *types; types++) { + type = *types; +for (die =0 ; die < __uncore_max_dies; die++) { +for (i =0 ; i < type->num_boxes; i++) { +if (!type->box_ctls[die]) +continue ; + box_ctl = type->box_ctls[die] + type->pci_offsets[i]; +if (pdev->devfn ==UNCORE_DISCOVERY_PCI_DEVFN (box_ctl) && + pdev->bus->number ==UNCORE_DISCOVERY_PCI_BUS (box_ctl) && +pci_domain_nr (pdev->bus) ==UNCORE_DISCOVERY_PCI_DOMAIN (box_ctl)) +return &type->pmus[i]; + } + } + } + +return NULL ; +} +/* * Find the PMU of a PCI device. * @pdev: The PCI device. * @ids: The ID table of the available PCI devices with a PMU. +* If NULL, search the whole uncore_pci_uncores. */ static struct intel_uncore_pmu *uncore_pci_find_dev_pmu (struct pci_dev *pdev,const struct pci_device_id *ids)
@@ -1041,6 +1068,9 @@ uncore_pci_find_dev_pmu(struct pci_dev *pdev, const struct pci_device_id *ids)kernel_ulong_t data;unsigned int devfn; +if (!ids) +return uncore_pci_find_dev_pmu_from_types (pdev); +while (ids && ids->vendor) {if ((ids->vendor == pdev->vendor) && (ids->device == pdev->device)) {
@@ -1279,6 +1309,48 @@ static void uncore_pci_sub_driver_init(void) uncore_pci_sub_driver =NULL ; } +static int uncore_pci_bus_notify (struct notifier_block *nb, +unsigned long action,void *data) +{ +return uncore_bus_notify (nb, action, data,NULL ); +} + +static struct notifier_block uncore_pci_notifier = { + .notifier_call = uncore_pci_bus_notify, +}; + + +static void uncore_pci_pmus_register (void ) +{ +struct intel_uncore_type **types = uncore_pci_uncores; +struct intel_uncore_type *type; +struct intel_uncore_pmu *pmu; +struct pci_dev *pdev; +u64 box_ctl; +int i, die; + +for (; *types; types++) { + type = *types; +for (die =0 ; die < __uncore_max_dies; die++) { +for (i =0 ; i < type->num_boxes; i++) { +if (!type->box_ctls[die]) +continue ; + box_ctl = type->box_ctls[die] + type->pci_offsets[i]; + pdev =pci_get_domain_bus_and_slot (UNCORE_DISCOVERY_PCI_DOMAIN (box_ctl), +UNCORE_DISCOVERY_PCI_BUS (box_ctl), +UNCORE_DISCOVERY_PCI_DEVFN (box_ctl)); +if (!pdev) +continue ; + pmu = &type->pmus[i]; + +uncore_pci_pmu_register (pdev, type, pmu, die); + } + } + } + +bus_register_notifier (&pci_bus_type, &uncore_pci_notifier); +} +static int __init uncore_pci_init (void ) {size_t size;
@@ -1295,12 +1367,15 @@ static int __init uncore_pci_init(void)if (ret) goto errtype; - uncore_pci_driver->probe = uncore_pci_probe; - uncore_pci_driver->remove = uncore_pci_remove; +if (uncore_pci_driver) { + uncore_pci_driver->probe = uncore_pci_probe; + uncore_pci_driver->remove = uncore_pci_remove; - ret =pci_register_driver (uncore_pci_driver); -if (ret) - goto errtype; + ret =pci_register_driver (uncore_pci_driver); +if (ret) + goto errtype; + }else +uncore_pci_pmus_register ();if (uncore_pci_sub_driver)uncore_pci_sub_driver_init ();
@@ -1324,7 +1399,10 @@ static void uncore_pci_exit(void) pcidrv_registered = false;if (uncore_pci_sub_driver)bus_unregister_notifier (&pci_bus_type, &uncore_pci_sub_notifier); -pci_unregister_driver (uncore_pci_driver); +if (uncore_pci_driver) +pci_unregister_driver (uncore_pci_driver); +else +bus_unregister_notifier (&pci_bus_type, &uncore_pci_notifier);uncore_types_exit (uncore_pci_uncores);kfree (uncore_extra_pci_dev);uncore_free_pcibus_map ();
@@ -1672,6 +1750,7 @@ static const struct intel_uncore_init_fun snr_uncore_init __initconst = {static const struct intel_uncore_init_fun generic_uncore_init__initconst = { .cpu_init = intel_uncore_generic_uncore_cpu_init, + .pci_init = intel_uncore_generic_uncore_pci_init, };static const struct x86_cpu_id intel_uncore_match[]__initconst = {
arch/x86/events/intel/uncore.h +5 -1
@@ -58,6 +58,7 @@ struct intel_uncore_type {unsigned fixed_ctr;unsigned fixed_ctl;unsigned box_ctl; +u64 *box_ctls;/* Unit ctrl addr of the first box of each die */ union {unsigned msr_offset;unsigned mmio_offset;
@@ -66,7 +67,10 @@ struct intel_uncore_type { unsigned num_shared_regs:8; unsigned single_fixed:1; unsigned pair_ctr_ctl:1; -unsigned *msr_offsets; +union { +unsigned *msr_offsets; +unsigned *pci_offsets; + };unsigned *box_ids;struct event_constraint unconstrainted;struct event_constraint *constraints;
arch/x86/events/intel/uncore_discovery.c +80 -0
95 lines not on this page · raw message
arch/x86/events/intel/uncore_discovery.h +7 -0
@@ -23,6 +23,12 @@/* Global discovery table size */ #define UNCORE_DISCOVERY_GLOBAL_MAP_SIZE 0x20 +#define UNCORE_DISCOVERY_PCI_DOMAIN (data) ((data >> 28) & 0x7) +#define UNCORE_DISCOVERY_PCI_BUS (data) ((data >> 20) & 0xff) +#define UNCORE_DISCOVERY_PCI_DEVFN (data) ((data >> 12) & 0xff) +#define UNCORE_DISCOVERY_PCI_BOX_CTRL (data) (data & 0xfff) + +#define uncore_discovery_invalid_unit (unit) \ (!unit.table1 || !unit.ctl || !unit.table3 || \ unit.table1 == -1ULL || unit.ctl == -1ULL || \
@@ -121,3 +127,4 @@ struct intel_uncore_discovery_type {bool intel_uncore_has_discovery_tables (void );void intel_uncore_clear_discovery_tables (void );void intel_uncore_generic_uncore_cpu_init (void ); +int intel_uncore_generic_uncore_pci_init (void );
Signature · 1 line
2.7.4
PATCH 5/5 perf/x86/intel/uncore: Generic support for the MMIO type of uncore blocks
In reply to [email protected]From: Kan Liang <[email protected]>
The discovery table provides the generic uncore block information for the MMIO type of uncore blocks, which is good enough to provide basic uncore support.
The box control field is composed of the BAR address and box control offset. When initializing the uncore blocks, perf should ioremap the address from the box control field.
Implement the generic support for the MMIO type of uncore block.
--- arch/x86/events/intel/uncore.c | 1 + arch/x86/events/intel/uncore.h | 1 + arch/x86/events/intel/uncore_discovery.c | 98 ++++++++++++++++++++++++++++++++ arch/x86/events/intel/uncore_discovery.h | 1 + 4 files changed, 101 insertions(+)
arch/x86/events/intel/uncore.c +1 -0
@@ -1751,6 +1751,7 @@ static const struct intel_uncore_init_fun snr_uncore_init __initconst = {static const struct intel_uncore_init_fun generic_uncore_init__initconst = { .cpu_init = intel_uncore_generic_uncore_cpu_init, .pci_init = intel_uncore_generic_uncore_pci_init, + .mmio_init = intel_uncore_generic_uncore_mmio_init, };static const struct x86_cpu_id intel_uncore_match[]__initconst = {
arch/x86/events/intel/uncore.h +1 -0
@@ -70,6 +70,7 @@ struct intel_uncore_type {union {unsigned *msr_offsets;unsigned *pci_offsets; +unsigned *mmio_offsets; };unsigned *box_ids;struct event_constraint unconstrainted;
arch/x86/events/intel/uncore_discovery.c +98 -0
113 lines not on this page · raw message
arch/x86/events/intel/uncore_discovery.h +1 -0
@@ -128,3 +128,4 @@ bool intel_uncore_has_discovery_tables(void);void intel_uncore_clear_discovery_tables (void );void intel_uncore_generic_uncore_cpu_init (void );int intel_uncore_generic_uncore_pci_init (void ); +void intel_uncore_generic_uncore_mmio_init (void );
Signature · 1 line
2.7.4