Skip to content

Commit

Permalink
virtio, krun: Name all the worker threads
Browse files Browse the repository at this point in the history
Helps debugging with gdb, otherwise they inherit another thread name and
it gets confusing.

Signed-off-by: Asahi Lina <[email protected]>
  • Loading branch information
asahilina committed Oct 7, 2024
1 parent 17655bc commit f8405d7
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 33 deletions.
5 changes: 4 additions & 1 deletion src/devices/src/virtio/block/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
27 changes: 15 additions & 12 deletions src/devices/src/virtio/console/port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
5 changes: 4 additions & 1 deletion src/devices/src/virtio/fs/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion src/devices/src/virtio/gpu/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion src/devices/src/virtio/net/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion src/devices/src/virtio/snd/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion src/devices/src/virtio/vsock/muxer_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion src/devices/src/virtio/vsock/reaper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
5 changes: 4 additions & 1 deletion src/devices/src/virtio/vsock/timesync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
29 changes: 16 additions & 13 deletions src/libkrun/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit f8405d7

Please sign in to comment.