|
1 | 1 | # Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
2 | 2 | # SPDX-License-Identifier: Apache-2.0 |
3 | 3 | """Performance benchmark for snapshot restore.""" |
| 4 | +import signal |
4 | 5 | import tempfile |
| 6 | +import time |
5 | 7 | from dataclasses import dataclass |
6 | 8 | from functools import lru_cache |
7 | 9 |
|
|
11 | 13 | from framework.microvm import Microvm |
12 | 14 |
|
13 | 15 | USEC_IN_MSEC = 1000 |
| 16 | +NS_IN_MSEC = 1_000_000 |
14 | 17 | ITERATIONS = 30 |
15 | 18 |
|
16 | 19 |
|
@@ -88,7 +91,7 @@ def configure_vm(self, microvm_factory, guest_kernel, rootfs, metrics) -> Microv |
88 | 91 | "test_setup", |
89 | 92 | [ |
90 | 93 | SnapshotRestoreTest(mem=128, vcpus=1), |
91 | | - SnapshotRestoreTest(mem=1024, vcpus=1), |
| 94 | + SnapshotRestoreTest(mem=1024, vcpus=2), |
92 | 95 | SnapshotRestoreTest(mem=2048, vcpus=2), |
93 | 96 | SnapshotRestoreTest(mem=4096, vcpus=3), |
94 | 97 | SnapshotRestoreTest(mem=6144, vcpus=4), |
@@ -127,3 +130,38 @@ def test_restore_latency( |
127 | 130 | break |
128 | 131 | assert value > 0 |
129 | 132 | metrics.put_metric("latency", value, "Milliseconds") |
| 133 | + |
| 134 | + |
| 135 | +@pytest.mark.nonci |
| 136 | +@pytest.mark.parametrize("uffd_handler", [None, "valid"]) |
| 137 | +def test_post_restore_latency( |
| 138 | + microvm_factory, rootfs, guest_kernel_linux_5_10, metrics, uffd_handler |
| 139 | +): |
| 140 | + """Collects latency metric of post-restore memory accesses done inside the guest""" |
| 141 | + test_setup = SnapshotRestoreTest(mem=1024, vcpus=2) |
| 142 | + vm = test_setup.configure_vm( |
| 143 | + microvm_factory, guest_kernel_linux_5_10, rootfs, metrics |
| 144 | + ) |
| 145 | + |
| 146 | + vm.ssh.check_output( |
| 147 | + "nohup /usr/local/bin/fast_page_fault_helper >/dev/null 2>&1 </dev/null &" |
| 148 | + ) |
| 149 | + |
| 150 | + # Give helper time to initialize |
| 151 | + time.sleep(5) |
| 152 | + |
| 153 | + snapshot = vm.snapshot_full() |
| 154 | + vm.kill() |
| 155 | + |
| 156 | + for microvm in microvm_factory.build_n_from_snapshot( |
| 157 | + snapshot, ITERATIONS, uffd_handler_name=uffd_handler |
| 158 | + ): |
| 159 | + _, pid, _ = microvm.ssh.check_output("pidof fast_page_fault_helper") |
| 160 | + |
| 161 | + microvm.ssh.check_output(f"kill -s {signal.SIGUSR1} {pid}") |
| 162 | + |
| 163 | + _, duration, _ = microvm.ssh.check_output( |
| 164 | + "while [ ! -f /tmp/fast_page_fault_helper.out ]; do sleep 1; done; cat /tmp/fast_page_fault_helper.out" |
| 165 | + ) |
| 166 | + |
| 167 | + metrics.put_metric("fault_latency", int(duration) / NS_IN_MSEC, "Milliseconds") |
0 commit comments