perf/x86/uncore: Factor out uncore_device_to_die()
The same code is used to retrieve the logical die ID with a given PCI device in both the discovery code and the code that supports a system with > 8 nodes. Factor out uncore_device_to_die() to replace the duplicate code. No functional change. Signed-off-by: Kan Liang <kan.liang@linux.intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Tested-by: Michael Petlan <mpetlan@redhat.com> Link: https://lore.kernel.org/r/20230112200105.733466-2-kan.liang@linux.intel.com
This commit is contained in:
parent
0eed282205
commit
dbf061b262
|
@ -65,6 +65,21 @@ int uncore_die_to_segment(int die)
|
|||
return bus ? pci_domain_nr(bus) : -EINVAL;
|
||||
}
|
||||
|
||||
int uncore_device_to_die(struct pci_dev *dev)
|
||||
{
|
||||
int node = pcibus_to_node(dev->bus);
|
||||
int cpu;
|
||||
|
||||
for_each_cpu(cpu, cpumask_of_pcibus(dev->bus)) {
|
||||
struct cpuinfo_x86 *c = &cpu_data(cpu);
|
||||
|
||||
if (c->initialized && cpu_to_node(cpu) == node)
|
||||
return c->logical_die_id;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void uncore_free_pcibus_map(void)
|
||||
{
|
||||
struct pci2phy_map *map, *tmp;
|
||||
|
|
|
@ -208,6 +208,7 @@ struct pci2phy_map {
|
|||
struct pci2phy_map *__find_pci2phy_map(int segment);
|
||||
int uncore_pcibus_to_dieid(struct pci_bus *bus);
|
||||
int uncore_die_to_segment(int die);
|
||||
int uncore_device_to_die(struct pci_dev *dev);
|
||||
|
||||
ssize_t uncore_event_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf);
|
||||
|
|
|
@ -33,7 +33,7 @@ static int logical_die_id;
|
|||
|
||||
static int get_device_die_id(struct pci_dev *dev)
|
||||
{
|
||||
int cpu, node = pcibus_to_node(dev->bus);
|
||||
int node = pcibus_to_node(dev->bus);
|
||||
|
||||
/*
|
||||
* If the NUMA info is not available, assume that the logical die id is
|
||||
|
@ -43,19 +43,7 @@ static int get_device_die_id(struct pci_dev *dev)
|
|||
if (node < 0)
|
||||
return logical_die_id++;
|
||||
|
||||
for_each_cpu(cpu, cpumask_of_node(node)) {
|
||||
struct cpuinfo_x86 *c = &cpu_data(cpu);
|
||||
|
||||
if (c->initialized && cpu_to_node(cpu) == node)
|
||||
return c->logical_die_id;
|
||||
}
|
||||
|
||||
/*
|
||||
* All CPUs of a node may be offlined. For this case,
|
||||
* the PCI and MMIO type of uncore blocks which are
|
||||
* enumerated by the device will be unavailable.
|
||||
*/
|
||||
return -1;
|
||||
return uncore_device_to_die(dev);
|
||||
}
|
||||
|
||||
#define __node_2_type(cur) \
|
||||
|
|
|
@ -1453,9 +1453,6 @@ static int snbep_pci2phy_map_init(int devid, int nodeid_loc, int idmap_loc, bool
|
|||
}
|
||||
raw_spin_unlock(&pci2phy_map_lock);
|
||||
} else {
|
||||
int node = pcibus_to_node(ubox_dev->bus);
|
||||
int cpu;
|
||||
|
||||
segment = pci_domain_nr(ubox_dev->bus);
|
||||
raw_spin_lock(&pci2phy_map_lock);
|
||||
map = __find_pci2phy_map(segment);
|
||||
|
@ -1465,15 +1462,8 @@ static int snbep_pci2phy_map_init(int devid, int nodeid_loc, int idmap_loc, bool
|
|||
break;
|
||||
}
|
||||
|
||||
die_id = -1;
|
||||
for_each_cpu(cpu, cpumask_of_pcibus(ubox_dev->bus)) {
|
||||
struct cpuinfo_x86 *c = &cpu_data(cpu);
|
||||
map->pbus_to_dieid[bus] = die_id = uncore_device_to_die(ubox_dev);
|
||||
|
||||
if (c->initialized && cpu_to_node(cpu) == node) {
|
||||
map->pbus_to_dieid[bus] = die_id = c->logical_die_id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
raw_spin_unlock(&pci2phy_map_lock);
|
||||
|
||||
if (WARN_ON_ONCE(die_id == -1)) {
|
||||
|
|
Loading…
Reference in New Issue