Support HBM and CXL PMON uncore counters
Subsystems (2)
v2 cover Support HBM and CXL PMON uncore counters
From: Kan Liang <[email protected]>
Changes since V2:
- Update the description of patch 1 to explain the design of the new RB tree. (Tim)
The uncore PMON information of both HBM and CXL can be retrieved from the discovery table. However, the CXL entries break the driver's assumption for the discovery table. The first 7 patches update the generic support of the discovery table. The last patch enables the HBM and CXL PMON uncore counters.
The discovery table support was introduced since commit edae1f06c2cd ("perf/x86/intel/uncore: Parse uncore discovery tables"). It's a self-describing mechanism for the uncore PerfMon hardware. By reading through an MMIO page worth of information, SW can ‘discover’ all the standard uncore PMON registers.
The entire discovery table could be big and contain duplicate information. To save space, the perf uncore driver only stores some key data. Others are calculated from the key data. The driver further assumes that the uncore PMON units are symmetric among dies. So only the unit control addresses on Die 0 are completely stored. The addresses on other Dies can be calculated via the address of the first entry on the Die + a fixed offset.
However, it doesn't work for the CXL PMON units. The CXL PMON units could be asymmetric among Dies. The offset between CXL PMON units may be different on different Die.
To address the issue, the complete unit control addresses for all Dies are stored in an RB tree. For a 2-socket EMR, it requires at most ~6KB extra space, which should be acceptable.
Kan Liang (8):
perf/x86/uncore: Save the unit control address of all units perf/x86/uncore: Support per PMU cpumask
perf/x86/uncore: Retrieve the unit ID from the unit control RB tree perf/x86/uncore: Apply the unit control RB tree to MMIO uncore units perf/x86/uncore: Apply the unit control RB tree to MSR uncore units perf/x86/uncore: Apply the unit control RB tree to PCI uncore units perf/x86/uncore: Cleanup unused unit structure perf/x86/intel/uncore: Support HBM and CXL PMON counters
arch/x86/events/intel/uncore.c | 97 ++++--- arch/x86/events/intel/uncore.h | 8 +- arch/x86/events/intel/uncore_discovery.c | 306 +++++++++++++++-------- arch/x86/events/intel/uncore_discovery.h | 22 +- arch/x86/events/intel/uncore_snbep.c | 128 ++++++++-- 5 files changed, 388 insertions(+), 173 deletions(-)
Signature · 1 line
2.35.1
PATCH v2 1/8 perf/x86/uncore: Save the unit control address of all units
From: Kan Liang <[email protected]>
The unit control address of some CXL units may be wrongly calculated under some configuration on a EMR machine.
The current implementation only saves the unit control address of the units from the first die, and the first unit of the rest of dies. Perf assumed that the units from the other dies have the same offset as the first die. So the unit control address of the rest of the units can be calculated. However, the assumption is wrong, especially for the CXL units.
Introduce an RB tree for each uncore type to save the unit control address and three kinds of ID information (unit ID, PMU ID, and die ID) for all units.
The unit ID is a physical ID of a unit.
The PMU ID is a logical ID assigned to a unit. The logical IDs start from 0 and must be contiguous. The physical ID and the logical ID are 1:1 mapping. The units with the same physical ID in different dies share the same PMU.
The die ID indicates which die a unit belongs to.
The RB tree can be searched by two different keys (unit ID or PMU ID + die ID). During the RB tree setup, the unit ID is used as a key to look up the RB tree. The perf can create/assign a proper PMU ID to the unit. Later, after the RB tree is setup, PMU ID + die ID is used as a key to look up the RB tree to fill the cpumask of a PMU. It's used more frequently, so PMU ID + die ID is compared in the unit_less(). The uncore_find_unit() has to be O(N). But the RB tree setup only occurs once during the driver load time. It should be acceptable.
Compared with the current implementation, more space is required to save the information of all units. The extra size should be acceptable. For example, on EMR, there are 221 units at most. For a 2-socket machine, the extra space is ~6KB at most.
--- arch/x86/events/intel/uncore_discovery.c | 79 +++++++++++++++++++++++- arch/x86/events/intel/uncore_discovery.h | 10 +++ 2 files changed, 87 insertions(+), 2 deletions(-)
arch/x86/events/intel/uncore_discovery.c +77 -2
@@ -93,6 +93,8 @@ add_uncore_discovery_type(struct uncore_unit_discovery *unit)if (!type->box_ctrl_die) goto free_type; + type->units =RB_ROOT ; + type->access_type = unit->access_type; num_discovered_types[type->access_type]++; type->type = unit->box_type;
@@ -120,10 +122,59 @@ get_uncore_discovery_type(struct uncore_unit_discovery *unit)return add_uncore_discovery_type (unit); } +static inline bool unit_less (struct rb_node *a,const struct rb_node *b) +{ +struct intel_uncore_discovery_unit *a_node, *b_node; + + a_node = rb_entry(a, struct intel_uncore_discovery_unit, node); + b_node = rb_entry(b, struct intel_uncore_discovery_unit, node); + +if (a_node->pmu_idx < b_node->pmu_idx) +return true; +if (a_node->pmu_idx > b_node->pmu_idx) +return false; + +if (a_node->die < b_node->die) +return true; +if (a_node->die > b_node->die) +return false; + +return 0 ; +} + +static inline struct intel_uncore_discovery_unit * +uncore_find_unit (struct rb_root *root,unsigned int id) +{ +struct intel_uncore_discovery_unit *unit; +struct rb_node *node; + +for (node =rb_first (root); node; node =rb_next (node)) { + unit = rb_entry(node, struct intel_uncore_discovery_unit, node); +if (unit->id == id) +return unit; + } + +return NULL ; +} + +static void uncore_find_add_unit (struct intel_uncore_discovery_unit *node, +struct rb_root *root,u16 *num_units) +{ +struct intel_uncore_discovery_unit *unit =uncore_find_unit (root, node->id); + +if (unit) + node->pmu_idx = unit->pmu_idx; +else if (num_units) + node->pmu_idx = (*num_units)++; + +rb_add (&node->node, root, unit_less); +} +static void uncore_insert_box_info (struct uncore_unit_discovery *unit,int die,bool parsed) { +struct intel_uncore_discovery_unit *node;struct intel_uncore_discovery_type *type;unsigned int *ids;u64 *box_offset;
@@ -136,14 +187,26 @@ uncore_insert_box_info(struct uncore_unit_discovery *unit,return ; } + node =kzalloc (sizeof (*node),GFP_KERNEL ); +if (!node) +return ; + + node->die = die; + node->id = unit->box_id; + node->addr = unit->ctl; +if (parsed) { type =search_uncore_discovery_type (unit->box_type);if (!type) {pr_info ("A spurious uncore type %d is detected, " "Disable the uncore type.\n" , unit->box_type); +kfree (node);return ; } + +uncore_find_add_unit (node, &type->units, &type->num_units); +/* Store the first box of each die */ if (!type->box_ctrl_die[die]) type->box_ctrl_die[die] = unit->ctl;
@@ -152,16 +215,18 @@ uncore_insert_box_info(struct uncore_unit_discovery *unit, type =get_uncore_discovery_type (unit);if (!type) -return ; + goto free_node; box_offset =kcalloc (type->num_boxes +1 ,sizeof (u64),GFP_KERNEL );if (!box_offset) -return ; + goto free_node; ids =kcalloc (type->num_boxes +1 ,sizeof (unsigned int ),GFP_KERNEL );if (!ids) goto free_box_offset; +uncore_find_add_unit (node, &type->units, &type->num_units); +/* Store generic information for the first box */ if (!type->num_boxes) { type->box_ctrl = unit->ctl;
@@ -201,6 +266,8 @@ uncore_insert_box_info(struct uncore_unit_discovery *unit, free_box_offset:kfree (box_offset); +free_node: +kfree (node); } static bool
@@ -339,8 +406,16 @@ bool intel_uncore_has_discovery_tables(int *ignore)void intel_uncore_clear_discovery_tables (void ) {struct intel_uncore_discovery_type *type, *next; +struct intel_uncore_discovery_unit *pos; +struct rb_node *node;rbtree_postorder_for_each_entry_safe (type, next, &discovery_tables, node) { +while (!RB_EMPTY_ROOT (&type->units)) { + node =rb_first (&type->units); + pos = rb_entry(node, struct intel_uncore_discovery_unit, node); +rb_erase (node, &type->units); +kfree (pos); + }kfree (type->box_ctrl_die);kfree (type); }
arch/x86/events/intel/uncore_discovery.h +10 -0
@@ -113,17 +113,27 @@ struct uncore_unit_discovery { }; }; +struct intel_uncore_discovery_unit { +struct rb_node node; +unsigned int pmu_idx;/* The idx of the corresponding PMU */ +unsigned int id;/* Unit ID */ +unsigned int die;/* Die ID */ +u64 addr;/* Unit Control Address */ +}; +struct intel_uncore_discovery_type {struct rb_node node;enum uncore_access_type access_type;u64 box_ctrl;/* Unit ctrl addr of the first box */ u64 *box_ctrl_die;/* Unit ctrl addr of the first box of each die */ +struct rb_root units;/* Unit ctrl addr for all units */ u16 type;/* Type ID of the uncore block */ u8 num_counters;u8 counter_width;u8 ctl_offset;/* Counter Control 0 offset */ u8 ctr_offset;/* Counter 0 offset */ u16 num_boxes;/* number of boxes for the uncore block */ +u16 num_units;/* number of units */ unsigned int *ids;/* Box IDs */ u64 *box_offset;/* Box offset */ };
Signature · 1 line
2.35.1
Peter Zijlstra
maintainerRe: [PATCH V2 1/8] perf/x86/uncore: Save the unit control address of all units
Quoted 11 lines · On Fri, Jun 14, 2024 at 06:46:24AM -0700, [email protected] wrote:
From: Kan Liang <[email protected]>
The unit control address of some CXL units may be wrongly calculated under some configuration on a EMR machine.
The current implementation only saves the unit control address of the units from the first die, and the first unit of the rest of dies. Perf assumed that the units from the other dies have the same offset as the first die. So the unit control address of the rest of the units can be calculated. However, the assumption is wrong, especially for the CXL units.
Oh gawd, that's terrible. Was this actually specified, or are we hacking around a firmware fail?
Re: [PATCH V2 1/8] perf/x86/uncore: Save the unit control address of all units
Quoted 13 lines · Peter Zijlstra
Quoted 11 lines · On Fri, Jun 14, 2024 at 06:46:24AM -0700, [email protected] wrote:
From: Kan Liang <[email protected]>
The unit control address of some CXL units may be wrongly calculated under some configuration on a EMR machine.
The current implementation only saves the unit control address of the units from the first die, and the first unit of the rest of dies. Perf assumed that the units from the other dies have the same offset as the first die. So the unit control address of the rest of the units can be calculated. However, the assumption is wrong, especially for the CXL units.
Quoted 2 lines
Oh gawd, that's terrible. Was this actually specified, or are we hacking around a firmware fail?
Not a workaround for a firmware fail. The the CXL discovery units depend on the stacks and CXL devices present on each socket. So different number of CXL devices on each socket is a valid combination. SW cannot calculate the address of the devices on the other sockets via the first socket. Full addresses have to be used.
Thanks,
Kan
[tip: perf/core] perf/x86/uncore: Save the unit control address of all units
In reply to [email protected]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: 0007f39325921351b7860a976a730acbb198b9ca Gitweb: https://git.kernel.org/tip/0007f39325921351b7860a976a730acbb198b9ca Author: Kan Liang <[email protected]> AuthorDate: Fri, 14 Jun 2024 06:46:24 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Mon, 17 Jun 2024 17:57:55 +02:00
perf/x86/uncore: Save the unit control address of all units
The unit control address of some CXL units may be wrongly calculated under some configuration on a EMR machine.
The current implementation only saves the unit control address of the units from the first die, and the first unit of the rest of dies. Perf assumed that the units from the other dies have the same offset as the first die. So the unit control address of the rest of the units can be calculated. However, the assumption is wrong, especially for the CXL units.
Introduce an RB tree for each uncore type to save the unit control address and three kinds of ID information (unit ID, PMU ID, and die ID) for all units.
The unit ID is a physical ID of a unit.
The PMU ID is a logical ID assigned to a unit. The logical IDs start from 0 and must be contiguous. The physical ID and the logical ID are 1:1 mapping. The units with the same physical ID in different dies share the same PMU.
The die ID indicates which die a unit belongs to.
The RB tree can be searched by two different keys (unit ID or PMU ID + die ID). During the RB tree setup, the unit ID is used as a key to look up the RB tree. The perf can create/assign a proper PMU ID to the unit. Later, after the RB tree is setup, PMU ID + die ID is used as a key to look up the RB tree to fill the cpumask of a PMU. It's used more frequently, so PMU ID + die ID is compared in the unit_less(). The uncore_find_unit() has to be O(N). But the RB tree setup only occurs once during the driver load time. It should be acceptable.
Compared with the current implementation, more space is required to save the information of all units. The extra size should be acceptable. For example, on EMR, there are 221 units at most. For a 2-socket machine, the extra space is ~6KB at most.
--- arch/x86/events/intel/uncore_discovery.c | 79 ++++++++++++++++++++++- arch/x86/events/intel/uncore_discovery.h | 10 +++- 2 files changed, 87 insertions(+), 2 deletions(-)
arch/x86/events/intel/uncore_discovery.c +77 -2
@@ -93,6 +93,8 @@ add_uncore_discovery_type(struct uncore_unit_discovery *unit)if (!type->box_ctrl_die) goto free_type; + type->units =RB_ROOT ; + type->access_type = unit->access_type; num_discovered_types[type->access_type]++; type->type = unit->box_type;
@@ -120,10 +122,59 @@ get_uncore_discovery_type(struct uncore_unit_discovery *unit)return add_uncore_discovery_type (unit); } +static inline bool unit_less (struct rb_node *a,const struct rb_node *b) +{ +struct intel_uncore_discovery_unit *a_node, *b_node; + + a_node = rb_entry(a, struct intel_uncore_discovery_unit, node); + b_node = rb_entry(b, struct intel_uncore_discovery_unit, node); + +if (a_node->pmu_idx < b_node->pmu_idx) +return true; +if (a_node->pmu_idx > b_node->pmu_idx) +return false; + +if (a_node->die < b_node->die) +return true; +if (a_node->die > b_node->die) +return false; + +return 0 ; +} + +static inline struct intel_uncore_discovery_unit * +uncore_find_unit (struct rb_root *root,unsigned int id) +{ +struct intel_uncore_discovery_unit *unit; +struct rb_node *node; + +for (node =rb_first (root); node; node =rb_next (node)) { + unit = rb_entry(node, struct intel_uncore_discovery_unit, node); +if (unit->id == id) +return unit; + } + +return NULL ; +} + +static void uncore_find_add_unit (struct intel_uncore_discovery_unit *node, +struct rb_root *root,u16 *num_units) +{ +struct intel_uncore_discovery_unit *unit =uncore_find_unit (root, node->id); + +if (unit) + node->pmu_idx = unit->pmu_idx; +else if (num_units) + node->pmu_idx = (*num_units)++; + +rb_add (&node->node, root, unit_less); +} +static void uncore_insert_box_info (struct uncore_unit_discovery *unit,int die,bool parsed) { +struct intel_uncore_discovery_unit *node;struct intel_uncore_discovery_type *type;unsigned int *ids;u64 *box_offset;
@@ -136,14 +187,26 @@ uncore_insert_box_info(struct uncore_unit_discovery *unit,return ; } + node =kzalloc (sizeof (*node),GFP_KERNEL ); +if (!node) +return ; + + node->die = die; + node->id = unit->box_id; + node->addr = unit->ctl; +if (parsed) { type =search_uncore_discovery_type (unit->box_type);if (!type) {pr_info ("A spurious uncore type %d is detected, " "Disable the uncore type.\n" , unit->box_type); +kfree (node);return ; } + +uncore_find_add_unit (node, &type->units, &type->num_units); +/* Store the first box of each die */ if (!type->box_ctrl_die[die]) type->box_ctrl_die[die] = unit->ctl;
@@ -152,16 +215,18 @@ uncore_insert_box_info(struct uncore_unit_discovery *unit, type =get_uncore_discovery_type (unit);if (!type) -return ; + goto free_node; box_offset =kcalloc (type->num_boxes +1 ,sizeof (u64),GFP_KERNEL );if (!box_offset) -return ; + goto free_node; ids =kcalloc (type->num_boxes +1 ,sizeof (unsigned int ),GFP_KERNEL );if (!ids) goto free_box_offset; +uncore_find_add_unit (node, &type->units, &type->num_units); +/* Store generic information for the first box */ if (!type->num_boxes) { type->box_ctrl = unit->ctl;
@@ -201,6 +266,8 @@ free_ids: free_box_offset:kfree (box_offset); +free_node: +kfree (node); } static bool
@@ -339,8 +406,16 @@ err:void intel_uncore_clear_discovery_tables (void ) {struct intel_uncore_discovery_type *type, *next; +struct intel_uncore_discovery_unit *pos; +struct rb_node *node;rbtree_postorder_for_each_entry_safe (type, next, &discovery_tables, node) { +while (!RB_EMPTY_ROOT (&type->units)) { + node =rb_first (&type->units); + pos = rb_entry(node, struct intel_uncore_discovery_unit, node); +rb_erase (node, &type->units); +kfree (pos); + }kfree (type->box_ctrl_die);kfree (type); }
arch/x86/events/intel/uncore_discovery.h +10 -0
@@ -113,17 +113,27 @@ struct uncore_unit_discovery { }; }; +struct intel_uncore_discovery_unit { +struct rb_node node; +unsigned int pmu_idx;/* The idx of the corresponding PMU */ +unsigned int id;/* Unit ID */ +unsigned int die;/* Die ID */ +u64 addr;/* Unit Control Address */ +}; +struct intel_uncore_discovery_type {struct rb_node node;enum uncore_access_type access_type;u64 box_ctrl;/* Unit ctrl addr of the first box */ u64 *box_ctrl_die;/* Unit ctrl addr of the first box of each die */ +struct rb_root units;/* Unit ctrl addr for all units */ u16 type;/* Type ID of the uncore block */ u8 num_counters;u8 counter_width;u8 ctl_offset;/* Counter Control 0 offset */ u8 ctr_offset;/* Counter 0 offset */ u16 num_boxes;/* number of boxes for the uncore block */ +u16 num_units;/* number of units */ unsigned int *ids;/* Box IDs */ u64 *box_offset;/* Box offset */ };
PATCH v2 2/8 perf/x86/uncore: Support per PMU cpumask
In reply to [email protected]From: Kan Liang <[email protected]>
The cpumask of some uncore units, e.g., CXL uncore units, may be wrong under some configurations. Perf may access an uncore counter of a non-existent uncore unit.
The uncore driver assumes that all uncore units are symmetric among dies. A global cpumask is shared among all uncore PMUs. However, some CXL uncore units may only be available on some dies.
A per PMU cpumask is introduced to track the CPU mask of this PMU. The driver searches the unit control RB tree to check whether the PMU is available on a given die, and updates the per PMU cpumask accordingly.
--- arch/x86/events/intel/uncore.c | 31 +++++++++++-- arch/x86/events/intel/uncore.h | 2 + arch/x86/events/intel/uncore_discovery.c | 58 ++++++++++++++++++++++++ arch/x86/events/intel/uncore_discovery.h | 3 ++ 4 files changed, 89 insertions(+), 5 deletions(-)
arch/x86/events/intel/uncore.c +26 -5
@@ -843,7 +843,9 @@ static void uncore_pmu_disable(struct pmu *pmu)static ssize_t uncore_get_attr_cpumask (struct device *dev,struct device_attribute *attr,char *buf) { -return cpumap_print_to_pagebuf (true, buf, &uncore_cpu_mask); + struct intel_uncore_pmu *pmu = container_of(dev_get_drvdata(dev), struct intel_uncore_pmu, pmu); + +return cpumap_print_to_pagebuf (true, buf, &pmu->cpu_mask); } static DEVICE_ATTR(cpumask, S_IRUGO, uncore_get_attr_cpumask, NULL);
@@ -1453,6 +1455,18 @@ static void uncore_pci_exit(void) } } +static bool uncore_die_has_box (struct intel_uncore_type *type, +int die,unsigned int pmu_idx) +{ +if (!type->boxes) +return true; + +if (intel_uncore_find_discovery_unit_id (type->boxes, die, pmu_idx) <0 ) +return false; + +return true; +} +static void uncore_change_type_ctx (struct intel_uncore_type *type,int old_cpu,int new_cpu) {
@@ -1468,18 +1482,25 @@ static void uncore_change_type_ctx(struct intel_uncore_type *type, int old_cpu,if (old_cpu <0 ) {WARN_ON_ONCE (box->cpu !=-1 ); - box->cpu = new_cpu; +if (uncore_die_has_box (type, die, pmu->pmu_idx)) { + box->cpu = new_cpu; +cpumask_set_cpu (new_cpu, &pmu->cpu_mask); + }continue ; } -WARN_ON_ONCE (box->cpu != old_cpu); +WARN_ON_ONCE (box->cpu !=-1 && box->cpu != old_cpu); box->cpu =-1 ; +cpumask_clear_cpu (old_cpu, &pmu->cpu_mask);if (new_cpu <0 )continue ; +if (!uncore_die_has_box (type, die, pmu->pmu_idx)) +continue ;uncore_pmu_cancel_hrtimer (box);perf_pmu_migrate_context (&pmu->pmu, old_cpu, new_cpu); box->cpu = new_cpu; +cpumask_set_cpu (new_cpu, &pmu->cpu_mask); } }
@@ -1502,7 +1523,7 @@ static void uncore_box_unref(struct intel_uncore_type **types, int id) pmu = type->pmus;for (i =0 ; i < type->num_boxes; i++, pmu++) { box = pmu->boxes[id]; -if (box &&atomic_dec_return (&box->refcnt) ==0 ) +if (box && box->cpu >=0 &&atomic_dec_return (&box->refcnt) ==0 )uncore_box_exit (box); } }
@@ -1592,7 +1613,7 @@ static int uncore_box_ref(struct intel_uncore_type **types, pmu = type->pmus;for (i =0 ; i < type->num_boxes; i++, pmu++) { box = pmu->boxes[id]; -if (box &&atomic_inc_return (&box->refcnt) ==1 ) +if (box && box->cpu >=0 &&atomic_inc_return (&box->refcnt) ==1 )uncore_box_init (box); } }
arch/x86/events/intel/uncore.h +2 -0
@@ -86,6 +86,7 @@ struct intel_uncore_type {const struct attribute_group *attr_groups[4 ];const struct attribute_group **attr_update;struct pmu *pmu;/* for custom pmu ops */ +struct rb_root *boxes;/* * Uncore PMU would store relevant platform topology configuration here * to identify which platform component each PMON block of that type is
@@ -125,6 +126,7 @@ struct intel_uncore_pmu {int func_id;bool registered;atomic_t activeboxes; +cpumask_t cpu_mask;struct intel_uncore_type *type;struct intel_uncore_box **boxes; };
arch/x86/events/intel/uncore_discovery.c +58 -0
64 lines not on this page · raw message
arch/x86/events/intel/uncore_discovery.h +3 -0
@@ -166,3 +166,6 @@ u64 intel_generic_uncore_pci_read_counter(struct intel_uncore_box *box,struct intel_uncore_type **intel_uncore_generic_init_uncores (enum uncore_access_type type_id,int num_extra); + +int intel_uncore_find_discovery_unit_id (struct rb_root *units,int die, +unsigned int pmu_idx);
Signature · 1 line
2.35.1
[tip: perf/core] perf/x86/uncore: Support per PMU cpumask
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: c74443d92f68f07c03ae242ced554b749e6c6736 Gitweb: https://git.kernel.org/tip/c74443d92f68f07c03ae242ced554b749e6c6736 Author: Kan Liang <[email protected]> AuthorDate: Fri, 14 Jun 2024 06:46:25 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Mon, 17 Jun 2024 17:57:56 +02:00
perf/x86/uncore: Support per PMU cpumask
The cpumask of some uncore units, e.g., CXL uncore units, may be wrong under some configurations. Perf may access an uncore counter of a non-existent uncore unit.
The uncore driver assumes that all uncore units are symmetric among dies. A global cpumask is shared among all uncore PMUs. However, some CXL uncore units may only be available on some dies.
A per PMU cpumask is introduced to track the CPU mask of this PMU. The driver searches the unit control RB tree to check whether the PMU is available on a given die, and updates the per PMU cpumask accordingly.
--- arch/x86/events/intel/uncore.c | 31 ++++++++++-- arch/x86/events/intel/uncore.h | 2 +- arch/x86/events/intel/uncore_discovery.c | 58 +++++++++++++++++++++++- arch/x86/events/intel/uncore_discovery.h | 3 +- 4 files changed, 89 insertions(+), 5 deletions(-)
arch/x86/events/intel/uncore.c +26 -5
@@ -843,7 +843,9 @@ static void uncore_pmu_disable(struct pmu *pmu)static ssize_t uncore_get_attr_cpumask (struct device *dev,struct device_attribute *attr,char *buf) { -return cpumap_print_to_pagebuf (true, buf, &uncore_cpu_mask); + struct intel_uncore_pmu *pmu = container_of(dev_get_drvdata(dev), struct intel_uncore_pmu, pmu); + +return cpumap_print_to_pagebuf (true, buf, &pmu->cpu_mask); } static DEVICE_ATTR(cpumask, S_IRUGO, uncore_get_attr_cpumask, NULL);
@@ -1453,6 +1455,18 @@ static void uncore_pci_exit(void) } } +static bool uncore_die_has_box (struct intel_uncore_type *type, +int die,unsigned int pmu_idx) +{ +if (!type->boxes) +return true; + +if (intel_uncore_find_discovery_unit_id (type->boxes, die, pmu_idx) <0 ) +return false; + +return true; +} +static void uncore_change_type_ctx (struct intel_uncore_type *type,int old_cpu,int new_cpu) {
@@ -1468,18 +1482,25 @@ static void uncore_change_type_ctx(struct intel_uncore_type *type, int old_cpu,if (old_cpu <0 ) {WARN_ON_ONCE (box->cpu !=-1 ); - box->cpu = new_cpu; +if (uncore_die_has_box (type, die, pmu->pmu_idx)) { + box->cpu = new_cpu; +cpumask_set_cpu (new_cpu, &pmu->cpu_mask); + }continue ; } -WARN_ON_ONCE (box->cpu != old_cpu); +WARN_ON_ONCE (box->cpu !=-1 && box->cpu != old_cpu); box->cpu =-1 ; +cpumask_clear_cpu (old_cpu, &pmu->cpu_mask);if (new_cpu <0 )continue ; +if (!uncore_die_has_box (type, die, pmu->pmu_idx)) +continue ;uncore_pmu_cancel_hrtimer (box);perf_pmu_migrate_context (&pmu->pmu, old_cpu, new_cpu); box->cpu = new_cpu; +cpumask_set_cpu (new_cpu, &pmu->cpu_mask); } }
@@ -1502,7 +1523,7 @@ static void uncore_box_unref(struct intel_uncore_type **types, int id) pmu = type->pmus;for (i =0 ; i < type->num_boxes; i++, pmu++) { box = pmu->boxes[id]; -if (box &&atomic_dec_return (&box->refcnt) ==0 ) +if (box && box->cpu >=0 &&atomic_dec_return (&box->refcnt) ==0 )uncore_box_exit (box); } }
@@ -1592,7 +1613,7 @@ static int uncore_box_ref(struct intel_uncore_type **types, pmu = type->pmus;for (i =0 ; i < type->num_boxes; i++, pmu++) { box = pmu->boxes[id]; -if (box &&atomic_inc_return (&box->refcnt) ==1 ) +if (box && box->cpu >=0 &&atomic_inc_return (&box->refcnt) ==1 )uncore_box_init (box); } }
arch/x86/events/intel/uncore.h +2 -0
@@ -86,6 +86,7 @@ struct intel_uncore_type {const struct attribute_group *attr_groups[4 ];const struct attribute_group **attr_update;struct pmu *pmu;/* for custom pmu ops */ +struct rb_root *boxes;/* * Uncore PMU would store relevant platform topology configuration here * to identify which platform component each PMON block of that type is
@@ -125,6 +126,7 @@ struct intel_uncore_pmu {int func_id;bool registered;atomic_t activeboxes; +cpumask_t cpu_mask;struct intel_uncore_type *type;struct intel_uncore_box **boxes; };
arch/x86/events/intel/uncore_discovery.c +58 -0
64 lines not on this page · raw message
arch/x86/events/intel/uncore_discovery.h +3 -0
@@ -166,3 +166,6 @@ u64 intel_generic_uncore_pci_read_counter(struct intel_uncore_box *box,struct intel_uncore_type **intel_uncore_generic_init_uncores (enum uncore_access_type type_id,int num_extra); + +int intel_uncore_find_discovery_unit_id (struct rb_root *units,int die, +unsigned int pmu_idx);
PATCH v2 3/8 perf/x86/uncore: Retrieve the unit ID from the unit control RB tree
In reply to [email protected]From: Kan Liang <[email protected]>
The box_ids only save the unit ID for the first die. If a unit, e.g., a CXL unit, doesn't exist in the first die. The unit ID cannot be retrieved.
The unit control RB tree also stores the unit ID information. Retrieve the unit ID from the unit control RB tree
--- arch/x86/events/intel/uncore.c | 3 +++ 1 file changed, 3 insertions(+)
arch/x86/events/intel/uncore.c +3 -0
@@ -862,6 +862,9 @@ static const struct attribute_group uncore_pmu_attr_group = {static inline int uncore_get_box_id (struct intel_uncore_type *type,struct intel_uncore_pmu *pmu) { +if (type->boxes) +return intel_uncore_find_discovery_unit_id (type->boxes,-1 , pmu->pmu_idx); +return type->box_ids ? type->box_ids[pmu->pmu_idx] : pmu->pmu_idx; }
Signature · 1 line
2.35.1
[tip: perf/core] perf/x86/uncore: Retrieve the unit ID from the unit control RB tree
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: 585463fee64270d4b4d80b1e433d2105ef555bec Gitweb: https://git.kernel.org/tip/585463fee64270d4b4d80b1e433d2105ef555bec Author: Kan Liang <[email protected]> AuthorDate: Fri, 14 Jun 2024 06:46:26 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Mon, 17 Jun 2024 17:57:56 +02:00
perf/x86/uncore: Retrieve the unit ID from the unit control RB tree
The box_ids only save the unit ID for the first die. If a unit, e.g., a CXL unit, doesn't exist in the first die. The unit ID cannot be retrieved.
The unit control RB tree also stores the unit ID information. Retrieve the unit ID from the unit control RB tree
--- arch/x86/events/intel/uncore.c | 3 +++ 1 file changed, 3 insertions(+)
arch/x86/events/intel/uncore.c +3 -0
@@ -862,6 +862,9 @@ static const struct attribute_group uncore_pmu_attr_group = {static inline int uncore_get_box_id (struct intel_uncore_type *type,struct intel_uncore_pmu *pmu) { +if (type->boxes) +return intel_uncore_find_discovery_unit_id (type->boxes,-1 , pmu->pmu_idx); +return type->box_ids ? type->box_ids[pmu->pmu_idx] : pmu->pmu_idx; }
PATCH v2 4/8 perf/x86/uncore: Apply the unit control RB tree to MMIO uncore units
In reply to [email protected]From: Kan Liang <[email protected]>
The unit control RB tree has the unit control and unit ID information for all the units. Use it to replace the box_ctls/mmio_offsets to get an accurate unit control address for MMIO uncore units.
--- arch/x86/events/intel/uncore_discovery.c | 30 +++++++++++------------- 1 file changed, 14 insertions(+), 16 deletions(-)
arch/x86/events/intel/uncore_discovery.c +14 -16
@@ -606,34 +606,30 @@ static struct intel_uncore_ops generic_uncore_pci_ops = {#define UNCORE_GENERIC_MMIO_SIZE 0x4000 -static u64 generic_uncore_mmio_box_ctl (struct intel_uncore_box *box) -{ -struct intel_uncore_type *type = box->pmu->type; - -if (!type->box_ctls || !type->box_ctls[box->dieid] || !type->mmio_offsets) -return 0 ; - -return type->box_ctls[box->dieid] + type->mmio_offsets[box->pmu->pmu_idx]; -} -void intel_generic_uncore_mmio_init_box (struct intel_uncore_box *box) { -u64 box_ctl =generic_uncore_mmio_box_ctl (box); +static struct intel_uncore_discovery_unit *unit;struct intel_uncore_type *type = box->pmu->type;resource_size_t addr; -if (!box_ctl) { + unit =intel_uncore_find_discovery_unit (type->boxes, box->dieid, box->pmu->pmu_idx); +if (!unit) { +pr_warn ("Uncore type %d id %d: Cannot find box control address.\n" , + type->type_id, box->pmu->pmu_idx); +return ; + } + +if (!unit->addr) {pr_warn ("Uncore type %d box %d: Invalid box control address.\n" , - type->type_id, type->box_ids[box->pmu->pmu_idx]); + type->type_id, unit->id);return ; } - addr = box_ctl; + addr = unit->addr; box->io_addr =ioremap (addr,UNCORE_GENERIC_MMIO_SIZE );if (!box->io_addr) {pr_warn ("Uncore type %d box %d: ioremap error for 0x%llx.\n" , - type->type_id, type->box_ids[box->pmu->pmu_idx], - (unsigned long long )addr); + type->type_id, unit->id, (unsigned long long )addr);return ; }
@@ -722,6 +718,8 @@ static bool uncore_update_uncore_type(enum uncore_access_type type_id, uncore->box_ctls = type->box_ctrl_die; uncore->mmio_offsets = type->box_offset; uncore->mmio_map_size =UNCORE_GENERIC_MMIO_SIZE ; + uncore->boxes = &type->units; + uncore->num_boxes = type->num_units;break ;default :return false;
Signature · 1 line
2.35.1
[tip: perf/core] perf/x86/uncore: Apply the unit control RB tree to MMIO uncore units
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: 80580dae65b941eb681bd79f31f64f91b58232b4 Gitweb: https://git.kernel.org/tip/80580dae65b941eb681bd79f31f64f91b58232b4 Author: Kan Liang <[email protected]> AuthorDate: Fri, 14 Jun 2024 06:46:27 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Mon, 17 Jun 2024 17:57:57 +02:00
perf/x86/uncore: Apply the unit control RB tree to MMIO uncore units
The unit control RB tree has the unit control and unit ID information for all the units. Use it to replace the box_ctls/mmio_offsets to get an accurate unit control address for MMIO uncore units.
--- arch/x86/events/intel/uncore_discovery.c | 30 ++++++++++------------- 1 file changed, 14 insertions(+), 16 deletions(-)
arch/x86/events/intel/uncore_discovery.c +14 -16
@@ -606,34 +606,30 @@ static struct intel_uncore_ops generic_uncore_pci_ops = {#define UNCORE_GENERIC_MMIO_SIZE 0x4000 -static u64 generic_uncore_mmio_box_ctl (struct intel_uncore_box *box) -{ -struct intel_uncore_type *type = box->pmu->type; - -if (!type->box_ctls || !type->box_ctls[box->dieid] || !type->mmio_offsets) -return 0 ; - -return type->box_ctls[box->dieid] + type->mmio_offsets[box->pmu->pmu_idx]; -} -void intel_generic_uncore_mmio_init_box (struct intel_uncore_box *box) { -u64 box_ctl =generic_uncore_mmio_box_ctl (box); +static struct intel_uncore_discovery_unit *unit;struct intel_uncore_type *type = box->pmu->type;resource_size_t addr; -if (!box_ctl) { + unit =intel_uncore_find_discovery_unit (type->boxes, box->dieid, box->pmu->pmu_idx); +if (!unit) { +pr_warn ("Uncore type %d id %d: Cannot find box control address.\n" , + type->type_id, box->pmu->pmu_idx); +return ; + } + +if (!unit->addr) {pr_warn ("Uncore type %d box %d: Invalid box control address.\n" , - type->type_id, type->box_ids[box->pmu->pmu_idx]); + type->type_id, unit->id);return ; } - addr = box_ctl; + addr = unit->addr; box->io_addr =ioremap (addr,UNCORE_GENERIC_MMIO_SIZE );if (!box->io_addr) {pr_warn ("Uncore type %d box %d: ioremap error for 0x%llx.\n" , - type->type_id, type->box_ids[box->pmu->pmu_idx], - (unsigned long long )addr); + type->type_id, unit->id, (unsigned long long )addr);return ; }
@@ -722,6 +718,8 @@ static bool uncore_update_uncore_type(enum uncore_access_type type_id, uncore->box_ctls = type->box_ctrl_die; uncore->mmio_offsets = type->box_offset; uncore->mmio_map_size =UNCORE_GENERIC_MMIO_SIZE ; + uncore->boxes = &type->units; + uncore->num_boxes = type->num_units;break ;default :return false;
PATCH v2 5/8 perf/x86/uncore: Apply the unit control RB tree to MSR uncore units
In reply to [email protected]From: Kan Liang <[email protected]>
The unit control RB tree has the unit control and unit ID information for all the MSR units. Use them to replace the box_ctl and uncore_msr_box_ctl() to get an accurate unit control address for MSR uncore units.
Add intel_generic_uncore_assign_hw_event(), which utilizes the accurate unit control address from the unit control RB tree to calculate the config_base and event_base.
The unit id related information should be retrieved from the unit control RB tree as well.
--- arch/x86/events/intel/uncore.c | 3 ++ arch/x86/events/intel/uncore_discovery.c | 49 +++++++++++++++++++++--- arch/x86/events/intel/uncore_discovery.h | 2 + arch/x86/events/intel/uncore_snbep.c | 16 +++++--- 4 files changed, 59 insertions(+), 11 deletions(-)
arch/x86/events/intel/uncore.c +3 -0
@@ -263,6 +263,9 @@ static void uncore_assign_hw_event(struct intel_uncore_box *box,return ; } +if (intel_generic_uncore_assign_hw_event (event, box)) +return ; + hwc->config_base =uncore_event_ctl (box, hwc->idx); hwc->event_base =uncore_perf_ctr (box, hwc->idx); }
arch/x86/events/intel/uncore_discovery.c +44 -5
79 lines not on this page · raw message
arch/x86/events/intel/uncore_discovery.h +2 -0
@@ -169,3 +169,5 @@ intel_uncore_generic_init_uncores(enum uncore_access_type type_id, int num_extraint intel_uncore_find_discovery_unit_id (struct rb_root *units,int die,unsigned int pmu_idx); +bool intel_generic_uncore_assign_hw_event (struct perf_event *event, +struct intel_uncore_box *box);
arch/x86/events/intel/uncore_snbep.c +10 -6
@@ -5932,10 +5932,11 @@ static int spr_cha_hw_config(struct intel_uncore_box *box, struct perf_event *evstruct hw_perf_event_extra *reg1 = &event->hw.extra_reg;bool tie_en = !!(event->hw.config &SPR_CHA_PMON_CTL_TID_EN );struct intel_uncore_type *type = box->pmu->type; +int id =intel_uncore_find_discovery_unit_id (type->boxes,-1 , box->pmu->pmu_idx);if (tie_en) { reg1->reg =SPR_C0_MSR_PMON_BOX_FILTER0 + -HSWEP_CBO_MSR_OFFSET * type->box_ids[box->pmu->pmu_idx]; +HSWEP_CBO_MSR_OFFSET * id; reg1->config = event->attr.config1 &SPR_CHA_PMON_BOX_FILTER_TID ; reg1->idx =0 ; }
@@ -6459,18 +6460,21 @@ uncore_find_type_by_id(struct intel_uncore_type **types, int type_id)static int uncore_type_max_boxes (struct intel_uncore_type **types,int type_id) { +struct intel_uncore_discovery_unit *unit;struct intel_uncore_type *type; -int i, max =0 ; +struct rb_node *node; +int max =0 ; type =uncore_find_type_by_id (types, type_id);if (!type)return 0 ; -for (i =0 ; i < type->num_boxes; i++) { -if (type->box_ids[i] > max) - max = type->box_ids[i]; - } +for (node =rb_first (type->boxes); node; node =rb_next (node)) { + unit = rb_entry(node, struct intel_uncore_discovery_unit, node); +if (unit->id > max) + max = unit->id; + }return max +1 ; }
Signature · 1 line
2.35.1
[tip: perf/core] perf/x86/uncore: Apply the unit control RB tree to MSR uncore units
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: b1d9ea2e1ca44987c8409cc628dfb0c84e93dce9 Gitweb: https://git.kernel.org/tip/b1d9ea2e1ca44987c8409cc628dfb0c84e93dce9 Author: Kan Liang <[email protected]> AuthorDate: Fri, 14 Jun 2024 06:46:28 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Mon, 17 Jun 2024 17:57:57 +02:00
perf/x86/uncore: Apply the unit control RB tree to MSR uncore units
The unit control RB tree has the unit control and unit ID information for all the MSR units. Use them to replace the box_ctl and uncore_msr_box_ctl() to get an accurate unit control address for MSR uncore units.
Add intel_generic_uncore_assign_hw_event(), which utilizes the accurate unit control address from the unit control RB tree to calculate the config_base and event_base.
The unit id related information should be retrieved from the unit control RB tree as well.
--- arch/x86/events/intel/uncore.c | 3 +- arch/x86/events/intel/uncore_discovery.c | 49 ++++++++++++++++++++--- arch/x86/events/intel/uncore_discovery.h | 2 +- arch/x86/events/intel/uncore_snbep.c | 16 +++++--- 4 files changed, 59 insertions(+), 11 deletions(-)
arch/x86/events/intel/uncore.c +3 -0
@@ -263,6 +263,9 @@ static void uncore_assign_hw_event(struct intel_uncore_box *box,return ; } +if (intel_generic_uncore_assign_hw_event (event, box)) +return ; + hwc->config_base =uncore_event_ctl (box, hwc->idx); hwc->event_base =uncore_perf_ctr (box, hwc->idx); }
arch/x86/events/intel/uncore_discovery.c +44 -5
79 lines not on this page · raw message
arch/x86/events/intel/uncore_discovery.h +2 -0
@@ -169,3 +169,5 @@ intel_uncore_generic_init_uncores(enum uncore_access_type type_id, int num_extraint intel_uncore_find_discovery_unit_id (struct rb_root *units,int die,unsigned int pmu_idx); +bool intel_generic_uncore_assign_hw_event (struct perf_event *event, +struct intel_uncore_box *box);
arch/x86/events/intel/uncore_snbep.c +10 -6
@@ -5933,10 +5933,11 @@ static int spr_cha_hw_config(struct intel_uncore_box *box, struct perf_event *evstruct hw_perf_event_extra *reg1 = &event->hw.extra_reg;bool tie_en = !!(event->hw.config &SPR_CHA_PMON_CTL_TID_EN );struct intel_uncore_type *type = box->pmu->type; +int id =intel_uncore_find_discovery_unit_id (type->boxes,-1 , box->pmu->pmu_idx);if (tie_en) { reg1->reg =SPR_C0_MSR_PMON_BOX_FILTER0 + -HSWEP_CBO_MSR_OFFSET * type->box_ids[box->pmu->pmu_idx]; +HSWEP_CBO_MSR_OFFSET * id; reg1->config = event->attr.config1 &SPR_CHA_PMON_BOX_FILTER_TID ; reg1->idx =0 ; }
@@ -6460,18 +6461,21 @@ uncore_find_type_by_id(struct intel_uncore_type **types, int type_id)static int uncore_type_max_boxes (struct intel_uncore_type **types,int type_id) { +struct intel_uncore_discovery_unit *unit;struct intel_uncore_type *type; -int i, max =0 ; +struct rb_node *node; +int max =0 ; type =uncore_find_type_by_id (types, type_id);if (!type)return 0 ; -for (i =0 ; i < type->num_boxes; i++) { -if (type->box_ids[i] > max) - max = type->box_ids[i]; - } +for (node =rb_first (type->boxes); node; node =rb_next (node)) { + unit = rb_entry(node, struct intel_uncore_discovery_unit, node); +if (unit->id > max) + max = unit->id; + }return max +1 ; }
PATCH v2 6/8 perf/x86/uncore: Apply the unit control RB tree to PCI uncore units
In reply to [email protected]From: Kan Liang <[email protected]>
The unit control RB tree has the unit control and unit ID information for all the PCI units. Use them to replace the box_ctls/pci_offsets to get an accurate unit control address for PCI uncore units.
The UPI/M3UPI units in the discovery table are ignored. Please see the commit 65248a9a9ee1 ("perf/x86/uncore: Add a quirk for UPI on SPR"). Manually allocate a unit control RB tree for UPI/M3UPI.
Add cleanup_extra_boxes to release such manual allocation.
--- arch/x86/events/intel/uncore.c | 53 +++++++++++----------- arch/x86/events/intel/uncore.h | 4 ++ arch/x86/events/intel/uncore_discovery.c | 26 ++++++++--- arch/x86/events/intel/uncore_discovery.h | 2 + arch/x86/events/intel/uncore_snbep.c | 57 ++++++++++++++++++------ 5 files changed, 94 insertions(+), 48 deletions(-)
arch/x86/events/intel/uncore.c +25 -28
@@ -969,6 +969,9 @@ static void uncore_type_exit(struct intel_uncore_type *type)if (type->cleanup_mapping) type->cleanup_mapping (type); +if (type->cleanup_extra_boxes) + type->cleanup_extra_boxes (type); +if (pmu) {for (i =0 ; i < type->num_boxes; i++, pmu++) {uncore_pmu_unregister (pmu);
@@ -1084,22 +1087,19 @@ 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_discovery_unit *unit;struct intel_uncore_type *type; -u64 box_ctl; -int i, die; +struct rb_node *node;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]; - } + +for (node =rb_first (type->boxes); node; node =rb_next (node)) { + unit = rb_entry(node, struct intel_uncore_discovery_unit, node); +if (pdev->devfn ==UNCORE_DISCOVERY_PCI_DEVFN (unit->addr) && + pdev->bus->number ==UNCORE_DISCOVERY_PCI_BUS (unit->addr) && +pci_domain_nr (pdev->bus) ==UNCORE_DISCOVERY_PCI_DOMAIN (unit->addr)) +return &type->pmus[unit->pmu_idx]; } }
@@ -1375,28 +1375,25 @@ static struct notifier_block uncore_pci_notifier = {static void uncore_pci_pmus_register (void ) {struct intel_uncore_type **types = uncore_pci_uncores; +struct intel_uncore_discovery_unit *unit;struct intel_uncore_type *type;struct intel_uncore_pmu *pmu; +struct rb_node *node;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); - } + +for (node =rb_first (type->boxes); node; node =rb_next (node)) { + unit = rb_entry(node, struct intel_uncore_discovery_unit, node); + pdev =pci_get_domain_bus_and_slot (UNCORE_DISCOVERY_PCI_DOMAIN (unit->addr), +UNCORE_DISCOVERY_PCI_BUS (unit->addr), +UNCORE_DISCOVERY_PCI_DEVFN (unit->addr)); + +if (!pdev) +continue ; + pmu = &type->pmus[unit->pmu_idx]; +uncore_pci_pmu_register (pdev, type, pmu, unit->die); } }
arch/x86/events/intel/uncore.h +4 -0
@@ -99,6 +99,10 @@ struct intel_uncore_type {int (*get_topology)(struct intel_uncore_type *type);void (*set_mapping)(struct intel_uncore_type *type);void (*cleanup_mapping)(struct intel_uncore_type *type); +/* +* Optional callbacks for extra uncore units cleanup +*/ +void (*cleanup_extra_boxes)(struct intel_uncore_type *type); };#define pmu_group attr_groups[0]
arch/x86/events/intel/uncore_discovery.c +20 -6
@@ -215,8 +215,8 @@ uncore_find_unit(struct rb_root *root, unsigned int id)return NULL ; } -static void uncore_find_add_unit (struct intel_uncore_discovery_unit *node, -struct rb_root *root,u16 *num_units) +void uncore_find_add_unit (struct intel_uncore_discovery_unit *node, +struct rb_root *root,u16 *num_units) {struct intel_uncore_discovery_unit *unit =uncore_find_unit (root, node->id);
@@ -560,7 +560,7 @@ bool intel_generic_uncore_assign_hw_event(struct perf_event *event,if (!box->pmu->type->boxes)return false; -if (box->pci_dev || box->io_addr) { +if (box->io_addr) { hwc->config_base =uncore_pci_event_ctl (box, hwc->idx); hwc->event_base =uncore_pci_perf_ctr (box, hwc->idx);return true;
@@ -570,16 +570,28 @@ bool intel_generic_uncore_assign_hw_event(struct perf_event *event,if (!box_ctl)return false; +if (box->pci_dev) { + box_ctl =UNCORE_DISCOVERY_PCI_BOX_CTRL (box_ctl); + hwc->config_base = box_ctl +uncore_pci_event_ctl (box, hwc->idx); + hwc->event_base = box_ctl +uncore_pci_perf_ctr (box, hwc->idx); +return true; + } + hwc->config_base = box_ctl + box->pmu->type->event_ctl + hwc->idx; hwc->event_base = box_ctl + box->pmu->type->perf_ctr + hwc->idx;return true; } +static inline int intel_pci_uncore_box_ctl (struct intel_uncore_box *box) +{ +return UNCORE_DISCOVERY_PCI_BOX_CTRL (intel_generic_uncore_box_ctl (box)); +} +void intel_generic_uncore_pci_init_box (struct intel_uncore_box *box) {struct pci_dev *pdev = box->pci_dev; -int box_ctl =uncore_pci_box_ctl (box); +int box_ctl =intel_pci_uncore_box_ctl (box);__set_bit (UNCORE_BOX_FLAG_CTL_OFFS8 , &box->flags);pci_write_config_dword (pdev, box_ctl,GENERIC_PMON_BOX_CTL_INT );
@@ -588,7 +600,7 @@ void intel_generic_uncore_pci_init_box(struct intel_uncore_box *box)void intel_generic_uncore_pci_disable_box (struct intel_uncore_box *box) {struct pci_dev *pdev = box->pci_dev; -int box_ctl =uncore_pci_box_ctl (box); +int box_ctl =intel_pci_uncore_box_ctl (box);pci_write_config_dword (pdev, box_ctl,GENERIC_PMON_BOX_CTL_FRZ ); }
@@ -596,7 +608,7 @@ void intel_generic_uncore_pci_disable_box(struct intel_uncore_box *box)void intel_generic_uncore_pci_enable_box (struct intel_uncore_box *box) {struct pci_dev *pdev = box->pci_dev; -int box_ctl =uncore_pci_box_ctl (box); +int box_ctl =intel_pci_uncore_box_ctl (box);pci_write_config_dword (pdev, box_ctl,0 ); }
@@ -748,6 +760,8 @@ static bool uncore_update_uncore_type(enum uncore_access_type type_id, uncore->box_ctl = (unsigned int )UNCORE_DISCOVERY_PCI_BOX_CTRL (type->box_ctrl); uncore->box_ctls = type->box_ctrl_die; uncore->pci_offsets = type->box_offset; + uncore->boxes = &type->units; + uncore->num_boxes = type->num_units;break ;case UNCORE_ACCESS_MMIO : uncore->ops = &generic_uncore_mmio_ops;
arch/x86/events/intel/uncore_discovery.h +2 -0
@@ -171,3 +171,5 @@ int intel_uncore_find_discovery_unit_id(struct rb_root *units, int die, unsigned int pmu_idx);bool intel_generic_uncore_assign_hw_event (struct perf_event *event,struct intel_uncore_box *box); +void uncore_find_add_unit (struct intel_uncore_discovery_unit *node, +struct rb_root *root,u16 *num_units);
arch/x86/events/intel/uncore_snbep.c +43 -14
107 lines not on this page · raw message
Signature · 1 line
2.35.1
[tip: perf/core] perf/x86/uncore: Apply the unit control RB tree to PCI uncore units
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: f76a8420444beb1c3968504c8176a67d2d5fe18f Gitweb: https://git.kernel.org/tip/f76a8420444beb1c3968504c8176a67d2d5fe18f Author: Kan Liang <[email protected]> AuthorDate: Fri, 14 Jun 2024 06:46:29 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Mon, 17 Jun 2024 17:57:58 +02:00
perf/x86/uncore: Apply the unit control RB tree to PCI uncore units
The unit control RB tree has the unit control and unit ID information for all the PCI units. Use them to replace the box_ctls/pci_offsets to get an accurate unit control address for PCI uncore units.
The UPI/M3UPI units in the discovery table are ignored. Please see the commit 65248a9a9ee1 ("perf/x86/uncore: Add a quirk for UPI on SPR"). Manually allocate a unit control RB tree for UPI/M3UPI.
Add cleanup_extra_boxes to release such manual allocation.
--- arch/x86/events/intel/uncore.c | 53 +++++++++------------ arch/x86/events/intel/uncore.h | 4 ++- arch/x86/events/intel/uncore_discovery.c | 26 +++++++--- arch/x86/events/intel/uncore_discovery.h | 2 +- arch/x86/events/intel/uncore_snbep.c | 57 +++++++++++++++++------ 5 files changed, 94 insertions(+), 48 deletions(-)
arch/x86/events/intel/uncore.c +25 -28
@@ -969,6 +969,9 @@ static void uncore_type_exit(struct intel_uncore_type *type)if (type->cleanup_mapping) type->cleanup_mapping (type); +if (type->cleanup_extra_boxes) + type->cleanup_extra_boxes (type); +if (pmu) {for (i =0 ; i < type->num_boxes; i++, pmu++) {uncore_pmu_unregister (pmu);
@@ -1084,22 +1087,19 @@ 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_discovery_unit *unit;struct intel_uncore_type *type; -u64 box_ctl; -int i, die; +struct rb_node *node;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]; - } + +for (node =rb_first (type->boxes); node; node =rb_next (node)) { + unit = rb_entry(node, struct intel_uncore_discovery_unit, node); +if (pdev->devfn ==UNCORE_DISCOVERY_PCI_DEVFN (unit->addr) && + pdev->bus->number ==UNCORE_DISCOVERY_PCI_BUS (unit->addr) && +pci_domain_nr (pdev->bus) ==UNCORE_DISCOVERY_PCI_DOMAIN (unit->addr)) +return &type->pmus[unit->pmu_idx]; } }
@@ -1375,28 +1375,25 @@ static struct notifier_block uncore_pci_notifier = {static void uncore_pci_pmus_register (void ) {struct intel_uncore_type **types = uncore_pci_uncores; +struct intel_uncore_discovery_unit *unit;struct intel_uncore_type *type;struct intel_uncore_pmu *pmu; +struct rb_node *node;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); - } + +for (node =rb_first (type->boxes); node; node =rb_next (node)) { + unit = rb_entry(node, struct intel_uncore_discovery_unit, node); + pdev =pci_get_domain_bus_and_slot (UNCORE_DISCOVERY_PCI_DOMAIN (unit->addr), +UNCORE_DISCOVERY_PCI_BUS (unit->addr), +UNCORE_DISCOVERY_PCI_DEVFN (unit->addr)); + +if (!pdev) +continue ; + pmu = &type->pmus[unit->pmu_idx]; +uncore_pci_pmu_register (pdev, type, pmu, unit->die); } }
arch/x86/events/intel/uncore.h +4 -0
@@ -99,6 +99,10 @@ struct intel_uncore_type {int (*get_topology)(struct intel_uncore_type *type);void (*set_mapping)(struct intel_uncore_type *type);void (*cleanup_mapping)(struct intel_uncore_type *type); +/* +* Optional callbacks for extra uncore units cleanup +*/ +void (*cleanup_extra_boxes)(struct intel_uncore_type *type); };#define pmu_group attr_groups[0]
arch/x86/events/intel/uncore_discovery.c +20 -6
@@ -215,8 +215,8 @@ uncore_find_unit(struct rb_root *root, unsigned int id)return NULL ; } -static void uncore_find_add_unit (struct intel_uncore_discovery_unit *node, -struct rb_root *root,u16 *num_units) +void uncore_find_add_unit (struct intel_uncore_discovery_unit *node, +struct rb_root *root,u16 *num_units) {struct intel_uncore_discovery_unit *unit =uncore_find_unit (root, node->id);
@@ -560,7 +560,7 @@ bool intel_generic_uncore_assign_hw_event(struct perf_event *event,if (!box->pmu->type->boxes)return false; -if (box->pci_dev || box->io_addr) { +if (box->io_addr) { hwc->config_base =uncore_pci_event_ctl (box, hwc->idx); hwc->event_base =uncore_pci_perf_ctr (box, hwc->idx);return true;
@@ -570,16 +570,28 @@ bool intel_generic_uncore_assign_hw_event(struct perf_event *event,if (!box_ctl)return false; +if (box->pci_dev) { + box_ctl =UNCORE_DISCOVERY_PCI_BOX_CTRL (box_ctl); + hwc->config_base = box_ctl +uncore_pci_event_ctl (box, hwc->idx); + hwc->event_base = box_ctl +uncore_pci_perf_ctr (box, hwc->idx); +return true; + } + hwc->config_base = box_ctl + box->pmu->type->event_ctl + hwc->idx; hwc->event_base = box_ctl + box->pmu->type->perf_ctr + hwc->idx;return true; } +static inline int intel_pci_uncore_box_ctl (struct intel_uncore_box *box) +{ +return UNCORE_DISCOVERY_PCI_BOX_CTRL (intel_generic_uncore_box_ctl (box)); +} +void intel_generic_uncore_pci_init_box (struct intel_uncore_box *box) {struct pci_dev *pdev = box->pci_dev; -int box_ctl =uncore_pci_box_ctl (box); +int box_ctl =intel_pci_uncore_box_ctl (box);__set_bit (UNCORE_BOX_FLAG_CTL_OFFS8 , &box->flags);pci_write_config_dword (pdev, box_ctl,GENERIC_PMON_BOX_CTL_INT );
@@ -588,7 +600,7 @@ void intel_generic_uncore_pci_init_box(struct intel_uncore_box *box)void intel_generic_uncore_pci_disable_box (struct intel_uncore_box *box) {struct pci_dev *pdev = box->pci_dev; -int box_ctl =uncore_pci_box_ctl (box); +int box_ctl =intel_pci_uncore_box_ctl (box);pci_write_config_dword (pdev, box_ctl,GENERIC_PMON_BOX_CTL_FRZ ); }
@@ -596,7 +608,7 @@ void intel_generic_uncore_pci_disable_box(struct intel_uncore_box *box)void intel_generic_uncore_pci_enable_box (struct intel_uncore_box *box) {struct pci_dev *pdev = box->pci_dev; -int box_ctl =uncore_pci_box_ctl (box); +int box_ctl =intel_pci_uncore_box_ctl (box);pci_write_config_dword (pdev, box_ctl,0 ); }
@@ -748,6 +760,8 @@ static bool uncore_update_uncore_type(enum uncore_access_type type_id, uncore->box_ctl = (unsigned int )UNCORE_DISCOVERY_PCI_BOX_CTRL (type->box_ctrl); uncore->box_ctls = type->box_ctrl_die; uncore->pci_offsets = type->box_offset; + uncore->boxes = &type->units; + uncore->num_boxes = type->num_units;break ;case UNCORE_ACCESS_MMIO : uncore->ops = &generic_uncore_mmio_ops;
arch/x86/events/intel/uncore_discovery.h +2 -0
@@ -171,3 +171,5 @@ int intel_uncore_find_discovery_unit_id(struct rb_root *units, int die, unsigned int pmu_idx);bool intel_generic_uncore_assign_hw_event (struct perf_event *event,struct intel_uncore_box *box); +void uncore_find_add_unit (struct intel_uncore_discovery_unit *node, +struct rb_root *root,u16 *num_units);
arch/x86/events/intel/uncore_snbep.c +43 -14
107 lines not on this page · raw message
PATCH v2 7/8 perf/x86/uncore: Cleanup unused unit structure
In reply to [email protected]From: Kan Liang <[email protected]>
The unit control and ID information are retrieved from the unit control RB tree. No one uses the old structure anymore. Remove them.
--- arch/x86/events/intel/uncore.c | 7 +- arch/x86/events/intel/uncore.h | 2 - arch/x86/events/intel/uncore_discovery.c | 110 +++-------------------- arch/x86/events/intel/uncore_discovery.h | 5 -- 4 files changed, 12 insertions(+), 112 deletions(-)
arch/x86/events/intel/uncore.c +2 -5
@@ -868,7 +868,7 @@ static inline int uncore_get_box_id(struct intel_uncore_type *type,if (type->boxes)return intel_uncore_find_discovery_unit_id (type->boxes,-1 , pmu->pmu_idx); -return type->box_ids ? type->box_ids[pmu->pmu_idx] : pmu->pmu_idx; +return pmu->pmu_idx; }void uncore_get_alias_name (char *pmu_name,struct intel_uncore_pmu *pmu)
@@ -980,10 +980,7 @@ 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 ; }
arch/x86/events/intel/uncore.h +0 -2
@@ -62,7 +62,6 @@ 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;
@@ -76,7 +75,6 @@ struct intel_uncore_type {u64 *pci_offsets;u64 *mmio_offsets; }; -unsigned *box_ids;struct event_constraint unconstrainted;struct event_constraint *constraints;struct intel_uncore_pmu *pmus;
arch/x86/events/intel/uncore_discovery.c +10 -100
179 lines not on this page · raw message
arch/x86/events/intel/uncore_discovery.h +0 -5
@@ -124,18 +124,13 @@ struct intel_uncore_discovery_unit {struct intel_uncore_discovery_type {struct rb_node node;enum uncore_access_type access_type; -u64 box_ctrl;/* Unit ctrl addr of the first box */ -u64 *box_ctrl_die;/* Unit ctrl addr of the first box of each die */ struct rb_root units;/* Unit ctrl addr for all units */ u16 type;/* Type ID of the uncore block */ u8 num_counters;u8 counter_width;u8 ctl_offset;/* Counter Control 0 offset */ u8 ctr_offset;/* Counter 0 offset */ -u16 num_boxes;/* number of boxes for the uncore block */ u16 num_units;/* number of units */ -unsigned int *ids;/* Box IDs */ -u64 *box_offset;/* Box offset */ };bool intel_uncore_has_discovery_tables (int *ignore);
Signature · 1 line
2.35.1
[tip: perf/core] perf/x86/uncore: Cleanup unused unit structure
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: 15a4bd51853b9c67f49bb03c20b6b6cb60fd204f Gitweb: https://git.kernel.org/tip/15a4bd51853b9c67f49bb03c20b6b6cb60fd204f Author: Kan Liang <[email protected]> AuthorDate: Fri, 14 Jun 2024 06:46:30 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Mon, 17 Jun 2024 17:57:59 +02:00
perf/x86/uncore: Cleanup unused unit structure
The unit control and ID information are retrieved from the unit control RB tree. No one uses the old structure anymore. Remove them.
--- arch/x86/events/intel/uncore.c | 7 +- arch/x86/events/intel/uncore.h | 2 +- arch/x86/events/intel/uncore_discovery.c | 110 ++-------------------- arch/x86/events/intel/uncore_discovery.h | 5 +- 4 files changed, 12 insertions(+), 112 deletions(-)
arch/x86/events/intel/uncore.c +2 -5
@@ -868,7 +868,7 @@ static inline int uncore_get_box_id(struct intel_uncore_type *type,if (type->boxes)return intel_uncore_find_discovery_unit_id (type->boxes,-1 , pmu->pmu_idx); -return type->box_ids ? type->box_ids[pmu->pmu_idx] : pmu->pmu_idx; +return pmu->pmu_idx; }void uncore_get_alias_name (char *pmu_name,struct intel_uncore_pmu *pmu)
@@ -980,10 +980,7 @@ 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 ; }
arch/x86/events/intel/uncore.h +0 -2
@@ -62,7 +62,6 @@ 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;
@@ -76,7 +75,6 @@ struct intel_uncore_type {u64 *pci_offsets;u64 *mmio_offsets; }; -unsigned *box_ids;struct event_constraint unconstrainted;struct event_constraint *constraints;struct intel_uncore_pmu *pmus;
arch/x86/events/intel/uncore_discovery.c +10 -100
179 lines not on this page · raw message
arch/x86/events/intel/uncore_discovery.h +0 -5
@@ -124,18 +124,13 @@ struct intel_uncore_discovery_unit {struct intel_uncore_discovery_type {struct rb_node node;enum uncore_access_type access_type; -u64 box_ctrl;/* Unit ctrl addr of the first box */ -u64 *box_ctrl_die;/* Unit ctrl addr of the first box of each die */ struct rb_root units;/* Unit ctrl addr for all units */ u16 type;/* Type ID of the uncore block */ u8 num_counters;u8 counter_width;u8 ctl_offset;/* Counter Control 0 offset */ u8 ctr_offset;/* Counter 0 offset */ -u16 num_boxes;/* number of boxes for the uncore block */ u16 num_units;/* number of units */ -unsigned int *ids;/* Box IDs */ -u64 *box_offset;/* Box offset */ };bool intel_uncore_has_discovery_tables (int *ignore);
PATCH v2 8/8 perf/x86/intel/uncore: Support HBM and CXL PMON counters
In reply to [email protected]From: Kan Liang <[email protected]>
Unknown uncore PMON types can be found in both SPR and EMR with HBM or CXL.
$ls /sys/devices/ | grep type
uncore_type_12_16
uncore_type_12_18
uncore_type_12_2
uncore_type_12_4
uncore_type_12_6
uncore_type_12_8
uncore_type_13_17
uncore_type_13_19
uncore_type_13_3
uncore_type_13_5
uncore_type_13_7
uncore_type_13_9
The unknown PMON types are HBM and CXL PMON. Except for the name, the other information regarding the HBM and CXL PMON counters can be retrieved via the discovery table. Add them into the uncores tables for SPR and EMR.
The event config registers for all CXL related units are 8-byte apart. Add SPR_UNCORE_MMIO_OFFS8_COMMON_FORMAT to specially handle it.
--- arch/x86/events/intel/uncore_snbep.c | 55 +++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-)
arch/x86/events/intel/uncore_snbep.c +53 -2
@@ -6162,7 +6162,55 @@ static struct intel_uncore_type spr_uncore_mdf = { .name = "mdf", }; -#define UNCORE_SPR_NUM_UNCORE_TYPES 12 +static void spr_uncore_mmio_offs8_init_box (struct intel_uncore_box *box) +{ +__set_bit (UNCORE_BOX_FLAG_CTL_OFFS8 , &box->flags); +intel_generic_uncore_mmio_init_box (box); +} + +static struct intel_uncore_ops spr_uncore_mmio_offs8_ops = { + .init_box = spr_uncore_mmio_offs8_init_box, + .exit_box = uncore_mmio_exit_box, + .disable_box = intel_generic_uncore_mmio_disable_box, + .enable_box = intel_generic_uncore_mmio_enable_box, + .disable_event = intel_generic_uncore_mmio_disable_event, + .enable_event = spr_uncore_mmio_enable_event, + .read_counter = uncore_mmio_read_counter, +}; + +#define SPR_UNCORE_MMIO_OFFS8_COMMON_FORMAT () \ + SPR_UNCORE_COMMON_FORMAT(), \ + .ops = &spr_uncore_mmio_offs8_ops + +static struct event_constraint spr_uncore_cxlcm_constraints[] = { +UNCORE_EVENT_CONSTRAINT (0x02 ,0x0f ), +UNCORE_EVENT_CONSTRAINT (0x05 ,0x0f ), +UNCORE_EVENT_CONSTRAINT (0x40 ,0xf0 ), +UNCORE_EVENT_CONSTRAINT (0x41 ,0xf0 ), +UNCORE_EVENT_CONSTRAINT (0x42 ,0xf0 ), +UNCORE_EVENT_CONSTRAINT (0x43 ,0xf0 ), +UNCORE_EVENT_CONSTRAINT (0x4b ,0xf0 ), +UNCORE_EVENT_CONSTRAINT (0x52 ,0xf0 ), +EVENT_CONSTRAINT_END +}; + +static struct intel_uncore_type spr_uncore_cxlcm = { +SPR_UNCORE_MMIO_OFFS8_COMMON_FORMAT (), + .name ="cxlcm" , + .constraints = spr_uncore_cxlcm_constraints, +}; + +static struct intel_uncore_type spr_uncore_cxldp = { +SPR_UNCORE_MMIO_OFFS8_COMMON_FORMAT (), + .name ="cxldp" , +}; + +static struct intel_uncore_type spr_uncore_hbm = { +SPR_UNCORE_COMMON_FORMAT (), + .name ="hbm" , +}; + +#define UNCORE_SPR_NUM_UNCORE_TYPES 15#define UNCORE_SPR_CHA 0#define UNCORE_SPR_IIO 1#define UNCORE_SPR_IMC 6
@@ -6186,6 +6234,9 @@ static struct intel_uncore_type *spr_uncores[UNCORE_SPR_NUM_UNCORE_TYPES] = {NULL ,NULL , &spr_uncore_mdf, + &spr_uncore_cxlcm, + &spr_uncore_cxldp, + &spr_uncore_hbm, };/*
@@ -6655,7 +6706,7 @@ static struct intel_uncore_type gnr_uncore_b2cmi = { };static struct intel_uncore_type gnr_uncore_b2cxl = { -SPR_UNCORE_MMIO_COMMON_FORMAT (), +SPR_UNCORE_MMIO_OFFS8_COMMON_FORMAT (), .name ="b2cxl" , };
Signature · 1 line
2.35.1
[tip: perf/core] perf/x86/intel/uncore: Support HBM and CXL PMON counters
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: f8a86a9bb5f7e65d8c4405052de062639a8783bb Gitweb: https://git.kernel.org/tip/f8a86a9bb5f7e65d8c4405052de062639a8783bb Author: Kan Liang <[email protected]> AuthorDate: Fri, 14 Jun 2024 06:46:31 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Mon, 17 Jun 2024 17:57:59 +02:00
perf/x86/intel/uncore: Support HBM and CXL PMON counters
Unknown uncore PMON types can be found in both SPR and EMR with HBM or CXL.
$ls /sys/devices/ | grep type
uncore_type_12_16
uncore_type_12_18
uncore_type_12_2
uncore_type_12_4
uncore_type_12_6
uncore_type_12_8
uncore_type_13_17
uncore_type_13_19
uncore_type_13_3
uncore_type_13_5
uncore_type_13_7
uncore_type_13_9
The unknown PMON types are HBM and CXL PMON. Except for the name, the other information regarding the HBM and CXL PMON counters can be retrieved via the discovery table. Add them into the uncores tables for SPR and EMR.
The event config registers for all CXL related units are 8-byte apart. Add SPR_UNCORE_MMIO_OFFS8_COMMON_FORMAT to specially handle it.
--- arch/x86/events/intel/uncore_snbep.c | 55 ++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-)
arch/x86/events/intel/uncore_snbep.c +53 -2
@@ -6163,7 +6163,55 @@ static struct intel_uncore_type spr_uncore_mdf = { .name = "mdf", }; -#define UNCORE_SPR_NUM_UNCORE_TYPES 12 +static void spr_uncore_mmio_offs8_init_box (struct intel_uncore_box *box) +{ +__set_bit (UNCORE_BOX_FLAG_CTL_OFFS8 , &box->flags); +intel_generic_uncore_mmio_init_box (box); +} + +static struct intel_uncore_ops spr_uncore_mmio_offs8_ops = { + .init_box = spr_uncore_mmio_offs8_init_box, + .exit_box = uncore_mmio_exit_box, + .disable_box = intel_generic_uncore_mmio_disable_box, + .enable_box = intel_generic_uncore_mmio_enable_box, + .disable_event = intel_generic_uncore_mmio_disable_event, + .enable_event = spr_uncore_mmio_enable_event, + .read_counter = uncore_mmio_read_counter, +}; + +#define SPR_UNCORE_MMIO_OFFS8_COMMON_FORMAT () \ + SPR_UNCORE_COMMON_FORMAT(), \ + .ops = &spr_uncore_mmio_offs8_ops + +static struct event_constraint spr_uncore_cxlcm_constraints[] = { +UNCORE_EVENT_CONSTRAINT (0x02 ,0x0f ), +UNCORE_EVENT_CONSTRAINT (0x05 ,0x0f ), +UNCORE_EVENT_CONSTRAINT (0x40 ,0xf0 ), +UNCORE_EVENT_CONSTRAINT (0x41 ,0xf0 ), +UNCORE_EVENT_CONSTRAINT (0x42 ,0xf0 ), +UNCORE_EVENT_CONSTRAINT (0x43 ,0xf0 ), +UNCORE_EVENT_CONSTRAINT (0x4b ,0xf0 ), +UNCORE_EVENT_CONSTRAINT (0x52 ,0xf0 ), +EVENT_CONSTRAINT_END +}; + +static struct intel_uncore_type spr_uncore_cxlcm = { +SPR_UNCORE_MMIO_OFFS8_COMMON_FORMAT (), + .name ="cxlcm" , + .constraints = spr_uncore_cxlcm_constraints, +}; + +static struct intel_uncore_type spr_uncore_cxldp = { +SPR_UNCORE_MMIO_OFFS8_COMMON_FORMAT (), + .name ="cxldp" , +}; + +static struct intel_uncore_type spr_uncore_hbm = { +SPR_UNCORE_COMMON_FORMAT (), + .name ="hbm" , +}; + +#define UNCORE_SPR_NUM_UNCORE_TYPES 15#define UNCORE_SPR_CHA 0#define UNCORE_SPR_IIO 1#define UNCORE_SPR_IMC 6
@@ -6187,6 +6235,9 @@ static struct intel_uncore_type *spr_uncores[UNCORE_SPR_NUM_UNCORE_TYPES] = {NULL ,NULL , &spr_uncore_mdf, + &spr_uncore_cxlcm, + &spr_uncore_cxldp, + &spr_uncore_hbm, };/*
@@ -6656,7 +6707,7 @@ static struct intel_uncore_type gnr_uncore_b2cmi = { };static struct intel_uncore_type gnr_uncore_b2cxl = { -SPR_UNCORE_MMIO_COMMON_FORMAT (), +SPR_UNCORE_MMIO_OFFS8_COMMON_FORMAT (), .name ="b2cxl" , };