Skip to content

Commit a166b7f

Browse files
committed
Revert "chore(docs): deprecate --start-time-cpu-us parameter"
This reverts commit 21f0dea. Signed-off-by: Patrick Roy <[email protected]>
1 parent 635096d commit a166b7f

File tree

6 files changed

+49
-43
lines changed

6 files changed

+49
-43
lines changed

CHANGELOG.md

-8
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,6 @@ and this project adheres to
4646
otherwise use anonymous private memory. This is because serving page faults of
4747
shared memory used by memfd is slower and may impact workloads.
4848

49-
### Deprecated
50-
51-
- Firecracker's `--start-time-cpu-us` parameter is deprecated and will be
52-
removed in v2.0 or later. It is used by the jailer to pass the value that
53-
should be subtracted from the CPU time, but in practice it is always 0. The
54-
parameter was never meant to be used by end customers, and we recommend doing
55-
any such time adjustments outside Firecracker.
56-
5749
### Fixed
5850

5951
- [#4409](https://github.com/firecracker-microvm/firecracker/pull/4409): Fixed a

docs/jailer.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,10 @@ After starting, the Jailer goes through the following operations:
144144
inside `<exec_file_name>.pid`, while the child drops privileges and `exec()`s
145145
into the `<exec_file_name>`, as described below.
146146
- Drop privileges via setting the provided `uid` and `gid`.
147-
- Exec into `<exec_file_name> --id=<id> --start-time-us=<opaque>` (and also
148-
forward any extra arguments provided to the jailer after `--`, as mentioned in
149-
the **Jailer Usage** section), where:
147+
- Exec into
148+
`<exec_file_name> --id=<id> --start-time-us=<opaque> --start-time-cpu-us=<opaque>`
149+
(and also forward any extra arguments provided to the jailer after `--`, as
150+
mentioned in the **Jailer Usage** section), where:
150151
- `id`: (`string`) - The `id` argument provided to jailer.
151152
- `opaque`: (`number`) time calculated by the jailer that it spent doing its
152153
work.
@@ -242,7 +243,8 @@ Finally, the jailer switches the `uid` to `123`, and `gid` to `100`, and execs
242243
```console
243244
./firecracker \
244245
--id="551e7604-e35c-42b3-b825-416853441234" \
245-
--start-time-us=<opaque>
246+
--start-time-us=<opaque> \
247+
--start-time-cpu-us=<opaque>
246248
```
247249

248250
Now firecracker creates the socket at

src/firecracker/src/main.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use utils::terminal::Terminal;
2222
use utils::validators::validate_instance_id;
2323
use vmm::builder::StartMicrovmError;
2424
use vmm::logger::{
25-
debug, error, info, warn, LoggerConfig, ProcessTimeReporter, StoreMetric, LOGGER, METRICS,
25+
debug, error, info, LoggerConfig, ProcessTimeReporter, StoreMetric, LOGGER, METRICS,
2626
};
2727
use vmm::persist::SNAPSHOT_VERSION;
2828
use vmm::resources::VmResources;
@@ -397,7 +397,6 @@ fn main_exec() -> Result<(), MainError> {
397397
});
398398

399399
let start_time_cpu_us = arguments.single_value("start-time-cpu-us").map(|s| {
400-
warn!("The --start-time-cpu-us argument is deprecated");
401400
s.parse::<u64>()
402401
.expect("'start-time-cpu-us' parameter expected to be of 'u64' type.")
403402
});

src/jailer/src/env.rs

