Skip to content

Commit

Permalink
vsock: Try processing raw packets on other events too
Browse files Browse the repository at this point in the history
Currently, the `raw_pkts_queue` is processed only when a
`SIBLING_VM_EVENT` is received. But it may happen that the
`raw_pkts_queue` could not be processed completely due to insufficient
space in the RX virtqueue at that time. So, try to process raw packets on
other events too similar to what happens in the RX of standard packets.

Signed-off-by: Priyansh Rathi <[email protected]>
  • Loading branch information
techiepriyansh committed Jul 13, 2023
1 parent 61573f3 commit 808a45e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
29 changes: 27 additions & 2 deletions crates/vsock/src/vhu_vsock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::{
collections::HashMap,
io::{self, Result as IoResult},
ops::DerefMut,
sync::{Arc, Mutex, RwLock},
u16, u32, u64, u8,
};
Expand Down Expand Up @@ -217,6 +218,7 @@ pub(crate) struct VhostUserVsockBackend {
pub threads: Vec<Mutex<VhostUserVsockThread>>,
queues_per_thread: Vec<u64>,
pub exit_event: EventFd,
last_processed: Mutex<RxQueueType>,
}

impl VhostUserVsockBackend {
Expand All @@ -236,6 +238,7 @@ impl VhostUserVsockBackend {
threads: vec![thread],
queues_per_thread,
exit_event: EventFd::new(EFD_NONBLOCK).map_err(Error::EventFdCreate)?,
last_processed: Mutex::new(RxQueueType::Standard),
})
}
}
Expand Down Expand Up @@ -317,8 +320,30 @@ impl VhostUserBackend<VringRwLock, ()> for VhostUserVsockBackend {
}
}

if device_event != EVT_QUEUE_EVENT && thread.thread_backend.pending_rx() {
thread.process_rx(vring_rx, evt_idx)?;
if device_event != EVT_QUEUE_EVENT {
let mut last_processed_lock = self.last_processed.lock().unwrap();
let last_processed = last_processed_lock.deref_mut();

match last_processed {
RxQueueType::Standard => {
if thread.thread_backend.pending_raw_pkts() {
thread.process_raw_pkts(vring_rx, evt_idx)?;
*last_processed = RxQueueType::RawPkts;
}
if thread.thread_backend.pending_rx() {
thread.process_rx(vring_rx, evt_idx)?;
}
}
RxQueueType::RawPkts => {
if thread.thread_backend.pending_rx() {
thread.process_rx(vring_rx, evt_idx)?;
*last_processed = RxQueueType::Standard;
}
if thread.thread_backend.pending_raw_pkts() {
thread.process_raw_pkts(vring_rx, evt_idx)?;
}
}
}
}

Ok(false)
Expand Down
2 changes: 1 addition & 1 deletion crates/vsock/src/vhu_vsock_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use crate::{

type ArcVhostBknd = Arc<VhostUserVsockBackend>;

enum RxQueueType {
pub enum RxQueueType {
Standard,
RawPkts,
}
Expand Down

0 comments on commit 808a45e

Please sign in to comment.