allow configuring size of virtio queues
This commit is contained in:
parent
90e1b26a11
commit
07d1c765d4
@ -6,6 +6,7 @@ use super::{VirtioDevice,VirtioDeviceOps,PciIrq};
|
|||||||
use super::consts::*;
|
use super::consts::*;
|
||||||
use super::pci::PciBus;
|
use super::pci::PciBus;
|
||||||
use crate::vm::Result;
|
use crate::vm::Result;
|
||||||
|
use std::iter;
|
||||||
|
|
||||||
|
|
||||||
pub struct VirtioBus {
|
pub struct VirtioBus {
|
||||||
@ -43,7 +44,7 @@ pub struct VirtioDeviceConfig<'a> {
|
|||||||
kvm: Kvm,
|
kvm: Kvm,
|
||||||
ops: Arc<RwLock<dyn VirtioDeviceOps>>,
|
ops: Arc<RwLock<dyn VirtioDeviceOps>>,
|
||||||
mmio: AddressRange,
|
mmio: AddressRange,
|
||||||
num_queues: usize,
|
queue_sizes: Vec<usize>,
|
||||||
config_size: usize,
|
config_size: usize,
|
||||||
device_class: u16,
|
device_class: u16,
|
||||||
features: u64,
|
features: u64,
|
||||||
@ -61,7 +62,7 @@ impl <'a> VirtioDeviceConfig<'a> {
|
|||||||
kvm,
|
kvm,
|
||||||
ops,
|
ops,
|
||||||
mmio,
|
mmio,
|
||||||
num_queues: 0,
|
queue_sizes: Vec::new(),
|
||||||
config_size: 0,
|
config_size: 0,
|
||||||
features: 0,
|
features: 0,
|
||||||
device_class: 0x0880,
|
device_class: 0x0880,
|
||||||
@ -100,7 +101,11 @@ impl <'a> VirtioDeviceConfig<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn num_queues(&self) -> usize {
|
pub fn num_queues(&self) -> usize {
|
||||||
self.num_queues
|
self.queue_sizes.len()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn queue_sizes(&self) -> &[usize] {
|
||||||
|
&self.queue_sizes
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
@ -108,8 +113,15 @@ impl <'a> VirtioDeviceConfig<'a> {
|
|||||||
self.config_size
|
self.config_size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_queue_sizes(&mut self, sizes: &[usize]) -> &'a mut VirtioDeviceConfig {
|
||||||
|
self.queue_sizes.clear();
|
||||||
|
self.queue_sizes.extend_from_slice(sizes);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_num_queues(&mut self, n: usize) -> &'a mut VirtioDeviceConfig {
|
pub fn set_num_queues(&mut self, n: usize) -> &'a mut VirtioDeviceConfig {
|
||||||
self.num_queues = n;
|
self.queue_sizes.clear();
|
||||||
|
self.queue_sizes.extend(iter::repeat(DEFAULT_QUEUE_SIZE as usize).take(n));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ use super::eventfd::IoEventFd;
|
|||||||
use super::vring::Vring;
|
use super::vring::Vring;
|
||||||
use super::virtqueue::InterruptLine;
|
use super::virtqueue::InterruptLine;
|
||||||
use super::bus::VirtioDeviceConfig;
|
use super::bus::VirtioDeviceConfig;
|
||||||
use super::consts::DEFAULT_QUEUE_SIZE;
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Manages a set of virtqueues during device intitialization.
|
/// Manages a set of virtqueues during device intitialization.
|
||||||
@ -28,7 +27,7 @@ impl VirtQueueConfig {
|
|||||||
num_queues: dev_config.num_queues(),
|
num_queues: dev_config.num_queues(),
|
||||||
selected_queue: 0,
|
selected_queue: 0,
|
||||||
enabled_features: 0,
|
enabled_features: 0,
|
||||||
vrings: create_vrings(memory,dev_config.num_queues()),
|
vrings: create_vrings(memory,dev_config.queue_sizes()),
|
||||||
interrupt: InterruptLine::from_config(&dev_config)?,
|
interrupt: InterruptLine::from_config(&dev_config)?,
|
||||||
events: create_ioeventfds(&dev_config)?,
|
events: create_ioeventfds(&dev_config)?,
|
||||||
})
|
})
|
||||||
@ -123,10 +122,10 @@ fn create_ioeventfds(conf: &VirtioDeviceConfig) -> Result<Vec<Arc<IoEventFd>>> {
|
|||||||
Ok(v)
|
Ok(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_vrings(memory: &GuestRam, n: usize) -> Vec<Vring> {
|
fn create_vrings(memory: &GuestRam, queue_sizes: &[usize]) -> Vec<Vring> {
|
||||||
let mut v = Vec::with_capacity(n);
|
let mut v = Vec::with_capacity(queue_sizes.len());
|
||||||
for _ in 0..n {
|
for &sz in queue_sizes {
|
||||||
v.push(Vring::new(memory.clone(), DEFAULT_QUEUE_SIZE));
|
v.push(Vring::new(memory.clone(), sz as u16))
|
||||||
}
|
}
|
||||||
v
|
v
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user