+32-22
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ pub struct Env {
125125
daemonize: bool,
126126
new_pid_ns: bool,
127127
start_time_us: u64,
128+
start_time_cpu_us: u64,
128129
jailer_cpu_time_us: u64,
129130
extra_args: Vec<String>,
130131
cgroups: Vec<Box<dyn Cgroup>>,
@@ -160,7 +161,11 @@ impl fmt::Debug for Env {
160161
}
161162

162163
impl Env {
163-
pub fn new(arguments: &arg_parser::Arguments, start_time_us: u64) -> Result<Self, JailerError> {
164+
pub fn new(
165+
arguments: &arg_parser::Arguments,
166+
start_time_us: u64,
167+
start_time_cpu_us: u64,
168+
) -> Result<Self, JailerError> {
164169
// Unwraps should not fail because the arguments are mandatory arguments or with default
165170
// values.
166171
let id = arguments
@@ -285,6 +290,7 @@ impl Env {
285290
daemonize,
286291
new_pid_ns,
287292
start_time_us,
293+
start_time_cpu_us,
288294
jailer_cpu_time_us: 0,
289295
extra_args: arguments.extra_args(),
290296
cgroups,
@@ -496,6 +502,7 @@ impl Env {
496502
Command::new(chroot_exec_file)
497503
.args(["--id", &self.id])
498504
.args(["--start-time-us", &self.start_time_us.to_string()])
505+
.args(["--start-time-cpu-us", &self.start_time_cpu_us.to_string()])
499506
.args(["--parent-cpu-time-us", &self.jailer_cpu_time_us.to_string()])
500507
.stdin(Stdio::inherit())
501508
.stdout(Stdio::inherit())
@@ -723,7 +730,10 @@ impl Env {
723730
}
724731

725732
// Compute jailer's total CPU time up to the current time.
726-
self.jailer_cpu_time_us += utils::time::get_time_us(utils::time::ClockType::ProcessCpu);
733+
self.jailer_cpu_time_us +=
734+
utils::time::get_time_us(utils::time::ClockType::ProcessCpu) - self.start_time_cpu_us;
735+
// Reset process start time.
736+
self.start_time_cpu_us = 0;
727737

728738
// If specified, exec the provided binary into a new PID namespace.
729739
if self.new_pid_ns {
@@ -848,7 +858,7 @@ mod tests {
848858
let arg_parser = build_arg_parser();
849859
let mut args = arg_parser.arguments().clone();
850860
args.parse(&make_args(&ArgVals::new())).unwrap();
851-
Env::new(&args, 0).unwrap()
861+
Env::new(&args, 0, 0).unwrap()
852862
}
853863

854864
#[test]
@@ -862,7 +872,7 @@ mod tests {
862872
args.parse(&make_args(&good_arg_vals)).unwrap();
863873
// This should be fine.
864874
let good_env =
865-
Env::new(&args, 0).expect("This new environment should be created successfully.");
875+
Env::new(&args, 0, 0).expect("This new environment should be created successfully.");
866876

867877
let mut chroot_dir = PathBuf::from(good_arg_vals.chroot_base);
868878
chroot_dir.push(Path::new(good_arg_vals.exec_file).file_name().unwrap());
@@ -887,7 +897,7 @@ mod tests {
887897
let arg_parser = build_arg_parser();
888898
args = arg_parser.arguments().clone();
889899
args.parse(&make_args(&another_good_arg_vals)).unwrap();
890-
let another_good_env = Env::new(&args, 0)
900+
let another_good_env = Env::new(&args, 0, 0)
891901
.expect("This another new environment should be created successfully.");
892902
assert!(!another_good_env.daemonize);
893903
assert!(!another_good_env.new_pid_ns);
@@ -905,7 +915,7 @@ mod tests {
905915
let arg_parser = build_arg_parser();
906916
args = arg_parser.arguments().clone();
907917
args.parse(&make_args(&invalid_cgroup_arg_vals)).unwrap();
908-
Env::new(&args, 0).unwrap_err();
918+
Env::new(&args, 0, 0).unwrap_err();
909919

910920
let invalid_res_limit_arg_vals = ArgVals {
911921
resource_limits: vec!["zzz"],
@@ -915,7 +925,7 @@ mod tests {
915925
let arg_parser = build_arg_parser();
916926
args = arg_parser.arguments().clone();
917927
args.parse(&make_args(&invalid_res_limit_arg_vals)).unwrap();
918-
Env::new(&args, 0).unwrap_err();
928+
Env::new(&args, 0, 0).unwrap_err();
919929

920930
let invalid_id_arg_vals = ArgVals {
921931
id: "/ad./sa12",
@@ -925,7 +935,7 @@ mod tests {
925935
let arg_parser = build_arg_parser();
926936
args = arg_parser.arguments().clone();
927937
args.parse(&make_args(&invalid_id_arg_vals)).unwrap();
928-
Env::new(&args, 0).unwrap_err();
938+
Env::new(&args, 0, 0).unwrap_err();
929939

930940
let inexistent_exec_file_arg_vals = ArgVals {
931941
exec_file: "/this!/file!/should!/not!/exist!/",
@@ -936,7 +946,7 @@ mod tests {
936946
args = arg_parser.arguments().clone();
937947
args.parse(&make_args(&inexistent_exec_file_arg_vals))
938948
.unwrap();
939-
Env::new(&args, 0).unwrap_err();
949+
Env::new(&args, 0, 0).unwrap_err();
940950

941951
let invalid_uid_arg_vals = ArgVals {
942952
uid: "zzz",
@@ -946,7 +956,7 @@ mod tests {
946956
let arg_parser = build_arg_parser();
947957
args = arg_parser.arguments().clone();
948958
args.parse(&make_args(&invalid_uid_arg_vals)).unwrap();
949-
Env::new(&args, 0).unwrap_err();
959+
Env::new(&args, 0, 0).unwrap_err();
950960

951961
let invalid_gid_arg_vals = ArgVals {
952962
gid: "zzz",
@@ -956,7 +966,7 @@ mod tests {
956966
let arg_parser = build_arg_parser();
957967
args = arg_parser.arguments().clone();
958968
args.parse(&make_args(&invalid_gid_arg_vals)).unwrap();
959-
Env::new(&args, 0).unwrap_err();
969+
Env::new(&args, 0, 0).unwrap_err();
960970

961971
let invalid_parent_cg_vals = ArgVals {
962972
parent_cgroup: Some("/root"),
@@ -966,7 +976,7 @@ mod tests {
966976
let arg_parser = build_arg_parser();
967977
args = arg_parser.arguments().clone();
968978
args.parse(&make_args(&invalid_parent_cg_vals)).unwrap();
969-
Env::new(&args, 0).unwrap_err();
979+
Env::new(&args, 0, 0).unwrap_err();
970980

971981
let invalid_controller_pt = ArgVals {
972982
cgroups: vec!["../file_name=1", "./root=1", "/home=1"],
@@ -975,7 +985,7 @@ mod tests {
975985
let arg_parser = build_arg_parser();
976986
args = arg_parser.arguments().clone();
977987
args.parse(&make_args(&invalid_controller_pt)).unwrap();
978-
Env::new(&args, 0).unwrap_err();
988+
Env::new(&args, 0, 0).unwrap_err();
979989

980990
let invalid_format = ArgVals {
981991
cgroups: vec!["./root/", "../root"],
@@ -984,7 +994,7 @@ mod tests {
984994
let arg_parser = build_arg_parser();
985995
args = arg_parser.arguments().clone();
986996
args.parse(&make_args(&invalid_format)).unwrap();
987-
Env::new(&args, 0).unwrap_err();
997+
Env::new(&args, 0, 0).unwrap_err();
988998

989999
// The chroot-base-dir param is not validated by Env::new, but rather in run, when we
9901000
// actually attempt to create the folder structure (the same goes for netns).
@@ -1186,7 +1196,7 @@ mod tests {
11861196
};
11871197
fs::write(exec_file_path, "some_content").unwrap();
11881198
args.parse(&make_args(&some_arg_vals)).unwrap();
1189-
let mut env = Env::new(&args, 0).unwrap();
1199+
let mut env = Env::new(&args, 0, 0).unwrap();
11901200

11911201
// Create the required chroot dir hierarchy.
11921202
fs::create_dir_all(env.chroot_dir()).expect("Could not create dir hierarchy.");
@@ -1248,7 +1258,7 @@ mod tests {
12481258
..good_arg_vals.clone()
12491259
};
12501260
args.parse(&make_args(&invalid_cgroup_arg_vals)).unwrap();
1251-
Env::new(&args, 0).unwrap_err();
1261+
Env::new(&args, 0, 0).unwrap_err();
12521262

12531263
// Check empty string
12541264
let mut args = arg_parser.arguments().clone();
@@ -1257,7 +1267,7 @@ mod tests {
12571267
..good_arg_vals.clone()
12581268
};
12591269
args.parse(&make_args(&invalid_cgroup_arg_vals)).unwrap();
1260-
Env::new(&args, 0).unwrap_err();
1270+
Env::new(&args, 0, 0).unwrap_err();
12611271

12621272
// Check valid file empty value
12631273
let mut args = arg_parser.arguments().clone();
@@ -1266,7 +1276,7 @@ mod tests {
12661276
..good_arg_vals.clone()
12671277
};
12681278
args.parse(&make_args(&invalid_cgroup_arg_vals)).unwrap();
1269-
Env::new(&args, 0).unwrap_err();
1279+
Env::new(&args, 0, 0).unwrap_err();
12701280

12711281
// Check valid file no value
12721282
let mut args = arg_parser.arguments().clone();
@@ -1275,7 +1285,7 @@ mod tests {
12751285
..good_arg_vals.clone()
12761286
};
12771287
args.parse(&make_args(&invalid_cgroup_arg_vals)).unwrap();
1278-
Env::new(&args, 0).unwrap_err();
1288+
Env::new(&args, 0, 0).unwrap_err();
12791289

12801290
// Cases that should succeed
12811291

@@ -1286,7 +1296,7 @@ mod tests {
12861296
..good_arg_vals.clone()
12871297
};
12881298
args.parse(&make_args(&invalid_cgroup_arg_vals)).unwrap();
1289-
Env::new(&args, 0).unwrap();
1299+
Env::new(&args, 0, 0).unwrap();
12901300

12911301
// Check valid case
12921302
let mut args = arg_parser.arguments().clone();
@@ -1295,7 +1305,7 @@ mod tests {
12951305
..good_arg_vals.clone()
12961306
};
12971307
args.parse(&make_args(&invalid_cgroup_arg_vals)).unwrap();
1298-
Env::new(&args, 0).unwrap();
1308+
Env::new(&args, 0, 0).unwrap();
12991309

13001310
// Check file with multiple "."
13011311
let mut args = arg_parser.arguments().clone();
@@ -1304,7 +1314,7 @@ mod tests {
13041314
..good_arg_vals.clone()
13051315
};
13061316
args.parse(&make_args(&invalid_cgroup_arg_vals)).unwrap();
1307-
Env::new(&args, 0).unwrap();
1317+
Env::new(&args, 0, 0).unwrap();
13081318
}
13091319

13101320
#[test]

src/jailer/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ fn main_exec() -> Result<(), JailerError> {
369369
Env::new(
370370
arguments,
371371
utils::time::get_time_us(utils::time::ClockType::Monotonic),
372+
utils::time::get_time_us(utils::time::ClockType::ProcessCpu),
372373
)
373374
.and_then(|env| {
374375
fs::create_dir_all(env.chroot_dir())

src/vmm/src/logger/metrics.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -333,13 +333,15 @@ impl ProcessTimeReporter {
333333

334334
/// Obtain process CPU start time in microseconds.
335335
pub fn report_cpu_start_time(&self) {
336-
let delta_us = utils::time::get_time_us(utils::time::ClockType::ProcessCpu)
337-
- self.start_time_cpu_us.unwrap_or_default()
338-
+ self.parent_cpu_time_us.unwrap_or_default();
339-
METRICS
340-
.api_server
341-
.process_startup_time_cpu_us
342-
.store(delta_us);
336+
if let Some(cpu_start_time) = self.start_time_cpu_us {
337+
let delta_us = utils::time::get_time_us(utils::time::ClockType::ProcessCpu)
338+
- cpu_start_time
339+
+ self.parent_cpu_time_us.unwrap_or_default();
340+
METRICS
341+
.api_server
342+
.process_startup_time_cpu_us
343+
.store(delta_us);
344+
}
343345
}
344346
}
345347

0 commit comments

Comments
 (0)