perf/x86/intel/uncore: Generalize get_topology() for SKX PMUs

Factor out a generic code from skx_iio_get_topology() to skx_pmu_get_topology()
to avoid code duplication. This code will be used by get_topology() procedure
for SKX UPI PMUs in the further patch.

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>
Link: https://lore.kernel.org/r/20221117122833.3103580-6-alexander.antonov@linux.intel.com
This commit is contained in:
Alexander Antonov 2022-11-17 12:28:27 +00:00 committed by Peter Zijlstra
parent efe062705d
commit 07813e2a59

View file

@ -3837,14 +3837,14 @@ static void pmu_free_topology(struct intel_uncore_type *type)
} }
} }
static int skx_iio_get_topology(struct intel_uncore_type *type) static int skx_pmu_get_topology(struct intel_uncore_type *type,
int (*topology_cb)(struct intel_uncore_type*, int, int, u64))
{ {
int die, ret = -EPERM; int die, ret = -EPERM;
u64 configuration; u64 cpu_bus_msr;
int idx;
for (die = 0; die < uncore_max_dies(); die++) { for (die = 0; die < uncore_max_dies(); die++) {
ret = skx_msr_cpu_bus_read(die_to_cpu(die), &configuration); ret = skx_msr_cpu_bus_read(die_to_cpu(die), &cpu_bus_msr);
if (ret) if (ret)
break; break;
@ -3852,17 +3852,35 @@ static int skx_iio_get_topology(struct intel_uncore_type *type)
if (ret < 0) if (ret < 0)
break; break;
for (idx = 0; idx < type->num_boxes; idx++) { ret = topology_cb(type, ret, die, cpu_bus_msr);
type->topology[die][idx].pmu_idx = idx; if (ret)
type->topology[die][idx].iio->segment = ret; break;
type->topology[die][idx].iio->pci_bus_no =
(configuration >> (idx * BUS_NUM_STRIDE)) & 0xff;
}
} }
return ret; return ret;
} }
static int skx_iio_topology_cb(struct intel_uncore_type *type, int segment,
int die, u64 cpu_bus_msr)
{
int idx;
struct intel_uncore_topology *t;
for (idx = 0; idx < type->num_boxes; idx++) {
t = &type->topology[die][idx];
t->pmu_idx = idx;
t->iio->segment = segment;
t->iio->pci_bus_no = (cpu_bus_msr >> (idx * BUS_NUM_STRIDE)) & 0xff;
}
return 0;
}
static int skx_iio_get_topology(struct intel_uncore_type *type)
{
return skx_pmu_get_topology(type, skx_iio_topology_cb);
}
static struct attribute_group skx_iio_mapping_group = { static struct attribute_group skx_iio_mapping_group = {
.is_visible = skx_iio_mapping_visible, .is_visible = skx_iio_mapping_visible,
}; };