Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Jan 9, 2025
1 parent 6cfd75f commit c91ff83
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions libcontainer/nsenter/nsexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,17 @@ void nsexec(void)
return;
}

cpu_set_t cpus = {};
if (sched_getaffinity(0, sizeof(cpus), &cpus) >= 0) {
char buf[128], *bp;
bp = buf;
for (int i = 0; i < 32; i++) {
if CPU_ISSET(i, &cpus)
bp += sprintf(bp, "%d ", i);
}
write_log(DEBUG, "=> nsexec CPUs: %s", buf);
}

write_log(DEBUG, "=> nsexec container setup");

/* Parse all of the netlink configuration. */
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/cpu_affinity.bats
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function first_cpu() {
exp=${exp//-/ } # 2. "-" --> " ".
echo "CPUS: $cpus, exp: $exp"
runc --debug exec --process <(echo "$proc") ct1
[[ "$output" == *"nsexec CPUs: $exp "* ]]
[[ "$output" == *"Initial CPU affinity: $cpus"* ]]
[[ "$output" == *"Initial CPUs: [$exp]"* ]]
done
Expand All @@ -59,6 +60,8 @@ function first_cpu() {

runc --debug exec ct1 grep "Cpus_allowed_list:" /proc/self/status
[ "$status" -eq 0 ]
[[ "$output" == *"nsexec CPUs: $first "* ]] # nsexec.c
[[ "$output" == *"Initial CPU affinity: $first"* ]]
[[ "$output" == *"Initial CPUs: [$first]"* ]]
[[ "$output" == *"Cpus_allowed_list: $second"* ]] # Mind the literal tab.
}

0 comments on commit c91ff83

Please sign in to comment.