Skip to content

Commit

Permalink
FW/Topology: fix num_packages() in -f exec mode (i.e. Windows)
Browse files Browse the repository at this point in the history
We weren't rebuilding the cached topology if the resulting set was the
same as the original. In general, that's a good thing, except when there
was no cached topology in the first place...

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
  • Loading branch information
thiagomacieira committed May 6, 2024
1 parent 35d60d0 commit 24430fe
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
33 changes: 33 additions & 0 deletions bats/sanity-check/20-selftests.bats
Expand Up @@ -1735,6 +1735,39 @@ selftest_cpuset_negated() {
selftest_cpuset_negated \!p${cpuinfo[1]}c${cpuinfo[2]}t${cpuinfo[3]} ${cpuinfo[0]}
}

@test "num_cpus" {
declare -A yamldump

sandstone_selftest -e selftest_skip
[[ "$status" -eq 0 ]]
test_yaml_regexp "/tests/0/threads/0/messages/0/text" '.*"cpus":\s*'$MAX_PROC'\b.*'
}

@test "num_packages" {
declare -A yamldump
sandstone_selftest -e selftest_skip --cpuset=p0
[[ "$status" -eq 0 ]]
test_yaml_regexp "/tests/0/threads/0/messages/0/text" '.*"packages":\s*1\b.*'

# attempt to run on two sockets
export SANDSTONE_MOCK_TOPOLOGY='0 1 0:1 1:1'
run $SANDSTONE --cpuset=p1 --dump-cpu-info
if [[ $status -ne 0 ]]; then
skip "Test only works with Debug builds (to mock the topology) or multi-socket systems"
fi

sandstone_selftest -e selftest_skip --cpuset=p0c0,p1c0 --no-slicing
test_yaml_regexp "/tests/0/threads/0/messages/0/text" '.*"packages":\s*2\b.*'

# now let's try 4 sockets
export SANDSTONE_MOCK_TOPOLOGY='0 1 2 3'
run $SANDSTONE --cpuset=p3 --dump-cpu-info
if [[ $status -eq 0 ]]; then
sandstone_selftest -e selftest_skip --cpuset=p0c0,p1c0,p2c0,p3c0 --no-slicing
test_yaml_regexp "/tests/0/threads/0/messages/0/text" '.*"packages":\s*4\b.*'
fi
}

# Confirm that we are roughly using the threads we said we would
@test "thread usage" {
local -a cpuset=(`$SANDSTONE --dump-cpu-info | awk '/^[0-9]/ { print $1 }'`)
Expand Down
1 change: 1 addition & 0 deletions framework/selftest.cpp
Expand Up @@ -204,6 +204,7 @@ static int selftest_cxxthrowcatch_run(struct test *test, int cpu)

static int selftest_skip_init(struct test *test)
{
log_info("{\"packages\": %d, \"cpus\": %d}", num_packages(), num_cpus());
log_info("Requesting skip (this message should be visible)");
return EXIT_SKIP;
}
Expand Down
7 changes: 4 additions & 3 deletions framework/topology.cpp
Expand Up @@ -1084,10 +1084,11 @@ void restrict_topology(CpuRange range)
assert(range.starting_cpu + range.cpu_count <= sApp->thread_count);
auto old_cpu_info = std::exchange(cpu_info, sApp->shmem->cpu_info + range.starting_cpu);
int old_thread_count = std::exchange(sApp->thread_count, range.cpu_count);
if (old_cpu_info == cpu_info && old_thread_count == sApp->thread_count)
return;

cached_topology() = build_topology();
Topology &topo = cached_topology();
if (old_cpu_info != cpu_info || old_thread_count != sApp->thread_count ||
topo.packages.size() == 0)
topo = build_topology();
}

static char character_for_mask(uint32_t mask)
Expand Down

0 comments on commit 24430fe

Please sign in to comment.