Skip to content

Commit cface03

Browse files
Alexander AntonovPeter Zijlstra
authored andcommitted
perf/x86/intel/uncore: Enable IIO stacks to PMON mapping for multi-segment SKX
IIO stacks to PMON mapping on Skylake servers is exposed through introduced early attributes /sys/devices/uncore_iio_<pmu_idx>/dieX, where dieX is a file which holds "Segment:Root Bus" for PCIe root port which can be monitored by that IIO PMON block. These sysfs attributes are disabled for multiple segment topologies except VMD domains which start at 0x10000. This patch removes the limitation and enables IIO stacks to PMON mapping for multi-segment Skylake servers by introducing segment-aware intel_uncore_topology structure and attributing the topology configuration to the segment in skx_iio_get_topology() function. Reported-by: kernel test robot <lkp@intel.com> Signed-off-by: Alexander Antonov <alexander.antonov@linux.intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Kan Liang <kan.liang@linux.intel.com> Reviewed-by: Andi Kleen <ak@linux.intel.com> Tested-by: Kyle Meyer <kyle.meyer@hpe.com> Link: https://lkml.kernel.org/r/20210323150507.2013-1-alexander.antonov@linux.intel.com
1 parent c4c55e3 commit cface03

3 files changed

Lines changed: 47 additions & 34 deletions

File tree

‎arch/x86/events/intel/uncore.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ int uncore_pcibus_to_dieid(struct pci_bus *bus)
5353
return die_id;
5454
}
5555

