mirror of
https://github.com/sched-ext/scx.git
synced 2024-11-25 04:00:24 +00:00
topology: TopologyMap: add nr_cpus_online()
Add a method to TopologyMap to get the amount of online CPUs. Considering that most of the schedulers are not handling CPU hotplugging it can be useful to expose also this metric in addition to the amount of available CPUs in the system. Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
This commit is contained in:
parent
f052493005
commit
63feba9c2b
@ -271,28 +271,35 @@ impl Topology {
|
||||
pub struct TopologyMap {
|
||||
map: Vec<Vec<usize>>,
|
||||
nr_cpus_possible: usize,
|
||||
nr_cpus_online: usize,
|
||||
}
|
||||
|
||||
impl TopologyMap {
|
||||
pub fn new(topo: Topology) -> Result<TopologyMap> {
|
||||
let mut map: Vec<Vec<usize>> = Vec::new();
|
||||
let mut nr_cpus_online = 0;
|
||||
|
||||
for core in topo.cores().into_iter() {
|
||||
let mut cpu_ids: Vec<usize> = Vec::new();
|
||||
for cpu_id in core.span().clone().into_iter() {
|
||||
cpu_ids.push(cpu_id);
|
||||
nr_cpus_online += 1;
|
||||
}
|
||||
map.push(cpu_ids);
|
||||
}
|
||||
let nr_cpus_possible = topo.nr_cpus_possible;
|
||||
|
||||
Ok(TopologyMap { map, nr_cpus_possible, })
|
||||
Ok(TopologyMap { map, nr_cpus_possible, nr_cpus_online })
|
||||
}
|
||||
|
||||
pub fn nr_cpus_possible(&self) -> usize {
|
||||
self.nr_cpus_possible
|
||||
}
|
||||
|
||||
pub fn nr_cpus_online(&self) -> usize {
|
||||
self.nr_cpus_online
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> Iter<Vec<usize>> {
|
||||
self.map.iter()
|
||||
}
|
||||
|
@ -290,7 +290,7 @@ impl<'a> Scheduler<'a> {
|
||||
let init_page_faults: u64 = 0;
|
||||
|
||||
// Low-level BPF connector.
|
||||
let nr_online_cpus = topo_map.nr_cpus_possible();
|
||||
let nr_online_cpus = topo_map.nr_cpus_online();
|
||||
let bpf = BpfScheduler::init(
|
||||
opts.slice_us,
|
||||
nr_online_cpus as i32,
|
||||
@ -385,7 +385,7 @@ impl<'a> Scheduler<'a> {
|
||||
//
|
||||
// This allows to survive stress tests that are spawning a massive amount of
|
||||
// tasks.
|
||||
self.eff_slice_boost = (self.slice_boost * self.topo_map.nr_cpus_possible() as u64
|
||||
self.eff_slice_boost = (self.slice_boost * self.topo_map.nr_cpus_online() as u64
|
||||
/ self.task_pool.tasks.len().max(1) as u64)
|
||||
.max(1);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user