Skip to content

Commit

Permalink
fix(virtio/console): process receiveq only when input buffer not empty
Browse files Browse the repository at this point in the history
Signed-off-by: Jose Martins <[email protected]>
  • Loading branch information
josecm authored and joaopeixoto13 committed Sep 28, 2024
1 parent 4bb33eb commit 1fef85d
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/virtio/src/console/virtio/console_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,32 @@ where
// To see why this is done in a loop, please look at the `Queue::enable_notification`
// comments in `virtio_queue`.
loop {
if self.console.is_input_buffer_empty() {
break;
}

// Disable the notifications.
self.input_queue.disable_notification(&self.mem)?;

// Process the queue.
while let Some(mut chain) = self.input_queue.iter(&self.mem.clone())?.next() {
let sent_bytes = self.console.process_receiveq_chain(&mut chain)?;
//println!("Sent bytes: {}", sent_bytes);

if sent_bytes > 0 {
println!("process_input_queue bytes: {}", sent_bytes);
self.input_queue
.add_used(chain.memory(), chain.head_index(), sent_bytes)?;

if self.input_queue.needs_notification(&self.mem)? {
self.driver_notify.signal_used_queue(INPUT_QUEUE_INDEX);
while !self.console.is_input_buffer_empty() {
// Process the queue.
if let Some(mut chain) = self.input_queue.iter(&self.mem.clone())?.next() {
let sent_bytes = self.console.process_receiveq_chain(&mut chain)?;

if sent_bytes > 0 {
self.input_queue.add_used(
chain.memory(),
chain.head_index(),
sent_bytes,
)?;
if self.input_queue.needs_notification(&self.mem)? {
self.driver_notify.signal_used_queue(INPUT_QUEUE_INDEX);
}
} else {
break;
}
} else {
break;
}
}

Expand Down

0 comments on commit 1fef85d

Please sign in to comment.