Following are the auxiliary function for creating the different nodes that we append to our FDT.
(
fdt: &mut FdtWriter,
vcpu_mpidr: &[u64],
vcpu_topology: Option<(u16, u16, u16, u16)>,
numa_nodes: &NumaNodes,
)
| 269 | |
| 270 | // Following are the auxiliary function for creating the different nodes that we append to our FDT. |
| 271 | fn create_cpu_nodes( |
| 272 | fdt: &mut FdtWriter, |
| 273 | vcpu_mpidr: &[u64], |
| 274 | vcpu_topology: Option<(u16, u16, u16, u16)>, |
| 275 | numa_nodes: &NumaNodes, |
| 276 | ) -> FdtWriterResult<()> { |
| 277 | // See https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/arm/cpus.yaml. |
| 278 | let cpus_node = fdt.begin_node("cpus")?; |
| 279 | fdt.property_u32("#address-cells", 0x1)?; |
| 280 | fdt.property_u32("#size-cells", 0x0)?; |
| 281 | |
| 282 | let num_cpus = vcpu_mpidr.len(); |
| 283 | let (threads_per_core, cores_per_die, dies_per_package, packages) = |
| 284 | vcpu_topology.unwrap_or((1, 1, 1, 1)); |
| 285 | let cores_per_package = cores_per_die * dies_per_package; |
| 286 | let max_cpus: u32 = |
| 287 | threads_per_core as u32 * cores_per_die as u32 * dies_per_package as u32 * packages as u32; |
| 288 | |
| 289 | // Add cache info. |
| 290 | // L1 Data Cache Info. |
| 291 | let mut l1_d_cache_size: u32 = 0; |
| 292 | let mut l1_d_cache_line_size: u32 = 0; |
| 293 | let mut l1_d_cache_sets: u32 = 0; |
| 294 | |
| 295 | // L1 Instruction Cache Info. |
| 296 | let mut l1_i_cache_size: u32 = 0; |
| 297 | let mut l1_i_cache_line_size: u32 = 0; |
| 298 | let mut l1_i_cache_sets: u32 = 0; |
| 299 | |
| 300 | // L2 Cache Info. |
| 301 | let mut l2_cache_size: u32 = 0; |
| 302 | let mut l2_cache_line_size: u32 = 0; |
| 303 | let mut l2_cache_sets: u32 = 0; |
| 304 | |
| 305 | // L3 Cache Info. |
| 306 | let mut l3_cache_size: u32 = 0; |
| 307 | let mut l3_cache_line_size: u32 = 0; |
| 308 | let mut l3_cache_sets: u32 = 0; |
| 309 | |
| 310 | // Cache Shared Info. |
| 311 | let mut l2_cache_shared: bool = false; |
| 312 | let mut l3_cache_shared: bool = false; |
| 313 | |
| 314 | let cache_path = Path::new("/sys/devices/system/cpu/cpu0/cache"); |
| 315 | let cache_exist: bool = cache_path.exists(); |
| 316 | if cache_exist { |
| 317 | // L1 Data Cache Info. |
| 318 | l1_d_cache_size = get_cache_size(CacheLevel::L1D); |
| 319 | l1_d_cache_line_size = get_cache_coherency_line_size(CacheLevel::L1D); |
| 320 | l1_d_cache_sets = get_cache_number_of_sets(CacheLevel::L1D); |
| 321 | |
| 322 | // L1 Instruction Cache Info. |
| 323 | l1_i_cache_size = get_cache_size(CacheLevel::L1I); |
| 324 | l1_i_cache_line_size = get_cache_coherency_line_size(CacheLevel::L1I); |
| 325 | l1_i_cache_sets = get_cache_number_of_sets(CacheLevel::L1I); |
| 326 | |
| 327 | // L2 Cache Info. |
| 328 | l2_cache_size = get_cache_size(CacheLevel::L2); |
no test coverage detected