Bladeren bron

Merge remote-tracking branch 'origin/wip/toolchain190gt' into wip/rollup028

# Conflicts:
#	scripts/build-local.sh
#	scripts/build-windows-zig.sh
#	src/engine/AudioEngine.cpp
#	tests/tests.cpp
Ka1-S 3 weken geleden
bovenliggende
commit
ce411f4625

+ 22 - 0
docs/PLATFORMS.md

@@ -81,6 +81,28 @@ round 117 notes (`docs/analise/REA_rodada117.md`) list the measured differences.
   app on Linux and macOS; `release.yml` builds all three platforms on a tag and attaches the packages and
   `SHA256SUMS.txt` to the draft release.
 
+## Release optimisation
+
+Measured in round toolchain190gt with `perfbench` (round 190ge: the engine's render as the audio callback does it,
+instructions and cycles per sample, a hash of every output sample), the same source built several ways, interleaved; on
+Windows `perfbench.exe` linked from a Windows build's own objects (thread cycles).
+- **Windows** (`scripts/build-windows-zig.sh`): `-O2`, `-ffp-contract=off` (as Linux and macOS; it was missing), and a
+  link that drops unreferenced code and folds identical functions (`-OPT:REF -OPT:SAFEICF`, objects with
+  `-ffunction-sections -fdata-sections -faddrsig`; see the script for why zig needs a hand here). LYNX.exe 53.8 →
+  48.2 MB (`.text` −9 %, `.rdata` −13 %), the same output, render cost within the run-to-run noise (±5 %).
+  - ThinLTO (`LYNX_WIN_LTO=thin`): streamed audio −14 %, synth100 −4 %, the rest −1…+5 %, and the FL Harmless engine
+    ran 1.5× slower under it (Harmless.cpp is kept out of LTO when it is on); the link takes 15–25 minutes. Off.
+  - `-fno-math-errno`: up to 25 % fewer cycles on Linux, none on Windows (0 to 3 % more); on MinGW it also turns `sin` +
+    `cos` of one value into the C runtime's `sincos`. Not used.
+  - zig gives `-O3` byte-identical objects to `-O2`; a real `-O3` (`-Xclang -O3`) measured no better than ThinLTO.
+  - `-mcpu=x86_64_v2` (SSE4.2, POPCNT): 0–3 % fewer cycles on Windows, outputs identical; it would need a CPU check
+    before any static constructor (a "CPU too old" box instead of a crash). Not used yet.
+  - Measuring: a zig build without `-target` compiles for the host CPU (`-mcpu=native`), unlike the release.
+- **Linux** (GCC 13, `-O3`, LTO of the app's own objects): unchanged. Link-time optimising the core too (it is a separate
+  static library the app's LTO never reached), and `-fno-math-errno`, measured no gain with GCC.
+- **macOS**: unchanged (Apple's clang `-O3`, LTO of the app's own objects; Darwin has no maths `errno`).
+- `scripts/build-local.sh` takes `LYNX_OPT_FLAGS` (default `-O2`) to run the test suite with other optimisation flags.
+
 ## Windows plugins on Linux (yabridge)
 
 [yabridge](https://github.com/robbert-vdh/yabridge) turns Windows VST2/VST3 plugins into Linux ones running in Wine.

File diff suppressed because it is too large
+ 3 - 1
scripts/build-local.sh


+ 70 - 9
scripts/build-windows-zig.sh

@@ -45,14 +45,29 @@ MODULES=(juce_core juce_data_structures juce_events juce_graphics juce_gui_basic
 # only replace the file if it changed, so the module cache is not invalidated
 cmp -s "$OUT/JuceConfig.h.new" "$OUT/JuceConfig.h" 2>/dev/null && rm "$OUT/JuceConfig.h.new" || mv "$OUT/JuceConfig.h.new" "$OUT/JuceConfig.h"
 
-COMMON=(-target "$TARGET" -std=c++20 -O2 -DNDEBUG=1 -fno-sanitize=undefined
+# Release optimisation (round toolchain190gt; numbers in docs/PLATFORMS.md "Release optimisation"):
+#  LYNX_WIN_OPT  the optimisation flags of LYNX's and JUCE's C++, default -O2. (zig gives -O3 the same code as -O2; a
+#                real -O3 is "-O2 -Xclang -O3". -fno-math-errno gained nothing on Windows (-3..0 %) and on MinGW
+#                it turns sin + cos of one value into a call of the C runtime's sincos. )
+#  LYNX_WIN_LTO  thin = ThinLTO for LYNX's own objects (JUCE's modules stay out), default 0: measured on Windows it gained
+#                0-14 % (streaming most) but made the FL Harmless engine 1.5x slower (fixed by keeping Harmless.cpp
+#                out of it), for a 15-25 minute link. Off until each engine is checked under it.
+#  LYNX_WIN_GC   1 = the link drops unreferenced code and folds identical functions (see "Linking" below), default 1.
+# -ffp-contract=off always, as CMakeLists.txt does for Linux and macOS: no fused multiply-add, so the FL-exact engines keep
+# their operation order whatever CPU the code is built for (baseline x86-64 has no FMA, so today it changes nothing).
+LYNX_WIN_OPT="${LYNX_WIN_OPT:--O2}"
+LYNX_WIN_LTO="${LYNX_WIN_LTO:-0}"
+LYNX_WIN_GC="${LYNX_WIN_GC:-1}"
+read -ra WIN_OPT <<< "$LYNX_WIN_OPT"
+WIN_LTO=(); [[ "$LYNX_WIN_LTO" == thin ]] && WIN_LTO=(-flto=thin)
+COMMON=(-target "$TARGET" -std=c++20 "${WIN_OPT[@]}" "${WIN_LTO[@]}" -ffp-contract=off -DNDEBUG=1 -fno-sanitize=undefined
         -include "$OUT/JuceConfig.h" -include cmake/mingw/mingw_compat.h
         -I"$OUT/shim" -I"$JUCE_DIR/modules" -I"$JUCE_DIR/modules/juce_audio_processors/format_types/VST3_SDK" -Ithird_party/clap/include -Ithird_party/wavpack/include -Ithird_party/vorbis/include -Ithird_party/lame/include -Ithird_party/asiosdk/common -Ithird_party/sse2neon -Ithird_party/pocketpy -Ithird_party/monocypher -Ithird_party/onnxruntime -Isrc)
 # The plugins (LYNX_BUILD_PLUGINS=1 below) link these objects with --gc-sections: with a section per function and per
 # datum the linker drops what a plugin never reaches (round 180b measured 32 % on Linux). Plugin builds only, so the app's
 # objects and their cache entries stay as they are (LYNX_PLUGIN_SECTIONS=0 turns it off).
-if [[ "${LYNX_BUILD_PLUGINS:-0}" == 1 && "${LYNX_PLUGIN_SECTIONS:-1}" == 1 ]]; then
-    COMMON+=(-ffunction-sections -fdata-sections)
+if [[ "$LYNX_WIN_GC" == 1 || ( "${LYNX_BUILD_PLUGINS:-0}" == 1 && "${LYNX_PLUGIN_SECTIONS:-1}" == 1 ) ]]; then
+    COMMON+=(-ffunction-sections -fdata-sections -faddrsig)
 fi
 
 # juce_gui_basics, juce_audio_processors, juce_graphics and juce_events are compiled from patched copies
@@ -147,6 +162,11 @@ export ZIG OUT JUCE_DIR TARGET GUI_BASICS_SRC AUDIO_PROCESSORS_SRC GRAPHICS_SRC
 export -f cached cached_pp
 mkdir -p "$OBJ_CACHE" && find "$OBJ_CACHE" -maxdepth 1 -type f -mtime +10 -delete 2>/dev/null || true
 export COMMON_STR="${COMMON[*]}"
+# JUCE's modules without LTO (round toolchain190gt): LYNX's audio code is in LYNX's own objects, and the big unity modules
+# made the ThinLTO link several times longer for UI code
+JUCE_COMMON=(); for a in "${COMMON[@]}"; do [[ "$a" == -flto* ]] || JUCE_COMMON+=("$a"); done
+export JUCE_COMMON_STR="${JUCE_COMMON[*]}"
+export NOLTO_COMMON_STR="$JUCE_COMMON_STR"
 
 echo "Compiling JUCE modules (cached)..."
 # the modules and the extra units JUCE's CMake compiles along with them, in one parallel pool
@@ -172,7 +192,7 @@ for m in "${MODULES[@]}" juce_core_CompilationTime juce_graphics_Harfbuzz juce_g
         if [[ "$m" == juce_graphics_Sheenbidi ]]; then
             cached "$obj" "$JUCE_DIR" -- "$ZIG" cc -target "$TARGET" -O2 -w -DJUCE_GLOBAL_MODULE_SETTINGS_INCLUDED=1 -I"$JUCE_DIR/modules" -c "$JUCE_DIR/modules/juce_graphics/juce_graphics_Sheenbidi.c" -o "$obj"
         else
-            cached "$obj" "$key" -- $ZIG c++ $COMMON_STR $extra -w -c "$src" -o "$obj"
+            cached "$obj" "$key" -- $ZIG c++ $JUCE_COMMON_STR $extra -w -c "$src" -o "$obj"
         fi
     fi'
 
@@ -359,7 +379,8 @@ printf '%s\n' "${APP_SOURCES[@]}" | xargs -P "$JOBS" -I{} bash -c '
     extra=""; [[ "$src" == src/platform/CrashGuard.cpp ]] && extra="-fms-extensions"
     [[ "$src" == src/ui/CrashReporter.cpp ]] && extra="-iquote $OUT"
     [[ "$src" == src/engine/AbletonLink.cpp ]] && extra="-isystem third_party/link/include -isystem third_party/link/asio/include"
-    cached_pp "$obj" -- $ZIG c++ $COMMON_STR $extra -Wall -Wextra -Werror=return-type -c "$src" -o "$obj"'
+    common="$COMMON_STR"; [[ "$src" == src/core/Harmless.cpp ]] && common="$NOLTO_COMMON_STR" # (1.5x slower under ThinLTO)
+    cached_pp "$obj" -- $ZIG c++ $common $extra -Wall -Wextra -Werror=return-type -c "$src" -o "$obj"'
 
 # 2026-11-04: an object whose source left APP_SOURCES (another branch's build in this folder) must not be linked
 # by the app/*.o glob below: it broke unrelated landings with undefined symbols.
@@ -388,8 +409,48 @@ APP_LIBS=(-lole32 -loleaut32 -luuid -lwinmm -lws2_32 -lshlwapi -lversion -lwinin
           -lgdi32 -luser32 -lcomctl32 -lshell32 -ladvapi32 -lrpcrt4 -ldbghelp -lsetupapi -luxtheme -ldwmapi
           -ld2d1 -ldcomp -ldwrite -ldxgi -ld3d11 -ldxguid -lwsock32 -lopengl32 -lpropsys -lmfplat -lmfreadwrite -lmfuuid -lksuser -lavrt -lwinhttp -lbcrypt
           -liphlpapi) # (iphlpapi: Ableton Link's network interfaces, round 190gl)
-"$ZIG" c++ -target "$TARGET" -O2 -o "$OUT/LYNX.exe" "$OUT"/juce/*.o "${APP_OBJECTS[@]}" "$OUT"/wavpack/*.o "$OUT"/vorbis/*.o "$OUT"/lame/*.o "$OUT"/pocketpy/*.o "$OUT"/monocypher/*.o "$OUT/LYNX.res" \
-    -Wl,--subsystem,windows "${APP_LIBS[@]}"
+link_start=$(date +%s)
+LINK_INPUTS=("$OUT"/juce/*.o "${APP_OBJECTS[@]}" "$OUT"/wavpack/*.o "$OUT"/vorbis/*.o "$OUT"/lame/*.o "$OUT"/pocketpy/*.o "$OUT"/monocypher/*.o "$OUT/LYNX.res")
+plain_link() {
+    "$ZIG" c++ -target "$TARGET" "${WIN_OPT[@]}" "${WIN_LTO[@]}" -o "$OUT/LYNX.exe" "${LINK_INPUTS[@]}" -Wl,--subsystem,windows "${APP_LIBS[@]}"
+}
+# LYNX_WIN_GC=1 (round toolchain190gt): zig links with -DEBUG (LYNX.pdb, for the crash reports) and passes no -OPT flag,
+# so lld keeps every function of every object (-opt:noref -opt:noicf), and zig refuses -Wl,--gc-sections / --icf for
+# COFF. So the link runs through zig's own lld-link with the command zig itself builds (taken from the link of a stub
+# object with the same flags and libraries: the C runtime, libc++, the import libraries), the stub replaced by LYNX's
+# objects, plus -OPT:REF (drop what nothing references) and -OPT:SAFEICF (fold identical functions whose address is never
+# taken, from the objects' address-significance tables, -faddrsig). One link, ThinLTO included. If that cannot be
+# done, the plain zig link runs instead.
+gc_link() {
+    printf 'int main() { return 0; }\n' > "$OUT/linkstub.cpp"
+    "$ZIG" c++ -target "$TARGET" -c "$OUT/linkstub.cpp" -o "$OUT/linkstub.o" || return 1
+    local line args=() a
+    line="$(ZIG_VERBOSE_LINK=1 "$ZIG" c++ -target "$TARGET" "${WIN_OPT[@]}" "${WIN_LTO[@]}" -o "$OUT/linkstub.exe" "$OUT/linkstub.o" \
+        -Wl,--subsystem,windows "${APP_LIBS[@]}" 2>&1 > /dev/null | grep -m 1 '^lld-link ')" || return 1
+    read -ra LINK_CMD <<< "$line"
+    for a in "${LINK_CMD[@]:1}"; do
+        case "$a" in
+            "$OUT/linkstub.o") args+=("${LINK_INPUTS[@]}") ;;
+            -OUT:*) args+=("-OUT:$OUT/LYNX.exe") ;;
+            -PDB:*) args+=("-PDB:$OUT/LYNX.pdb") ;;
+            -PDBALTPATH:*) args+=("-PDBALTPATH:LYNX.pdb") ;;
+            -IMPLIB:*) ;;
+            *) args+=("$a") ;;
+        esac
+    done
+    [[ " ${args[*]} " == *" $OUT/LYNX.res "* ]] || return 1
+    rm -f "$OUT/linkstub".*
+    # ThinLTO: one backend job per build job (lld's default is the physical cores: 2 on a 4-thread CI runner), and a cache
+    # so a relink after a small change recompiles only the modules that changed
+    [[ ${#WIN_LTO[@]} -gt 0 ]] && args+=("-OPT:lldltojobs=$JOBS" "-lldltocache:$OUT/ltocache")
+    "$ZIG" lld-link "${args[@]}" -OPT:REF -OPT:SAFEICF
+}
+if [[ "$LYNX_WIN_GC" == 1 ]]; then
+    gc_link || { echo "warning: the -OPT:REF link did not run; plain link" >&2; plain_link; }
+else
+    plain_link
+fi
+echo "link: $(( $(date +%s) - link_start )) s"
 
 ls -la "$OUT/LYNX.exe"
 
@@ -411,7 +472,7 @@ if [[ "${LYNX_BUILD_PLUGINS:-0}" == 1 ]]; then
     }
     plugin_link() { # <output> <objects...>
         local output="$1"; shift
-        "$ZIG" c++ -target "$TARGET" -O2 -shared -s -o "$output" "$@" "$OUT/plugin/ExportProcessor.o" "${PLUGIN_OBJECTS[@]}" "$OUT"/juce/*.o "$OUT"/wavpack/*.o "$OUT"/vorbis/*.o "$OUT"/lame/*.o "$OUT"/pocketpy/*.o "$OUT"/monocypher/*.o "$OUT/plugin/LynxPlugin.res" "${PLUGIN_LIBS[@]}" -Wl,--gc-sections
+        "$ZIG" c++ -target "$TARGET" "${WIN_OPT[@]}" "${WIN_LTO[@]}" -shared -s -o "$output" "$@" "$OUT/plugin/ExportProcessor.o" "${PLUGIN_OBJECTS[@]}" "$OUT"/juce/*.o "$OUT"/wavpack/*.o "$OUT"/vorbis/*.o "$OUT"/lame/*.o "$OUT"/pocketpy/*.o "$OUT"/monocypher/*.o "$OUT/plugin/LynxPlugin.res" "${PLUGIN_LIBS[@]}" -Wl,--gc-sections
         rm -f "$(dirname "$output")"/*.lib "$(dirname "$output")"/*.pdb # (the linker's import library: not part of a plugin)
     }
     ( cd resources && "$ZIG" rc /fo "$OUT_ABS/plugin/LynxPlugin.res" LynxPlugin.rc )
@@ -431,6 +492,6 @@ if [[ "${LYNX_BUILD_PLUGINS:-0}" == 1 ]]; then
     done < <(sed -nE 's/^LYNX_PLUGIN \("([^"]+)", ([01]), [^,]+, [^,]+, "[^"]+", (0x[0-9a-f]+), "([^"]+)", ([12])\)$/\1~\2~\3~\4~\5/p' src/plugin/plugins.def)
     plugin_cxx "$OUT/plugin/plugexporttest.o" tools/plugexporttest.cpp -Wall -Wextra
     plugin_cxx_link=("$OUT/plugin/plugexporttest.o" "$OUT/plugin/ExportProcessor.o" "${PLUGIN_OBJECTS[@]}" "$OUT"/juce/*.o "$OUT"/wavpack/*.o "$OUT"/vorbis/*.o "$OUT"/lame/*.o "$OUT"/pocketpy/*.o "$OUT"/monocypher/*.o "$OUT/LYNX.res")
-    "$ZIG" c++ -target "$TARGET" -O2 -o "$OUT/plugexporttest.exe" "${plugin_cxx_link[@]}" "${PLUGIN_LIBS[@]}"
+    "$ZIG" c++ -target "$TARGET" "${WIN_OPT[@]}" "${WIN_LTO[@]}" -o "$OUT/plugexporttest.exe" "${plugin_cxx_link[@]}" "${PLUGIN_LIBS[@]}"
     ls -la "$OUT"/plugins/*.clap "$OUT"/plugins/*/Contents/x86_64-win/*
 fi

+ 19 - 0
src/core/WorkerPool.cpp

@@ -105,6 +105,21 @@ WorkerPool::~WorkerPool()
         t.join();
 }
 
+void WorkerPool::setThreadRefresh (std::function<void()> fn)
+{
+    threadRefresh = std::move (fn); // (the workers read it only after a request: its release publishes it)
+}
+
+void WorkerPool::refreshIfAsked (std::uint32_t& seen) const
+{
+    if (const auto now = refreshGeneration.load (std::memory_order_acquire); now != seen)
+    {
+        seen = now;
+        if (threadRefresh)
+            threadRefresh();
+    }
+}
+
 bool WorkerPool::hasWork() const noexcept
 {
     constexpr auto mask = (std::uint64_t (1) << indexBits) - 1;
@@ -125,9 +140,12 @@ void WorkerPool::workerLoop (std::function<void()> onStart)
         onStart();
 
     using clock = std::chrono::steady_clock;
+    std::uint32_t refreshSeen = 0; // (the generation the pool started with: a request made before this thread ran counts too)
 
     while (! quit.load (std::memory_order_relaxed))
     {
+        refreshIfAsked (refreshSeen);
+
         // spin a little: within a block the next parallelFor (next mixer layer or chunk) follows right away
         auto spinStart = clock::now();
         auto found = false;
@@ -177,6 +195,7 @@ void WorkerPool::workerLoop (std::function<void()> onStart)
         if (quit.load())
             return;
 
+        refreshIfAsked (refreshSeen); // (before the block's work: a new workgroup is joined before working for it)
         work (true);
     }
 }

+ 10 - 0
src/core/WorkerPool.h

@@ -38,6 +38,13 @@ public:
 
     int workers() const noexcept { return (int) threads.size(); }
 
+    // Per-thread set-up that can change while the pool lives (round toolchain190gt: on macOS the workers join the audio
+    // device's workgroup, which changes with the device). `fn` runs on every worker thread, on that thread, the next time
+    // it looks for work after requestThreadRefresh(). Set it once, before the first request; it runs outside the work,
+    // so it may take a short lock. requestThreadRefresh() may be called from any thread and is wait-free.
+    void setThreadRefresh (std::function<void()> fn);
+    void requestThreadRefresh() noexcept { refreshGeneration.fetch_add (1, std::memory_order_acq_rel); }
+
     // a spin-wait pause (x86 PAUSE / ARM YIELD), for callers waiting on each other inside a parallelFor
     static void relax() noexcept;
 
@@ -71,6 +78,7 @@ private:
     bool hasWork() const noexcept;
     bool isParked() const noexcept;
     void workerLoop (std::function<void()> onStart);
+    void refreshIfAsked (std::uint32_t& seen) const;
 
     struct Semaphore; // OS semaphore (WorkerPool.cpp)
     std::unique_ptr<Semaphore> wake;
@@ -91,5 +99,7 @@ private:
     std::uint64_t generation = 0; // caller thread only
     std::atomic<int> done { 0 };
     std::atomic<std::uint64_t> byWorkers { 0 }, wokenUp { 0 };
+    std::function<void()> threadRefresh;          // (published by refreshGeneration)
+    std::atomic<std::uint32_t> refreshGeneration { 0 };
 };
 } // namespace lynx

+ 155 - 2
src/engine/AudioEngine.cpp

@@ -51,6 +51,7 @@
 #include "engine/PipeWireDevice.h"
 #include "platform/LinuxRealtime.h"
 #include "engine/PowerHints.h"
+#include "platform/PowerThrottling.h"
 #include "engine/Metronome.h"
 #include "core/NoteTools.h"
 #include "core/VfxScript.h"
@@ -63,6 +64,9 @@
 #if JUCE_WINDOWS
  #include <windows.h>
 #elif JUCE_MAC
+ #include <mach/mach.h>
+ #include <mach/mach_time.h>
+ #include <mach/thread_policy.h>
  #include <pthread.h>
  #include <sys/qos.h>
 #elif JUCE_LINUX || JUCE_BSD
@@ -244,6 +248,44 @@ void enableCompositorMmcss() noexcept
 
 namespace
 {
+#if JUCE_WINDOWS
+// what the audio threads reached (round toolchain190gt, REA 190hc: LYNX's were seen at dynamic priority 15 in some runs
+// and 24-25 in others, Live's always at 26): threads raised, how many joined MMCSS at CRITICAL, their thread priority
+std::atomic<int> rtThreadsRaised { 0 }, rtThreadsMmcss { 0 }, rtThreadsCritical { 0 };
+std::atomic<int> rtPriorityMin { 1000 }, rtPriorityMax { -1000 };
+
+// The process priority class (round toolchain190gt, REA 190hb): Windows' WinMM driver (wdmaud2.drv) raises a process
+// that opens a WinMM device to HIGH (and asks REALTIME), FL's and LYNX's alike, so the UI, decoders, prefetch and plugin
+// scans ran above every normal program; FL itself asks ABOVE_NORMAL. LYNX_PRIORITY_CLASS=above asks ABOVE_NORMAL when a
+// device starts (and again 2 s later, after the MIDI ports), relying on MMCSS for the audio threads. Default: left as
+// Windows sets it — measured with --rtstress (Exoplanet, 10 ms buffer, 3 x 3000 callbacks each, loaded PC): HIGH 0
+// callbacks over the deadline, ABOVE_NORMAL 1, the same average load; a 64-sample run was not possible on this PC.
+std::atomic<unsigned long> priorityClassFound { 0 }, priorityClassNow { 0 };
+void choosePriorityClass() noexcept
+{
+    static const auto keep = juce::SystemStats::getEnvironmentVariable ("LYNX_PRIORITY_CLASS", {}) != "above";
+    const auto found = GetPriorityClass (GetCurrentProcess());
+    if (priorityClassFound.load (std::memory_order_relaxed) == 0 || found != ABOVE_NORMAL_PRIORITY_CLASS)
+        priorityClassFound.store (found, std::memory_order_relaxed);
+    if (! keep && found != ABOVE_NORMAL_PRIORITY_CLASS)
+        SetPriorityClass (GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS);
+    priorityClassNow.store (GetPriorityClass (GetCurrentProcess()), std::memory_order_relaxed);
+}
+juce::String priorityClassName (unsigned long c)
+{
+    switch (c)
+    {
+        case IDLE_PRIORITY_CLASS: return "idle";
+        case BELOW_NORMAL_PRIORITY_CLASS: return "below normal";
+        case NORMAL_PRIORITY_CLASS: return "normal";
+        case ABOVE_NORMAL_PRIORITY_CLASS: return "above normal";
+        case HIGH_PRIORITY_CLASS: return "high";
+        case REALTIME_PRIORITY_CLASS: return "realtime";
+        default: return c == 0 ? juce::String ("not seen") : juce::String::toHexString ((juce::int64) c);
+    }
+}
+#endif
+
 // Audio workers with real-time priority (MMCSS "Pro Audio" on Windows, like the driver; QoS class on macOS; SCHED_FIFO
 // on Linux when allowed).
 void raiseAudioThreadPriority()
@@ -255,7 +297,9 @@ void raiseAudioThreadPriority()
             return reinterpret_cast<AvSet> (reinterpret_cast<void*> (GetProcAddress (avrt, "AvSetMmThreadCharacteristicsW")));
         return nullptr;
     }();
-    // FL's audio worker threads also raise their MMCSS priority to "high" (FLEngine_x64.dll, REA round 87)
+    // FL's audio worker threads raise their MMCSS priority to "high" (FLEngine_x64.dll, REA round 87); Live's to "critical"
+    // (REA round 190hc: its 22 audio threads sat at dynamic priority 26 in every snapshot), which LYNX uses since round
+    // toolchain190gt
     using AvPriority = int (__stdcall*) (void*, int);
     static const auto avPriority = [] () -> AvPriority {
         if (auto* avrt = LoadLibraryW (L"avrt.dll"))
@@ -266,11 +310,20 @@ void raiseAudioThreadPriority()
 
     if (auto* handle = avSet != nullptr ? avSet (L"Pro Audio", &task) : nullptr)
     {
-        if (avPriority != nullptr)
+        rtThreadsMmcss.fetch_add (1, std::memory_order_relaxed);
+        if (avPriority != nullptr && avPriority (handle, 2 /* AVRT_PRIORITY_CRITICAL */) != 0)
+            rtThreadsCritical.fetch_add (1, std::memory_order_relaxed);
+        else if (avPriority != nullptr)
             avPriority (handle, 1 /* AVRT_PRIORITY_HIGH */);
     }
     else
         SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
+    // and full speed while LYNX is in the background (no EcoQoS: platform/PowerThrottling.h, round toolchain190gt)
+    power::optOutOfPowerThrottling();
+    const auto reached = GetThreadPriority (GetCurrentThread());
+    rtThreadsRaised.fetch_add (1, std::memory_order_relaxed);
+    for (auto low = rtPriorityMin.load(); reached < low && ! rtPriorityMin.compare_exchange_weak (low, reached);) {}
+    for (auto high = rtPriorityMax.load(); reached > high && ! rtPriorityMax.compare_exchange_weak (high, reached);) {}
    #elif JUCE_MAC
     // the highest quality-of-service class: scheduled like the UI's own interactive work, on the performance cores
     pthread_set_qos_class_self_np (QOS_CLASS_USER_INTERACTIVE, 0);
@@ -284,6 +337,23 @@ void raiseAudioThreadPriority()
    #endif
 }
 
