Skip to content

Commit

Permalink
core: remove some redundant checks when setting filters
Browse files Browse the repository at this point in the history
When setting filters for multiple types, only check
the topology status once, and avoid checks on hardwired type values.

Signed-off-by: Brice Goglin <Brice.Goglin@inria.fr>
  • Loading branch information
bgoglin committed Jun 15, 2023
1 parent 12e346d commit 690367b
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions hwloc/topology.c
Expand Up @@ -3949,26 +3949,38 @@ int
hwloc_topology_set_cache_types_filter(hwloc_topology_t topology, enum hwloc_type_filter_e filter)
{
unsigned i;
if (!(topology->state & HWLOC_TOPOLOGY_STATE_IS_INIT)) {
errno = EBUSY;
return -1;
}
for(i=HWLOC_OBJ_L1CACHE; i<=HWLOC_OBJ_L3ICACHE; i++)
hwloc_topology_set_type_filter(topology, (hwloc_obj_type_t) i, filter);
hwloc__topology_set_type_filter(topology, (hwloc_obj_type_t) i, filter);
return 0;
}

int
hwloc_topology_set_icache_types_filter(hwloc_topology_t topology, enum hwloc_type_filter_e filter)
{
unsigned i;
if (!(topology->state & HWLOC_TOPOLOGY_STATE_IS_INIT)) {
errno = EBUSY;
return -1;
}
for(i=HWLOC_OBJ_L1ICACHE; i<=HWLOC_OBJ_L3ICACHE; i++)
hwloc_topology_set_type_filter(topology, (hwloc_obj_type_t) i, filter);
hwloc__topology_set_type_filter(topology, (hwloc_obj_type_t) i, filter);
return 0;
}

int
hwloc_topology_set_io_types_filter(hwloc_topology_t topology, enum hwloc_type_filter_e filter)
{
hwloc_topology_set_type_filter(topology, HWLOC_OBJ_BRIDGE, filter);
hwloc_topology_set_type_filter(topology, HWLOC_OBJ_PCI_DEVICE, filter);
hwloc_topology_set_type_filter(topology, HWLOC_OBJ_OS_DEVICE, filter);
if (!(topology->state & HWLOC_TOPOLOGY_STATE_IS_INIT)) {
errno = EBUSY;
return -1;
}
hwloc__topology_set_type_filter(topology, HWLOC_OBJ_BRIDGE, filter);
hwloc__topology_set_type_filter(topology, HWLOC_OBJ_PCI_DEVICE, filter);
hwloc__topology_set_type_filter(topology, HWLOC_OBJ_OS_DEVICE, filter);
return 0;
}

Expand Down

0 comments on commit 690367b

Please sign in to comment.