Skip to content

Commit d5dceb7

Browse files
Manciukicbchalios
authored andcommitted
feat(virtio/interrupt): add trigger_queues method
This method is used to notify the guest about queue events in a way that's most performant with the underlying interrupt implementation. As in IrqTrigger there is no distinction between different queues, it's best to send just one interrupt notifiying that "some queues" have a pending event. Conversely, in VirtioInterruptMsix, we need to trigger a MSI for each distinct queue. Signed-off-by: Riccardo Mancini <[email protected]> Signed-off-by: Babis Chalios <[email protected]>
1 parent dfa69db commit d5dceb7

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/vmm/src/devices/virtio/transport/mmio.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,14 @@ impl VirtioInterrupt for IrqTrigger {
406406
}
407407
}
408408

409+
fn trigger_queues(&self, queues: &[u16]) -> Result<(), std::io::Error> {
410+
if queues.is_empty() {
411+
Ok(())
412+
} else {
413+
self.trigger_irq(IrqType::Vring)
414+
}
415+
}
416+
409417
fn notifier(&self, _interrupt_type: VirtioInterruptType) -> Option<&EventFd> {
410418
Some(&self.irq_evt)
411419
}

src/vmm/src/devices/virtio/transport/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ pub trait VirtioInterrupt: std::fmt::Debug + Send + Sync {
2525
/// Trigger a VirtIO interrupt.
2626
fn trigger(&self, interrupt_type: VirtioInterruptType) -> Result<(), std::io::Error>;
2727

28+
/// Trigger multiple Virtio interrupts for selected queues.
29+
/// The caller needs to ensure that [`queues`] does not include duplicate entries to
30+
/// avoid sending multiple interrupts for the same queue.
31+
/// This is to allow sending a single interrupt for implementations that don't
32+
/// distinguish different queues, like IrqTrigger, instead of sending multiple same
33+
/// interrupts.
34+
fn trigger_queues(&self, queues: &[u16]) -> Result<(), std::io::Error> {
35+
queues
36+
.iter()
37+
.try_for_each(|&qidx| self.trigger(VirtioInterruptType::Queue(qidx)))
38+
}
39+
2840
/// Get the `EventFd` (if any) that backs the underlying interrupt.
2941
fn notifier(&self, _interrupt_type: VirtioInterruptType) -> Option<&EventFd> {
3042
None

0 commit comments

Comments
 (0)