infra: fly-cpu-confine also confines /.lxc, check ignores its own chain (PERF-02 review R1-R3)

apply/release/status now cover the cgroup pct exec lands in (/.lxc, only when
it already exists, warn-only when unwritable). check no longer counts its own
process or its parents. Runbook: rollback via an older 05-deploy needs
fly-cpu-confine release; the exact post-first-deploy status/check commands.
This commit is contained in:
acamilo 2026-10-01 15:57:42 +00:00
parent ab537d1045
commit ac7be4a204
4 changed files with 133 additions and 25 deletions

View file

@ -269,7 +269,7 @@ refuses to write the drop-ins until the conf actually carries
The sim's CPUs are also kept exclusive to it (PERF-02 review N1, `infra/docs/runbook.md` "The sim's The sim's CPUs are also kept exclusive to it (PERF-02 review N1, `infra/docs/runbook.md` "The sim's
CPUs are exclusive to the sim"): the sim units run in `flysim.slice`, and `bin/fly-cpu-confine` CPUs are exclusive to the sim"): the sim units run in `flysim.slice`, and `bin/fly-cpu-confine`
confines `system.slice`, `user.slice` and `init.scope` to the other CPUs when the sim starts. confines `system.slice`, `user.slice`, `init.scope` and `/.lxc` (`pct exec`) to the other CPUs when the sim starts.
Without a partition (`CPUSET` unset) none of this applies and the deploy turns the session Without a partition (`CPUSET` unset) none of this applies and the deploy turns the session
runtime's worker pinning off (`FLY_SESSION_PIN=0`). runtime's worker pinning off (`FLY_SESSION_PIN=0`).

View file

