Skip to content

Commit

Permalink
pci: rework the main function for inserting an OS device by PCI busid
Browse files Browse the repository at this point in the history
We always used hwloc_pcidisc_find_busid_parent() to find a non-IO ancestor
when hwloc_pcidisc_find_by_busid() failed to find the exact PCI ancestor.
Merge those inside a new hwloc_pci_find_parent_by_busid() and remove
the now unused hwloc_pcidisc_find_busid_parent().

Also remove the 'disc' prefix-suffix since this function works outside
of the main PCI discovery.

This breaks the plugin ABI but HWLOC_COMPONENT_ABI was already bumped to 6 for 2.1.

Signed-off-by: Brice Goglin <Brice.Goglin@inria.fr>
  • Loading branch information
bgoglin committed Mar 19, 2019
1 parent 4a1b647 commit b2ac976
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 29 deletions.
14 changes: 11 additions & 3 deletions hwloc/pci-common.c
@@ -1,5 +1,5 @@
/*
* Copyright © 2009-2018 Inria. All rights reserved.
* Copyright © 2009-2019 Inria. All rights reserved.
* See COPYING in top-level directory.
*/

Expand Down Expand Up @@ -633,10 +633,18 @@ hwloc_pcidisc_tree_attach(struct hwloc_topology *topology, struct hwloc_obj *tre
}

