From f8405d7928ce7765639ef315e77111310bdc331b Mon Sep 17 00:00:00 2001 From: Asahi Lina Date: Tue, 8 Oct 2024 05:36:29 +0900 Subject: [PATCH] virtio, krun: Name all the worker threads Helps debugging with gdb, otherwise they inherit another thread name and it gets confusing. Signed-off-by: Asahi Lina --- src/devices/src/virtio/block/worker.rs | 5 +++- src/devices/src/virtio/console/port.rs | 27 ++++++++++-------- src/devices/src/virtio/fs/worker.rs | 5 +++- src/devices/src/virtio/gpu/worker.rs | 5 +++- src/devices/src/virtio/net/worker.rs | 5 +++- src/devices/src/virtio/snd/worker.rs | 5 +++- src/devices/src/virtio/vsock/muxer_thread.rs | 5 +++- src/devices/src/virtio/vsock/reaper.rs | 5 +++- src/devices/src/virtio/vsock/timesync.rs | 5 +++- src/libkrun/src/lib.rs | 29 +++++++++++--------- 10 files changed, 63 insertions(+), 33 deletions(-) diff --git a/src/devices/src/virtio/block/worker.rs b/src/devices/src/virtio/block/worker.rs index cf7e5a36..1590ee13 100644 --- a/src/devices/src/virtio/block/worker.rs +++ b/src/devices/src/virtio/block/worker.rs @@ -87,7 +87,10 @@ impl BlockWorker { } pub fn run(self) -> thread::JoinHandle<()> { - thread::spawn(|| self.work()) + thread::Builder::new() + .name("block worker".into()) + .spawn(|| self.work()) + .unwrap() } fn work(mut self) { diff --git a/src/devices/src/virtio/console/port.rs b/src/devices/src/virtio/console/port.rs index 8a5ca304..b959172d 100644 --- a/src/devices/src/virtio/console/port.rs +++ b/src/devices/src/virtio/console/port.rs @@ -131,18 +131,21 @@ impl Port { let port_id = self.port_id; let stopfd = stopfd.try_clone().unwrap(); let stop = stop.clone(); - thread::spawn(move || { - process_rx( - mem, - rx_queue, - irq_signaler, - input, - control, - port_id, - stopfd, - stop, - ) - }) + thread::Builder::new() + .name("console port".into()) + .spawn(move || { + process_rx( + mem, + rx_queue, + irq_signaler, + input, + control, + port_id, + stopfd, + stop, + ) + }) + .unwrap() }); let tx_thread = output.map(|output| { diff --git a/src/devices/src/virtio/fs/worker.rs b/src/devices/src/virtio/fs/worker.rs index 475133da..cfd058e1 100644 --- a/src/devices/src/virtio/fs/worker.rs +++ b/src/devices/src/virtio/fs/worker.rs @@ -69,7 +69,10 @@ impl FsWorker { } pub fn run(self) -> thread::JoinHandle<()> { - thread::spawn(|| self.work()) + thread::Builder::new() + .name("fs worker".into()) + .spawn(|| self.work()) + .unwrap() } fn work(mut self) { diff --git a/src/devices/src/virtio/gpu/worker.rs b/src/devices/src/virtio/gpu/worker.rs index 16c15ca2..7c2827f9 100644 --- a/src/devices/src/virtio/gpu/worker.rs +++ b/src/devices/src/virtio/gpu/worker.rs @@ -71,7 +71,10 @@ impl Worker { } pub fn run(self) { - thread::spawn(|| self.work()); + thread::Builder::new() + .name("gpu worker".into()) + .spawn(|| self.work()) + .unwrap(); } fn work(mut self) { diff --git a/src/devices/src/virtio/net/worker.rs b/src/devices/src/virtio/net/worker.rs index b698b26a..fb669058 100644 --- a/src/devices/src/virtio/net/worker.rs +++ b/src/devices/src/virtio/net/worker.rs @@ -92,7 +92,10 @@ impl NetWorker { } pub fn run(self) { - thread::spawn(|| self.work()); + thread::Builder::new() + .name("virtio-net worker".into()) + .spawn(|| self.work()) + .unwrap(); } fn work(mut self) { diff --git a/src/devices/src/virtio/snd/worker.rs b/src/devices/src/virtio/snd/worker.rs index 090e2b65..f2600807 100644 --- a/src/devices/src/virtio/snd/worker.rs +++ b/src/devices/src/virtio/snd/worker.rs @@ -126,7 +126,10 @@ impl SndWorker { } pub fn run(self) -> thread::JoinHandle<()> { - thread::spawn(|| self.work()) + thread::Builder::new() + .name("virtio-snd worker".into()) + .spawn(|| self.work()) + .unwrap() } fn work(mut self) { diff --git a/src/devices/src/virtio/vsock/muxer_thread.rs b/src/devices/src/virtio/vsock/muxer_thread.rs index acff6b25..09a32361 100644 --- a/src/devices/src/virtio/vsock/muxer_thread.rs +++ b/src/devices/src/virtio/vsock/muxer_thread.rs @@ -62,7 +62,10 @@ impl MuxerThread { } pub fn run(self) { - thread::spawn(|| self.work()); + thread::Builder::new() + .name("vsock muxer".into()) + .spawn(|| self.work()) + .unwrap(); } fn send_credit_request(&self, credit_rx: MuxerRx) { diff --git a/src/devices/src/virtio/vsock/reaper.rs b/src/devices/src/virtio/vsock/reaper.rs index 46f07a17..8b3f41e2 100644 --- a/src/devices/src/virtio/vsock/reaper.rs +++ b/src/devices/src/virtio/vsock/reaper.rs @@ -66,6 +66,9 @@ impl ReaperThread { } pub fn run(mut self) { - thread::spawn(move || self.work()); + thread::Builder::new() + .name("vsock reaper".into()) + .spawn(move || self.work()) + .unwrap(); } } diff --git a/src/devices/src/virtio/vsock/timesync.rs b/src/devices/src/virtio/vsock/timesync.rs index 08daf7a2..c415b621 100644 --- a/src/devices/src/virtio/vsock/timesync.rs +++ b/src/devices/src/virtio/vsock/timesync.rs @@ -98,6 +98,9 @@ impl TimesyncThread { } pub fn run(mut self) { - thread::spawn(move || self.work()); + thread::Builder::new() + .name("vsock timesync".into()) + .spawn(move || self.work()) + .unwrap(); } } diff --git a/src/libkrun/src/lib.rs b/src/libkrun/src/lib.rs index 543df745..ff3123b7 100644 --- a/src/libkrun/src/lib.rs +++ b/src/libkrun/src/lib.rs @@ -1172,19 +1172,22 @@ pub extern "C" fn krun_start_enter(ctx_id: u32) -> i32 { let mapper_vmm = _vmm.clone(); #[cfg(target_os = "macos")] - std::thread::spawn(move || loop { - match receiver.recv() { - Err(e) => error!("Error in receiver: {:?}", e), - Ok(m) => match m { - MemoryMapping::AddMapping(s, h, g, l) => { - mapper_vmm.lock().unwrap().add_mapping(s, h, g, l) - } - MemoryMapping::RemoveMapping(s, g, l) => { - mapper_vmm.lock().unwrap().remove_mapping(s, g, l) - } - }, - } - }); + std::thread::Builder::new() + .name("mapping worker") + .spawn(move || loop { + match receiver.recv() { + Err(e) => error!("Error in receiver: {:?}", e), + Ok(m) => match m { + MemoryMapping::AddMapping(s, h, g, l) => { + mapper_vmm.lock().unwrap().add_mapping(s, h, g, l) + } + MemoryMapping::RemoveMapping(s, g, l) => { + mapper_vmm.lock().unwrap().remove_mapping(s, g, l) + } + }, + } + }) + .unwrap(); loop { match event_manager.run() {