Skip to content

Commit 6512ffb

Browse files
committed
misc: vm: pre-allocate irq routing entries
Do a single allocation when setting irq routing instead of pushing to KvmIrqRouting multiple times. Saves us from dynamic re-alloations. Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
1 parent ecd5ea9 commit 6512ffb

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

src/vmm/src/vstate/vm.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -714,13 +714,10 @@ impl KvmVm {
714714
/// Set GSI routes to KVM
715715
pub fn set_gsi_routes(&self) -> Result<(), InterruptError> {
716716
let entries = self.common.interrupts.lock().expect("Poisoned lock");
717-
let mut routes = KvmIrqRouting::new(0)?;
718-
719-
for entry in entries.values() {
720-
if entry.masked {
721-
continue;
722-
}
723-
routes.push(entry.entry)?;
717+
let unmasked = entries.values().filter(|e| !e.masked).count();
718+
let mut routes = KvmIrqRouting::new(unmasked)?;
719+
for (slot, entry) in entries.values().filter(|e| !e.masked).enumerate() {
720+
routes.as_mut_slice()[slot] = entry.entry;
724721
}
725722

726723
self.common.fd.set_gsi_routing(&routes)?;

0 commit comments

Comments
 (0)