spike: pin cores, per-overrun wall timestamps, noop control; max block time marked unexplained
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
489405a377
commit
e4c6b2d3b3
3 changed files with 64 additions and 14 deletions
|
|
@ -12,15 +12,38 @@ Limitation: AOT fixes the patch set at build time, so player-authored patches ca
|
|||
`aqs_thruster_process` rejects NULL, negative or >`AQS_MAX_BLOCK` frames instead of truncating.
|
||||
- `test_thruster.c`: plain-C behaviour test (bounds, clamp, NaN, inf, hostile values give finite bounded
|
||||
output, rpm actually changes the output, instances are deterministic). A flipped clamp bound fails it.
|
||||
- `bench_thruster.c`: per-block `process` time at 48 kHz / 512 frames against the 10.667 ms deadline.
|
||||
- `bench_thruster.c`: per-block `process` time at 48 kHz / 512 frames against the 10.667 ms deadline; prints one `OVERRUN` line
|
||||
per block over the deadline with wall-clock timestamp, wall ms and thread CPU ms.
|
||||
- `run.sh`: generate, build, test, bench. `FAUST`, `FAUST_PREFIX` (needs `include/faust`), `FAUST_LIBS`
|
||||
(needs `stdfaust.lib`), `BLOCKS`, `RATE`, `FRAMES` override defaults. Exit status is test status; timing
|
||||
(needs `stdfaust.lib`), `BLOCKS`, `RATE`, `FRAMES`, `CORE` (pin the bench to one cpu via `taskset`), `NOOP=1` (time a busy-wait
|
||||
instead of the patch) override defaults. Exit status is test status; timing
|
||||
is reported, not gated.
|
||||
|
||||
Measured 2026-11-06, Faust 2.90.20, AMD EPYC-Genoa, shared Linux host, 20000 blocks, 3 runs:
|
||||
median 0.052 ms (0.49% of deadline), p99 0.10-0.16 ms (~1-1.5%), max 10.8-17.1 ms (4-5 blocks of 20000 over
|
||||
the deadline). The max is a scheduler preemption on a shared host, not DSP cost (median and p99 are
|
||||
two orders under the deadline); a quiet or realtime-priority host is needed to say anything about the max.
|
||||
**Scope: this measures a bare C loop.** `bench_thruster` calls `aqs_thruster_process` back to back on one
|
||||
Linux thread. It shows the patch is cheap, not that a Unity player meets its deadline (no Unity audio
|
||||
thread, P/Invoke, IL2CPP, mixer or Windows scheduling in it).
|
||||
|
||||
Measured 2026-11-06/07, Faust 2.90.20, AMD EPYC-Genoa, shared Linux host (load average ~8 on 16 cores):
|
||||
median 0.052 ms (0.49% of the 10.667 ms deadline), p99 0.08-0.16 ms (~1-1.5%). Cheap: that part is
|
||||
reliable.
|
||||
|
||||
**Max block time: UNEXPLAINED. It is not a pass.** Max was 10.8-17.1 ms, with 1-5 of 20000 blocks over
|
||||
the deadline per run (70-74 of 400000). What the instrumented runs (`run.sh`, `CORE=<cpu>` pins with
|
||||
`taskset`; every overrun prints a `wall_unix` timestamp, wall ms and thread CPU ms) do show:
|
||||
|
||||
- Not per-block DSP cost: `NOOP=1` times a 0.05 ms busy-wait instead of `process`, and stalls the same
|
||||
way (core 3, 400000 blocks: 74 overruns with `process`, 67 with the busy-wait, both ~11 ms).
|
||||
- Not a DSP-state pattern: overrun block indices differ every run and are not tied to the rpm sweep.
|
||||
- Periodic in wall time, per core: pinned to core 3, overruns recur every ~0.3-0.4 s (mostly); pinned
|
||||
to core 9, every ~1-2 s (17 in 400000 blocks). Unpinned runs get 1-5 per 20000.
|
||||
- The thread's CPU time over a stalled block is about equal to its wall time (e.g. 10.84 vs 10.85 ms),
|
||||
so the stall is charged to the thread rather than showing as time off-CPU. Ordinary run-queue
|
||||
preemption would not look like that. The earlier claim that these were scheduler preemption is
|
||||
withdrawn.
|
||||
|
||||
Cause not identified (candidates: hypervisor/container CPU accounting, per-core host timer or housekeeping
|
||||
work, SMI; none tested). Whether the player would see it is unknown. A quiet, realtime-priority or
|
||||
isolated-core host is needed before the max can be called anything.
|
||||
|
||||
**Unverified:** Windows (MSVC build, `__declspec(dllexport)`), Unity P/Invoke, IL2CPP, the Unity audio
|
||||
thread, any device. Nothing here ran inside Unity.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
/* Per-block callback time vs deadline. usage: bench_thruster [blocks] [rate] [frames] */
|
||||
/* Per-block callback time vs deadline. usage: bench_thruster [blocks] [rate] [frames] [noop]
|
||||
noop: time a 0.05 ms busy-wait instead of process(), to tell host stalls from DSP cost */
|
||||
#define _GNU_SOURCE
|
||||
#include <sched.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
|
@ -10,29 +13,47 @@ int main(int argc, char** argv) {
|
|||
int blocks = argc > 1 ? atoi(argv[1]) : 20000;
|
||||
int rate = argc > 2 ? atoi(argv[2]) : 48000;
|
||||
int frames = argc > 3 ? atoi(argv[3]) : 512;
|
||||
int noop = argc > 4;
|
||||
aqs_thruster* t = aqs_thruster_create(rate);
|
||||
if (!t || blocks < 100) return 2;
|
||||
float* out = malloc(sizeof(float) * frames);
|
||||
double* ms = malloc(sizeof(double) * blocks);
|
||||
double* cpu = malloc(sizeof(double) * blocks); /* thread CPU time per block: wall >> cpu means preempted, not DSP */
|
||||
double* wall = malloc(sizeof(double) * blocks); /* CLOCK_REALTIME at block end, seconds, for lining up with host load */
|
||||
const int warm = 200;
|
||||
for (int i = 0; i < warm + blocks; ++i) {
|
||||
/* sweep rpm across its whole range so the smoother and filters keep moving */
|
||||
aqs_thruster_set_rpm(t, 300.f + 5700.f * (0.5f + 0.5f * (float)((i % 997) - 498) / 498.f));
|
||||
struct timespec a, b;
|
||||
struct timespec a, b, ca, cb, w;
|
||||
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ca);
|
||||
clock_gettime(CLOCK_MONOTONIC, &a);
|
||||
aqs_thruster_process(t, out, frames);
|
||||
if (noop) { struct timespec s; do clock_gettime(CLOCK_MONOTONIC, &s); while ((s.tv_sec - a.tv_sec) * 1e9 + (s.tv_nsec - a.tv_nsec) < 5e4); }
|
||||
else aqs_thruster_process(t, out, frames);
|
||||
clock_gettime(CLOCK_MONOTONIC, &b);
|
||||
if (i >= warm) ms[i - warm] = (b.tv_sec - a.tv_sec) * 1e3 + (b.tv_nsec - a.tv_nsec) / 1e6;
|
||||
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &cb);
|
||||
clock_gettime(CLOCK_REALTIME, &w);
|
||||
if (i >= warm) {
|
||||
ms[i - warm] = (b.tv_sec - a.tv_sec) * 1e3 + (b.tv_nsec - a.tv_nsec) / 1e6;
|
||||
cpu[i - warm] = (cb.tv_sec - ca.tv_sec) * 1e3 + (cb.tv_nsec - ca.tv_nsec) / 1e6;
|
||||
wall[i - warm] = w.tv_sec + w.tv_nsec / 1e9;
|
||||
}
|
||||
}
|
||||
double deadline = 1e3 * frames / rate, sum = 0;
|
||||
int over = 0;
|
||||
for (int i = 0; i < blocks; ++i) { sum += ms[i]; if (ms[i] > deadline) ++over; }
|
||||
printf("start_cpu=%d\n", sched_getcpu());
|
||||
for (int i = 0; i < blocks; ++i) {
|
||||
sum += ms[i];
|
||||
if (ms[i] > deadline) {
|
||||
++over;
|
||||
printf("OVERRUN block=%d wall_unix=%.6f wall_ms=%.4f thread_cpu_ms=%.4f\n", i, wall[i], ms[i], cpu[i]);
|
||||
}
|
||||
}
|
||||
qsort(ms, blocks, sizeof *ms, cmp);
|
||||
double med = ms[blocks / 2], p99 = ms[(int)(blocks * 0.99)], mx = ms[blocks - 1];
|
||||
printf("rate=%d frames=%d blocks=%d deadline_ms=%.4f\n", rate, frames, blocks, deadline);
|
||||
printf("median_ms=%.4f p99_ms=%.4f max_ms=%.4f mean_ms=%.4f\n", med, p99, mx, sum / blocks);
|
||||
printf("median_pct_deadline=%.2f p99_pct_deadline=%.2f max_pct_deadline=%.2f over_deadline=%d\n",
|
||||
100 * med / deadline, 100 * p99 / deadline, 100 * mx / deadline, over);
|
||||
free(out); free(ms); aqs_thruster_destroy(t);
|
||||
free(out); free(ms); free(cpu); free(wall); aqs_thruster_destroy(t);
|
||||
return 0; /* timing is reported, not gated: a shared host preempts */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
# Build the AOT thruster spike, run the boundary test, then the per-block timing report.
|
||||
# Linux only. usage: run.sh [--bench-only] ; env: FAUST (faust CLI), FAUST_PREFIX (has include/faust),
|
||||
# FAUST_LIBS (dir with stdfaust.lib), OUT (build dir), BLOCKS, RATE, FRAMES.
|
||||
# FAUST_LIBS (dir with stdfaust.lib), CORE (cpu to pin the bench to via taskset; default: unpinned), OUT (build dir), BLOCKS, RATE, FRAMES.
|
||||
set -euo pipefail
|
||||
here=$(cd "$(dirname "$0")" && pwd)
|
||||
FAUST=${FAUST:-faust}
|
||||
|
|
@ -18,4 +18,10 @@ gcc -O2 -I"$here" -o "$OUT/test_thruster" "$here/test_thruster.c" -L"$OUT" -laqs
|
|||
gcc -O2 -I"$here" -o "$OUT/bench_thruster" "$here/bench_thruster.c" -L"$OUT" -laqs_thruster -lm -Wl,-rpath,"$OUT"
|
||||
"$OUT/test_thruster"
|
||||
echo "--- timing (Linux $(uname -r), $(grep -m1 'model name' /proc/cpuinfo | cut -d: -f2 | xargs)); Windows/Unity: unverified"
|
||||
"$OUT/bench_thruster" "${BLOCKS:-20000}" "${RATE:-48000}" "${FRAMES:-512}"
|
||||
PIN=()
|
||||
if [ -n "${CORE:-}" ]; then
|
||||
command -v taskset >/dev/null && PIN=(taskset -c "$CORE") || echo "CORE set but taskset missing: running unpinned" >&2
|
||||
fi
|
||||
echo "bench start $(date -u +%FT%T.%NZ) pin=${PIN[*]:-none} loadavg_before=$(cut -d' ' -f1-3 /proc/loadavg)"
|
||||
"${PIN[@]}" "$OUT/bench_thruster" "${BLOCKS:-20000}" "${RATE:-48000}" "${FRAMES:-512}" ${NOOP:+noop}
|
||||
echo "bench end $(date -u +%FT%T.%NZ) loadavg_after=$(cut -d' ' -f1-3 /proc/loadavg)"
|
||||
|
|
|
|||
Loading…
Reference in a new issue