struct hwloc_obj *
hwloc_pcidisc_find_busid_parent(struct hwloc_topology *topology,
unsigned domain, unsigned bus, unsigned dev, unsigned func)
hwloc_pci_find_parent_by_busid(struct hwloc_topology *topology,
unsigned domain, unsigned bus, unsigned dev, unsigned func)
{
struct hwloc_pcidev_attr_s busid;
hwloc_obj_t parent;

/* try to find that exact busid */
parent = hwloc_pcidisc_find_by_busid(topology, domain, bus, dev, func);
if (parent)
return parent;

/* try to find the locality of that bus instead */
busid.domain = domain;
busid.bus = bus;
busid.dev = dev;
Expand Down
4 changes: 1 addition & 3 deletions hwloc/topology-cuda.c
Expand Up @@ -110,9 +110,7 @@ hwloc_cuda_discover(struct hwloc_backend *backend, struct hwloc_disc_status *dst

parent = NULL;
if (hwloc_cudart_get_device_pci_ids(NULL /* topology unused */, i, &domain, &bus, &dev) == 0) {
parent = hwloc_pcidisc_find_by_busid(topology, domain, bus, dev, 0);
if (!parent)
parent = hwloc_pcidisc_find_busid_parent(topology, domain, bus, dev, 0);
parent = hwloc_pci_find_parent_by_busid(topology, domain, bus, dev, 0);
}
if (!parent)
parent = hwloc_get_root_obj(topology);
Expand Down
4 changes: 1 addition & 3 deletions hwloc/topology-gl.c
Expand Up @@ -119,9 +119,7 @@ hwloc_gl_discover(struct hwloc_backend *backend, struct hwloc_disc_status *dstat
if (productname)
hwloc_obj_add_info(osdev, "GPUModel", productname);

parent = hwloc_pcidisc_find_by_busid(topology, (unsigned)nv_ctrl_pci_domain, (unsigned)nv_ctrl_pci_bus, (unsigned)nv_ctrl_pci_device, (unsigned)nv_ctrl_pci_func);
if (!parent)
parent = hwloc_pcidisc_find_busid_parent(topology, (unsigned)nv_ctrl_pci_domain, (unsigned)nv_ctrl_pci_bus, (unsigned)nv_ctrl_pci_device, (unsigned)nv_ctrl_pci_func);
parent = hwloc_pci_find_parent_by_busid(topology, (unsigned)nv_ctrl_pci_domain, (unsigned)nv_ctrl_pci_bus, (unsigned)nv_ctrl_pci_device, (unsigned)nv_ctrl_pci_func);
if (!parent)
parent = hwloc_get_root_obj(topology);

Expand Down
8 changes: 2 additions & 6 deletions hwloc/topology-linux.c
Expand Up @@ -5383,12 +5383,8 @@ hwloc_linuxfs_find_osdev_parent(struct hwloc_backend *backend, int root_fd,
}

if (foundpci) {
/* attach to a PCI parent */
parent = hwloc_pcidisc_find_by_busid(topology, pcidomain, pcibus, pcidev, pcifunc);
if (parent)
return parent;
/* attach to a normal (non-I/O) parent found by PCI affinity */
parent = hwloc_pcidisc_find_busid_parent(topology, pcidomain, pcibus, pcidev, pcifunc);
/* attach to a PCI parent or to a normal (non-I/O) parent found by PCI affinity */
parent = hwloc_pci_find_parent_by_busid(topology, pcidomain, pcibus, pcidev, pcifunc);
if (parent)
return parent;
}
Expand Down
4 changes: 1 addition & 3 deletions hwloc/topology-nvml.c
Expand Up @@ -69,9 +69,7 @@ hwloc_nvml_discover(struct hwloc_backend *backend, struct hwloc_disc_status *dst

parent = NULL;
if (NVML_SUCCESS == nvmlDeviceGetPciInfo(device, &pci)) {
parent = hwloc_pcidisc_find_by_busid(topology, pci.domain, pci.bus, pci.device, 0);
if (!parent)
parent = hwloc_pcidisc_find_busid_parent(topology, pci.domain, pci.bus, pci.device, 0);
parent = hwloc_pci_find_parent_by_busid(topology, pci.domain, pci.bus, pci.device, 0);
#if HAVE_DECL_NVMLDEVICEGETMAXPCIELINKGENERATION
if (parent && parent->type == HWLOC_OBJ_PCI_DEVICE) {
unsigned maxwidth = 0, maxgen = 0;
Expand Down
4 changes: 1 addition & 3 deletions hwloc/topology-opencl.c
Expand Up @@ -140,9 +140,7 @@ hwloc_opencl_discover(struct hwloc_backend *backend, struct hwloc_disc_status *d

parent = NULL;
if (hwloc_opencl_get_device_pci_busid(device_ids[i], &pcidomain, &pcibus, &pcidev, &pcifunc) == 0) {
parent = hwloc_pcidisc_find_by_busid(topology, pcidomain, pcibus, pcidev, pcifunc);
if (!parent)
parent = hwloc_pcidisc_find_busid_parent(topology, pcidomain, pcibus, pcidev, pcifunc);
parent = hwloc_pci_find_parent_by_busid(topology, pcidomain, pcibus, pcidev, pcifunc);
} else {
hwloc_debug("Failed to find the PCI id of the device\n");
}
Expand Down
9 changes: 3 additions & 6 deletions include/hwloc/plugins.h
Expand Up @@ -542,13 +542,10 @@ HWLOC_DECLSPEC struct hwloc_obj * hwloc_pcidisc_find_by_busid(struct hwloc_topol
*
* Look at PCI affinity to find out where the given PCI bus ID should be attached.
*
* This function should be used to attach an I/O device directly under a normal
* (non-I/O) object, instead of below a PCI object.
* It is usually used by backends when hwloc_pcidisc_find_by_busid() failed
* to find the hwloc object corresponding to this bus ID, for instance because
* PCI discovery is not supported on this platform.
* This function should be used to attach an I/O device under the corresponding
* PCI object (if any), or under a normal (non-I/O) object with same locality.
*/
HWLOC_DECLSPEC struct hwloc_obj * hwloc_pcidisc_find_busid_parent(struct hwloc_topology *topology, unsigned domain, unsigned bus, unsigned dev, unsigned func);
HWLOC_DECLSPEC struct hwloc_obj * hwloc_pci_find_parent_by_busid(struct hwloc_topology *topology, unsigned domain, unsigned bus, unsigned dev, unsigned func);

/** @} */

Expand Down
4 changes: 2 additions & 2 deletions include/hwloc/rename.h
@@ -1,6 +1,6 @@
/*
* Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
* Copyright © 2010-2018 Inria. All rights reserved.
* Copyright © 2010-2019 Inria. All rights reserved.
* See COPYING in top-level directory.
*/

Expand Down Expand Up @@ -565,7 +565,7 @@ extern "C" {
#define hwloc_pcidisc_tree_attach HWLOC_NAME(pcidisc_tree_attach)

#define hwloc_pcidisc_find_by_busid HWLOC_NAME(pcidisc_find_by_busid)
#define hwloc_pcidisc_find_busid_parent HWLOC_NAME(pcidisc_find_busid_parent)
#define hwloc_pci_find_parent_by_busid HWLOC_NAME(pcidisc_find_busid_parent)

/* hwloc/deprecated.h */

Expand Down

0 comments on commit b2ac976

Please sign in to comment.