+#if JUCE_MAC
+// The calling thread becomes a time-constraint (real-time) thread with the device's buffer as its period: about half of
+// it to compute, the whole of it as the deadline. Apple's audio workgroups take only such threads (os_workgroup_join
+// fails with EINVAL before; research round 190gs B1).
+void becomeTimeConstraintThread (double blockMs) noexcept
+{
+    mach_timebase_info_data_t timebase {};
+    if (mach_timebase_info (&timebase) != KERN_SUCCESS || timebase.numer == 0)
+        return;
+    const auto ticks = [&] (double ms) { return (uint32_t) (ms * 1.0e6 * (double) timebase.denom / (double) timebase.numer); };
+    const auto period = juce::jlimit (0.5, 50.0, blockMs); // (above 50 ms the kernel refuses the policy)
+    thread_time_constraint_policy_data_t policy { ticks (period), ticks (0.5 * period), ticks (period), 1 };
+    thread_policy_set (pthread_mach_thread_np (pthread_self()), THREAD_TIME_CONSTRAINT_POLICY, (thread_policy_t) &policy,
+                       THREAD_TIME_CONSTRAINT_POLICY_COUNT);
+}
+#endif
+
 int workerCount()
 {
     // diagnostics: LYNX_WORKERS=n fixes the number of extra threads
@@ -5724,6 +5794,12 @@ juce::String AudioEngine::describeRealtime (bool withUnits) const
             text << "  device thread priority " << before << (deviceThreadPriorityAfter.load (std::memory_order_relaxed) != before
                                                                 ? " -> " + juce::String (deviceThreadPriorityAfter.load (std::memory_order_relaxed)) + " (raised to MMCSS Pro Audio)"
                                                                 : juce::String (boostDeviceThread ? " (kept)" : " (kept: LYNX_DEVICE_BOOST=0)")) << "\n";
+        if (const auto raised = rtThreadsRaised.load (std::memory_order_relaxed); raised > 0)
+            text << "  audio threads raised " << raised << ": MMCSS Pro Audio " << rtThreadsMmcss.load (std::memory_order_relaxed)
+                 << " (critical " << rtThreadsCritical.load (std::memory_order_relaxed) << "), thread priority "
+                 << rtPriorityMin.load (std::memory_order_relaxed) << ".." << rtPriorityMax.load (std::memory_order_relaxed) << "\n";
+        text << "  process priority class " << priorityClassName (priorityClassNow.load (std::memory_order_relaxed)) << " (found "
+             << priorityClassName (priorityClassFound.load (std::memory_order_relaxed)) << ")\n";
        #endif
     }
     else