56+
int uncore_die_to_segment(int die)
57+
{
58+
struct pci_bus *bus = NULL;
59+
60+
/* Find first pci bus which attributes to specified die. */
61+
while ((bus = pci_find_next_bus(bus)) &&
62+
(die != uncore_pcibus_to_dieid(bus)))
63+
;
64+
65+
return bus ? pci_domain_nr(bus) : -EINVAL;
66+
}
67+
5668
static void uncore_free_pcibus_map(void)
5769
{
5870
struct pci2phy_map *map, *tmp;

‎arch/x86/events/intel/uncore.h‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct intel_uncore_pmu;
4242
struct intel_uncore_box;
4343
struct uncore_event_desc;
4444
struct freerunning_counters;
45+
struct intel_uncore_topology;
4546

4647
struct intel_uncore_type {
4748
const char *name;
@@ -87,7 +88,7 @@ struct intel_uncore_type {
8788
* to identify which platform component each PMON block of that type is
8889
* supposed to monitor.
8990
*/
90-
u64 *topology;
91+
struct intel_uncore_topology *topology;
9192
/*
9293
* Optional callbacks for managing mapping of Uncore units to PMONs
9394
*/
@@ -176,6 +177,11 @@ struct freerunning_counters {
176177
unsigned *box_offsets;
177178
};
178179

180+
struct intel_uncore_topology {
181+
u64 configuration;
182+
int segment;
183+
};
184+
179185
struct pci2phy_map {
180186
struct list_head list;
181187
int segment;
@@ -184,6 +190,7 @@ struct pci2phy_map {
184190

185191
struct pci2phy_map *__find_pci2phy_map(int segment);
186192
int uncore_pcibus_to_dieid(struct pci_bus *bus);
193+
int uncore_die_to_segment(int die);
187194

188195
ssize_t uncore_event_show(struct device *dev,
189196
struct device_attribute *attr, char *buf);

‎arch/x86/events/intel/uncore_snbep.c‎

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3684,7 +3684,8 @@ static struct intel_uncore_ops skx_uncore_iio_ops = {
36843684

36853685
static inline u8 skx_iio_stack(struct intel_uncore_pmu *pmu, int die)
36863686
{
3687-
return pmu->type->topology[die] >> (pmu->pmu_idx * BUS_NUM_STRIDE);
3687+
return pmu->type->topology[die].configuration >>
3688+
(pmu->pmu_idx * BUS_NUM_STRIDE);
36883689
}
36893690

36903691
static umode_t
@@ -3697,19 +3698,14 @@ skx_iio_mapping_visible(struct kobject *kobj, struct attribute *attr, int die)
36973698
}
36983699

36993700
static ssize_t skx_iio_mapping_show(struct device *dev,
3700-
struct device_attribute *attr, char *buf)
3701+
struct device_attribute *attr, char *buf)
37013702
{
3702-
struct pci_bus *bus = pci_find_next_bus(NULL);
3703-
struct intel_uncore_pmu *uncore_pmu = dev_to_uncore_pmu(dev);
3703+
struct intel_uncore_pmu *pmu = dev_to_uncore_pmu(dev);
37043704
struct dev_ext_attribute *ea = to_dev_ext_attribute(attr);
37053705
long die = (long)ea->var;
37063706

3707-
/*
3708-
* Current implementation is for single segment configuration hence it's
3709-
* safe to take the segment value from the first available root bus.
3710-
*/
3711-
return sprintf(buf, "%04x:%02x\n", pci_domain_nr(bus),
3712-
skx_iio_stack(uncore_pmu, die));
3707+
return sprintf(buf, "%04x:%02x\n", pmu->type->topology[die].segment,
3708+
skx_iio_stack(pmu, die));
37133709
}
37143710

37153711
static int skx_msr_cpu_bus_read(int cpu, u64 *topology)
@@ -3746,34 +3742,32 @@ static int die_to_cpu(int die)
37463742

37473743
static int skx_iio_get_topology(struct intel_uncore_type *type)
37483744
{
3749-
int i, ret;
3750-
struct pci_bus *bus = NULL;
3751-
3752-
/*
3753-
* Verified single-segment environments only; disabled for multiple
3754-
* segment topologies for now except VMD domains.
3755-
* VMD domains start at 0x10000 to not clash with ACPI _SEG domains.
3756-
*/
3757-
while ((bus = pci_find_next_bus(bus))
3758-
&& (!pci_domain_nr(bus) || pci_domain_nr(bus) > 0xffff))
3759-
;
3760-
if (bus)
3761-
return -EPERM;
3745+
int die, ret = -EPERM;
37623746

3763-
type->topology = kcalloc(uncore_max_dies(), sizeof(u64), GFP_KERNEL);
3747+
type->topology = kcalloc(uncore_max_dies(), sizeof(*type->topology),
3748+
GFP_KERNEL);
37643749
if (!type->topology)
37653750
return -ENOMEM;
37663751

3767-
for (i = 0; i < uncore_max_dies(); i++) {
3768-
ret = skx_msr_cpu_bus_read(die_to_cpu(i), &type->topology[i]);
3769-
if (ret) {
3770-
kfree(type->topology);
3771-
type->topology = NULL;
3772-
return ret;
3773-
}
3752+
for (die = 0; die < uncore_max_dies(); die++) {
3753+
ret = skx_msr_cpu_bus_read(die_to_cpu(die),
3754+
&type->topology[die].configuration);
3755+
if (ret)
3756+
break;
3757+
3758+
ret = uncore_die_to_segment(die);
3759+
if (ret < 0)
3760+
break;
3761+
3762+
type->topology[die].segment = ret;
37743763
}
37753764

3776-
return 0;
3765+
if (ret < 0) {
3766+
kfree(type->topology);
3767+
type->topology = NULL;
3768+
}
3769+
3770+
return ret;
37773771
}
37783772

37793773
static struct attribute_group skx_iio_mapping_group = {
@@ -3794,7 +3788,7 @@ static int skx_iio_set_mapping(struct intel_uncore_type *type)
37943788
struct dev_ext_attribute *eas = NULL;
37953789

37963790
ret = skx_iio_get_topology(type);
3797-
if (ret)
3791+
if (ret < 0)
37983792
goto clear_attr_update;
37993793

38003794
ret = -ENOMEM;

0 commit comments

Comments
 (0)