From 8a49638387b95c50ed6f5d9746d6461a6992c00a Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Mon, 5 Oct 2026 08:37:45 -0500 Subject: [PATCH] r15_machine_state: perf's workload ends on stop, no 24 h sleep left holding the quiet flag `start` ran `sudo perf stat ... -- sleep 86400`; `stop` pkilled perf but not its workload, so a root `sleep 86400` (reparented to init) outlived every R15 run. Under quietlock the hold stays until every process of the job's group exits, so the 2026-10-05 window-2 hold (q1883332) would have stayed for 24 h; it was released at 13:35:36Z only after the leftover was killed by hand. The workload is now a 1 s loop that exits when `stop` creates $OUT/.perf.stop (cap 86400 iterations, same 24 h bound); `stop` waits up to 5 s for perf to exit and flush its last interval, then keeps the old pkill as the fallback. Tested on this host with real sudo perf: new start/stop -> 0 leftover processes, machine-perf.csv 148 cycles lines in 4 s; origin/main start/stop -> leftover `sleep 86400` (red; cleaned up). Co-Authored-By: Claude Opus 5.5 --- .crumb | 16 ++++++++-------- tools/.crumb | 8 ++++---- tools/r15_machine_state.sh | 14 +++++++++++++- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/.crumb b/.crumb index f9e1daba6..5af781ace 100644 --- a/.crumb +++ b/.crumb @@ -52,7 +52,7 @@ }, { "digest": "b2164e33bc82e720bdaf1d26820682308a051aa6a108457b6d2a367529b26093", - "last_commit": "10ca03b", + "last_commit": "e9c2829", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, @@ -99,21 +99,21 @@ "purpose": "Directory tests. Purpose not yet described by a human." }, { - "digest": "084aca8aaf5c386b4459e9aeeff2ddbe68169bb94c7c86e2bf1037dd1763e23c", - "last_commit": "3822a0d", + "digest": "59136def1fad3d627f93534c3e5e4a8d93a57c12f10fab5dce0221c6e6c3590b", + "last_commit": "183fdc0", "name": "tools", "purpose": "Directory tools. Purpose not yet described by a human." } ], - "children_root": "sha256:64864796730a7776ec560f96b28a8bc47b4e77f80f95c18ab99c18ccf2edf3c1", - "compiled_at": "2026-10-05T13:47:02Z", + "children_root": "sha256:abd08092105a0d71476434df3aa2109fd32fea34bb8f3e674ff51e07564d49ff", + "compiled_at": "2026-10-05T13:50:43Z", "compiler": "crumb-compile/1", - "digest": "sha256:9f32af6bb1759f3006ebaf078e91950114e721b66c74685f37970cfb97a46136", + "digest": "sha256:1f0282e1e65ce52181f7e1514dcde811f6d8cd4d2115bf06e5f1570a8232006c", "evidence_files": 2184, "evidence_root": "sha256:6cbb4ec5b368be70f37cda92e0577f6a996f9c52042838375735c10268963c12", "files": 3965, - "generated_at_commit": "10ca03b5c0595dbebdade269fe828318c2d6f1b0", - "source_tree": "sha256:5f0fbd19e7447a52b63437bc8e887b8eda2fa7224884d7afc1b2e069a7c2e43d" + "generated_at_commit": "183fdc04306bae459caf82c7370cec0fe96c8887", + "source_tree": "sha256:9778f1a19cb8aa3b8ea522b0afd1745e535eff6a1d1ec4af144b493e3e6f255a" }, "owner_lane": "", "provenance": { diff --git a/tools/.crumb b/tools/.crumb index 92ca7df25..0d7b76dfd 100644 --- a/tools/.crumb +++ b/tools/.crumb @@ -56,14 +56,14 @@ } ], "children_root": "sha256:6ed09e33b610372de30ea2d6372b94240127e9acb4d178879cbd5448faab6909", - "compiled_at": "2026-10-05T13:05:21Z", + "compiled_at": "2026-10-05T13:50:43Z", "compiler": "crumb-compile/1", - "digest": "sha256:084aca8aaf5c386b4459e9aeeff2ddbe68169bb94c7c86e2bf1037dd1763e23c", + "digest": "sha256:59136def1fad3d627f93534c3e5e4a8d93a57c12f10fab5dce0221c6e6c3590b", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 127, - "generated_at_commit": "9974ecc3b5c7afac1e4b92d3e686a75230736829", - "source_tree": "sha256:b8692b3c809b29c989fad0f1e8417e2c730b72224b40d9b7cd9eccad69814502" + "generated_at_commit": "183fdc04306bae459caf82c7370cec0fe96c8887", + "source_tree": "sha256:ae4426759c2f3df989c5627665fcdb3461bf45dab9efbf38dfe87c808f340b89" }, "owner_lane": "", "provenance": { diff --git a/tools/r15_machine_state.sh b/tools/r15_machine_state.sh index 7ae308c03..b940cae60 100755 --- a/tools/r15_machine_state.sh +++ b/tools/r15_machine_state.sh @@ -71,7 +71,13 @@ start) for c in /sys/devices/system/cpu/cpu[0-9]*; do echo "${c##*/} $(cat "$c/cpufreq/scaling_governor" 2>/dev/null) max=$(cat "$c/cpufreq/cpuinfo_max_freq" 2>/dev/null)" done >> "$OUT/machine-state-start.txt" - sudo -n perf stat -a -A -e cycles -I 1000 -x, -o "$OUT/machine-perf.csv" -- sleep 86400 >/dev/null 2>&1 & + # perf's workload ends by itself when stop drops .perf.stop (cap 24 h). A + # bare `sleep 86400` outlived pkill of perf (root, reparented to init) and + # kept the caller's quietlock hold alive for a day (2026-10-05 13:35Z). + rm -f "$OUT/.perf.stop" + sudo -n perf stat -a -A -e cycles -I 1000 -x, -o "$OUT/machine-perf.csv" -- \ + sh -c 'i=0; while [ ! -e "$1/.perf.stop" ] && [ $i -lt 86400 ]; do sleep 1; i=$((i + 1)); done' \ + r15-sampler "$OUT" >/dev/null 2>&1 & echo $! > "$OUT/.perf.pid" ( n=0 @@ -96,6 +102,12 @@ mark) echo "$(date +%s.%N) ${3:-}" >> "$OUT/machine-state-marks.txt" ;; stop) + # Let perf's workload end on its own so perf exits and flushes its last + # interval; the pkill below is only the fallback. + touch "$OUT/.perf.stop" + if [ -f "$OUT/.perf.pid" ]; then + w=0; while [ -d "/proc/$(cat "$OUT/.perf.pid")" ] && [ $w -lt 5 ]; do sleep 1; w=$((w + 1)); done + fi for p in .sampler.pid .perf.pid; do [ -f "$OUT/$p" ] || continue pid=$(cat "$OUT/$p")