@@ -6477,6 +6553,8 @@ void AudioEngine::audioDeviceIOCallbackWithContext (const float* const* inputCha
         deviceThreadPriorityBefore.store (before, std::memory_order_relaxed);
         if (boostDeviceThread && before < THREAD_PRIORITY_TIME_CRITICAL)
             raiseAudioThreadPriority();
+        else
+            power::optOutOfPowerThrottling(); // (a driver's own time-critical thread too: no EcoQoS, round toolchain190gt)
         deviceThreadPriorityAfter.store (GetThreadPriority (GetCurrentThread()), std::memory_order_relaxed);
     }
    #endif
@@ -6843,12 +6921,87 @@ void AudioEngine::audioDeviceAboutToStart (juce::AudioIODevice* device)
     hwOutput.clear();
     hwOutput.active.store (true);
     player.audioDeviceAboutToStart (device);
+    joinDeviceWorkgroup (device);
+    if (! processFullSpeed) // (Windows: the process stays out of EcoQoS while a device is open, round toolchain190gt)
+    {
+        processFullSpeed = true;
+        power::holdProcessFullSpeed (true);
+    }
+   #if JUCE_WINDOWS
+    choosePriorityClass();
+    juce::Timer::callAfterDelay (2000, [] { choosePriorityClass(); }); // (after the MIDI ports: WinMM raises it again)
+   #endif
 }
 
 void AudioEngine::audioDeviceStopped()
 {
     hwOutput.active.store (false);
     player.audioDeviceStopped();
+    joinDeviceWorkgroup (nullptr);
+    if (processFullSpeed)
+    {
+        processFullSpeed = false;
+        power::holdProcessFullSpeed (false);
+    }
+}
+
+// macOS (round toolchain190gt): the render workers join the device's audio workgroup (os_workgroup, macOS 11+), so the
+// scheduler runs them with the device's I/O thread as one real-time job with the buffer's deadline: on Apple silicon,
+// on the performance cores. Each worker joins on its own thread (WorkerPool::setThreadRefresh) the next time it wakes,
+// first becoming a time-constraint thread. A stopped device: the workers leave. LYNX_WORKGROUP=0 turns it off.
+// Elsewhere this does nothing (Windows: MMCSS "Pro Audio" and no EcoQoS; Linux: SCHED_FIFO / RealtimeKit, round 161).
+struct AudioEngine::DeviceWorkgroup
+{
+    juce::SpinLock lock;
+    juce::AudioWorkgroup workgroup; // (empty: no device, or one without a workgroup)
+    double blockMs = 0.0;
+};
+
+void AudioEngine::joinDeviceWorkgroup ([[maybe_unused]] juce::AudioIODevice* device)
+{
+   #if JUCE_MAC
+    static const auto off = juce::SystemStats::getEnvironmentVariable ("LYNX_WORKGROUP", {}) == "0";
+    if (off || workers == nullptr || workers->workers() == 0)
+        return;
+    auto wanted = device != nullptr ? device->getWorkgroup() : juce::AudioWorkgroup {};
+    if (deviceWorkgroup == nullptr)
+    {
+        if (! wanted)
+            return;
+        deviceWorkgroup = std::make_shared<DeviceWorkgroup>();
+        // (the pool keeps the holder alive as long as its workers can run the refresh)
+        workers->setThreadRefresh ([holder = deviceWorkgroup] {
+            struct Joined
+            {
+                juce::AudioWorkgroup workgroup; // (retained while joined: the token leaves it before it is released)
+                juce::WorkgroupToken token;
+            };
+            thread_local Joined joined;
+            juce::AudioWorkgroup next;
+            double blockMs = 0.0;
+            {
+                const juce::SpinLock::ScopedLockType sl (holder->lock);
+                next = holder->workgroup;
+                blockMs = holder->blockMs;
+            }
+            if (next == joined.workgroup && (! next || static_cast<bool> (joined.token)))
+                return;
+            joined.token.reset();
+            joined.workgroup = next;
+            if (! next)
+                return;
+            becomeTimeConstraintThread (blockMs);
+            next.join (joined.token);
+        });
+    }
+    {
+        const juce::SpinLock::ScopedLockType sl (deviceWorkgroup->lock);
+        deviceWorkgroup->workgroup = std::move (wanted);
+        deviceWorkgroup->blockMs = device != nullptr ? 1000.0 * device->getCurrentBufferSizeSamples() / juce::jmax (1.0, device->getCurrentSampleRate())
+                                                     : 0.0;
+    }
+    workers->requestThreadRefresh();
+   #endif
 }
 
 // The Master's own target (its default: the graph's output as it is, on the first open pair) and the inserts'

+ 5 - 0
src/engine/AudioEngine.h

@@ -1318,6 +1318,11 @@ private:
     std::atomic<unsigned long> deviceThreadId { 0 };
     std::atomic<int> deviceThreadPriorityBefore { -100 }, deviceThreadPriorityAfter { -100 };
     bool boostDeviceThread = true;
+    // macOS: the device's audio workgroup the render workers join (AudioEngine.cpp, round toolchain190gt)
+    struct DeviceWorkgroup;
+    std::shared_ptr<DeviceWorkgroup> deviceWorkgroup;
+    void joinDeviceWorkgroup (juce::AudioIODevice* device); // message thread (device start / stop)
+    bool processFullSpeed = false; // Windows: this engine holds the process out of EcoQoS (platform/PowerThrottling.h)
     // the live clock (round 170d): the musical position of the next block (count-in included), its tempo, and whether
     // it runs; the output latency the played notes are moved back by
     std::atomic<double> clockTick { 0.0 }, clockTicksPerMs { 0.0 }, outputCompensationMs { 0.0 };

+ 4 - 0
src/engine/SandboxWorker.cpp

@@ -3,6 +3,7 @@
 #include <juce_gui_extra/juce_gui_extra.h>
 
 #include "core/Denormals.h"
+#include "platform/PowerThrottling.h"
 #include "engine/PluginSandbox.h"
 #include "engine/SandboxShared.h"
 
