summary refs log tree commit diff
path: root/devices/src/virtio/vhost/vsock.rs
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/src/virtio/vhost/vsock.rs
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/src/virtio/vhost/vsock.rs')
-rw-r--r--devices/src/virtio/vhost/vsock.rs52
1 files changed, 29 insertions, 23 deletions
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;
+                    }
                 }
             }
         }