scx_nitosis/topology.rs
1// Copyright (c) Meta Platforms, Inc. and affiliates.
2
3// This software may be used and distributed according to the terms of the
4// GNU General Public License version 2.
5
6use std::collections::BTreeMap;
7
8use scx_utils::Topology;
9
10/*
11 * The BPF side derives its LLC and shard layout from the kernel cid tables in
12 * ops.init(). Userspace only keeps the cpu-to-LLC map for the cell manager's
13 * reporting.
14 */
15pub struct MitosisTopology {
16 pub cpu_to_llc: BTreeMap<usize, usize>,
17}
18
19impl MitosisTopology {
20 pub fn new(topology: &Topology) -> Self {
21 let mut cpu_to_llc = BTreeMap::new();
22 for cpu in 0..*scx_utils::NR_CPUS_POSSIBLE {
23 cpu_to_llc.insert(
24 cpu,
25 topology
26 .all_cpus
27 .get(&cpu)
28 .map(|cpu| cpu.llc_id)
29 .unwrap_or(0),
30 );
31 }
32
33 MitosisTopology { cpu_to_llc }
34 }
35}