@ -2,11 +2,13 @@
# infra/bin/fly-cpu-confine — keep every process that is not the sim off the sim's CPUs. # infra/bin/fly-cpu-confine — keep every process that is not the sim off the sim's CPUs.
# #
# Usage (INSIDE the container, as root): # Usage (INSIDE the container, as root):
# fly-cpu-confine apply confine system.slice, user.slice and init.scope to the non-sim CPUs # fly-cpu-confine apply confine system.slice, user.slice, init.scope and /.lxc (where `pct exec`
# fly-cpu-confine release undo `apply` (those three go back to the container's whole cpuset) # lands) to the non-sim CPUs
# fly-cpu-confine release undo `apply` (all of them go back to the container's whole cpuset)
# fly-cpu-confine status what each of them is confined to, and where the sim runs # fly-cpu-confine status what each of them is confined to, and where the sim runs
# fly-cpu-confine check list every process that is not in flysim.slice but may run on a # fly-cpu-confine check list every process that is not in flysim.slice but may run on a
# sim CPU (exit 1 if there is one) # sim CPU (exit 1 if there is one); this command's own process and its
# parents (the shell it was started from) are noted, not failed
# #
# Why. The session runtime pins its sweep workers one per CPU (PERF-02). A pinned worker cannot # Why. The session runtime pins its sweep workers one per CPU (PERF-02). A pinned worker cannot
# leave its CPU, so any sustained CPU-bound process that may run there stalls every barrier: # leave its CPU, so any sustained CPU-bound process that may run there stalls every barrier:
@ -30,8 +32,11 @@
# sim that has not been restarted into flysim.slice would silently make it float over the page # sim that has not been restarted into flysim.slice would silently make it float over the page
# CPUs. `apply` refuses (exit 3, nothing changed) if a sim unit is outside flysim.slice. # CPUs. `apply` refuses (exit 3, nothing changed) if a sim unit is outside flysim.slice.
# #
# Not reachable from here: a process the host starts into the container with `pct exec` # `pct exec` / `pct enter` (lxc-attach) put their processes in the cgroup `/.lxc` (or `/.lxc-N`),
# (lxc-attach). Check where it lands with `check`; run long operator jobs with # a sibling of system.slice that systemd does not manage. It is written directly
# (cpuset.cpus), only if it already exists (a cgroup lxc owns is never created here), and a
# failure is a warning, never an error: it must not stop the sim from starting. If it cannot be
# written, `check` lists what is running there; run long operator jobs with
# `systemd-run --scope --slice=system.slice -- <cmd>` (or `... -- bash`). # `systemd-run --scope --slice=system.slice -- <cmd>` (or `... -- bash`).
set -euo pipefail set -euo pipefail
@ -43,6 +48,26 @@ set -euo pipefail
: "${SIM_UNITS:=flysim.service flysim-session.service}" : "${SIM_UNITS:=flysim.service flysim-session.service}"
CONFINED_UNITS="system.slice user.slice init.scope" CONFINED_UNITS="system.slice user.slice init.scope"
# existing lxc attach cgroups (/.lxc, /.lxc-N) that have a cpuset
lxc_cgroups() {
local d
for d in "$CGROUP_ROOT"/.lxc "$CGROUP_ROOT"/.lxc-*; do
[ -d "$d" ] && [ -e "$d/cpuset.cpus" ] && echo "$d"
done
return 0
}
# set_lxc CPUS — write CPUS into every lxc attach cgroup; warn, never fail.
set_lxc() {
local d
for d in $(lxc_cgroups); do
if ! echo "$1" > "$d/cpuset.cpus" 2>/dev/null; then
log "WARNING: cannot write ${d}/cpuset.cpus; processes started with pct exec stay unconfined (run long jobs with systemd-run --scope --slice=system.slice)"
fi
done
return 0
}
log() { echo "fly-cpu-confine: $*" >&2; } log() { echo "fly-cpu-confine: $*" >&2; }
# read_env — set SIM_CPUS and OTHER_CPUS from ${CPUSET_ENV}, or return 1 when there is no partition. # read_env — set SIM_CPUS and OTHER_CPUS from ${CPUSET_ENV}, or return 1 when there is no partition.
@ -92,7 +117,8 @@ case "$cmd" in
for u in $CONFINED_UNITS; do for u in $CONFINED_UNITS; do
timeout 20 "$SYSTEMCTL" set-property --runtime "$u" "AllowedCPUs=${OTHER_CPUS}" timeout 20 "$SYSTEMCTL" set-property --runtime "$u" "AllowedCPUs=${OTHER_CPUS}"
done done
log "system.slice, user.slice and init.scope confined to ${OTHER_CPUS}; ${SIM_SLICE} keeps ${SIM_CPUS}" set_lxc "$OTHER_CPUS"
log "system.slice, user.slice, init.scope and /.lxc confined to ${OTHER_CPUS}; ${SIM_SLICE} keeps ${SIM_CPUS}"
;; ;;
release) release)
# Not `AllowedCPUs=` (empty): systemd leaves the cgroup's cpuset.cpus at its last value while # Not `AllowedCPUs=` (empty): systemd leaves the cgroup's cpuset.cpus at its last value while
@ -102,12 +128,16 @@ case "$cmd" in
for u in $CONFINED_UNITS; do for u in $CONFINED_UNITS; do
timeout 20 "$SYSTEMCTL" set-property --runtime "$u" "AllowedCPUs=${all_cpus}" timeout 20 "$SYSTEMCTL" set-property --runtime "$u" "AllowedCPUs=${all_cpus}"
done done
log "system.slice, user.slice and init.scope released to the container's whole cpuset (${all_cpus:-unknown})" set_lxc "$all_cpus"
log "system.slice, user.slice, init.scope and /.lxc released to the container's whole cpuset (${all_cpus:-unknown})"
;; ;;
status) status)
for u in $CONFINED_UNITS $SIM_SLICE; do for u in $CONFINED_UNITS $SIM_SLICE; do
echo "$u AllowedCPUs=$("$SYSTEMCTL" show -p AllowedCPUs --value "$u" 2>/dev/null || true)" echo "$u AllowedCPUs=$("$SYSTEMCTL" show -p AllowedCPUs --value "$u" 2>/dev/null || true)"
done done
for d in $(lxc_cgroups); do
echo "${d#"$CGROUP_ROOT"} cpuset.cpus=$(cat "$d/cpuset.cpus" 2>/dev/null || true)"
done
for u in $SIM_UNITS; do for u in $SIM_UNITS; do
echo "$u ControlGroup=$("$SYSTEMCTL" show -p ControlGroup --value "$u" 2>/dev/null || true)" echo "$u ControlGroup=$("$SYSTEMCTL" show -p ControlGroup --value "$u" 2>/dev/null || true)"
done done
@ -119,6 +149,13 @@ case "$cmd" in
fi fi
sim="$(expand "$SIM_CPUS" | sort -n | tr '\n' ' ')" sim="$(expand "$SIM_CPUS" | sort -n | tr '\n' ' ')"
bad=0 bad=0
# this process and its parents (the pct exec shell chain) are not a CPU hog
self=" "
p="${SELF_PID:-$$}"
while [ -n "$p" ] && [ "$p" -gt 1 ] 2>/dev/null && [ "${#self}" -lt 400 ]; do
self="$self$p "
p="$(sed -n 's/^PPid:[[:space:]]*//p' "$PROC_ROOT/$p/status" 2>/dev/null || true)"
done
for d in "$PROC_ROOT"/[0-9]*; do for d in "$PROC_ROOT"/[0-9]*; do
pid="${d##*/}" pid="${d##*/}"
[ -r "$d/status" ] || continue [ -r "$d/status" ] || continue
@ -133,6 +170,10 @@ case "$cmd" in
for s in $sim; do [ "$c" = "$s" ] && hit="$hit$c,"; done for s in $sim; do [ "$c" = "$s" ] && hit="$hit$c,"; done
done done
if [ -n "$hit" ]; then if [ -n "$hit" ]; then
case "$self" in *" $pid "*)
log "note: ${pid} ($(cat "$d/comm" 2>/dev/null)) is this check's own process chain in ${cg:-?} and may run on sim cpu ${hit%,}; not counted"
continue ;;
esac
echo "process $pid ($(cat "$d/comm" 2>/dev/null)) in ${cg:-?} may run on sim cpu ${hit%,}" echo "process $pid ($(cat "$d/comm" 2>/dev/null)) in ${cg:-?} may run on sim cpu ${hit%,}"
bad=1 bad=1
fi fi
@ -141,7 +182,7 @@ case "$cmd" in
exit "$bad" exit "$bad"
;; ;;
*) *)
sed -n '2,12p' "$0" >&2 sed -n '2,11p' "$0" >&2
exit 2 exit 2
;; ;;
esac esac

