mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
virtio-devices: make ioeventfds() return an iterator
MSHV's SEV-SNP implementation calls ioeventfds whenever there is an event. This change removes the need frequent allocation and deallocation of a vector, while at the same time makes sure other call sites are unaffected. Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
@@ -9,5 +9,5 @@ pub use pci_common_config::{VirtioPciCommonConfig, VIRTIO_PCI_COMMON_CONFIG_ID};
|
|||||||
pub use pci_device::{VirtioPciDevice, VirtioPciDeviceActivator, VirtioPciDeviceError};
|
pub use pci_device::{VirtioPciDevice, VirtioPciDeviceActivator, VirtioPciDeviceError};
|
||||||
|
|
||||||
pub trait VirtioTransport {
|
pub trait VirtioTransport {
|
||||||
fn ioeventfds(&self, base_addr: u64) -> Vec<(&EventFd, u64)>;
|
fn ioeventfds(&self, base_addr: u64) -> impl Iterator<Item = (&EventFd, u64)>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -830,18 +830,14 @@ impl VirtioPciDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl VirtioTransport for VirtioPciDevice {
|
impl VirtioTransport for VirtioPciDevice {
|
||||||
fn ioeventfds(&self, base_addr: u64) -> Vec<(&EventFd, u64)> {
|
fn ioeventfds(&self, base_addr: u64) -> impl Iterator<Item = (&EventFd, u64)> {
|
||||||
let notify_base = base_addr + NOTIFICATION_BAR_OFFSET;
|
let notify_base = base_addr + NOTIFICATION_BAR_OFFSET;
|
||||||
self.queue_evts()
|
self.queue_evts().iter().enumerate().map(move |(i, event)| {
|
||||||
.iter()
|
(
|
||||||
.enumerate()
|
event,
|
||||||
.map(|(i, event)| {
|
notify_base + i as u64 * u64::from(NOTIFY_OFF_MULTIPLIER),
|
||||||
(
|
)
|
||||||
event,
|
})
|
||||||
notify_base + i as u64 * u64::from(NOTIFY_OFF_MULTIPLIER),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user