mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
performance-metrics: Refactor fio_control to BlockControl
Introduce a new BlockControl struct to encapsulate fio operation parameters. This replaces the tuple-based fio_control with a more extensible structure that includes: - fio_ops: The FIO operation type - bandwidth: Whether to measure bandwidth or IOPS - test_file: The file path to test against This refactoring enables reusing performance_block_io with different test files. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
@@ -162,6 +162,13 @@ impl fmt::Display for PerformanceTestOverrides {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct BlockControl {
|
||||||
|
pub fio_ops: FioOps,
|
||||||
|
pub bandwidth: bool,
|
||||||
|
pub test_file: &'static str,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct PerformanceTestControl {
|
pub struct PerformanceTestControl {
|
||||||
test_timeout: u32,
|
test_timeout: u32,
|
||||||
@@ -169,7 +176,7 @@ pub struct PerformanceTestControl {
|
|||||||
num_queues: Option<u32>,
|
num_queues: Option<u32>,
|
||||||
queue_size: Option<u32>,
|
queue_size: Option<u32>,
|
||||||
net_control: Option<(bool, bool)>, // First bool is for RX(true)/TX(false), second bool is for bandwidth or PPS
|
net_control: Option<(bool, bool)>, // First bool is for RX(true)/TX(false), second bool is for bandwidth or PPS
|
||||||
fio_control: Option<(FioOps, bool)>, // Second parameter controls whether we want bandwidth or IOPS
|
block_control: Option<BlockControl>,
|
||||||
num_boot_vcpus: Option<u8>,
|
num_boot_vcpus: Option<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,9 +196,11 @@ impl fmt::Display for PerformanceTestControl {
|
|||||||
let (rx, bw) = o;
|
let (rx, bw) = o;
|
||||||
output = format!("{output}, rx = {rx}, bandwidth = {bw}");
|
output = format!("{output}, rx = {rx}, bandwidth = {bw}");
|
||||||
}
|
}
|
||||||
if let Some(o) = &self.fio_control {
|
if let Some(o) = &self.block_control {
|
||||||
let (ops, bw) = o;
|
output = format!(
|
||||||
output = format!("{output}, fio_ops = {ops}, bandwidth = {bw}");
|
"{output}, fio_ops = {}, bandwidth = {}, test_file = {}",
|
||||||
|
o.fio_ops, o.bandwidth, o.test_file
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
write!(f, "{output}")
|
write!(f, "{output}")
|
||||||
@@ -206,7 +215,7 @@ impl PerformanceTestControl {
|
|||||||
num_queues: None,
|
num_queues: None,
|
||||||
queue_size: None,
|
queue_size: None,
|
||||||
net_control: None,
|
net_control: None,
|
||||||
fio_control: None,
|
block_control: None,
|
||||||
num_boot_vcpus: Some(1),
|
num_boot_vcpus: Some(1),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -467,7 +476,11 @@ const TEST_LIST: [PerformanceTest; 30] = [
|
|||||||
control: PerformanceTestControl {
|
control: PerformanceTestControl {
|
||||||
num_queues: Some(1),
|
num_queues: Some(1),
|
||||||
queue_size: Some(128),
|
queue_size: Some(128),
|
||||||
fio_control: Some((FioOps::Read, true)),
|
block_control: Some(BlockControl {
|
||||||
|
fio_ops: FioOps::Read,
|
||||||
|
bandwidth: true,
|
||||||
|
test_file: BLK_IO_TEST_IMG,
|
||||||
|
}),
|
||||||
..PerformanceTestControl::default()
|
..PerformanceTestControl::default()
|
||||||
},
|
},
|
||||||
unit_adjuster: adjuster::Bps_to_MiBps,
|
unit_adjuster: adjuster::Bps_to_MiBps,
|
||||||
@@ -478,7 +491,11 @@ const TEST_LIST: [PerformanceTest; 30] = [
|
|||||||
control: PerformanceTestControl {
|
control: PerformanceTestControl {
|
||||||
num_queues: Some(1),
|
num_queues: Some(1),
|
||||||
queue_size: Some(128),
|
queue_size: Some(128),
|
||||||
fio_control: Some((FioOps::Write, true)),
|
block_control: Some(BlockControl {
|
||||||
|
fio_ops: FioOps::Write,
|
||||||
|
bandwidth: true,
|
||||||
|
test_file: BLK_IO_TEST_IMG,
|
||||||
|
}),
|
||||||
..PerformanceTestControl::default()
|
..PerformanceTestControl::default()
|
||||||
},
|
},
|
||||||
unit_adjuster: adjuster::Bps_to_MiBps,
|
unit_adjuster: adjuster::Bps_to_MiBps,
|
||||||
@@ -489,7 +506,11 @@ const TEST_LIST: [PerformanceTest; 30] = [
|
|||||||
control: PerformanceTestControl {
|
control: PerformanceTestControl {
|
||||||
num_queues: Some(1),
|
num_queues: Some(1),
|
||||||
queue_size: Some(128),
|
queue_size: Some(128),
|
||||||
fio_control: Some((FioOps::RandomRead, true)),
|
block_control: Some(BlockControl {
|
||||||
|
fio_ops: FioOps::RandomRead,
|
||||||
|
bandwidth: true,
|
||||||
|
test_file: BLK_IO_TEST_IMG,
|
||||||
|
}),
|
||||||
..PerformanceTestControl::default()
|
..PerformanceTestControl::default()
|
||||||
},
|
},
|
||||||
unit_adjuster: adjuster::Bps_to_MiBps,
|
unit_adjuster: adjuster::Bps_to_MiBps,
|
||||||
@@ -500,7 +521,11 @@ const TEST_LIST: [PerformanceTest; 30] = [
|
|||||||
control: PerformanceTestControl {
|
control: PerformanceTestControl {
|
||||||
num_queues: Some(1),
|
num_queues: Some(1),
|
||||||
queue_size: Some(128),
|
queue_size: Some(128),
|
||||||
fio_control: Some((FioOps::RandomWrite, true)),
|
block_control: Some(BlockControl {
|
||||||
|
fio_ops: FioOps::RandomWrite,
|
||||||
|
bandwidth: true,
|
||||||
|
test_file: BLK_IO_TEST_IMG,
|
||||||
|
}),
|
||||||
..PerformanceTestControl::default()
|
..PerformanceTestControl::default()
|
||||||
},
|
},
|
||||||
unit_adjuster: adjuster::Bps_to_MiBps,
|
unit_adjuster: adjuster::Bps_to_MiBps,
|
||||||
@@ -511,7 +536,11 @@ const TEST_LIST: [PerformanceTest; 30] = [
|
|||||||
control: PerformanceTestControl {
|
control: PerformanceTestControl {
|
||||||
num_queues: Some(2),
|
num_queues: Some(2),
|
||||||
queue_size: Some(128),
|
queue_size: Some(128),
|
||||||
fio_control: Some((FioOps::Read, true)),
|
block_control: Some(BlockControl {
|
||||||
|
fio_ops: FioOps::Read,
|
||||||
|
bandwidth: true,
|
||||||
|
test_file: BLK_IO_TEST_IMG,
|
||||||
|
}),
|
||||||
..PerformanceTestControl::default()
|
..PerformanceTestControl::default()
|
||||||
},
|
},
|
||||||
unit_adjuster: adjuster::Bps_to_MiBps,
|
unit_adjuster: adjuster::Bps_to_MiBps,
|
||||||
@@ -522,7 +551,11 @@ const TEST_LIST: [PerformanceTest; 30] = [
|
|||||||
control: PerformanceTestControl {
|
control: PerformanceTestControl {
|
||||||
num_queues: Some(2),
|
num_queues: Some(2),
|
||||||
queue_size: Some(128),
|
queue_size: Some(128),
|
||||||
fio_control: Some((FioOps::Write, true)),
|
block_control: Some(BlockControl {
|
||||||
|
fio_ops: FioOps::Write,
|
||||||
|
bandwidth: true,
|
||||||
|
test_file: BLK_IO_TEST_IMG,
|
||||||
|
}),
|
||||||
..PerformanceTestControl::default()
|
..PerformanceTestControl::default()
|
||||||
},
|
},
|
||||||
unit_adjuster: adjuster::Bps_to_MiBps,
|
unit_adjuster: adjuster::Bps_to_MiBps,
|
||||||
@@ -533,7 +566,11 @@ const TEST_LIST: [PerformanceTest; 30] = [
|
|||||||
control: PerformanceTestControl {
|
control: PerformanceTestControl {
|
||||||
num_queues: Some(2),
|
num_queues: Some(2),
|
||||||
queue_size: Some(128),
|
queue_size: Some(128),
|
||||||
fio_control: Some((FioOps::RandomRead, true)),
|
block_control: Some(BlockControl {
|
||||||
|
fio_ops: FioOps::RandomRead,
|
||||||
|
bandwidth: true,
|
||||||
|
test_file: BLK_IO_TEST_IMG,
|
||||||
|
}),
|
||||||
..PerformanceTestControl::default()
|
..PerformanceTestControl::default()
|
||||||
},
|
},
|
||||||
unit_adjuster: adjuster::Bps_to_MiBps,
|
unit_adjuster: adjuster::Bps_to_MiBps,
|
||||||
@@ -544,7 +581,11 @@ const TEST_LIST: [PerformanceTest; 30] = [
|
|||||||
control: PerformanceTestControl {
|
control: PerformanceTestControl {
|
||||||
num_queues: Some(2),
|
num_queues: Some(2),
|
||||||
queue_size: Some(128),
|
queue_size: Some(128),
|
||||||
fio_control: Some((FioOps::RandomWrite, true)),
|
block_control: Some(BlockControl {
|
||||||
|
fio_ops: FioOps::RandomWrite,
|
||||||
|
bandwidth: true,
|
||||||
|
test_file: BLK_IO_TEST_IMG,
|
||||||
|
}),
|
||||||
..PerformanceTestControl::default()
|
..PerformanceTestControl::default()
|
||||||
},
|
},
|
||||||
unit_adjuster: adjuster::Bps_to_MiBps,
|
unit_adjuster: adjuster::Bps_to_MiBps,
|
||||||
@@ -555,7 +596,11 @@ const TEST_LIST: [PerformanceTest; 30] = [
|
|||||||
control: PerformanceTestControl {
|
control: PerformanceTestControl {
|
||||||
num_queues: Some(1),
|
num_queues: Some(1),
|
||||||
queue_size: Some(128),
|
queue_size: Some(128),
|
||||||
fio_control: Some((FioOps::Read, false)),
|
block_control: Some(BlockControl {
|
||||||
|
fio_ops: FioOps::Read,
|
||||||
|
bandwidth: false,
|
||||||
|
test_file: BLK_IO_TEST_IMG,
|
||||||
|
}),
|
||||||
..PerformanceTestControl::default()
|
..PerformanceTestControl::default()
|
||||||
},
|
},
|
||||||
unit_adjuster: adjuster::identity,
|
unit_adjuster: adjuster::identity,
|
||||||
@@ -566,7 +611,11 @@ const TEST_LIST: [PerformanceTest; 30] = [
|
|||||||
control: PerformanceTestControl {
|
control: PerformanceTestControl {
|
||||||
num_queues: Some(1),
|
num_queues: Some(1),
|
||||||
queue_size: Some(128),
|
queue_size: Some(128),
|
||||||
fio_control: Some((FioOps::Write, false)),
|
block_control: Some(BlockControl {
|
||||||
|
fio_ops: FioOps::Write,
|
||||||
|
bandwidth: false,
|
||||||
|
test_file: BLK_IO_TEST_IMG,
|
||||||
|
}),
|
||||||
..PerformanceTestControl::default()
|
..PerformanceTestControl::default()
|
||||||
},
|
},
|
||||||
unit_adjuster: adjuster::identity,
|
unit_adjuster: adjuster::identity,
|
||||||
@@ -577,7 +626,11 @@ const TEST_LIST: [PerformanceTest; 30] = [
|
|||||||
control: PerformanceTestControl {
|
control: PerformanceTestControl {
|
||||||
num_queues: Some(1),
|
num_queues: Some(1),
|
||||||
queue_size: Some(128),
|
queue_size: Some(128),
|
||||||
fio_control: Some((FioOps::RandomRead, false)),
|
block_control: Some(BlockControl {
|
||||||
|
fio_ops: FioOps::RandomRead,
|
||||||
|
bandwidth: false,
|
||||||
|
test_file: BLK_IO_TEST_IMG,
|
||||||
|
}),
|
||||||
..PerformanceTestControl::default()
|
..PerformanceTestControl::default()
|
||||||
},
|
},
|
||||||
unit_adjuster: adjuster::identity,
|
unit_adjuster: adjuster::identity,
|
||||||
@@ -588,7 +641,11 @@ const TEST_LIST: [PerformanceTest; 30] = [
|
|||||||
control: PerformanceTestControl {
|
control: PerformanceTestControl {
|
||||||
num_queues: Some(1),
|
num_queues: Some(1),
|
||||||
queue_size: Some(128),
|
queue_size: Some(128),
|
||||||
fio_control: Some((FioOps::RandomWrite, false)),
|
block_control: Some(BlockControl {
|
||||||
|
fio_ops: FioOps::RandomWrite,
|
||||||
|
bandwidth: false,
|
||||||
|
test_file: BLK_IO_TEST_IMG,
|
||||||
|
}),
|
||||||
..PerformanceTestControl::default()
|
..PerformanceTestControl::default()
|
||||||
},
|
},
|
||||||
unit_adjuster: adjuster::identity,
|
unit_adjuster: adjuster::identity,
|
||||||
@@ -599,7 +656,11 @@ const TEST_LIST: [PerformanceTest; 30] = [
|
|||||||
control: PerformanceTestControl {
|
control: PerformanceTestControl {
|
||||||
num_queues: Some(2),
|
num_queues: Some(2),
|
||||||
queue_size: Some(128),
|
queue_size: Some(128),
|
||||||
fio_control: Some((FioOps::Read, false)),
|
block_control: Some(BlockControl {
|
||||||
|
fio_ops: FioOps::Read,
|
||||||
|
bandwidth: false,
|
||||||
|
test_file: BLK_IO_TEST_IMG,
|
||||||
|
}),
|
||||||
..PerformanceTestControl::default()
|
..PerformanceTestControl::default()
|
||||||
},
|
},
|
||||||
unit_adjuster: adjuster::identity,
|
unit_adjuster: adjuster::identity,
|
||||||
@@ -610,7 +671,11 @@ const TEST_LIST: [PerformanceTest; 30] = [
|
|||||||
control: PerformanceTestControl {
|
control: PerformanceTestControl {
|
||||||
num_queues: Some(2),
|
num_queues: Some(2),
|
||||||
queue_size: Some(128),
|
queue_size: Some(128),
|
||||||
fio_control: Some((FioOps::Write, false)),
|
block_control: Some(BlockControl {
|
||||||
|
fio_ops: FioOps::Write,
|
||||||
|
bandwidth: false,
|
||||||
|
test_file: BLK_IO_TEST_IMG,
|
||||||
|
}),
|
||||||
..PerformanceTestControl::default()
|
..PerformanceTestControl::default()
|
||||||
},
|
},
|
||||||
unit_adjuster: adjuster::identity,
|
unit_adjuster: adjuster::identity,
|
||||||
@@ -621,7 +686,11 @@ const TEST_LIST: [PerformanceTest; 30] = [
|
|||||||
control: PerformanceTestControl {
|
control: PerformanceTestControl {
|
||||||
num_queues: Some(2),
|
num_queues: Some(2),
|
||||||
queue_size: Some(128),
|
queue_size: Some(128),
|
||||||
fio_control: Some((FioOps::RandomRead, false)),
|
block_control: Some(BlockControl {
|
||||||
|
fio_ops: FioOps::RandomRead,
|
||||||
|
bandwidth: false,
|
||||||
|
test_file: BLK_IO_TEST_IMG,
|
||||||
|
}),
|
||||||
..PerformanceTestControl::default()
|
..PerformanceTestControl::default()
|
||||||
},
|
},
|
||||||
unit_adjuster: adjuster::identity,
|
unit_adjuster: adjuster::identity,
|
||||||
@@ -632,7 +701,11 @@ const TEST_LIST: [PerformanceTest; 30] = [
|
|||||||
control: PerformanceTestControl {
|
control: PerformanceTestControl {
|
||||||
num_queues: Some(2),
|
num_queues: Some(2),
|
||||||
queue_size: Some(128),
|
queue_size: Some(128),
|
||||||
fio_control: Some((FioOps::RandomWrite, false)),
|
block_control: Some(BlockControl {
|
||||||
|
fio_ops: FioOps::RandomWrite,
|
||||||
|
bandwidth: false,
|
||||||
|
test_file: BLK_IO_TEST_IMG,
|
||||||
|
}),
|
||||||
..PerformanceTestControl::default()
|
..PerformanceTestControl::default()
|
||||||
},
|
},
|
||||||
unit_adjuster: adjuster::identity,
|
unit_adjuster: adjuster::identity,
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ enum Error {
|
|||||||
|
|
||||||
// The test image cannot be created on tmpfs (e.g. /tmp) filesystem,
|
// The test image cannot be created on tmpfs (e.g. /tmp) filesystem,
|
||||||
// as tmpfs does not support O_DIRECT
|
// as tmpfs does not support O_DIRECT
|
||||||
const BLK_IO_TEST_IMG: &str = "/var/tmp/ch-blk-io-test.img";
|
pub const BLK_IO_TEST_IMG: &str = "/var/tmp/ch-blk-io-test.img";
|
||||||
|
|
||||||
pub fn init_tests(overrides: &PerformanceTestOverrides) {
|
pub fn init_tests(overrides: &PerformanceTestOverrides) {
|
||||||
let mut cmd = format!("dd if=/dev/zero of={BLK_IO_TEST_IMG} bs=1M count=4096");
|
let mut cmd = format!("dd if=/dev/zero of={BLK_IO_TEST_IMG} bs=1M count=4096");
|
||||||
@@ -366,7 +366,10 @@ pub fn performance_block_io(control: &PerformanceTestControl) -> f64 {
|
|||||||
let test_timeout = control.test_timeout;
|
let test_timeout = control.test_timeout;
|
||||||
let num_queues = control.num_queues.unwrap();
|
let num_queues = control.num_queues.unwrap();
|
||||||
let queue_size = control.queue_size.unwrap();
|
let queue_size = control.queue_size.unwrap();
|
||||||
let (fio_ops, bandwidth) = control.fio_control.as_ref().unwrap();
|
let block_control = control.block_control.as_ref().unwrap();
|
||||||
|
let fio_ops = &block_control.fio_ops;
|
||||||
|
let bandwidth = block_control.bandwidth;
|
||||||
|
let test_file = block_control.test_file;
|
||||||
|
|
||||||
let focal = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_string());
|
let focal = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_string());
|
||||||
let guest = performance_test_new_guest(Box::new(focal));
|
let guest = performance_test_new_guest(Box::new(focal));
|
||||||
@@ -395,8 +398,7 @@ pub fn performance_block_io(control: &PerformanceTestControl) -> f64 {
|
|||||||
guest.disk_config.disk(DiskType::CloudInit).unwrap()
|
guest.disk_config.disk(DiskType::CloudInit).unwrap()
|
||||||
)
|
)
|
||||||
.as_str(),
|
.as_str(),
|
||||||
format!("path={BLK_IO_TEST_IMG},queue_size={queue_size},num_queues={num_queues}")
|
format!("path={test_file},queue_size={queue_size},num_queues={num_queues}").as_str(),
|
||||||
.as_str(),
|
|
||||||
])
|
])
|
||||||
.default_net()
|
.default_net()
|
||||||
.args(["--api-socket", &api_socket])
|
.args(["--api-socket", &api_socket])
|
||||||
@@ -420,7 +422,7 @@ pub fn performance_block_io(control: &PerformanceTestControl) -> f64 {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Parse fio output
|
// Parse fio output
|
||||||
if *bandwidth {
|
if bandwidth {
|
||||||
parse_fio_output(&output, fio_ops, num_queues).unwrap()
|
parse_fio_output(&output, fio_ops, num_queues).unwrap()
|
||||||
} else {
|
} else {
|
||||||
parse_fio_output_iops(&output, fio_ops, num_queues).unwrap()
|
parse_fio_output_iops(&output, fio_ops, num_queues).unwrap()
|
||||||
|
|||||||
Reference in New Issue
Block a user