runtime: name scheduler threads smarm-sched-{slot}
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/<pid>/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.
This commit is contained in:
+18
-7
@@ -967,16 +967,27 @@ impl Runtime {
|
|||||||
self.inner.root_swept.store(false, Ordering::Relaxed);
|
self.inner.root_swept.store(false, Ordering::Relaxed);
|
||||||
self.inner.set_root(initial_handle.pid());
|
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/<pid>/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();
|
let mut os_threads = Vec::new();
|
||||||
for slot in 1..self.thread_count {
|
for slot in 1..self.thread_count {
|
||||||
let inner = self.inner.clone();
|
let inner = self.inner.clone();
|
||||||
let t = thread::spawn(move || {
|
let t = thread::Builder::new()
|
||||||
RUNTIME.with(|r| *r.borrow_mut() = Some(inner.clone()));
|
.name(format!("smarm-sched-{slot}"))
|
||||||
SCHED_SLOT.with(|s| s.set(slot));
|
.spawn(move || {
|
||||||
schedule_loop(&inner, slot);
|
RUNTIME.with(|r| *r.borrow_mut() = Some(inner.clone()));
|
||||||
RUNTIME.with(|r| *r.borrow_mut() = None);
|
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);
|
os_threads.push(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user