summary refs log tree commit diff
path: root/devices
diff options
context:
space:
mode:
authorStephen Barber <smbarber@chromium.org>2017-10-29 23:13:48 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-10-30 23:21:37 -0700
commitce374793bf1b40838c7588620ac5b3784fa4997a (patch)
tree71d908d9c27b9b5d1422e45647d90be1e5a3c1a6 /devices
parentd657af628a2f0967d8a004946abde3ed34dd6dd7 (diff)
downloadcrosvm-ce374793bf1b40838c7588620ac5b3784fa4997a.tar
crosvm-ce374793bf1b40838c7588620ac5b3784fa4997a.tar.gz
crosvm-ce374793bf1b40838c7588620ac5b3784fa4997a.tar.bz2
crosvm-ce374793bf1b40838c7588620ac5b3784fa4997a.tar.lz
crosvm-ce374793bf1b40838c7588620ac5b3784fa4997a.tar.xz
crosvm-ce374793bf1b40838c7588620ac5b3784fa4997a.tar.zst
crosvm-ce374793bf1b40838c7588620ac5b3784fa4997a.zip
crosvm/devices: set thread names
crosvm spawns a lot of processes/threads, and having these all use the same
name as the original process can be confusing. So at least in the instances
where Rust threads are spawned (vs. minijail_fork()), use a thread::Builder
to allow setting the thread name.

BUG=none
TEST=start crosvm, check thread names with top

Change-Id: I6e55ff5fd60f258880bda8e656ab7f9da82c656e
Reviewed-on: https://chromium-review.googlesource.com/742394
Commit-Ready: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Diffstat (limited to 'devices')
-rw-r--r--devices/src/virtio/block.rs29
-rw-r--r--devices/src/virtio/net.rs55
-rw-r--r--devices/src/virtio/rng.rs29
-rw-r--r--devices/src/virtio/vhost/net.rs51
-rw-r--r--devices/src/virtio/vhost/vsock.rs52
-rw-r--r--devices/src/virtio/wl.rs29
6 files changed, 142 insertions, 103 deletions
diff --git a/devices/src/virtio/block.rs b/devices/src/virtio/block.rs
index 1af2693..ed78849 100644
--- a/devices/src/virtio/block.rs
+++ b/devices/src/virtio/block.rs
@@ -9,7 +9,7 @@ use std::os::unix::io::{AsRawFd, RawFd};
 use std::result;
 use std::sync::Arc;
 use std::sync::atomic::{AtomicUsize, Ordering};
-use std::thread::spawn;
+use std::thread;
 
 use sys_util::Result as SysResult;
 use sys_util::{EventFd, GuestAddress, GuestMemory, GuestMemoryError, Poller};
@@ -364,16 +364,23 @@ impl VirtioDevice for Block {
         self.kill_evt = Some(self_kill_evt);
 
         if let Some(disk_image) = self.disk_image.take() {
-            spawn(move || {
-                let mut worker = Worker {
-                    queues: queues,
-                    mem: mem,
-                    disk_image: disk_image,
-                    interrupt_status: status,
-                    interrupt_evt: interrupt_evt,
-                };
-                worker.run(queue_evts.remove(0), kill_evt);
-            });
+            let worker_result = thread::Builder::new()
+                .name("virtio_blk".to_string())
+                .spawn(move || {
+                    let mut worker = Worker {
+                        queues: queues,
+                        mem: mem,
+                        disk_image: disk_image,
+                        interrupt_status: status,
+                        interrupt_evt: interrupt_evt,
+                    };
+                    worker.run(queue_evts.remove(0), kill_evt);
+                });
+
+            if let Err(e) = worker_result {
+                error!("failed to spawn virtio_blk worker: {}", e);
+                return;
+            }
         }
     }
 }
diff --git a/devices/src/virtio/net.rs b/devices/src/virtio/net.rs
index d632dd6..a4df8c9 100644
--- a/devices/src/virtio/net.rs
+++ b/devices/src/virtio/net.rs
@@ -9,7 +9,7 @@ use std::net::Ipv4Addr;
 use std::os::unix::io::{AsRawFd, RawFd};
 use std::sync::Arc;
 use std::sync::atomic::{AtomicUsize, Ordering};
-use std::thread::spawn;
+use std::thread;
 
 use libc::EAGAIN;
 use net_sys;
