Skip to content

Commit a1b9391

Browse files
committed
core: disable all distances/cpukinds/memattrs call if flags are set
Don't even bother calling the distances/cpukinds/memattrs which will do not nothing. init()/destroy() calls are kept because init() doesn't know yet if flags will be set to disable distances/cpukinds/memattrs. Signed-off-by: Brice Goglin <[email protected]>
1 parent 882563c commit a1b9391

File tree

1 file changed

+43
-24
lines changed

1 file changed

+43
-24
lines changed

hwloc/topology.c

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3870,6 +3870,7 @@ hwloc__topology_init (struct hwloc_topology **topologyp,
38703870

38713871
hwloc__topology_filter_init(topology);
38723872

3873+
/* always initialize since we don't know flags to disable those yet */
38733874
hwloc_internal_distances_init(topology);
38743875
hwloc_internal_memattrs_init(topology);
38753876
hwloc_internal_cpukinds_init(topology);
@@ -4134,9 +4135,12 @@ hwloc_topology_clear (struct hwloc_topology *topology)
41344135
{
41354136
/* no need to set to NULL after free() since callers will call setup_defaults() or just destroy the rest of the topology */
41364137
unsigned l;
4138+
4139+
/* always destroy cpukinds/distances/memattrs since there are always initialized during init() */
41374140
hwloc_internal_cpukinds_destroy(topology);
41384141
hwloc_internal_distances_destroy(topology);
41394142
hwloc_internal_memattrs_destroy(topology);
4143+
41404144
hwloc_free_object_and_children(topology->levels[0][0]);
41414145
hwloc_bitmap_free(topology->allowed_cpuset);
41424146
hwloc_bitmap_free(topology->allowed_nodeset);
@@ -4189,8 +4193,10 @@ hwloc_topology_load (struct hwloc_topology *topology)
41894193
topology->state |= HWLOC_TOPOLOGY_STATE_IS_LOADING;
41904194

41914195
/* initialize envvar-related things */
4192-
hwloc_internal_distances_prepare(topology);
4193-
hwloc_internal_memattrs_prepare(topology);
4196+
if (!(topology->flags & HWLOC_TOPOLOGY_FLAG_NO_DISTANCES))
4197+
hwloc_internal_distances_prepare(topology);
4198+
if (!(topology->flags & HWLOC_TOPOLOGY_FLAG_NO_MEMATTRS))
4199+
hwloc_internal_memattrs_prepare(topology);
41944200

41954201
/* check if any cpu cache filter is not NONE */
41964202
topology->want_some_cpu_caches = 0;
@@ -4275,24 +4281,29 @@ hwloc_topology_load (struct hwloc_topology *topology)
42754281
#endif
42764282
hwloc_topology_check(topology);
42774283

4278-
/* Rank cpukinds */
4279-
hwloc_internal_cpukinds_rank(topology);
4284+
if (!(topology->flags & HWLOC_TOPOLOGY_FLAG_NO_CPUKINDS)) {
4285+
/* Rank cpukinds */
4286+
hwloc_internal_cpukinds_rank(topology);
4287+
}
42804288

4281-
/* Mark distances objs arrays as invalid since we may have removed objects
4282-
* from the topology after adding the distances (remove_empty, etc).
4283-
* It would be hard to actually verify whether it's needed.
4284-
*/
4285-
hwloc_internal_distances_invalidate_cached_objs(topology);
4286-
/* And refresh distances so that multithreaded concurrent distances_get()
4287-
* don't refresh() concurrently (disallowed).
4288-
*/
4289-
hwloc_internal_distances_refresh(topology);
4289+
if (!(topology->flags & HWLOC_TOPOLOGY_FLAG_NO_DISTANCES)) {
4290+
/* Mark distances objs arrays as invalid since we may have removed objects
4291+
* from the topology after adding the distances (remove_empty, etc).
4292+
* It would be hard to actually verify whether it's needed.
4293+
*/
4294+
hwloc_internal_distances_invalidate_cached_objs(topology);
4295+
/* And refresh distances so that multithreaded concurrent distances_get()
4296+
* don't refresh() concurrently (disallowed).
4297+
*/
4298+
hwloc_internal_distances_refresh(topology);
4299+
}
42904300

4291-
/* Same for memattrs */
4292-
hwloc_internal_memattrs_need_refresh(topology);
4293-
hwloc_internal_memattrs_refresh(topology);
4294-
if (!(topology->flags & HWLOC_TOPOLOGY_FLAG_NO_MEMATTRS))
4301+
if (!(topology->flags & HWLOC_TOPOLOGY_FLAG_NO_MEMATTRS)) {
4302+
/* Same for memattrs */
4303+
hwloc_internal_memattrs_need_refresh(topology);
4304+
hwloc_internal_memattrs_refresh(topology);
42954305
hwloc_internal_memattrs_guess_memory_tiers(topology);
4306+
}
42964307

42974308
topology->state &= ~HWLOC_TOPOLOGY_STATE_IS_LOADING;
42984309
topology->state |= HWLOC_TOPOLOGY_STATE_IS_LOADED;
@@ -4582,13 +4593,18 @@ hwloc_topology_restrict(struct hwloc_topology *topology, hwloc_const_bitmap_t se
45824593
if (hwloc_filter_levels_keep_structure(topology) < 0) /* takes care of reconnecting internally */
45834594
goto out;
45844595

4585-
/* some objects may have disappeared, we need to update distances objs arrays */
4586-
hwloc_internal_distances_invalidate_cached_objs(topology);
4587-
hwloc_internal_memattrs_need_refresh(topology);
4596+
/* some objects may have disappeared and sets were modified,
4597+
* we need to update distances, etc */
4598+
if (!(topology->flags & HWLOC_TOPOLOGY_FLAG_NO_DISTANCES))
4599+
hwloc_internal_distances_invalidate_cached_objs(topology);
4600+
if (!(topology->flags & HWLOC_TOPOLOGY_FLAG_NO_MEMATTRS))
4601+
hwloc_internal_memattrs_need_refresh(topology);
4602+
if (!(topology->flags & HWLOC_TOPOLOGY_FLAG_NO_CPUKINDS))
4603+
hwloc_internal_cpukinds_restrict(topology);
4604+
45884605

45894606
hwloc_propagate_symmetric_subtree(topology, topology->levels[0][0]);
45904607
propagate_total_memory(topology->levels[0][0]);
4591-
hwloc_internal_cpukinds_restrict(topology);
45924608

45934609
#ifndef HWLOC_DEBUG
45944610
if (getenv("HWLOC_DEBUG_CHECK"))
@@ -4671,9 +4687,12 @@ hwloc_topology_allow(struct hwloc_topology *topology,
46714687
int
46724688
hwloc_topology_refresh(struct hwloc_topology *topology)
46734689
{
4674-
hwloc_internal_cpukinds_rank(topology);
4675-
hwloc_internal_distances_refresh(topology);
4676-
hwloc_internal_memattrs_refresh(topology);
4690+
if (!(topology->flags & HWLOC_TOPOLOGY_FLAG_NO_CPUKINDS))
4691+
hwloc_internal_cpukinds_rank(topology);
4692+
if (!(topology->flags & HWLOC_TOPOLOGY_FLAG_NO_DISTANCES))
4693+
hwloc_internal_distances_refresh(topology);
4694+
if (!(topology->flags & HWLOC_TOPOLOGY_FLAG_NO_MEMATTRS))
4695+
hwloc_internal_memattrs_refresh(topology);
46774696
return 0;
46784697
}
46794698

0 commit comments

Comments
 (0)