Commit bc859a23 by PLN (Algolia)

autoroute: only issue pw-link for links that are missing

The loop re-issued all 24 orbit links every 2 s and every pw-link connects to
the PipeWire daemon: 12 min of CPU in 85 min, about 15% of a core at idle.
Index the existing links from the one snapshot in pure bash and link only the
absent pairs.
parent e566bbd6
...@@ -128,3 +128,27 @@ def test_the_midi_through_playback_side_is_never_taken_for_the_source(tmp_path): ...@@ -128,3 +128,27 @@ def test_the_midi_through_playback_side_is_never_taken_for_the_source(tmp_path):
lo = "Midi-Bridge:Midi Through:(playback_0) Midi Through Port-0\n" + MASTER_ON_SPEAKER lo = "Midi-Bridge:Midi Through:(playback_0) Midi Through Port-0\n" + MASTER_ON_SPEAKER
calls, _ = _reconcile(tmp_path, lo) calls, _ = _reconcile(tmp_path, lo)
assert not [c for c in calls if "MIDI Control In" in c] assert not [c for c in calls if "MIDI Control In" in c]
ORBIT_1_LINKED = ("SuperCollider:out_1\n |-> ardour:Tidal 01/audio_in 1\n"
"SuperCollider:out_2\n |-> ardour:Tidal 01/audio_in 2\n")
def test_orbit_links_that_exist_cost_no_pw_link_call(tmp_path):
"""The loop re-issued every orbit link each 2 s; each pw-link call connects to
the PipeWire daemon, which alone was ~15% of a core at idle."""
calls, _ = _reconcile(tmp_path, CTRL_LINKED + MASTER_ON_SPEAKER + ORBIT_1_LINKED)
assert calls == []
def test_a_missing_orbit_link_is_still_made(tmp_path):
only_first = "SuperCollider:out_1\n |-> ardour:Tidal 01/audio_in 1\n"
calls, _ = _reconcile(tmp_path, CTRL_LINKED + MASTER_ON_SPEAKER + only_first)
assert calls == ["SuperCollider:out_2 ardour:Tidal 01/audio_in 2"]
def test_a_link_to_the_wrong_track_does_not_count(tmp_path):
"""Presence is per (source, destination) pair, never per source."""
wrong = "SuperCollider:out_1\n |-> ardour:Tidal 02/audio_in 1\n"
calls, _ = _reconcile(tmp_path, CTRL_LINKED + MASTER_ON_SPEAKER + wrong)
assert "SuperCollider:out_1 ardour:Tidal 01/audio_in 1" in calls
...@@ -34,11 +34,36 @@ link() { # $1 = source port, $2 = dest port ; silent (already-linked is fine) ...@@ -34,11 +34,36 @@ link() { # $1 = source port, $2 = dest port ; silent (already-linked is fine)
pw-link "$1" "$2" 2>/dev/null pw-link "$1" "$2" 2>/dev/null
} }
# Print the set of Ardour "Tidal NN" track numbers currently present. # Print the set of Ardour "Tidal NN" track numbers present in a `pw-link -i`
# snapshot (stdin). Pure bash: this runs every tick.
tidal_track_numbers() { tidal_track_numbers() {
pw-link -i 2>/dev/null \ local line
| grep -oE "ardour:Tidal [0-9]+/audio_in 1" \ local re='^ardour:Tidal ([0-9]+)/audio_in 1$'
| grep -oE "[0-9]+" | sort -un while IFS= read -r line; do
[[ "$line" =~ $re ]] && echo "${BASH_REMATCH[1]}"
done | sort -un
}
# HAVE["src>dst"]=1 for every link in a `pw-link -lo` snapshot (stdin), so a
# link that already exists costs no pw-link call. The loop used to re-issue all
# 24 orbit links every 2 s; every pw-link connects to the PipeWire daemon, and
# that alone was ~15% of a core at idle (measured 2026-10-11: 12 min of CPU in
# 85 min). Pure bash, no forks.
declare -A HAVE=()
index_links() {
local line src=""
HAVE=()
while IFS= read -r line; do
if [[ "$line" =~ ^[^[:space:]] ]]; then
src="$line"
elif [[ "$line" == *"|-> "* ]]; then
HAVE["$src>${line#*|-> }"]=1
fi
done
}
link_missing() { # $1 = source port, $2 = dest port; a no-op when already linked
[[ -n "${HAVE["$1>$2"]:-}" ]] || link "$1" "$2"
} }
# Print "src<TAB>dest" for every SuperCollider:out_* -> hardware playback link. # Print "src<TAB>dest" for every SuperCollider:out_* -> hardware playback link.
...@@ -96,8 +121,10 @@ relink_master() { ...@@ -96,8 +121,10 @@ relink_master() {
} }
reconcile() { reconcile() {
local lo src local lo src inp
lo="$(pw-link -lo 2>/dev/null)" # ONE snapshot per tick, shared below lo="$(pw-link -lo 2>/dev/null)" # ONE snapshot per tick, shared below
inp="$(pw-link -i 2>/dev/null)"
index_links <<<"$lo"
# ADD: the control surface feed (no-op until Ardour registers the port) # ADD: the control surface feed (no-op until Ardour registers the port)
if [[ "$lo" != *"|-> $CTRL_IN"* ]]; then if [[ "$lo" != *"|-> $CTRL_IN"* ]]; then
...@@ -112,7 +139,7 @@ reconcile() { ...@@ -112,7 +139,7 @@ reconcile() {
# SOF DSP's IPC until the firmware wedged and every sink vanished # SOF DSP's IPC until the firmware wedged and every sink vanished
# (2026-09-07). "SC must never reach hardware" is Ardour-session policy, # (2026-09-07). "SC must never reach hardware" is Ardour-session policy,
# not idle-laptop policy. # not idle-laptop policy.
tracks="$(tidal_track_numbers)" tracks="$(tidal_track_numbers <<<"$inp")"
[ -n "$tracks" ] || return 0 [ -n "$tracks" ] || return 0
# ADD: a hardware output for Master when it has none (additive, see header) # ADD: a hardware output for Master when it has none (additive, see header)
...@@ -132,8 +159,8 @@ reconcile() { ...@@ -132,8 +159,8 @@ reconcile() {
[ -n "${nn:-}" ] || continue [ -n "${nn:-}" ] || continue
k=$((10#$nn)) # strip leading zero (NN -> k) k=$((10#$nn)) # strip leading zero (NN -> k)
l=$((2 * k - 1)); r=$((2 * k)) l=$((2 * k - 1)); r=$((2 * k))
link "$SC:out_$l" "ardour:Tidal $nn/audio_in 1" link_missing "$SC:out_$l" "ardour:Tidal $nn/audio_in 1"
link "$SC:out_$r" "ardour:Tidal $nn/audio_in 2" link_missing "$SC:out_$r" "ardour:Tidal $nn/audio_in 2"
done <<< "$tracks" done <<< "$tracks"
# PRUNE: while Ardour is up, SuperCollider must never reach hardware # PRUNE: while Ardour is up, SuperCollider must never reach hardware
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment