Skip to content

Commit 5d152eb

Browse files
committed
test(apf): add functional and perf tests
Add integration and performance tests for APF to compare the perf impact Signed-off-by: Jack Thomson <jackabt@amazon.com>
1 parent b4ce748 commit 5d152eb

6 files changed

Lines changed: 862 additions & 9 deletions

File tree

src/firecracker/examples/uffd/uffd_utils.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,6 @@ impl Runtime {
885885
"received bogus offset from firecracker"
886886
);
887887

888-
// Handle one of FaultRequest page faults
889888
pf_vcpu_event_dispatch(
890889
&mut self.handler,
891890
fault_request.offset as usize,

src/vmm/src/builder.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,8 @@ pub fn build_microvm_from_snapshot(
769769
use vmm_sys_util::sock_ctrl_msg::ScmSocket;
770770
if let Some(uff_socket) = uffd_socket {
771771
let broker = UffdMessageBroker::new(uff_socket);
772-
let (contexts, done) = if apf_supported {
772+
let apf_exitless = apf_supported && std::env::var("FC_APF_NO_EXITLESS").is_err();
773+
let (contexts, done) = if apf_exitless {
773774
let mut contexts = Vec::new();
774775
let mut handler_fds = Vec::new();
775776
for &vcpu_fd in &vcpu_fds {

tests/framework/microvm.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,7 @@ def restore_from_snapshot(
10921092
rename_interfaces: dict = None,
10931093
*,
10941094
uffd_handler_name: str = None,
1095+
apf: bool = True,
10951096
):
10961097
"""Restore a snapshot"""
10971098

@@ -1102,6 +1103,7 @@ def restore_from_snapshot(
11021103
self,
11031104
uffd_handler(uffd_handler_name, binary_dir=self.fc_binary_path.parent),
11041105
jailed_snapshot,
1106+
apf=apf,
11051107
)
11061108

11071109
jailed_mem = Path("/") / jailed_snapshot.mem.name
@@ -1308,12 +1310,15 @@ def build(self, kernel=None, rootfs=None, **kwargs):
13081310
vm.ssh_key = ssh_key
13091311
return vm
13101312

1311-
def build_from_snapshot(self, snapshot: Snapshot, uffd_handler_name=None):
1313+
def build_from_snapshot(self, snapshot: Snapshot, uffd_handler_name=None, apf=True):
13121314
"""Build a microvm from a snapshot"""
13131315
vm = self.build()
13141316
vm.spawn()
13151317
vm.restore_from_snapshot(
1316-
snapshot, resume=True, uffd_handler_name=uffd_handler_name
1318+
snapshot,
1319+
resume=True,
1320+
uffd_handler_name=uffd_handler_name,
1321+
apf=apf,
13171322
)
13181323
return vm
13191324

@@ -1323,6 +1328,7 @@ def build_n_from_snapshot(
13231328
nr_vms,
13241329
*,
13251330
uffd_handler_name=None,
1331+
apf=True,
13261332
incremental=False,
13271333
use_snapshot_editor=True,
13281334
no_netns_reuse=False,
@@ -1342,7 +1348,10 @@ def build_n_from_snapshot(
13421348
microvm.spawn()
13431349

13441350
snapshot_copy = microvm.restore_from_snapshot(
1345-
current_snapshot, resume=True, uffd_handler_name=uffd_handler_name
1351+
current_snapshot,
1352+
resume=True,
1353+
uffd_handler_name=uffd_handler_name,
1354+
apf=apf,
13461355
)
13471356

13481357
yield microvm

tests/framework/utils_uffd.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ class UffdHandler:
1919
"""Describe the UFFD page fault handler process."""
2020

2121
def __init__(
22-
self, name, socket_path, snapshot: "Snapshot", chroot_path, log_file_name
22+
self,
23+
name,
24+
socket_path,
25+
snapshot: "Snapshot",
26+
chroot_path,
27+
log_file_name,
28+
apf=True,
2329
):
2430
"""Instantiate the handler process with arguments."""
2531
self._proc = None
@@ -28,6 +34,7 @@ def __init__(
2834
self.snapshot = snapshot
2935
self._chroot = chroot_path
3036
self._log_file = log_file_name
37+
self._apf = apf
3138

3239
def spawn(self, uid, gid):
3340
"""Spawn handler process using arguments provided."""
@@ -42,8 +49,9 @@ def spawn(self, uid, gid):
4249
f"/{self._handler_name}",
4350
self.socket_path,
4451
self.snapshot.mem.name,
45-
APF_SOCKET_PATH,
4652
]
53+
if self._apf:
54+
args.append(APF_SOCKET_PATH)
4755
self._proc = subprocess.Popen(
4856
args, stdout=logfile, stderr=subprocess.STDOUT
4957
)
@@ -99,15 +107,20 @@ def __del__(self):
99107
self.kill()
100108

101109

102-
def spawn_pf_handler(vm, handler_path, jailed_snapshot):
110+
def spawn_pf_handler(vm, handler_path, jailed_snapshot, apf=True):
103111
"""Spawn page fault handler process."""
104112
# Copy snapshot memory file into chroot of microVM.
105113
# Copy the valid page fault binary into chroot of microVM.
106114
jailed_handler = vm.create_jailed_resource(handler_path)
107115
handler_name = os.path.basename(jailed_handler)
108116

109117
uffd_handler = UffdHandler(
110-
handler_name, SOCKET_PATH, jailed_snapshot, vm.chroot(), "uffd.log"
118+
handler_name,
119+
SOCKET_PATH,
120+
jailed_snapshot,
121+
vm.chroot(),
122+
"uffd.log",
123+
apf=apf,
111124
)
112125
uffd_handler.spawn(vm.jailer.uid, vm.jailer.gid)
113126

0 commit comments

Comments
 (0)