|
10 | 10 | import pytest
|
11 | 11 |
|
12 | 12 | import host_tools.drive as drive_tools
|
13 |
| -from framework.utils import CmdBuilder, get_cpu_percent, run_cmd |
| 13 | +from framework.utils import CmdBuilder, ProcessManager, get_cpu_percent, run_cmd |
| 14 | +from framework.utils_vhost_user_backend import ( |
| 15 | + VHOST_USER_SOCKET, |
| 16 | + spawn_vhost_user_backend, |
| 17 | +) |
14 | 18 |
|
15 | 19 | # size of the block device used in the test, in MB
|
16 | 20 | BLOCK_DEVICE_SIZE_MB = 2048
|
@@ -188,3 +192,59 @@ def test_block_performance(
|
188 | 192 | **vm.dimensions,
|
189 | 193 | }
|
190 | 194 | )
|
| 195 | + |
| 196 | + |
| 197 | +def pin_backend(backend, cpu_id: int): |
| 198 | + """Pin the vhost-user backend to a cpu list.""" |
| 199 | + return ProcessManager.set_cpu_affinity(backend.pid, [cpu_id]) |
| 200 | + |
| 201 | + |
| 202 | +@pytest.mark.nonci |
| 203 | +@pytest.mark.parametrize("vcpus", [1, 2], ids=["1vcpu", "2vcpu"]) |
| 204 | +@pytest.mark.parametrize("fio_mode", ["randread", "randwrite"]) |
| 205 | +@pytest.mark.parametrize("fio_block_size", [4096], ids=["bs4096"]) |
| 206 | +def test_block_vhost_user_performance( |
| 207 | + microvm_factory, |
| 208 | + guest_kernel, |
| 209 | + rootfs, |
| 210 | + vcpus, |
| 211 | + fio_mode, |
| 212 | + fio_block_size, |
| 213 | + metrics, |
| 214 | +): |
| 215 | + """ |
| 216 | + Execute block device emulation benchmarking scenarios. |
| 217 | + """ |
| 218 | + vm = microvm_factory.build(guest_kernel, rootfs, monitor_memory=False) |
| 219 | + vm.spawn(log_level="Info") |
| 220 | + vm.basic_config(vcpu_count=vcpus, mem_size_mib=GUEST_MEM_MIB) |
| 221 | + vm.add_net_iface() |
| 222 | + |
| 223 | + # Add a secondary block device for benchmark tests. |
| 224 | + fs = drive_tools.FilesystemFile(size=BLOCK_DEVICE_SIZE_MB) |
| 225 | + backend = spawn_vhost_user_backend(vm, fs.path, readonly=False) |
| 226 | + vm.add_vhost_user_block("scratch", VHOST_USER_SOCKET) |
| 227 | + vm.start() |
| 228 | + |
| 229 | + # Pin uVM threads to physical cores. |
| 230 | + assert vm.pin_vmm(0), "Failed to pin firecracker thread." |
| 231 | + assert vm.pin_api(1), "Failed to pin fc_api thread." |
| 232 | + pin_backend(backend, 2) |
| 233 | + for i in range(vm.vcpus_count): |
| 234 | + assert vm.pin_vcpu(i, i + 3), f"Failed to pin fc_vcpu {i} thread." |
| 235 | + |
| 236 | + logs_dir, cpu_load = run_fio(vm, fio_mode, fio_block_size) |
| 237 | + |
| 238 | + process_fio_logs(vm, fio_mode, logs_dir, metrics) |
| 239 | + |
| 240 | + for cpu_util_data_point in list(cpu_load["firecracker"].values())[0]: |
| 241 | + metrics.put_metric("cpu_utilization_vmm", cpu_util_data_point, "Percent") |
| 242 | + |
| 243 | + metrics.set_dimensions( |
| 244 | + { |
| 245 | + "performance_test": "test_block_vhost_user_performance", |
| 246 | + "fio_mode": fio_mode, |
| 247 | + "fio_block_size": str(fio_block_size), |
| 248 | + **vm.dimensions, |
| 249 | + } |
| 250 | + ) |
0 commit comments