Skip to content

Commit dbf061b

Browse files
Kan LiangPeter Zijlstra
authored andcommitted
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
1 parent 0eed282 commit dbf061b

File tree

4 files changed

+19
-25
lines changed

4 files changed

+19
-25
lines changed

arch/x86/events/intel/uncore.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@ int uncore_die_to_segment(int die)
6565
return bus ? pci_domain_nr(bus) : -EINVAL;
6666
}
6767

68+
int uncore_device_to_die(struct pci_dev *dev)
69+
{
70+
int node = pcibus_to_node(dev->bus);
71+
int cpu;
72+
73+
for_each_cpu(cpu, cpumask_of_pcibus(dev->bus)) {
74+
struct cpuinfo_x86 *c = &cpu_data(cpu);
75+
76+
if (c->initialized && cpu_to_node(cpu) == node)
77+
return c->logical_die_id;
78+
}
79+
80+
return -1;
81+
}
82+
6883
static void uncore_free_pcibus_map(void)
6984
{
7085
struct pci2phy_map *map, *tmp;

arch/x86/events/intel/uncore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ struct pci2phy_map {
208208
struct pci2phy_map *__find_pci2phy_map(int segment);
209209
int uncore_pcibus_to_dieid(struct pci_bus *bus);
210210
int uncore_die_to_segment(int die);
211+
int uncore_device_to_die(struct pci_dev *dev);
211212

212213
ssize_t uncore_event_show(struct device *dev,
213214
struct device_attribute *attr, char *buf);

arch/x86/events/intel/uncore_discovery.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static int logical_die_id;
3333

3434
static int get_device_die_id(struct pci_dev *dev)
3535
{
36-
int cpu, node = pcibus_to_node(dev->bus);
36+
int node = pcibus_to_node(dev->bus);
3737

3838
/*
3939
* 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)
4343
if (node < 0)
4444
return logical_die_id++;
4545

46-
for_each_cpu(cpu, cpumask_of_node(node)) {
47-
struct cpuinfo_x86 *c = &cpu_data(cpu);
48-
49-
if (c->initialized && cpu_to_node(cpu) == node)
50-
return c->logical_die_id;
51-
}
52-
53-
/*
54-
* All CPUs of a node may be offlined. For this case,
55-
* the PCI and MMIO type of uncore blocks which are
56-
* enumerated by the device will be unavailable.
57-
*/
58-
return -1;
46+
return uncore_device_to_die(dev);
5947
}
6048

6149
#define __node_2_type(cur) \

arch/x86/events/intel/uncore_snbep.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,9 +1453,6 @@ static int snbep_pci2phy_map_init(int devid, int nodeid_loc, int idmap_loc, bool
14531453
}
14541454
raw_spin_unlock(&pci2phy_map_lock);
14551455
} else {
1456-
int node = pcibus_to_node(ubox_dev->bus);
1457-
int cpu;
1458-
14591456
segment = pci_domain_nr(ubox_dev->bus);
14601457
raw_spin_lock(&pci2phy_map_lock);
14611458
map = __find_pci2phy_map(segment);
@@ -1465,15 +1462,8 @@ static int snbep_pci2phy_map_init(int devid, int nodeid_loc, int idmap_loc, bool
14651462
break;
14661463
}
14671464

1468-
die_id = -1;
1469-
for_each_cpu(cpu, cpumask_of_pcibus(ubox_dev->bus)) {
1470-
struct cpuinfo_x86 *c = &cpu_data(cpu);
1465+
map->pbus_to_dieid[bus] = die_id = uncore_device_to_die(ubox_dev);
14711466

1472-
if (c->initialized && cpu_to_node(cpu) == node) {
1473-
map->pbus_to_dieid[bus] = die_id = c->logical_die_id;
1474-
break;
1475-
}
1476-
}
14771467
raw_spin_unlock(&pci2phy_map_lock);
14781468

14791469
if (WARN_ON_ONCE(die_id == -1)) {

0 commit comments

Comments
 (0)