@@ -403,29 +403,36 @@ impl VirtioDevice for Net {
         if let Some(tap) = self.tap.take() {
             if let Some(kill_evt) = self.workers_kill_evt.take() {
                 let acked_features = self.acked_features;
-                spawn(move || {
-                    // First queue is rx, second is tx.
-                    let rx_queue = queues.remove(0);
-                    let tx_queue = queues.remove(0);
-                    let mut worker = Worker {
-                        mem: mem,
-                        rx_queue: rx_queue,
-                        tx_queue: tx_queue,
-                        tap: tap,
-                        interrupt_status: status,
-                        interrupt_evt: interrupt_evt,
-                        rx_buf: [0u8; MAX_BUFFER_SIZE],
-                        rx_count: 0,
-                        deferred_rx: false,
-                        acked_features: acked_features,
-                    };
-                    let rx_queue_evt = queue_evts.remove(0);
-                    let tx_queue_evt = queue_evts.remove(0);
-                    let result = worker.run(rx_queue_evt, tx_queue_evt, kill_evt);
-                    if let Err(e) = result {
-                        error!("net worker thread exited with error: {:?}", e);
-                    }
-                });
+                let worker_result = thread::Builder::new()
+                    .name("virtio_net".to_string())
+                    .spawn(move || {
+                        // First queue is rx, second is tx.
+                        let rx_queue = queues.remove(0);
+                        let tx_queue = queues.remove(0);
+                        let mut worker = Worker {
+                            mem: mem,
+                            rx_queue: rx_queue,
+                            tx_queue: tx_queue,
+                            tap: tap,
+                            interrupt_status: status,
+                            interrupt_evt: interrupt_evt,
+                            rx_buf: [0u8; MAX_BUFFER_SIZE],
+                            rx_count: 0,
+                            deferred_rx: false,
+                            acked_features: acked_features,
+                        };
+                        let rx_queue_evt = queue_evts.remove(0);
+                        let tx_queue_evt = queue_evts.remove(0);
+                        let result = worker.run(rx_queue_evt, tx_queue_evt, kill_evt);
+                        if let Err(e) = result {
+                            error!("net worker thread exited with error: {:?}", e);
+                        }
+                    });
+
+                if let Err(e) = worker_result {
+                    error!("failed to spawn virtio_net worker: {}", e);
+                    return;
+                }
             }
         }
     }
diff --git a/devices/src/virtio/rng.rs b/devices/src/virtio/rng.rs
index 292d3f1..da5d40b 100644
--- a/devices/src/virtio/rng.rs
+++ b/devices/src/virtio/rng.rs
@@ -8,7 +8,7 @@ use std::io;
 use std::os::unix::io::{AsRawFd, RawFd};
 use std::sync::Arc;
 use std::sync::atomic::{AtomicUsize, Ordering};
-use std::thread::spawn;
+use std::thread;
 
 use sys_util::{EventFd, GuestMemory, Poller};
 
@@ -172,16 +172,23 @@ impl VirtioDevice for Rng {
         let queue = queues.remove(0);
 
         if let Some(random_file) = self.random_file.take() {
-            spawn(move || {
-                let mut worker = Worker {
-                    queue: queue,
-                    mem: mem,
-                    random_file: random_file,
-                    interrupt_status: status,
-                    interrupt_evt: interrupt_evt,
-                };
-                worker.run(queue_evts.remove(0), kill_evt);
-            });
+            let worker_result = thread::Builder::new()
+                .name("virtio_rng".to_string())
+                .spawn(move || {
+                    let mut worker = Worker {
+                        queue: queue,
+                        mem: mem,
+                        random_file: random_file,
+                        interrupt_status: status,
+                        interrupt_evt: interrupt_evt,
+                    };
+                    worker.run(queue_evts.remove(0), kill_evt);
+                });
+
+            if let Err(e) = worker_result {
+                error!("failed to spawn virtio_rng worker: {}", e);
+                return;
+            }
         }
     }
 }
diff --git a/devices/src/virtio/vhost/net.rs b/devices/src/virtio/vhost/net.rs
index 6fc978e..473c7e8 100644
--- a/devices/src/virtio/vhost/net.rs
+++ b/devices/src/virtio/vhost/net.rs
@@ -7,7 +7,7 @@ use std::net::Ipv4Addr;
 use std::os::unix::io::{AsRawFd, RawFd};
 use std::sync::Arc;
 use std::sync::atomic::AtomicUsize;
-use std::thread::spawn;
+use std::thread;
 
 use net_sys;
 use net_util::Tap;
