Skip to content

Commit

Permalink
pci+linuxio: use discovery status flags to dynamically exclude PCI ba…
Browse files Browse the repository at this point in the history
…ckends

In 2.0, linuxio and pci backends attached PCI objects to the root during
discovery and they were moved to the actual location at the end.
Checking whether another backend already performed PCI discovery was as
easy as looking for PCI objects attached to root.

In 2.1, we directly attach PCI objects to their correct location
(since f121096), which means the above
dynamic exclusion doesn't work anymore (except when all I/Os are attached
to root for real).

Use a discovery status flag to store/check that information.

We could also remember whether we added PCI objects but that would
require to rebuild levels (what we did in 1.x) or add a specific variable.

Signed-off-by: Brice Goglin <Brice.Goglin@inria.fr>
  • Loading branch information
bgoglin committed Jan 11, 2019
1 parent e2b2ea2 commit 6ac6f16
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 36 deletions.
27 changes: 6 additions & 21 deletions hwloc/topology-linux.c
Expand Up @@ -6455,17 +6455,13 @@ hwloc_linuxfs_pci_look_pcislots(struct hwloc_backend *backend)
#endif /* HWLOC_HAVE_LINUXPCI */

static int
hwloc_look_linuxfs_io(struct hwloc_backend *backend, struct hwloc_disc_status *dstatus __hwloc_attribute_unused)
hwloc_look_linuxfs_io(struct hwloc_backend *backend, struct hwloc_disc_status *dstatus)
{
struct hwloc_topology *topology = backend->topology;
struct hwloc_linux_backend_data_s *data = NULL;
struct hwloc_backend *tmpbackend;
enum hwloc_type_filter_e pfilter, bfilter, ofilter, mfilter;
int root_fd = -1;
#ifdef HWLOC_HAVE_LINUXPCI
struct hwloc_obj *child;
int needpcidiscovery;
#endif

hwloc_topology_get_type_filter(topology, HWLOC_OBJ_PCI_DEVICE, &pfilter);
hwloc_topology_get_type_filter(topology, HWLOC_OBJ_BRIDGE, &bfilter);
Expand Down Expand Up @@ -6497,23 +6493,12 @@ hwloc_look_linuxfs_io(struct hwloc_backend *backend, struct hwloc_disc_status *d
if (bfilter != HWLOC_TYPE_FILTER_KEEP_NONE
|| pfilter != HWLOC_TYPE_FILTER_KEEP_NONE) {
#ifdef HWLOC_HAVE_LINUXPCI
/* don't rediscovery PCI devices if another backend did it
* (they are attached to root until later in the core discovery)
*/
needpcidiscovery = 1;
for_each_io_child(child, hwloc_get_root_obj(topology)) {
if (child->type == HWLOC_OBJ_PCI_DEVICE
|| (child->type == HWLOC_OBJ_BRIDGE &&
(child->attr->bridge.upstream_type == HWLOC_OBJ_BRIDGE_PCI
|| child->attr->bridge.downstream_type == HWLOC_OBJ_BRIDGE_PCI))) {
hwloc_debug("%s", "Topology already contains PCI objects, skipping linuxio PCI discovery.\n");
needpcidiscovery = 0;
break;
}
}

if (needpcidiscovery)
if (dstatus->flags & HWLOC_DISC_STATUS_FLAG_PCI_DONE) {
hwloc_debug("%s", "PCI discovery has already been performed, skipping PCI in linuxio backend.\n");
} else {
hwloc_linuxfs_pci_look_pcidevices(backend);
dstatus->flags |= HWLOC_DISC_STATUS_FLAG_PCI_DONE;
}

hwloc_linuxfs_pci_look_pcislots(backend);
#endif /* HWLOC_HAVE_LINUXPCI */
Expand Down
19 changes: 6 additions & 13 deletions hwloc/topology-pci.c
Expand Up @@ -88,11 +88,11 @@ static pthread_mutex_t hwloc_pciaccess_mutex = PTHREAD_MUTEX_INITIALIZER;
#endif

static int
hwloc_look_pci(struct hwloc_backend *backend, struct hwloc_disc_status *dstatus __hwloc_attribute_unused)
hwloc_look_pci(struct hwloc_backend *backend, struct hwloc_disc_status *dstatus)
{
struct hwloc_topology *topology = backend->topology;
enum hwloc_type_filter_e pfilter, bfilter;
struct hwloc_obj *tree = NULL, *child;
struct hwloc_obj *tree = NULL;
int ret;
struct pci_device_iterator *iter;
struct pci_device *pcidev;
Expand All @@ -103,17 +103,9 @@ hwloc_look_pci(struct hwloc_backend *backend, struct hwloc_disc_status *dstatus
&& pfilter == HWLOC_TYPE_FILTER_KEEP_NONE)
return 0;

/* don't do anything if another backend attached PCI already
* (they are attached to root until later in the core discovery)
*/
for_each_io_child(child, hwloc_get_root_obj(topology)) {
if (child->type == HWLOC_OBJ_PCI_DEVICE
|| (child->type == HWLOC_OBJ_BRIDGE &&
(child->attr->bridge.upstream_type == HWLOC_OBJ_BRIDGE_PCI
|| child->attr->bridge.downstream_type == HWLOC_OBJ_BRIDGE_PCI))) {
hwloc_debug("%s", "Topology already contains PCI objects, skipping PCI backend.\n");
return 0;
}
if (dstatus->flags & HWLOC_DISC_STATUS_FLAG_PCI_DONE) {
hwloc_debug("%s", "PCI discovery has already been performed, skipping PCI backend.\n");
return 0;
}

hwloc_debug("%s", "\nScanning PCI buses...\n");
Expand Down Expand Up @@ -320,6 +312,7 @@ hwloc_look_pci(struct hwloc_backend *backend, struct hwloc_disc_status *dstatus
HWLOC_PCIACCESS_UNLOCK();

hwloc_pcidisc_tree_attach(topology, tree);
dstatus->flags |= HWLOC_DISC_STATUS_FLAG_PCI_DONE;
return 0;
}

Expand Down
3 changes: 2 additions & 1 deletion include/hwloc/plugins.h
Expand Up @@ -109,7 +109,8 @@ struct hwloc_disc_component {

/** \brief Discovery status flags */
enum hwloc_disc_status_flag_e {
HWLOC_DISC_STATUS_FLAG_DUMMY
/** \brief PCI discovery has been performed \hideinitializer */
HWLOC_DISC_STATUS_FLAG_PCI_DONE = (1UL<<0)
};

/** \brief Discovery status structure
Expand Down
2 changes: 1 addition & 1 deletion include/hwloc/rename.h
Expand Up @@ -525,7 +525,7 @@ extern "C" {
#define hwloc_disc_component HWLOC_NAME(disc_component)

#define hwloc_disc_status_flag_e HWLOC_NAME(disc_status_flag_e)
#define HWLOC_DISC_STATUS_FLAG_DUMMY HWLOC_NAME_CAPS(DISC_STATUS_FLAG_DUMMY)
#define HWLOC_DISC_STATUS_FLAG_PCI_DONE HWLOC_NAME_CAPS(DISC_STATUS_FLAG_PCI_DONE)
#define hwloc_disc_status HWLOC_NAME(disc_status)

#define hwloc_backend HWLOC_NAME(backend)
Expand Down

0 comments on commit 6ac6f16

Please sign in to comment.