Skip to content

Commit e725e3b

Browse files
committed
fix: stop double counting jailer time in process_startup_time_cpu_us
In `report_cpu_start_time()`, Firecracker computers the CPU time it took until the API socket was available as CLOCK_PROCESS_CPUTIME_ID - cpu_start_time + jailer_time However, here `cpu_start_time` is always zero currently (it's the value the jailer passes via `--cpu-start-time`), and in the case where the jailer exec()s into Firecracker (without prior fork() or clone()), this is wrong: CLOCK_PROCESS_CPUTIME_ID will now be the CPU time since the _jailer_ process started, and thus adding the jailer_time to it is nonsense. This all works out if we set cpu_start_time to be the CPU time right before we exec() into Firecracker: If we did not fork(), then it will cause the calculation above to correctly discard all time before exec()-ing into Firecracker (before re-adding specifically the time spent in the jailer). If we _did_ fork(), then it will be approximately zero, and thus preserve the current semantics (as the jailer time will only be the time _until_ we did the last fork(), and CLOCK_PROCESS_CPUTIME_ID will only be the absolute CPU time _since_ the last fork()). Signed-off-by: Patrick Roy <[email protected]>
1 parent 95858fb commit e725e3b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/jailer/src/env.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,10 @@ impl Env {
476476
Command::new(chroot_exec_file)
477477
.args(["--id", &self.id])
478478
.args(["--start-time-us", &self.start_time_us.to_string()])
479-
.args(["--start-time-cpu-us", &self.start_time_cpu_us.to_string()])
479+
.args([
480+
"--start-time-cpu-us",
481+
&get_time_us(ClockType::ProcessCpu).to_string(),
482+
])
480483
.args(["--parent-cpu-time-us", &self.jailer_cpu_time_us.to_string()])
481484
.stdin(Stdio::inherit())
482485
.stdout(Stdio::inherit())
@@ -698,8 +701,6 @@ impl Env {
698701
// Compute jailer's total CPU time up to the current time.
699702
self.jailer_cpu_time_us += get_time_us(ClockType::ProcessCpu);
700703
self.jailer_cpu_time_us -= self.start_time_cpu_us;
701-
// Reset process start time.
702-
self.start_time_cpu_us = 0;
703704

704705
// If specified, exec the provided binary into a new PID namespace.
705706
if self.new_pid_ns {

0 commit comments

Comments
 (0)