Files
JIANT/tests/cpu_vg.py
T
Claude caa8b2557b ctl64 (0.9.9): the control block 64 samples, notes at their sample inside the block
core.h CTL 32 -> 64 (tools/gen_tables.py; the half buffer 128 frames: two mix_block passes a half, not
four), so the fixed cost of a block (events_block, mc_split, the core-1 handshake, buffers cleared and
summed, sends, buses, master) is paid half as often. Everything that counted blocks of 32 counts in CTL:
envelope / LFO tables, glides, fades, the steal fade, the leveler's (its peak still read over 32) and
DUCK's followers, DRUM-X FLAM / PUNCH / pan slew / group fade, the FX gate, DJF crossfade, SPRING / RESO
glides, WORDS' phoneme timing, the FX layer's LPF / HPF sweep (perform.c PF_CSTEP), the mod matrix's
NOISE and STEP eases.

The sequencer did not get coarser: a note inside the block carries its sample (core.h ev_off; voice.c
voice_begin / voice_off_at / track_render render the sounding voice up to it and the new one from it;
every engine but FM6, which renders whole blocks and keeps the nearer edge). tests/ctl64_timing_test.c:
on a MICRO-shifted pattern every rendered onset is within 2 samples of the sample-at-a-time sequencer
(ANALOG POLY worst 2, ANALOG MONO cuts worst 2, DRUM kit hits worst 1); the 32-sample build placed them
-22 .. +5 samples off.

Host CPU (tests/cpu_vg.py, exact instructions / sample, 32 -> 64): mix/idle 516 -> 426 (-17.5 %),
seq/mono4 1514 -> 1188 (-21.5 %), eng/DRUM 1477 -> 1156 (-21.7 %), eng/FM6 1710 -> 1507 (-11.9 %),
eng/VOICE 1500 -> 1337 (-10.9 %), VOICE.EN 1783 -> 1619 (-9.2 %), ANALOG / PHASE / LOFI / NOISE / WHEEL
-6 .. -9 %, reverbs and delays -7 .. -8 %, mix/full 2671 -> 2505 (-6.2 %), seq/plain 2381 -> 2158
(-9.4 %), seq/heavy 2783 -> 2485 (-10.7 %), song/cputest 3016 -> 2742 (-9.1 %), peak/VOICE.EN6
3304 -> 2937 (-11.1 %). Firmware: image 567896 B, .data+.bss 88276 of 98304 (+9 KB: the CTL-long
buffers), RAM code 21848 of 24576; the render loops' target cost as before (tests/target_budget.txt).
docs/CPU3_PERFORMANCE.md, README (the dual-core section), CPU5_PERFORMANCE.md.

Goldens: tests/golden.txt, cpu_baseline_vg.txt, target_budget.txt regenerated (GOLDEN_UPDATE /
BUDGET_UPDATE: the sound changes through the buses' one-block lag, now 1.45 ms, and the leveler's
reading); djf_test / micro_test reference hashes of the 0.9.0 renders redone at CTL 64. Host tests that
counted blocks count in CTL (reverb DUCK 3 / 20 ms, voice glide 163 blocks of 32 and 1/8 st a block,
click_test, drumx_oct_test); drumx_test's HANDS and PUNCH checks reset the kit's noise generator before
each compared strike (they compared different noise realizations: up to x5 strike to strike on the
32-sample build too, measured). Full host suite: every section passes but gen_nav_map's stale
docs/navigation-map.svg, which the base reports as well.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KMHk6yH4XbP1xxHYKCo9Mh
2026-10-23 17:07:04 +00:00

75 lines
3.5 KiB
Python

#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-only
"""(JIANT 0.6.83) the audio path's CPU under valgrind (tests/cpu_vg.c): instructions per sample, section by section,
against tests/cpu_baseline_vg.txt (peak/*: instructions in the worst single block of the section's rounds). callgrind's
counts are exact (the same on every run of the same build), so the
tolerance is small: a section more than TOL over its baseline fails; one far under only notes it.
python3 tests/cpu_vg.py BINARY [BASELINE] (run_tests.sh, when valgrind is there)
BUDGET_UPDATE=1 rewrites the baseline (on purpose: look at the diff)."""
import glob, os, re, subprocess, sys, tempfile
TOL = 0.08 # +8 %: a real change, never noise
def ctl(): # (0.9.9 ctl64) CTL from the generated tables (64; 32 before)
try:
return int(re.search(r"^#define CTL (\d+)", open("build/gen/felucca_tables.h").read(), re.M).group(1))
except (OSError, AttributeError):
return 64
SAMPLES = 256 * ctl() # cpu_vg.c NB blocks of CTL samples
binary = sys.argv[1]
base_path = sys.argv[2] if len(sys.argv) > 2 else "tests/cpu_baseline_vg.txt"
out = tempfile.mkdtemp(prefix="cpu_vg_")
prefix = os.path.join(out, "cg.out")
r = subprocess.run(["valgrind", "--tool=callgrind", "--collect-atstart=yes", "--instr-atstart=no",
f"--callgrind-out-file={prefix}", binary], stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, text=True)
if r.returncode:
print("cpu_vg: the run failed\n" + r.stderr[-2000:])
sys.exit(1)
now = {}
for f in glob.glob(prefix + "*"):
txt = open(f, errors="replace").read()
m = re.search(r"^desc: Trigger: Client Request: (\S+)", txt, re.M)
t = re.search(r"^(?:totals|summary): (\d+)", txt, re.M)
if m and t and m.group(1).startswith("peak/"): # (0.9.0) one block each: the worst of its rounds (.rNN)
k = re.sub(r"\.r\d+$", "", m.group(1))
now[k] = max(now.get(k, 0), int(t.group(1)))
elif m and t:
now[m.group(1)] = int(t.group(1)) / SAMPLES
if not now:
print("cpu_vg: no sections measured")
sys.exit(1)
base = {}
if os.path.exists(base_path):
for line in open(base_path):
p = line.split()
if len(p) == 2 and not line.startswith("#"):
base[p[0]] = float(p[1])
if os.environ.get("BUDGET_UPDATE"):
with open(base_path, "w") as fo:
fo.write("# JIANT audio path CPU under valgrind (tests/cpu_vg.c, tests/cpu_vg.py): instructions per sample,\n"
"# x86-64 gcc -O2. Exact counts; the check allows +8 %. Rewritten by BUDGET_UPDATE=1.\n")
for k in sorted(now):
fo.write(f"{k} {now[k]:.0f}\n")
print(f"cpu_vg: {len(now)} sections written to {base_path}")
sys.exit(0)
bad = 0
for k in sorted(now):
b = base.get(k)
if b is None:
print(f"cpu_vg: {k:12s} {now[k]:8.0f} instructions / sample no baseline (BUDGET_UPDATE=1 adds it)")
continue
d = now[k] / b - 1
state = "ok"
if d > TOL:
state = f"OVER BUDGET (+{d * 100:.1f} %, limit +{TOL * 100:.0f} %)"
bad += 1
elif d < -0.25:
state = f"ok, {-d * 100:.0f} % under (BUDGET_UPDATE=1 to keep it)"
unit = "instructions, the worst block" if k.startswith("peak/") else "instructions / sample"
print(f"cpu_vg: {k:12s} {now[k]:8.0f} {unit} (baseline {b:.0f}, {d * 100:+.1f} %) {state}")
print("cpu_vg: " + ("FAILED" if bad else "all within budget"))
sys.exit(1 if bad else 0)