@@ -173,29 +173,34 @@ impl VirtioDevice for Net {
                 if let Some(vhost_interrupt) = self.vhost_interrupt.take() {
                     if let Some(kill_evt) = self.workers_kill_evt.take() {
                         let acked_features = self.acked_features;
-                        spawn(move || {
-                            let mut worker = Worker::new(
-                                queues,
-                                vhost_net_handle,
-                                vhost_interrupt,
-                                status,
-                                interrupt_evt,
-                                acked_features,
-                            );
-                            let activate_vqs = |handle: &VhostNetHandle| -> Result<()> {
-                                for idx in 0..NUM_QUEUES {
-                                    handle
-                                        .set_backend(idx, &tap)
-                                        .map_err(Error::VhostNetSetBackend)?;
+                        let worker_result = thread::Builder::new()
+                            .name("vhost_net".to_string())
+                            .spawn(move || {
+                                let mut worker = Worker::new(queues,
+                                                             vhost_net_handle,
+                                                             vhost_interrupt,
+                                                             status,
+                                                             interrupt_evt,
+                                                             acked_features);
+                                let activate_vqs = |handle: &VhostNetHandle| -> Result<()> {
+                                    for idx in 0..NUM_QUEUES {
+                                        handle
+                                            .set_backend(idx, &tap)
+                                            .map_err(Error::VhostNetSetBackend)?;
+                                    }
+                                    Ok(())
+                                };
+                                let result =
+                                    worker.run(queue_evts, QUEUE_SIZES, kill_evt, activate_vqs);
+                                if let Err(e) = result {
+                                    error!("net worker thread exited with error: {:?}", e);
                                 }
-                                Ok(())
-                            };
-                            let result =
-                                worker.run(queue_evts, QUEUE_SIZES, kill_evt, activate_vqs);
-                            if let Err(e) = result {
-                                error!("net worker thread exited with error: {:?}", e);
-                            }
-                        });
+                            });
+
+                        if let Err(e) = worker_result {
+                            error!("failed to spawn vhost_net worker: {}", e);
+                            return;
+                        }
                     }
                 }
             }
diff --git a/devices/src/virtio/vhost/vsock.rs b/devices/src/virtio/vhost/vsock.rs
index a3c24aa..b55b6a0 100644
--- a/devices/src/virtio/vhost/vsock.rs
+++ b/devices/src/virtio/vhost/vsock.rs
@@ -5,7 +5,7 @@
 use std::os::unix::io::{AsRawFd, RawFd};
 use std::sync::Arc;
 use std::sync::atomic::AtomicUsize;
-use std::thread::spawn;
+use std::thread;
 
 use byteorder::{ByteOrder, LittleEndian};
 
@@ -182,28 +182,34 @@ impl VirtioDevice for Vsock {
                 if let Some(kill_evt) = self.worker_kill_evt.take() {
                     let acked_features = self.acked_features;
                     let cid = self.cid;
-                    spawn(move || {
-                        // The third vq is an event-only vq that is not handled by the vhost
-                        // subsystem (but still needs to exist).  Split it off here.
-                        let vhost_queues = queues[..2].to_vec();
-                        let mut worker = Worker::new(
-                            vhost_queues,
-                            vhost_handle,
-                            interrupt,
-                            status,
-                            interrupt_evt,
-                            acked_features,
-                        );
-                        let activate_vqs = |handle: &VhostVsockHandle| -> Result<()> {
-                            handle.set_cid(cid).map_err(Error::VhostVsockSetCid)?;
-                            handle.start().map_err(Error::VhostVsockStart)?;
-                            Ok(())
-                        };
-                        let result = worker.run(queue_evts, QUEUE_SIZES, kill_evt, activate_vqs);
-                        if let Err(e) = result {
-                            error!("vsock worker thread exited with error: {:?}", e);
-                        }
-                    });
+                    let worker_result = thread::Builder::new()
+                        .name("vhost_vsock".to_string())
+                        .spawn(move || {
+                            // The third vq is an event-only vq that is not handled by the vhost
+                            // subsystem (but still needs to exist).  Split it off here.
+                            let vhost_queues = queues[..2].to_vec();
+                            let mut worker = Worker::new(vhost_queues,
+                                                         vhost_handle,
+                                                         interrupt,
+                                                         status,
+                                                         interrupt_evt,
+                                                         acked_features);
+                            let activate_vqs = |handle: &VhostVsockHandle| -> Result<()> {
+                                handle.set_cid(cid).map_err(Error::VhostVsockSetCid)?;
+                                handle.start().map_err(Error::VhostVsockStart)?;
+                                Ok(())
+                            };
+                            let result =
+                                worker.run(queue_evts, QUEUE_SIZES, kill_evt, activate_vqs);
+                            if let Err(e) = result {
+                                error!("vsock worker thread exited with error: {:?}", e);
+                            }
+                        });
+
+                    if let Err(e) = worker_result {
+                        error!("failed to spawn vhost_vsock worker: {}", e);
+                        return;
+                    }
                 }
             }
         }
diff --git a/devices/src/virtio/wl.rs b/devices/src/virtio/wl.rs
index 1ea384c..c5a67d7 100644
--- a/devices/src/virtio/wl.rs
+++ b/devices/src/virtio/wl.rs
@@ -44,7 +44,7 @@ use std::rc::Rc;
 use std::result;
 use std::sync::Arc;
 use std::sync::atomic::{AtomicUsize, Ordering};
-use std::thread::spawn;
+use std::thread;
 
 use data_model::*;
 use data_model::VolatileMemoryError;
@@ -1018,16 +1018,23 @@ impl VirtioDevice for Wl {
 
         if let Some(vm_socket) = self.vm_socket.take() {
             let wayland_path = self.wayland_path.clone();
-            spawn(move || {
-                Worker::new(mem,
-                            interrupt_evt,
-                            status,
-                            queues.remove(0),
-                            queues.remove(0),
-                            wayland_path,
-                            vm_socket)
-                        .run(queue_evts, kill_evt);
-            });
+            let worker_result = thread::Builder::new()
+                .name("virtio_wl".to_string())
+                .spawn(move || {
+                    Worker::new(mem,
+                                interrupt_evt,
+                                status,
+                                queues.remove(0),
+                                queues.remove(0),
+                                wayland_path,
+                                vm_socket)
+                            .run(queue_evts, kill_evt);
+                });
+
+            if let Err(e) = worker_result {
+                error!("failed to spawn virtio_wl worker: {}", e);
+                return;
+            }
         }
     }
 }