diff options
| author | Lennard Kittner <lennard@kittner.dev> | 2025-03-09 15:22:44 +0100 |
|---|---|---|
| committer | Lennard Kittner <lennard@kittner.dev> | 2025-03-09 15:23:09 +0100 |
| commit | dac2e1ac162c82bf02be2859e5a5d9860d0ef061 (patch) | |
| tree | d891d732b2251b64eca9f8341cad5902918ca856 | |
| parent | 7af8a52e2ff92518b8c737dfe74d9ed68d5f4943 (diff) | |
Use topology to get core types
| -rw-r--r-- | src/scheduler.rs | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/src/scheduler.rs b/src/scheduler.rs index 6188da1..7645498 100644 --- a/src/scheduler.rs +++ b/src/scheduler.rs @@ -59,22 +59,19 @@ impl<'a> Scheduler<'a> { energy::start_energy_service(use_mocking, power_cap, shared_budgets.clone()); let topology = Topology::new().unwrap(); - - let read_cores = |core_type: &str| { - let e_cores_file = File::open(format!("/sys/devices/cpu_{core_type}/cpus"))?; - let e_cores_reader = BufReader::new(e_cores_file); - let e_cores = if let Some(Ok(line)) = e_cores_reader.lines().next() { - let cores: Vec<&str> = line.split('-').collect(); - cores[0].parse::<i32>().unwrap()..cores[1].parse::<i32>().unwrap() - } else { - panic!( - "Was not able to differentiate between core types. Does the system have e cores?" - ) - }; - Ok::<_, std::io::Error>(e_cores) - }; - let e_cores = read_cores("atom").unwrap_or(0..4); - let p_cores = read_cores("core").unwrap_or(4..8); + let mut e_core_ids = Vec::new(); + let mut p_core_ids = Vec::new(); + for (id, cpu) in &topology.all_cpus { + match cpu.core_type { + scx_utils::CoreType::Big { turbo: _ } => p_core_ids.push(*id as i32), + scx_utils::CoreType::Little => e_core_ids.push(*id as i32), + } + } + // We assume that the CPU IDs for each core type are assigned contiguously. + e_core_ids.sort(); + p_core_ids.sort(); + let e_cores = *e_core_ids.first().unwrap_or(&0)..*e_core_ids.last().unwrap_or(&0); + let p_cores = *p_core_ids.first().unwrap_or(&0)..*p_core_ids.last().unwrap_or(&0); let selector = Box::new(RoundRobinSelector::new(&e_cores)); let to_remove = Vec::with_capacity(1000); |
