Skip to content

Commit 9e0f0d7

Browse files
committed
test(virtio-mem): add performance test
Add a performance test that measures the latency to hot(un)plug different amounts of memory. Signed-off-by: Riccardo Mancini <[email protected]>
1 parent 27692b6 commit 9e0f0d7

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

tests/framework/microvm.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,16 +1207,22 @@ def wait_for_ssh_up(self):
12071207
def hotplug_memory(
12081208
self, requested_size_mib: int, timeout: int = 60, poll: float = 0.1
12091209
):
1210-
"""Send a hot(un)plug request and wait up to timeout seconds for completion polling every poll seconds"""
1210+
"""Send a hot(un)plug request and wait up to timeout seconds for completion polling every poll seconds
1211+
1212+
Returns: api latency (secs), total latency (secs)
1213+
"""
1214+
api_start = time.time()
12111215
self.api.memory_hotplug.patch(requested_size_mib=requested_size_mib)
1216+
api_end = time.time()
12121217
# Wait for the hotplug to complete
12131218
deadline = time.time() + timeout
12141219
while time.time() < deadline:
12151220
if (
12161221
self.api.memory_hotplug.get().json()["plugged_size_mib"]
12171222
== requested_size_mib
12181223
):
1219-
return
1224+
plug_end = time.time()
1225+
return api_end - api_start, plug_end - api_start
12201226
time.sleep(poll)
12211227
raise TimeoutError(f"Hotplug did not complete within {timeout} seconds")
12221228

tests/integration_tests/performance/test_hotplug_memory.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from framework.guest_stats import MeminfoGuest
1616
from framework.microvm import HugePagesConfig
17+
from framework.properties import global_props
1718
from framework.utils import get_kernel_version, get_resident_memory
1819

1920
MEMHP_BOOTARGS = "console=ttyS0 reboot=k panic=1 memhp_default_state=online_movable"
@@ -290,3 +291,76 @@ def test_snapshot_restore_persistence(uvm_plain_6_1, microvm_factory):
290291
assert checksum_before == checksum_after, "Checksums didn't match"
291292

292293
validate_metrics(restored_vm)
294+
295+
296+
def timed_memory_hotplug(uvm, size, metrics, metric_prefix, fc_metric_name):
297+
"""Wait for all memory hotplug events to be processed"""
298+
299+
uvm.flush_metrics()
300+
301+
api_time, total_time = uvm.hotplug_memory(size)
302+
303+
fc_metrics = uvm.flush_metrics()
304+
305+
metrics.put_metric(
306+
f"{metric_prefix}_api_time",
307+
api_time,
308+
unit="Seconds",
309+
)
310+
metrics.put_metric(
311+
f"{metric_prefix}_total_time",
312+
total_time,
313+
unit="Seconds",
314+
)
315+
metrics.put_metric(
316+
f"{metric_prefix}_fc_time",
317+
fc_metrics["memory_hotplug"][fc_metric_name]["sum_us"],
318+
unit="Microseconds",
319+
)
320+
321+
322+
@pytest.mark.nonci
323+
@pytest.mark.parametrize(
324+
"hotplug_size",
325+
[
326+
1024,
327+
2048,
328+
4096,
329+
8192,
330+
16384,
331+
],
332+
)
333+
@pytest.mark.parametrize(
334+
"huge_pages",
335+
[HugePagesConfig.NONE, HugePagesConfig.HUGETLBFS_2MB],
336+
)
337+
def test_memory_hotplug_latency(
338+
microvm_factory, guest_kernel_linux_6_1, rootfs, hotplug_size, huge_pages, metrics
339+
):
340+
"""Test the latency of hotplugging memory"""
341+
342+
for i in range(20):
343+
config = {
344+
"total_size_mib": hotplug_size,
345+
"slot_size_mib": 128,
346+
"block_size_mib": 2,
347+
}
348+
uvm_plain_6_1 = microvm_factory.build(guest_kernel_linux_6_1, rootfs, pci=True)
349+
uvm = uvm_booted_memhp(uvm_plain_6_1, None, None, False, config, None, None)
350+
351+
if i == 0:
352+
metrics.set_dimensions(
353+
{
354+
"instance": global_props.instance,
355+
"cpu_model": global_props.cpu_model,
356+
"host_kernel": f"linux-{global_props.host_linux_version}",
357+
"performance_test": "test_memory_hotplug_latency",
358+
"hotplug_size": str(hotplug_size),
359+
"huge_pages": huge_pages,
360+
**uvm.dimensions,
361+
}
362+
)
363+
364+
timed_memory_hotplug(uvm, hotplug_size, metrics, "hotplug", "plug_agg")
365+
timed_memory_hotplug(uvm, 0, metrics, "hotunplug", "unplug_agg")
366+
timed_memory_hotplug(uvm, hotplug_size, metrics, "hotplug_2nd", "plug_agg")

0 commit comments

Comments
 (0)