Commit ba9506be authored by Steve Wahl's avatar Steve Wahl Committed by Peter Zijlstra

perf/x86/intel/uncore: Store the logical die id instead of the physical die id.

The phys_id isn't really used other than to map to a logical die id.
Calculate the logical die id earlier, and store that instead of the
phys_id.
Signed-off-by: default avatarSteve Wahl <steve.wahl@hpe.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: default avatarKan Liang <kan.liang@linux.intel.com>
Link: https://lkml.kernel.org/r/20210108153549.108989-2-steve.wahl@hpe.com
parent e71ba945
...@@ -31,21 +31,21 @@ struct event_constraint uncore_constraint_empty = ...@@ -31,21 +31,21 @@ struct event_constraint uncore_constraint_empty =
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
int uncore_pcibus_to_physid(struct pci_bus *bus) int uncore_pcibus_to_dieid(struct pci_bus *bus)
{ {
struct pci2phy_map *map; struct pci2phy_map *map;
int phys_id = -1; int die_id = -1;
raw_spin_lock(&pci2phy_map_lock); raw_spin_lock(&pci2phy_map_lock);
list_for_each_entry(map, &pci2phy_map_head, list) { list_for_each_entry(map, &pci2phy_map_head, list) {
if (map->segment == pci_domain_nr(bus)) { if (map->segment == pci_domain_nr(bus)) {
phys_id = map->pbus_to_physid[bus->number]; die_id = map->pbus_to_dieid[bus->number];
break; break;
} }
} }
raw_spin_unlock(&pci2phy_map_lock); raw_spin_unlock(&pci2phy_map_lock);
return phys_id; return die_id;
} }
static void uncore_free_pcibus_map(void) static void uncore_free_pcibus_map(void)
...@@ -86,7 +86,7 @@ struct pci2phy_map *__find_pci2phy_map(int segment) ...@@ -86,7 +86,7 @@ struct pci2phy_map *__find_pci2phy_map(int segment)
alloc = NULL; alloc = NULL;
map->segment = segment; map->segment = segment;
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
map->pbus_to_physid[i] = -1; map->pbus_to_dieid[i] = -1;
list_add_tail(&map->list, &pci2phy_map_head); list_add_tail(&map->list, &pci2phy_map_head);
end: end:
...@@ -332,7 +332,6 @@ static struct intel_uncore_box *uncore_alloc_box(struct intel_uncore_type *type, ...@@ -332,7 +332,6 @@ static struct intel_uncore_box *uncore_alloc_box(struct intel_uncore_type *type,
uncore_pmu_init_hrtimer(box); uncore_pmu_init_hrtimer(box);
box->cpu = -1; box->cpu = -1;
box->pci_phys_id = -1;
box->dieid = -1; box->dieid = -1;
/* set default hrtimer timeout */ /* set default hrtimer timeout */
...@@ -993,18 +992,11 @@ uncore_types_init(struct intel_uncore_type **types, bool setid) ...@@ -993,18 +992,11 @@ uncore_types_init(struct intel_uncore_type **types, bool setid)
/* /*
* Get the die information of a PCI device. * Get the die information of a PCI device.
* @pdev: The PCI device. * @pdev: The PCI device.
* @phys_id: The physical socket id which the device maps to.
* @die: The die id which the device maps to. * @die: The die id which the device maps to.
*/ */
static int uncore_pci_get_dev_die_info(struct pci_dev *pdev, static int uncore_pci_get_dev_die_info(struct pci_dev *pdev, int *die)
int *phys_id, int *die)
{ {
*phys_id = uncore_pcibus_to_physid(pdev->bus); *die = uncore_pcibus_to_dieid(pdev->bus);
if (*phys_id < 0)
return -ENODEV;
*die = (topology_max_die_per_package() > 1) ? *phys_id :
topology_phys_to_logical_pkg(*phys_id);
if (*die < 0) if (*die < 0)
return -EINVAL; return -EINVAL;
...@@ -1046,13 +1038,12 @@ uncore_pci_find_dev_pmu(struct pci_dev *pdev, const struct pci_device_id *ids) ...@@ -1046,13 +1038,12 @@ uncore_pci_find_dev_pmu(struct pci_dev *pdev, const struct pci_device_id *ids)
* @pdev: The PCI device. * @pdev: The PCI device.
* @type: The corresponding PMU type of the device. * @type: The corresponding PMU type of the device.
* @pmu: The corresponding PMU of the device. * @pmu: The corresponding PMU of the device.
* @phys_id: The physical socket id which the device maps to.
* @die: The die id which the device maps to. * @die: The die id which the device maps to.
*/ */
static int uncore_pci_pmu_register(struct pci_dev *pdev, static int uncore_pci_pmu_register(struct pci_dev *pdev,
struct intel_uncore_type *type, struct intel_uncore_type *type,
struct intel_uncore_pmu *pmu, struct intel_uncore_pmu *pmu,
int phys_id, int die) int die)
{ {
struct intel_uncore_box *box; struct intel_uncore_box *box;
int ret; int ret;
...@@ -1070,7 +1061,6 @@ static int uncore_pci_pmu_register(struct pci_dev *pdev, ...@@ -1070,7 +1061,6 @@ static int uncore_pci_pmu_register(struct pci_dev *pdev,
WARN_ON_ONCE(pmu->func_id != pdev->devfn); WARN_ON_ONCE(pmu->func_id != pdev->devfn);
atomic_inc(&box->refcnt); atomic_inc(&box->refcnt);
box->pci_phys_id = phys_id;
box->dieid = die; box->dieid = die;
box->pci_dev = pdev; box->pci_dev = pdev;
box->pmu = pmu; box->pmu = pmu;
...@@ -1097,9 +1087,9 @@ static int uncore_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id ...@@ -1097,9 +1087,9 @@ static int uncore_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id
{ {
struct intel_uncore_type *type; struct intel_uncore_type *type;
struct intel_uncore_pmu *pmu = NULL; struct intel_uncore_pmu *pmu = NULL;
int phys_id, die, ret; int die, ret;
ret = uncore_pci_get_dev_die_info(pdev, &phys_id, &die); ret = uncore_pci_get_dev_die_info(pdev, &die);
if (ret) if (ret)
return ret; return ret;
...@@ -1132,7 +1122,7 @@ static int uncore_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id ...@@ -1132,7 +1122,7 @@ static int uncore_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id
pmu = &type->pmus[UNCORE_PCI_DEV_IDX(id->driver_data)]; pmu = &type->pmus[UNCORE_PCI_DEV_IDX(id->driver_data)];
} }
ret = uncore_pci_pmu_register(pdev, type, pmu, phys_id, die); ret = uncore_pci_pmu_register(pdev, type, pmu, die);
pci_set_drvdata(pdev, pmu->boxes[die]); pci_set_drvdata(pdev, pmu->boxes[die]);
...@@ -1142,17 +1132,12 @@ static int uncore_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id ...@@ -1142,17 +1132,12 @@ static int uncore_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id
/* /*
* Unregister the PMU of a PCI device * Unregister the PMU of a PCI device
* @pmu: The corresponding PMU is unregistered. * @pmu: The corresponding PMU is unregistered.
* @phys_id: The physical socket id which the device maps to.
* @die: The die id which the device maps to. * @die: The die id which the device maps to.
*/ */
static void uncore_pci_pmu_unregister(struct intel_uncore_pmu *pmu, static void uncore_pci_pmu_unregister(struct intel_uncore_pmu *pmu, int die)
int phys_id, int die)
{ {
struct intel_uncore_box *box = pmu->boxes[die]; struct intel_uncore_box *box = pmu->boxes[die];
if (WARN_ON_ONCE(phys_id != box->pci_phys_id))
return;
pmu->boxes[die] = NULL; pmu->boxes[die] = NULL;
if (atomic_dec_return(&pmu->activeboxes) == 0) if (atomic_dec_return(&pmu->activeboxes) == 0)
uncore_pmu_unregister(pmu); uncore_pmu_unregister(pmu);
...@@ -1164,9 +1149,9 @@ static void uncore_pci_remove(struct pci_dev *pdev) ...@@ -1164,9 +1149,9 @@ static void uncore_pci_remove(struct pci_dev *pdev)
{ {
struct intel_uncore_box *box; struct intel_uncore_box *box;
struct intel_uncore_pmu *pmu; struct intel_uncore_pmu *pmu;
int i, phys_id, die; int i, die;
if (uncore_pci_get_dev_die_info(pdev, &phys_id, &die)) if (uncore_pci_get_dev_die_info(pdev, &die))
return; return;
box = pci_get_drvdata(pdev); box = pci_get_drvdata(pdev);
...@@ -1185,7 +1170,7 @@ static void uncore_pci_remove(struct pci_dev *pdev) ...@@ -1185,7 +1170,7 @@ static void uncore_pci_remove(struct pci_dev *pdev)
pci_set_drvdata(pdev, NULL); pci_set_drvdata(pdev, NULL);
uncore_pci_pmu_unregister(pmu, phys_id, die); uncore_pci_pmu_unregister(pmu, die);
} }
static int uncore_bus_notify(struct notifier_block *nb, static int uncore_bus_notify(struct notifier_block *nb,
...@@ -1194,7 +1179,7 @@ static int uncore_bus_notify(struct notifier_block *nb, ...@@ -1194,7 +1179,7 @@ static int uncore_bus_notify(struct notifier_block *nb,
struct device *dev = data; struct device *dev = data;
struct pci_dev *pdev = to_pci_dev(dev); struct pci_dev *pdev = to_pci_dev(dev);
struct intel_uncore_pmu *pmu; struct intel_uncore_pmu *pmu;
int phys_id, die; int die;
/* Unregister the PMU when the device is going to be deleted. */ /* Unregister the PMU when the device is going to be deleted. */
if (action != BUS_NOTIFY_DEL_DEVICE) if (action != BUS_NOTIFY_DEL_DEVICE)
...@@ -1204,10 +1189,10 @@ static int uncore_bus_notify(struct notifier_block *nb, ...@@ -1204,10 +1189,10 @@ static int uncore_bus_notify(struct notifier_block *nb,
if (!pmu) if (!pmu)
return NOTIFY_DONE; return NOTIFY_DONE;
if (uncore_pci_get_dev_die_info(pdev, &phys_id, &die)) if (uncore_pci_get_dev_die_info(pdev, &die))
return NOTIFY_DONE; return NOTIFY_DONE;
uncore_pci_pmu_unregister(pmu, phys_id, die); uncore_pci_pmu_unregister(pmu, die);
return NOTIFY_OK; return NOTIFY_OK;
} }
...@@ -1224,7 +1209,7 @@ static void uncore_pci_sub_driver_init(void) ...@@ -1224,7 +1209,7 @@ static void uncore_pci_sub_driver_init(void)
struct pci_dev *pci_sub_dev; struct pci_dev *pci_sub_dev;
bool notify = false; bool notify = false;
unsigned int devfn; unsigned int devfn;
int phys_id, die; int die;
while (ids && ids->vendor) { while (ids && ids->vendor) {
pci_sub_dev = NULL; pci_sub_dev = NULL;
...@@ -1244,12 +1229,11 @@ static void uncore_pci_sub_driver_init(void) ...@@ -1244,12 +1229,11 @@ static void uncore_pci_sub_driver_init(void)
if (!pmu) if (!pmu)
continue; continue;
if (uncore_pci_get_dev_die_info(pci_sub_dev, if (uncore_pci_get_dev_die_info(pci_sub_dev, &die))
&phys_id, &die))
continue; continue;
if (!uncore_pci_pmu_register(pci_sub_dev, type, pmu, if (!uncore_pci_pmu_register(pci_sub_dev, type, pmu,
phys_id, die)) die))
notify = true; notify = true;
} }
ids++; ids++;
......
...@@ -124,7 +124,6 @@ struct intel_uncore_extra_reg { ...@@ -124,7 +124,6 @@ struct intel_uncore_extra_reg {
}; };
struct intel_uncore_box { struct intel_uncore_box {
int pci_phys_id;
int dieid; /* Logical die ID */ int dieid; /* Logical die ID */
int n_active; /* number of active events */ int n_active; /* number of active events */
int n_events; int n_events;
...@@ -173,11 +172,11 @@ struct freerunning_counters { ...@@ -173,11 +172,11 @@ struct freerunning_counters {
struct pci2phy_map { struct pci2phy_map {
struct list_head list; struct list_head list;
int segment; int segment;
int pbus_to_physid[256]; int pbus_to_dieid[256];
}; };
struct pci2phy_map *__find_pci2phy_map(int segment); struct pci2phy_map *__find_pci2phy_map(int segment);
int uncore_pcibus_to_physid(struct pci_bus *bus); int uncore_pcibus_to_dieid(struct pci_bus *bus);
ssize_t uncore_event_show(struct device *dev, ssize_t uncore_event_show(struct device *dev,
struct device_attribute *attr, char *buf); struct device_attribute *attr, char *buf);
......
...@@ -657,7 +657,7 @@ int snb_pci2phy_map_init(int devid) ...@@ -657,7 +657,7 @@ int snb_pci2phy_map_init(int devid)
pci_dev_put(dev); pci_dev_put(dev);
return -ENOMEM; return -ENOMEM;
} }
map->pbus_to_physid[bus] = 0; map->pbus_to_dieid[bus] = 0;
raw_spin_unlock(&pci2phy_map_lock); raw_spin_unlock(&pci2phy_map_lock);
pci_dev_put(dev); pci_dev_put(dev);
......
...@@ -1359,7 +1359,7 @@ static struct pci_driver snbep_uncore_pci_driver = { ...@@ -1359,7 +1359,7 @@ static struct pci_driver snbep_uncore_pci_driver = {
static int snbep_pci2phy_map_init(int devid, int nodeid_loc, int idmap_loc, bool reverse) static int snbep_pci2phy_map_init(int devid, int nodeid_loc, int idmap_loc, bool reverse)
{ {
struct pci_dev *ubox_dev = NULL; struct pci_dev *ubox_dev = NULL;
int i, bus, nodeid, segment; int i, bus, nodeid, segment, die_id;
struct pci2phy_map *map; struct pci2phy_map *map;
int err = 0; int err = 0;
u32 config = 0; u32 config = 0;
...@@ -1395,7 +1395,11 @@ static int snbep_pci2phy_map_init(int devid, int nodeid_loc, int idmap_loc, bool ...@@ -1395,7 +1395,11 @@ static int snbep_pci2phy_map_init(int devid, int nodeid_loc, int idmap_loc, bool
*/ */
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
if (nodeid == ((config >> (3 * i)) & 0x7)) { if (nodeid == ((config >> (3 * i)) & 0x7)) {
map->pbus_to_physid[bus] = i; if (topology_max_die_per_package() > 1)
die_id = i;
else
die_id = topology_phys_to_logical_pkg(i);
map->pbus_to_dieid[bus] = die_id;
break; break;
} }
} }
...@@ -1412,17 +1416,17 @@ static int snbep_pci2phy_map_init(int devid, int nodeid_loc, int idmap_loc, bool ...@@ -1412,17 +1416,17 @@ static int snbep_pci2phy_map_init(int devid, int nodeid_loc, int idmap_loc, bool
i = -1; i = -1;
if (reverse) { if (reverse) {
for (bus = 255; bus >= 0; bus--) { for (bus = 255; bus >= 0; bus--) {
if (map->pbus_to_physid[bus] >= 0) if (map->pbus_to_dieid[bus] >= 0)
i = map->pbus_to_physid[bus]; i = map->pbus_to_dieid[bus];
else else
map->pbus_to_physid[bus] = i; map->pbus_to_dieid[bus] = i;
} }
} else { } else {
for (bus = 0; bus <= 255; bus++) { for (bus = 0; bus <= 255; bus++) {
if (map->pbus_to_physid[bus] >= 0) if (map->pbus_to_dieid[bus] >= 0)
i = map->pbus_to_physid[bus]; i = map->pbus_to_dieid[bus];
else else
map->pbus_to_physid[bus] = i; map->pbus_to_dieid[bus] = i;
} }
} }
} }
...@@ -4646,19 +4650,14 @@ int snr_uncore_pci_init(void) ...@@ -4646,19 +4650,14 @@ int snr_uncore_pci_init(void)
static struct pci_dev *snr_uncore_get_mc_dev(int id) static struct pci_dev *snr_uncore_get_mc_dev(int id)
{ {
struct pci_dev *mc_dev = NULL; struct pci_dev *mc_dev = NULL;
int phys_id, pkg; int pkg;
while (1) { while (1) {
mc_dev = pci_get_device(PCI_VENDOR_ID_INTEL, 0x3451, mc_dev); mc_dev = pci_get_device(PCI_VENDOR_ID_INTEL, 0x3451, mc_dev);
if (!mc_dev) if (!mc_dev)
break; break;
phys_id = uncore_pcibus_to_physid(mc_dev->bus); pkg = uncore_pcibus_to_dieid(mc_dev->bus);
if (phys_id < 0) if (pkg == id)
continue;
pkg = topology_phys_to_logical_pkg(phys_id);
if (pkg < 0)
continue;
else if (pkg == id)
break; break;
} }
return mc_dev; return mc_dev;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment