Run the threads that take command buffers to their handlers at user-interactive on macOS

What: on macOS the scheduler thread, the completion thread, each VkQueue's waiter and every
thread of the handler pool (its first and the ones it starts later) request the user-interactive
quality of service as they start, before any work: exit_guard::spawn_user_interactive starts them
as exit_guard::spawn does, then calls pthread_set_qos_class_self_np(QOS_CLASS_USER_INTERACTIVE, 0)
(<pthread/qos.h>). The compile threads keep their user-initiated raise and every other thread of
the runtime keeps the existing raise to at least the default class. No change elsewhere than
macOS.

Why: Metal runs every command buffer's scheduled and completed handlers at user-interactive,
whatever the class of the committing thread (probe on an M3 Max, macOS 27.0.1: commits from
dispatch queues at user-interactive, user-initiated, default, utility and background; every
handler ran at user-interactive). These threads ran at the default class, where a new pthread
starts (<sys/qos.h>, and seen on this Mac from creators at every class). No CPU affinity, and no
option or environment variable turns it off; the comment at the call says so.

Test: tests::exit_guard::the_threads_that_take_command_buffers_to_their_handlers_run_at_the_
user_interactive_class starts the scheduler, the completion thread with two waiters and the
handler pool from threads at each class, background to user-interactive, and reads each thread's
class from inside it (qos_class_self, through a test-only start hook; the pool's items read their
own). It also checks the reaper runs as exit_guard::spawn starts a thread, below user-interactive.

The runtime-sources pin moves (recomputed over this tree); RUNTIME_VERSION stays, since no
run's results change.

Verified on this Mac (M3 Max, macOS 27.0.1, Rust 1.98.1): cargo nextest run -p
metal2vulkan-runtime --all-features, 869 of 869 passed, the new test among them, and the existing
compile-thread and pipeline-pool class tests unchanged and passing; the new test fails with the
old class (the scheduler read 0x15, default, against 0x21, user-interactive); cargo check
--workspace --all-targets --all-features, plain and with RUSTFLAGS='--cfg m2v_gpu', clean. No MoltenVK lane or latency run (skipped at the user's request).
This commit is contained in:
Anees Iqbal committed 2026-10-14 12:34:30 +03:00
1 parent c5e585f9be
commit f99d6b9895
6 files changed
+194 -6

No files matched your search

@@ -137,7 +137,7 @@ impl Completion {
let spawned: std::io::Result<()> = (|| {
let thread = {
let watch = Arc::clone(&watch);
exit_guard::spawn(
exit_guard::spawn_user_interactive(
std::thread::Builder::new().name("metal2vulkan-completion".into()),
move || run(&watch),
)?
@@ -145,7 +145,7 @@ impl Completion {
lock(&completion.threads).push(thread);
for queue in 0..queues {
let watch = Arc::clone(&watch);
let waiter = exit_guard::spawn(
let waiter = exit_guard::spawn_user_interactive(
std::thread::Builder::new().name(format!("metal2vulkan-queue-wait-{queue}")),
move || wait_for_queue(&watch, queue),
)?;