From f6641cd266a85ce46d6f13d9a63480405b49fe31 Mon Sep 17 00:00:00 2001 From: smarm-agent Date: Sat, 11 Jul 2026 19:17:52 +0000 Subject: [PATCH] runtime: name scheduler threads smarm-sched-{slot} MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extra scheduler threads (slots 1..N-1) are now spawned via thread::Builder with the name smarm-sched-{slot}, so they are identifiable in /proc//task/*/comm, stack dumps and debuggers. Thread 0 keeps its caller-given name (an embedder names the thread that calls run — smarm_beam names it smarm-runtime). A refused spawn still panics, matching the previous thread::spawn semantics. Motivation: the §17 scheduler-width knob in smarm_beam asserts the *live* width by counting these named threads, and a 20-scheduler soak needs the threads tellable apart in wedge captures. --- src/runtime.rs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/runtime.rs b/src/runtime.rs index 3baf993..a980420 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -967,16 +967,27 @@ impl Runtime { self.inner.root_swept.store(false, Ordering::Relaxed); self.inner.set_root(initial_handle.pid()); - // Launch N-1 extra scheduler threads. The calling thread is thread 0. + // Launch N-1 extra scheduler threads, named `smarm-sched-{slot}` so + // they are identifiable in `/proc//task/*/comm`, stack dumps and + // debuggers. The calling thread is thread 0 and keeps its caller-given + // name (an embedder typically names it when spawning `run`). let mut os_threads = Vec::new(); for slot in 1..self.thread_count { let inner = self.inner.clone(); - let t = thread::spawn(move || { - RUNTIME.with(|r| *r.borrow_mut() = Some(inner.clone())); - SCHED_SLOT.with(|s| s.set(slot)); - schedule_loop(&inner, slot); - RUNTIME.with(|r| *r.borrow_mut() = None); - }); + let t = thread::Builder::new() + .name(format!("smarm-sched-{slot}")) + .spawn(move || { + RUNTIME.with(|r| *r.borrow_mut() = Some(inner.clone())); + SCHED_SLOT.with(|s| s.set(slot)); + schedule_loop(&inner, slot); + RUNTIME.with(|r| *r.borrow_mut() = None); + }); + // `thread::spawn` (the previous form) also panics when the OS + // refuses a thread, so this keeps the failure semantics. + let t = match t { + Ok(t) => t, + Err(e) => panic!("failed to spawn smarm scheduler thread: {e}"), + }; os_threads.push(t); }