@@ -331,6 +332,9 @@ private:
     {
         // the sandbox's audio thread gets the same FTZ/DAZ as LYNX's own audio threads (round 160: it had none)
         const lynx::ScopedFlushDenormals noDenormals;
+        // Windows: MMCSS "Pro Audio" as LYNX's own audio threads, and no EcoQoS while LYNX is in the background (a
+        // sandbox or bridge process inherits the window owner's Low QoS; round toolchain190gt)
+        lynx::power::becomeProAudioThread();
         while (! threadShouldExit())
         {
             if (! channel.waitRequest (100))

+ 3 - 0
src/engine/StreamPrefetcher.cpp

@@ -1,5 +1,7 @@
 #include "engine/StreamPrefetcher.h"
 
+#include "platform/PowerThrottling.h"
+
 namespace lynx
 {
 StreamPrefetcher::StreamPrefetcher (const Transport& t)
@@ -40,6 +42,7 @@ void StreamPrefetcher::update (const Song& song, SampleLibrary& samples)
 
 void StreamPrefetcher::run()
 {
+    power::optOutOfPowerThrottling(); // (it feeds the audio thread: no EcoQoS in the background, round toolchain190gt)
     while (! threadShouldExit())
     {
         {

+ 114 - 0
src/platform/PowerThrottling.h

@@ -0,0 +1,114 @@
+#pragma once
+// Windows power throttling (EcoQoS) and LYNX's audio threads (round toolchain190gt; research round 190gs Q6).
+//
+// Windows 11 gives a process it considers in the background (window minimised or covered, and not heard through the
+// Windows audio engine: an ASIO driver bypasses that engine, so a DAW playing through ASIO counts as silent) Low QoS /
+// EcoQoS: the efficiency cores on hybrid CPUs, lowered clocks on battery, and it ignores the process' timer resolution
+// request. An audio thread that loses clock speed misses its buffer deadline.
+//  - The threads that render audio (the device's callback thread, the render workers, the stream prefetcher, the
+//    sandbox's and the 32-bit bridge's audio thread) opt out, one call per thread at its start.
+//  - While an audio device is open the whole process opts out too (execution speed and the timer resolution: the UI,
+//    MIDI sync and the plugins' own threads keep running at full speed when LYNX is minimised); closing the device gives
+//    the choice back to the system.
+//
+// Header-only. Elsewhere (macOS, Linux) it does nothing.
+
+#if defined(_WIN32)
+ #ifndef WIN32_LEAN_AND_MEAN
+  #define WIN32_LEAN_AND_MEAN
+ #endif
+ #ifndef NOMINMAX
+  #define NOMINMAX
+ #endif
+ #include <windows.h>
+#endif
+
+namespace lynx::power
+{
+#if defined(_WIN32)
+namespace detail
+{
+// THREAD_POWER_THROTTLING_STATE (processthreadsapi.h, Windows 10 1709+); declared here so older SDK headers build too
+struct ThreadThrottlingState
+{
+    unsigned long version;     // THREAD_POWER_THROTTLING_CURRENT_VERSION (1)
+    unsigned long controlMask; // THREAD_POWER_THROTTLING_EXECUTION_SPEED (1): this thread decides its execution speed
+    unsigned long stateMask;   // 0: never throttled; THREAD_POWER_THROTTLING_EXECUTION_SPEED: EcoQoS
+};
+using GetSetThreadInformation = BOOL (WINAPI*) (HANDLE, int, void*, DWORD);
+constexpr int threadPowerThrottling = 3; // THREAD_INFORMATION_CLASS::ThreadPowerThrottling
+
+inline GetSetThreadInformation load (const char* name) noexcept
+{
+    if (auto* kernel = GetModuleHandleW (L"kernel32.dll"))
+        return reinterpret_cast<GetSetThreadInformation> (reinterpret_cast<void*> (GetProcAddress (kernel, name)));
+    return nullptr;
+}
+} // namespace detail
+
+// The calling thread runs at full speed whatever Windows decides about the process. False when the system has no
+// such setting (before Windows 10 1709). Real-time safe after its first call (a cached function pointer, one syscall).
+inline bool optOutOfPowerThrottling() noexcept
+{
+    static const auto set = detail::load ("SetThreadInformation");
+    detail::ThreadThrottlingState state { 1, 1, 0 };
+    return set != nullptr && set (GetCurrentThread(), detail::threadPowerThrottling, &state, sizeof (state)) != 0;
+}
+
+// The calling thread joins MMCSS "Pro Audio" at critical priority (the class of LYNX's own render workers, AudioEngine.cpp)
+// and opts out of power throttling. For audio threads outside the engine (the plugin sandbox, the 32-bit bridge).
+inline void becomeProAudioThread() noexcept
+{
+    using AvSet = HANDLE (WINAPI*) (LPCWSTR, LPDWORD);
+    using AvPriority = BOOL (WINAPI*) (HANDLE, int);
+    static auto* const avrt = LoadLibraryW (L"avrt.dll");
+    static const auto avSet = avrt != nullptr ? reinterpret_cast<AvSet> (reinterpret_cast<void*> (GetProcAddress (avrt, "AvSetMmThreadCharacteristicsW"))) : nullptr;
+    static const auto avPriority = avrt != nullptr ? reinterpret_cast<AvPriority> (reinterpret_cast<void*> (GetProcAddress (avrt, "AvSetMmThreadPriority"))) : nullptr;
+    DWORD task = 0;
+    if (auto* handle = avSet != nullptr ? avSet (L"Pro Audio", &task) : nullptr)
+    {
+        if (avPriority != nullptr && avPriority (handle, 2 /* AVRT_PRIORITY_CRITICAL, as LYNX's own audio threads */) == 0)
+            avPriority (handle, 1 /* AVRT_PRIORITY_HIGH */);
+    }
+    else
+        SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
+    optOutOfPowerThrottling();
+}
+
+// The whole process at full speed (`on`) or back to the system's choice. Counted: the process opts out while at
+// least one caller holds it on (each `true` matched by one `false`). Message thread (device start / stop).
+inline bool holdProcessFullSpeed (bool on) noexcept
+{
+    struct ProcessThrottlingState
+    {
+        unsigned long version, controlMask, stateMask; // PROCESS_POWER_THROTTLING_STATE
+    };
+    static int holders = 0;
+    const auto before = holders;
+    holders = on ? holders + 1 : (holders > 0 ? holders - 1 : 0);
+    if ((before > 0) == (holders > 0))
+        return true;
+    static const auto set = reinterpret_cast<BOOL (WINAPI*) (HANDLE, int, void*, DWORD)> (
+        reinterpret_cast<void*> (GetProcAddress (GetModuleHandleW (L"kernel32.dll"), "SetProcessInformation")));
+    // EXECUTION_SPEED (1) | IGNORE_TIMER_RESOLUTION (4); state 0 = never throttled. Control 0 = the system decides.
+    ProcessThrottlingState state { 1, holders > 0 ? 1ul | 4ul : 0ul, 0 };
+    return set != nullptr && set (GetCurrentProcess(), 4 /* ProcessPowerThrottling */, &state, sizeof (state)) != 0;
+}
+
+// The calling thread's setting: 1 = opted out (never throttled), 0 = the system decides, -1 = unknown. (Tests and
+// diagnostics.)
+inline int powerThrottlingOptOut() noexcept
+{
+    static const auto get = detail::load ("GetThreadInformation");
+    detail::ThreadThrottlingState state { 1, 0, 0 };
+    if (get == nullptr || get (GetCurrentThread(), detail::threadPowerThrottling, &state, sizeof (state)) == 0)
+        return -1;
+    return (state.controlMask & 1u) != 0 && (state.stateMask & 1u) == 0 ? 1 : 0;
+}
+#else
+inline bool optOutOfPowerThrottling() noexcept { return false; }
+inline void becomeProAudioThread() noexcept {}
+inline bool holdProcessFullSpeed (bool) noexcept { return false; }
+inline int powerThrottlingOptOut() noexcept { return -1; }
+#endif
+} // namespace lynx::power

+ 136 - 0
tests/Toolchain190gtTests.inc

@@ -0,0 +1,136 @@
+// Round toolchain190gt: release build flags and the audio threads' OS set-up.
+// (1) WorkerPool::setThreadRefresh / requestThreadRefresh: a per-thread set-up that runs on every worker, on that
+//     worker's own thread, once per request (macOS joins the workers to the audio device's workgroup with it).
+// (2) Every worker runs its work with flush-to-zero + denormals-are-zero (the audio callback sets it on its own thread).
+// (3) Source guards: the audio threads (device, workers, prefetcher, sandbox / bridge) opt out of Windows' EcoQoS and the
+//     process stays out of it while a device is open (platform/PowerThrottling.h); the device's workgroup is joined on
+//     start and left on stop (macOS).
+
+#include <mutex>
+
+namespace toolchain190gt
+{
+// runs parallelFor rounds until every worker has done `want` refreshes (a sleeping worker refreshes when it wakes), for
+// at most `rounds` rounds or 10 s (a loaded CI runner may not schedule a worker for a while)
+inline bool waitForRefreshes (lynx::WorkerPool& pool, const std::map<std::thread::id, int>& counts, std::mutex& m, int want,
+                              int rounds = 1000000)
+{
+    auto fn = [] (int i) {
+        volatile int x = i;
+        for (int k = 0; k < 200; ++k)
+            x = x + k;
+    };
+    const auto until = std::chrono::steady_clock::now() + std::chrono::seconds (10);
+    for (int round = 0; round < rounds && std::chrono::steady_clock::now() < until; ++round)
+    {
+        pool.parallelFor (64, fn);
+        {
+            const std::lock_guard<std::mutex> lock (m);
+            auto all = (int) counts.size() == pool.workers();
+            for (const auto& [id, n] : counts)
+                all = all && n >= want;
+            if (all)
+                return true;
+        }
+        if (round % 10 == 9) // (let the workers and the other test shards run: never a busy wall of spinning threads)
+            std::this_thread::sleep_for (std::chrono::milliseconds (1));
+    }
+    return false;
+}
+} // namespace toolchain190gt
+
+TEST (toolchain190gt_worker_refresh_runs_once_per_request_on_every_worker)
+{
+    lynx::WorkerPool pool (3);
+    std::mutex m;
+    std::map<std::thread::id, int> counts;
+    pool.setThreadRefresh ([&] {
+        const std::lock_guard<std::mutex> lock (m);
+        ++counts[std::this_thread::get_id()];
+    });
+    // nothing runs before a request
+    toolchain190gt::waitForRefreshes (pool, counts, m, 1, 100); // (work for the workers, no request yet)
+    {
+        const std::lock_guard<std::mutex> lock (m);
+        CHECK (counts.empty());
+    }
+    pool.requestThreadRefresh();
+    CHECK (toolchain190gt::waitForRefreshes (pool, counts, m, 1));
+    {
+        const std::lock_guard<std::mutex> lock (m);
+        CHECK ((int) counts.size() == 3);
+        CHECK (counts.count (std::this_thread::get_id()) == 0); // only the workers, never the calling thread
+        for (const auto& [id, n] : counts)
+            CHECK (n == 1);
+    }
+    pool.requestThreadRefresh();
+    CHECK (toolchain190gt::waitForRefreshes (pool, counts, m, 2));
+    {
+        const std::lock_guard<std::mutex> lock (m);
+        for (const auto& [id, n] : counts)
+            CHECK (n == 2);
+    }
+}
+
+TEST (toolchain190gt_workers_run_with_flush_to_zero_and_denormals_are_zero)
+{
+#if defined(__SSE__) || defined(_M_X64) || defined(__x86_64__) || defined(__aarch64__) || defined(_M_ARM64)
+    lynx::WorkerPool pool (3);
+    const auto caller = std::this_thread::get_id();
+    std::atomic<int> byWorkers { 0 }, withoutFlush { 0 };
+    std::atomic<float> sink { 0.0f };
+    auto fn = [&] (int i) {
+        float x = 1.0e-30f + (float) i;
+        for (int k = 0; k < 4000; ++k)
+            x = x * 0.999f + 1.0e-38f;
+        sink.store (x, std::memory_order_relaxed);
+        if (std::this_thread::get_id() != caller)
+        {
+            byWorkers.fetch_add (1);
+            // FTZ (bit 15) and DAZ (bit 6); on ARM64 sse2neon maps both to FPCR.FZ
+            if ((_mm_getcsr() & 0x8040u) != 0x8040u)
+                withoutFlush.fetch_add (1);
+        }
+    };
+    const auto until = std::chrono::steady_clock::now() + std::chrono::seconds (20);
+    while (byWorkers.load() < 50 && std::chrono::steady_clock::now() < until)
+        pool.parallelFor (64, fn);
+    CHECK (byWorkers.load() > 0);
+    CHECK (withoutFlush.load() == 0);
+#endif
+}
+
+TEST (toolchain190gt_audio_threads_opt_out_of_ecoqos_and_join_the_device_workgroup)
+{
+    using namespace i18ntest;
+    const auto engine = readFile ("src/engine/AudioEngine.cpp");
+    // the workers (their start: raiseAudioThreadPriority) and the device's own callback thread
+    const auto raise = engine.find ("void raiseAudioThreadPriority()");
+    const auto raiseEnd = engine.find ("\n}\n", raise);
+    CHECK (raise != std::string::npos && engine.find ("power::optOutOfPowerThrottling();", raise) < raiseEnd);
+    const auto callback = engine.find ("void AudioEngine::audioDeviceIOCallbackWithContext");
+    CHECK (callback != std::string::npos && engine.find ("power::optOutOfPowerThrottling();", callback) != std::string::npos);
+    // MMCSS "Pro Audio" at CRITICAL, as Live (REA 190hc), and the reached priority in the real-time report
+    CHECK (engine.find ("avPriority (handle, 2 /* AVRT_PRIORITY_CRITICAL */)", raise) < raiseEnd);
+    CHECK (engine.find ("audio threads raised ") != std::string::npos);
+    CHECK (readFile ("src/platform/PowerThrottling.h").find ("avPriority (handle, 2 /* AVRT_PRIORITY_CRITICAL") != std::string::npos);
+    // the process priority class chosen on device start (WinMM raises it to HIGH otherwise), and reported
+    CHECK (engine.find ("choosePriorityClass();", engine.find ("void AudioEngine::audioDeviceAboutToStart")) < engine.find ("void AudioEngine::audioDeviceStopped"));
+    CHECK (engine.find ("process priority class ") != std::string::npos);
+    // the stream prefetcher's thread
+    CHECK (readFile ("src/engine/StreamPrefetcher.cpp").find ("power::optOutOfPowerThrottling();") != std::string::npos);
+    // the plugin sandbox's / 32-bit bridge's audio thread: MMCSS + no EcoQoS
+    const auto sandbox = readFile ("src/engine/SandboxWorker.cpp");
+    CHECK (sandbox.find ("lynx::power::becomeProAudioThread();", sandbox.find ("void run() override")) != std::string::npos);
+    // the whole process out of EcoQoS while a device is open (held on start, given back on stop)
+    CHECK (engine.find ("power::holdProcessFullSpeed (true);", engine.find ("void AudioEngine::audioDeviceAboutToStart")) < engine.find ("void AudioEngine::audioDeviceStopped"));
+    CHECK (engine.find ("power::holdProcessFullSpeed (false);", engine.find ("void AudioEngine::audioDeviceStopped")) != std::string::npos);
+    // the device's workgroup: joined on start, left on stop
+    const auto start = engine.find ("void AudioEngine::audioDeviceAboutToStart");
+    const auto stop = engine.find ("void AudioEngine::audioDeviceStopped");
+    CHECK (start != std::string::npos && engine.find ("joinDeviceWorkgroup (device);", start) < stop);
+    CHECK (stop != std::string::npos && engine.find ("joinDeviceWorkgroup (nullptr);", stop) < engine.find ("\n}\n", stop));
+    // the pool's refresh is set before the first request
+    const auto join = engine.find ("void AudioEngine::joinDeviceWorkgroup");
+    CHECK (join != std::string::npos && engine.find ("setThreadRefresh", join) < engine.find ("requestThreadRefresh", join));
+}

+ 1 - 0
tests/tests.cpp

@@ -17786,4 +17786,5 @@ TEST (fl_low_lifter_matches_fl_engine)
 #include "SchedIndex190gpTests.inc"
 #include "SmartTails190gpTests.inc"
 #include "ApexMeter190gpTests.inc"
+#include "Toolchain190gtTests.inc"
 #include "Rollup028Tests.inc" // round 190fv: semantic interactions of the 0.1.28 rollup

Some files were not shown because too many files changed in this diff