View file

@ -862,7 +862,9 @@ the partition above is completed by making the sim's CPUs exclusive:
whose `AllowedCPUs=` is the sim's set (`flysim.slice.d/cpuset.conf`, written by `05-deploy.sh` from whose `AllowedCPUs=` is the sim's set (`flysim.slice.d/cpuset.conf`, written by `05-deploy.sh` from
`lib/common.sh`'s `cpuset_dropin_plan`, the same call that writes every other drop-in). `lib/common.sh`'s `cpuset_dropin_plan`, the same call that writes every other drop-in).
- `bin/fly-cpu-confine apply` sets `AllowedCPUs=` the **non-sim** CPUs on `system.slice` (every - `bin/fly-cpu-confine apply` sets `AllowedCPUs=` the **non-sim** CPUs on `system.slice` (every
other service, cron, apt, sshd), `user.slice` (every login session) and `init.scope`. It runs as other service, cron, apt, sshd), `user.slice` (every login session) and `init.scope`, and writes
the same list to `/sys/fs/cgroup/.lxc/cpuset.cpus` (where `pct exec` / `pct enter` processes land,
see below). It runs as
both sim units' `ExecStartPre` (root, failure never blocks the start), so it is re-applied after both sim units' `ExecStartPre` (root, failure never blocks the start), so it is re-applied after
every boot and every restart. The lists come from `/etc/fly/cpuset.env`, which the deploy writes. every boot and every restart. The lists come from `/etc/fly/cpuset.env`, which the deploy writes.
- The slice is named without a dash on purpose: systemd nests `a-b.slice` under `a.slice`, and a - The slice is named without a dash on purpose: systemd nests `a-b.slice` under `a.slice`, and a
@ -881,18 +883,38 @@ the partition above is completed by making the sim's CPUs exclusive:
is no confinement, so `05-deploy.sh` writes `FLY_SESSION_PIN=0` to `/etc/fly/fly.env` and the is no confinement, so `05-deploy.sh` writes `FLY_SESSION_PIN=0` to `/etc/fly/fly.env` and the
session runtime's threads float, as before PERF-02. With the partition in force it writes session runtime's threads float, as before PERF-02. With the partition in force it writes
`FLY_SESSION_PIN=1`. (The runtime treats exactly `0` as off.) `FLY_SESSION_PIN=1`. (The runtime treats exactly `0` as off.)
- **Not reachable from inside:** a process the host starts into the container with `pct exec` - **`pct exec` / `pct enter`:** `lxc-attach` puts its processes in the cgroup `/.lxc` (or
(`lxc-attach`) is not placed by systemd, so these two slices may not cover it (which cgroup it `/.lxc-N`), a sibling of `system.slice` that systemd does not manage. `apply` writes the non-sim
lands in has not been verified on the release container). `fly-cpu-confine check` lists every list into the `cpuset.cpus` of every such cgroup that already exists (it never creates one; lxc
process outside `flysim.slice` that may run on a sim CPU (exit 1 if there is one): run it after owns it). Where that file is not writable it logs a warning and carries on: `apply` never fails
a deploy and after anything unusual. Run long operator jobs through the sim's start. In that case run long operator jobs through
`pct exec <ctid> -- systemd-run --scope --slice=system.slice -- <command>`; the deploy itself `pct exec <ctid> -- systemd-run --scope --slice=system.slice -- <command>`. A `.lxc-N` created
already pins its heavy steps to the page CPUs. after `apply` is not covered until the next sim start. `fly-cpu-confine check` lists every
process outside `flysim.slice` that may run on a sim CPU (exit 1 if there is one); its own
process and the shell chain it was started from are printed as a note and not counted, so it
exits 0 on a healthy container when run through `pct exec`.
- **After the first deploy (once):** restart the sim so the confinement is applied, then read it.
`apply` is refused while flysim still runs outside `flysim.slice`, so nothing changes until then.
```
pct exec <ctid> -- systemctl restart flysim.service
pct exec <ctid> -- /opt/fly/bin/fly-cpu-confine status # system.slice, user.slice, init.scope and /.lxc = the non-sim cpus; flysim.slice = the sim's; flysim ControlGroup under /flysim.slice/
pct exec <ctid> -- /opt/fly/bin/fly-cpu-confine check # exit 0: "ok: only flysim.slice can reach ..."
pct exec <ctid> -- systemctl show -p AllowedCPUs flycast.service xvfb.service # still the drop-in values
```
Then watch the probation RTF. A `check` that names a process is a hog to move or stop.
- **If lag grows on the session runtime**: `fly-cpu-confine check`, then `top -H` for a stray hog on - **If lag grows on the session runtime**: `fly-cpu-confine check`, then `top -H` for a stray hog on
the sim's CPUs. `FLY_SESSION_PIN=0` (a drop-in) restores floating. the sim's CPUs. `FLY_SESSION_PIN=0` (a drop-in) restores floating.
- `fly-cpu-confine release` undoes the runtime confinement (until the next sim start); it sets - `fly-cpu-confine release` undoes the runtime confinement (until the next sim start); it sets
the three back to the container's whole cpuset explicitly, because systemd keeps the old mask for `system.slice`, `user.slice`, `init.scope` and `/.lxc` back to the container's whole cpuset
an empty `AllowedCPUs=` while the cpuset controller stays on for another unit. explicitly, because systemd keeps the old mask for an empty `AllowedCPUs=` while the cpuset
controller stays on for another unit. (Tested in `tests/lint.sh` against a fake cgroup tree.)
- **Rollback by re-running an older infra tree's `05-deploy.sh`** (rather than the symlink flip in
"Roll back a release", which is fine): an infra tree older than this change has no
`Slice=flysim.slice`, so flysim restarts into `system.slice`, which is still confined to the
non-sim CPUs. Its `AllowedCPUs=` then does not intersect that set and it floats over the page and
encoder CPUs while the sim's own CPUs sit idle (the slow shape again, not a black stream). After
such a rollback run `pct exec <ctid> -- /opt/fly/bin/fly-cpu-confine release` (or reboot), then
restart flysim.
Verified on a real-systemd box (4 CPUs, the sim as a unit in `flysim.slice` on 3 of them, 3 sweep Verified on a real-systemd box (4 CPUs, the sim as a unit in `flysim.slice` on 3 of them, 3 sweep
threads, paced at 0.55x): confined or not, with no hog the session holds 0.55; five busy loops (three threads, paced at 0.55x): confined or not, with no hog the session holds 0.55; five busy loops (three

View file

@ -1572,7 +1572,8 @@ grep -qE 'FLY_SESSION_PIN=0' "$INFRA_DIR/05-deploy.sh" && grep -qE 'PARTITION_AC
# bin/fly-cpu-confine against a stub systemctl and a fake /proc # bin/fly-cpu-confine against a stub systemctl and a fake /proc
cc="$INFRA_DIR/bin/fly-cpu-confine" cc="$INFRA_DIR/bin/fly-cpu-confine"
cc_dir="$(mktemp -d "${TMPDIR:-/tmp}/fly-lint-confine.XXXXXX")" cc_dir="$(mktemp -d "${TMPDIR:-/tmp}/fly-lint-confine.XXXXXX")"
mkdir -p "$cc_dir/bin" "$cc_dir/proc" mkdir -p "$cc_dir/bin" "$cc_dir/proc" "$cc_dir/cg/.lxc"
echo 0-15 > "$cc_dir/cg/.lxc/cpuset.cpus"
cat > "$cc_dir/bin/systemctl" <<'STUB' cat > "$cc_dir/bin/systemctl" <<'STUB'
#!/usr/bin/env bash #!/usr/bin/env bash
echo "systemctl $*" >> "$STUB_LOG" echo "systemctl $*" >> "$STUB_LOG"
@ -1591,7 +1592,7 @@ STUB
chmod +x "$cc_dir/bin/systemctl" "$cc_dir/bin/timeout" chmod +x "$cc_dir/bin/systemctl" "$cc_dir/bin/timeout"
printf 'FLY_SIM_CPUS=1,3,5,7\nFLY_OTHER_CPUS=9,11,13-15\n' > "$cc_dir/cpuset.env" printf 'FLY_SIM_CPUS=1,3,5,7\nFLY_OTHER_CPUS=9,11,13-15\n' > "$cc_dir/cpuset.env"
cc_run() { cc_run() {
PATH="$cc_dir/bin:$PATH" CPUSET_ENV="${CPUSET_ENV:-$cc_dir/cpuset.env}" PROC_ROOT="$cc_dir/proc" STUB_LOG="$cc_dir/log" "$@" PATH="$cc_dir/bin:$PATH" CPUSET_ENV="${CPUSET_ENV:-$cc_dir/cpuset.env}" PROC_ROOT="$cc_dir/proc" CGROUP_ROOT="${CGROUP_ROOT:-$cc_dir/cg}" STUB_LOG="$cc_dir/log" "$@"
} }
: > "$cc_dir/log" : > "$cc_dir/log"
out="$(cc_run "$cc" apply 2>&1)" && rc=0 || rc=$? out="$(cc_run "$cc" apply 2>&1)" && rc=0 || rc=$?
@ -1602,6 +1603,28 @@ if [ "$rc" -eq 0 ] && [ "$(grep -c 'set-property --runtime .* AllowedCPUs=9,11,1
else else
fail "fly-cpu-confine apply (rc=$rc): $out / $(cat "$cc_dir/log")" fail "fly-cpu-confine apply (rc=$rc): $out / $(cat "$cc_dir/log")"
fi fi
[ "$(cat "$cc_dir/cg/.lxc/cpuset.cpus")" = "9,11,13-15" ] \
&& pass "fly-cpu-confine apply also confines /.lxc (where pct exec lands) to the non-sim cpus" \
|| fail "fly-cpu-confine apply must write the non-sim cpus into /.lxc/cpuset.cpus (got $(cat "$cc_dir/cg/.lxc/cpuset.cpus"))"
out="$(cc_run "$cc" status 2>&1)"
grep -q '^/.lxc cpuset.cpus=9,11,13-15$' <<< "$out" \
&& pass "fly-cpu-confine status shows /.lxc" \
|| fail "fly-cpu-confine status must show /.lxc: $out"
# unwritable /.lxc: warn, still exit 0, slices still confined; absent /.lxc: nothing created
: > "$cc_dir/log"
mkdir -p "$cc_dir/cg2/.lxc"
mkdir "$cc_dir/cg2/.lxc/cpuset.cpus" # a directory: the write fails, like a read-only cgroup file
out="$(CGROUP_ROOT="$cc_dir/cg2" cc_run "$cc" apply 2>&1)" && rc=0 || rc=$?
if [ "$rc" -eq 0 ] && grep -q 'WARNING: cannot write' <<< "$out" && [ "$(grep -c set-property "$cc_dir/log")" = 3 ]; then
pass "fly-cpu-confine apply warns, never fails, when /.lxc cannot be written (slices still confined)"
else
fail "fly-cpu-confine apply with an unwritable /.lxc (rc=$rc): $out"
fi
mkdir -p "$cc_dir/cg3"
CGROUP_ROOT="$cc_dir/cg3" cc_run "$cc" apply >/dev/null 2>&1
[ -z "$(ls -A "$cc_dir/cg3")" ] \
&& pass "fly-cpu-confine apply does not create /.lxc (lxc owns it)" \
|| fail "fly-cpu-confine apply must not create cgroups under the root: $(ls -A "$cc_dir/cg3")"
: > "$cc_dir/log" : > "$cc_dir/log"
out="$(CG_flysim=/system.slice/flysim.service cc_run "$cc" apply 2>&1)" && rc=0 || rc=$? out="$(CG_flysim=/system.slice/flysim.service cc_run "$cc" apply 2>&1)" && rc=0 || rc=$?
if [ "$rc" -eq 3 ] && ! grep -q set-property "$cc_dir/log"; then if [ "$rc" -eq 3 ] && ! grep -q set-property "$cc_dir/log"; then
@ -1622,11 +1645,12 @@ else
fail "fly-cpu-confine apply without cpuset.env must change nothing (rc=$rc): $out $(cat "$cc_dir/log")" fail "fly-cpu-confine apply without cpuset.env must change nothing (rc=$rc): $out $(cat "$cc_dir/log")"
fi fi
: > "$cc_dir/log" : > "$cc_dir/log"
echo 0-15 > "$cc_dir/cpuset.cpus.effective" echo 0-15 > "$cc_dir/cg/cpuset.cpus.effective"
CGROUP_ROOT="$cc_dir" cc_run "$cc" release >/dev/null 2>&1 CGROUP_ROOT="$cc_dir/cg" cc_run "$cc" release >/dev/null 2>&1
[ "$(grep -c 'set-property --runtime .* AllowedCPUs=0-15$' "$cc_dir/log")" = 3 ] \ [ "$(grep -c 'set-property --runtime .* AllowedCPUs=0-15$' "$cc_dir/log")" = 3 ] \
&& pass "fly-cpu-confine release sets all three back to the container's whole cpuset (an empty AllowedCPUs= leaves the old mask in place)" \ && [ "$(cat "$cc_dir/cg/.lxc/cpuset.cpus")" = "0-15" ] \
|| fail "fly-cpu-confine release: $(cat "$cc_dir/log")" && pass "fly-cpu-confine release sets all three and /.lxc back to the container's whole cpuset (an empty AllowedCPUs= leaves the old mask in place)" \
|| fail "fly-cpu-confine release: $(cat "$cc_dir/log") / lxc=$(cat "$cc_dir/cg/.lxc/cpuset.cpus")"
# check: a fake /proc with a sim process in the slice, a clean neighbour, a kernel thread, then a hog # check: a fake /proc with a sim process in the slice, a clean neighbour, a kernel thread, then a hog
mkproc() { # pid comm cgroup allowed mkproc() { # pid comm cgroup allowed
mkdir -p "$cc_dir/proc/$1" mkdir -p "$cc_dir/proc/$1"
@ -1651,6 +1675,27 @@ if [ "$rc" -eq 1 ] && grep -q 'process 13 (hog).*sim cpu 1,3,5,7' <<< "$out"; th
else else
fail "fly-cpu-confine check must flag the hog (rc=$rc): $out" fail "fly-cpu-confine check must flag the hog (rc=$rc): $out"
fi fi
# the check's own process chain (a pct exec shell) is noted, not failed; a stranger in /.lxc still fails
rm -rf "$cc_dir/proc/13"
mkproc 20 pctexec /.lxc 0-15
mkproc 21 bash /.lxc 0-15
mkproc 22 fly-cpu-confine /.lxc 0-15
printf 'Name:\tx\nPPid:\t21\nCpus_allowed_list:\t0-15\n' > "$cc_dir/proc/22/status"
printf 'Name:\tx\nPPid:\t20\nCpus_allowed_list:\t0-15\n' > "$cc_dir/proc/21/status"
printf 'Name:\tx\nPPid:\t1\nCpus_allowed_list:\t0-15\n' > "$cc_dir/proc/20/status"
out="$(SELF_PID=22 cc_run "$cc" check 2>&1)" && rc=0 || rc=$?
if [ "$rc" -eq 0 ] && grep -q 'own process chain' <<< "$out" && ! grep -q '^process' <<< "$out"; then
pass "fly-cpu-confine check exits 0 when the only process on a sim cpu is its own pct exec chain"
else
fail "fly-cpu-confine check must not count its own process or ancestors (rc=$rc): $out"
fi
mkproc 23 tar /.lxc 0-15
out="$(SELF_PID=22 cc_run "$cc" check 2>&1)" && rc=0 || rc=$?
if [ "$rc" -eq 1 ] && grep -q '^process 23 (tar)' <<< "$out" && ! grep -q '^process 2[012] ' <<< "$out"; then
pass "fly-cpu-confine check still flags a different process in /.lxc"
else
fail "fly-cpu-confine check must flag a stranger in /.lxc (rc=$rc): $out"
fi
rm -rf "$cc_dir" rm -rf "$cc_dir"
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------