diff --git a/init.d/00_ipcd.service b/init.d/00_ipcd.service index 39a359a780..d9252da3ad 100644 --- a/init.d/00_ipcd.service +++ b/init.d/00_ipcd.service @@ -3,4 +3,4 @@ description = "IPC daemon" [service] cmd = "ipcd" -type = "notify" +type = "oneshot_async" diff --git a/init.d/00_pcid-spawner.service b/init.d/00_pcid-spawner.service index 8ba6fc6cec..eb269342b1 100644 --- a/init.d/00_pcid-spawner.service +++ b/init.d/00_pcid-spawner.service @@ -3,4 +3,4 @@ description = "PCI driver spawner" [service] cmd = "pcid-spawner" -type = "oneshot" +type = "oneshot_async" diff --git a/init.d/00_ptyd.service b/init.d/00_ptyd.service index 2879c8ad70..f7138836ac 100644 --- a/init.d/00_ptyd.service +++ b/init.d/00_ptyd.service @@ -3,4 +3,4 @@ description = "PTY daemon" [service] cmd = "ptyd" -type = "notify" +type = "oneshot_async" diff --git a/init.d/10_smolnetd.service b/init.d/10_smolnetd.service index 1ee54ad0e7..7d1ee4d7b9 100644 --- a/init.d/10_smolnetd.service +++ b/init.d/10_smolnetd.service @@ -8,4 +8,4 @@ requires_weak = [ [service] cmd = "netstack" -type = "notify" +type = "oneshot_async" diff --git a/init.d/20_audiod.service b/init.d/20_audiod.service index 68332093d3..4c9da7c425 100644 --- a/init.d/20_audiod.service +++ b/init.d/20_audiod.service @@ -6,4 +6,4 @@ requires_weak = [ [service] cmd = "audiod" -type = { scheme = "audio" } +type = "oneshot_async" diff --git a/init.initfs.d/10_inputd.service b/init.initfs.d/10_inputd.service index ba291046ab..8d1fa9eb31 100644 --- a/init.initfs.d/10_inputd.service +++ b/init.initfs.d/10_inputd.service @@ -3,4 +3,4 @@ description = "VT input and graphics multiplexer" [service] cmd = "inputd" -type = { scheme = "input" } +type = "oneshot_async" diff --git a/init.initfs.d/10_lived.service b/init.initfs.d/10_lived.service index 7745f4b761..7da522a4cb 100644 --- a/init.initfs.d/10_lived.service +++ b/init.initfs.d/10_lived.service @@ -4,4 +4,4 @@ description = "Live disk" [service] cmd = "lived" -type = "notify" +type = "oneshot_async" diff --git a/init.initfs.d/20_fbbootlogd.service b/init.initfs.d/20_fbbootlogd.service index 5a8bf3c820..da16d763a4 100644 --- a/init.initfs.d/20_fbbootlogd.service +++ b/init.initfs.d/20_fbbootlogd.service @@ -4,4 +4,4 @@ requires_weak = ["10_inputd.service", "20_vesad.service"] [service] cmd = "fbbootlogd" -type = { scheme = "fbbootlog" } +type = "oneshot_async" diff --git a/init.initfs.d/20_fbcond.service b/init.initfs.d/20_fbcond.service index 8db3dfdbeb..712c8fd7cd 100644 --- a/init.initfs.d/20_fbcond.service +++ b/init.initfs.d/20_fbcond.service @@ -5,4 +5,4 @@ requires_weak = ["10_inputd.service", "20_vesad.service"] [service] cmd = "fbcond" args = ["2"] -type = { scheme = "fbcon" } +type = "oneshot_async" diff --git a/init.initfs.d/20_vesad.service b/init.initfs.d/20_vesad.service index 4d907c314f..8fa8578d0f 100644 --- a/init.initfs.d/20_vesad.service +++ b/init.initfs.d/20_vesad.service @@ -10,4 +10,4 @@ inherit_envs = [ "FRAMEBUFFER_HEIGHT", "FRAMEBUFFER_STRIDE", ] -type = "notify" +type = "oneshot_async" diff --git a/init.initfs.d/40_bcm2835-sdhcid.service b/init.initfs.d/40_bcm2835-sdhcid.service index 8c05462017..b7ccdc3da8 100644 --- a/init.initfs.d/40_bcm2835-sdhcid.service +++ b/init.initfs.d/40_bcm2835-sdhcid.service @@ -6,4 +6,4 @@ condition_board = ["raspi3bp"] [service] cmd = "bcm2835-sdhcid" -type = "notify" +type = "oneshot_async" diff --git a/init.initfs.d/40_hwd.service b/init.initfs.d/40_hwd.service index cba12dde61..993b303762 100644 --- a/init.initfs.d/40_hwd.service +++ b/init.initfs.d/40_hwd.service @@ -5,4 +5,4 @@ requires_weak = ["10_inputd.service", "10_lived.service", "20_graphics.target"] [service] cmd = "hwd" inherit_envs = ["RSDP_ADDR", "RSDP_SIZE"] -type = "notify" +type = "oneshot_async" diff --git a/init.initfs.d/40_ps2d.service b/init.initfs.d/40_ps2d.service index 881e75ea52..bbee2699ed 100644 --- a/init.initfs.d/40_ps2d.service +++ b/init.initfs.d/40_ps2d.service @@ -5,4 +5,4 @@ condition_architecture = ["x86", "x86_64"] [service] cmd = "ps2d" -type = "notify" +type = "oneshot_async" diff --git a/init/src/main.rs b/init/src/main.rs index 5682cf4455..23ad432de6 100644 --- a/init/src/main.rs +++ b/init/src/main.rs @@ -173,7 +173,17 @@ fn main() { } }; + eprintln!("INIT: starting /usr scheduler step"); + if let Ok(mut f) = std::fs::OpenOptions::new().write(true).open("/scheme/debug/no-preserve") { + use std::io::Write; + let _ = writeln!(f, "BEFORE_STEP"); + } scheduler.step(&mut unit_store, &mut init_config); + eprintln!("INIT: waitpid loop"); + if let Ok(mut f) = std::fs::OpenOptions::new().write(true).open("/scheme/debug/no-preserve") { + use std::io::Write; + let _ = writeln!(f, "AFTER_STEP"); + } libredox::call::setrens(0, 0).expect("init: failed to enter null namespace"); diff --git a/init/src/scheduler.rs b/init/src/scheduler.rs index dc7c21f727..e211e5546c 100644 --- a/init/src/scheduler.rs +++ b/init/src/scheduler.rs @@ -1,4 +1,4 @@ -use std::collections::VecDeque; +use std::collections::{BTreeMap, VecDeque}; use std::io::Write; use crate::InitConfig; @@ -56,34 +56,42 @@ impl Scheduler { } pub fn step(&mut self, unit_store: &mut UnitStore, init_config: &mut InitConfig) { - let mut count: usize = 0; + let mut defer_count: BTreeMap = BTreeMap::new(); 'a: loop { let Some(job) = self.pending.pop_front() else { if let Ok(mut f) = std::fs::OpenOptions::new().write(true).open("/scheme/debug/no-preserve") { - let _ = writeln!(f, "DONE: {} units", count); + let _ = writeln!(f, "STEP_DONE"); } return; }; - count += 1; match job.kind { JobKind::Start => { let unit = unit_store.unit_mut(&job.unit); + let mut blocked = false; for dep in &unit.info.requires_weak { for pending_job in &self.pending { if &pending_job.unit == dep { - self.pending.push_back(job); - continue 'a; + blocked = true; + break; } } + if blocked { break; } + } + + if blocked { + let cnt = defer_count.entry(job.unit.0.clone()).or_insert(0); + *cnt += 1; + if *cnt <= 3 { + self.pending.push_back(job); + continue 'a; + } } run(unit, init_config); - if count % 50 == 0 { - if let Ok(mut f) = std::fs::OpenOptions::new().write(true).open("/scheme/debug/no-preserve") { - let _ = writeln!(f, "LIVE: {} units processed", count); - } + if let Ok(mut f) = std::fs::OpenOptions::new().write(true).open("/scheme/debug/no-preserve") { + let _ = writeln!(f, "RAN {}", unit.id.0); } } }