interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / ng / bench / slice / idleround.sh.txt

63 lines · 3940 bytes Raw Blame History
1#!/bin/bash
2# ng-bench idle-gated round driver (scratch; copied into evidence as idleround.sh.txt).
3# idleround.sh CORE LOCK LO HI OUTDIR TAG FIXDIR BLOCKS WARM "ARMS" "CASES"
4# Waits until the machine is idle (PREREG-slice.md: no spark-window window held or waiting, no process whose comm
5# starts with ollm), takes LOCK, re-checks, runs ngbench v3 pinned to CORE, records, releases. Never stops others.
6set -u
7core=$1; lock=$2; lo=$3; hi=$4; E=$5; tag=$6; fix=$7; blocks=$8; warm=$9; arms=${10}; cases=${11}
8NB=/tmp/ngb/sl/ngbench3.run
9board() { flock ~/handoffs/BOARD.md.lock -c "echo \"$(date -u +%FT%TZ) ng-bench -> omp-queen-ng: $1\" >> ~/handoffs/BOARD.md"; }
10idlecheck() { # writes the evidence of one check to $1; exit 0 when idle
11 local f=$1 sw swrc fmt nwin nwait nollm
12 sw=$(spark-window status 2>&1); swrc=$?
13 # fail closed: the status command must succeed and print its known section headers, else not idle
14 fmt=0
15 printf '%s\n' "$sw" | grep -q '^quiet lock holders:' && printf '%s\n' "$sw" | grep -q '^gb10 lock holders:' &&
16 printf '%s\n' "$sw" | grep -q '^waiting line (--wait):' && fmt=1
17 nwin=$(printf '%s\n' "$sw" | grep -c '^window ')
18 nwait=$(printf '%s\n' "$sw" | awk '/^waiting line/ {w=1; next} w && NF {n++} END {print n+0}')
19 nollm=0; : > $f.ollm
20 for p in /proc/[0-9]*; do c=$(cat $p/comm 2>/dev/null) || continue; case $c in ollm*) nollm=$((nollm+1)); echo "${p#/proc/} $c" >> $f.ollm;; esac; done
21 { date -u +%FT%TZ; echo "status_rc=$swrc status_format_ok=$fmt windows=$nwin waiting=$nwait ollm=$nollm"; echo "--- spark-window status"; printf '%s\n' "$sw";
22 echo "--- ollm processes"; cat $f.ollm; echo "--- nvidia-smi compute apps";
23 nvidia-smi --query-compute-apps=pid,process_name,used_memory --format=csv 2>&1; } > $f
24 rm -f $f.ollm
25 [ $swrc -eq 0 ] && [ $fmt -eq 1 ] && [ $nwin -eq 0 ] && [ $nwait -eq 0 ] && [ $nollm -eq 0 ]
26}
27mkdir -p $E
28date -u +%FT%TZ > $E/lock-request.txt
29said=0
30# optional hold (queen order): when HOLD_PAT is set, this lock is not requested until a BOARD line after line
31# HOLD_LINE matches HOLD_PAT (e.g. the owner's END line of a measurement on these cores); the match is recorded.
32holdok() {
33 [ -z "${HOLD_PAT:-}" ] && return 0
34 tail -n +$((HOLD_LINE + 1)) ~/handoffs/BOARD.md | grep -E "$HOLD_PAT" | grep -viE "${HOLD_NOT:-^$}" | head -1 > $E/hold-release.txt
35 [ -s $E/hold-release.txt ] && return 0
36 rm -f $E/hold-release.txt; return 1
37}
38while true; do
39 if holdok && idlecheck $E/idle-poll.txt; then
40 exec 9> $lock
41 flock -x -w 3600 9 || { exec 9>&-; continue; }
42 if holdok && idlecheck $E/idle-start.txt; then break; fi
43 flock -u 9; exec 9>&-
44 fi
45 if [ $said -eq 0 ]; then
46 if holdok; then why=$(sed -n 2p $E/idle-poll.txt); else why="queen hold on $(basename $lock) until a BOARD line matching '$HOLD_PAT'"; fi
47 board "WAITING before $tag on core $core (PREREG-slice.md idle condition): $why. Checks every 60 s; stops nobody."; said=1
48 fi
49 sleep 60
50done
51rm -f $E/idle-poll.txt
52board "LOCK HELD $(basename $lock) core $core: $tag (ngbench v3, $blocks+$warm blocks), machine idle at start."
53date -u +%FT%TZ > $E/start.txt; cat /proc/loadavg >> $E/start.txt
54ps -eo pid,psr,pcpu,stat,comm | awk -v lo=$lo -v hi=$hi 'NR==1 || ($2>=lo && $2<=hi)' > $E/cluster-start.txt
55cat /sys/devices/system/cpu/cpu$core/regs/identification/midr_el1 > $E/midr.txt 2>&1
56sha256sum $NB > $E/ngbench.sha256
57cd $fix && taskset -c $core nice -n 10 $NB run $blocks $warm $fix $arms -- $cases > $E/rows.txt 2> $E/stderr.txt
58echo $? > $E/rc.txt
59date -u +%FT%TZ > $E/end.txt; cat /proc/loadavg >> $E/end.txt
60ps -eo pid,psr,pcpu,stat,comm | awk -v lo=$lo -v hi=$hi 'NR==1 || ($2>=lo && $2<=hi)' > $E/cluster-end.txt
61idlecheck $E/idle-end.txt; echo "idle_at_end=$?" >> $E/idle-end.txt
62flock -u 9; exec 9>&-
63board "RELEASED $(basename $lock) core $core: $tag done, rc=$(cat $E/rc.txt), $(grep '^S ' $E/rows.txt), busy blocks $(grep -c 'busy=1' $E/rows.txt)."