From cfffb7edb061c72dedf0f4180fcfd24bd881b10b Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Thu, 9 Apr 2020 17:49:11 +0200 Subject: [PATCH] vhost_user_backend: Allow for one exit_event per thread By adding the "thread_index" parameter to the function exit_event() from the VhostUserBackend trait, the backend crate now has the ability to ask the backend implementation about the exit event related to a specific thread. Signed-off-by: Sebastien Boeuf --- src/bin/vhost_user_fs.rs | 2 +- vhost_user_backend/src/lib.rs | 6 +++--- vhost_user_block/src/lib.rs | 2 +- vhost_user_net/src/lib.rs | 10 +++++----- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/bin/vhost_user_fs.rs b/src/bin/vhost_user_fs.rs index 002b2a49e..4046e8336 100644 --- a/src/bin/vhost_user_fs.rs +++ b/src/bin/vhost_user_fs.rs @@ -266,7 +266,7 @@ impl VhostUserBackend for VhostUserFsBack Ok(false) } - fn exit_event(&self) -> Option<(EventFd, Option)> { + fn exit_event(&self, _thread_index: usize) -> Option<(EventFd, Option)> { Some(( self.thread.lock().unwrap().kill_evt.try_clone().unwrap(), Some(KILL_EVENT), diff --git a/vhost_user_backend/src/lib.rs b/vhost_user_backend/src/lib.rs index 602fcdaa6..969c7ac83 100644 --- a/vhost_user_backend/src/lib.rs +++ b/vhost_user_backend/src/lib.rs @@ -105,7 +105,7 @@ pub trait VhostUserBackend: Send + Sync + 'static { /// When this EventFd is written to the worker thread will exit. An optional id may /// also be provided, if it not provided then the exit event will be first event id /// after the last queue - fn exit_event(&self) -> Option<(EventFd, Option)> { + fn exit_event(&self, _thread_index: usize) -> Option<(EventFd, Option)> { None } @@ -484,7 +484,7 @@ impl VhostUserHandler { let mut workers = Vec::new(); let mut worker_threads = Vec::new(); - for queues_mask in queues_per_thread.iter() { + for (thread_index, queues_mask) in queues_per_thread.iter().enumerate() { // Create the epoll file descriptor let epoll_fd = epoll::create(true).map_err(VhostUserHandlerError::EpollCreateFd)?; @@ -492,7 +492,7 @@ impl VhostUserHandler { let worker = vring_worker.clone(); let exit_event_id = if let Some((exit_event_fd, exit_event_id)) = - backend.read().unwrap().exit_event() + backend.read().unwrap().exit_event(thread_index) { let exit_event_id = exit_event_id.unwrap_or(num_queues as u16); worker diff --git a/vhost_user_block/src/lib.rs b/vhost_user_block/src/lib.rs index e1c5c11ae..8a35f4b9f 100644 --- a/vhost_user_block/src/lib.rs +++ b/vhost_user_block/src/lib.rs @@ -342,7 +342,7 @@ impl VhostUserBackend for VhostUserBlkBackend { buf.to_vec() } - fn exit_event(&self) -> Option<(EventFd, Option)> { + fn exit_event(&self, _thread_index: usize) -> Option<(EventFd, Option)> { Some(( self.thread.lock().unwrap().kill_evt.try_clone().unwrap(), None, diff --git a/vhost_user_net/src/lib.rs b/vhost_user_net/src/lib.rs index 53d6ced70..8b5eb74bc 100644 --- a/vhost_user_net/src/lib.rs +++ b/vhost_user_net/src/lib.rs @@ -337,17 +337,17 @@ impl VhostUserBackend for VhostUserNetBackend { Ok(false) } - fn exit_event(&self) -> Option<(EventFd, Option)> { - let tap_end_index = (self.num_queues + self.num_queues / 2 - 1) as u16; - let kill_index = tap_end_index + 1; + fn exit_event(&self, thread_index: usize) -> Option<(EventFd, Option)> { + // The exit event is placed after the queues and the tap event, which + // is event index 3. Some(( - self.threads[0] + self.threads[thread_index] .lock() .unwrap() .kill_evt .try_clone() .unwrap(), - Some(kill_index), + Some(3), )) } }