From 9cd03ca8e300ecdd263369d374e3bceceefb95a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sat, 31 Oct 2020 19:19:41 +0100 Subject: [PATCH] make scheduler timeslice configurable --- launcher/src/main.rs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/launcher/src/main.rs b/launcher/src/main.rs index bee91c4..080bd30 100644 --- a/launcher/src/main.rs +++ b/launcher/src/main.rs @@ -108,6 +108,14 @@ impl AppConfig for Config { .help("Cycle time (us, append \"s\" or \"ms\" for coarser time)") .takes_value(true), ) + .arg( + clap::Arg::with_name("sched") + .long("sched") + .short("S") + .value_name("MILLIS") + .help("Scheduler switch time (ms, append \"u\", \"s\" or \"ms\" for other unit)") + .takes_value(true), + ) } fn configure(mut self, clap: &ArgMatches) -> anyhow::Result { @@ -126,11 +134,28 @@ impl AppConfig for Config { } else if t.ends_with("s") { (&t[..(t.len()-1)], 1000_000) } else { - (t, 1) + (t, 1) // us default }; self.cycle_time = Duration::from_micros(t.parse::().expect("parse -C value") * mul); - println!("ct = {:?}", self.cycle_time); + } + + if let Some(t) = clap.value_of("sched") { + let (t, mul) = if t.ends_with("us") { + (&t[..(t.len()-2)], 1) + } else if t.ends_with("ms") { + (&t[..(t.len()-2)], 1000) + } else if t.ends_with("m") { + (&t[..(t.len()-1)], 1000) + } else if t.ends_with("u") { + (&t[..(t.len()-1)], 1) + } else if t.ends_with("s") { + (&t[..(t.len()-1)], 1000_000) + } else { + (t, 1000) // ms default + }; + + self.switch_time = Duration::from_micros(t.parse::().expect("parse -S value") * mul); } Ok(self) }