processor_cache/
processor_cache.rs

1extern crate hwloc;
2
3use hwloc::{Topology, ObjectType};
4
5/// Compute the amount of cache that the first logical processor
6/// has above it.
7fn main() {
8    let topo = Topology::new();
9
10    let pu = topo.objects_with_type(&ObjectType::PU).unwrap()[0];
11
12    let mut parent = pu.parent();
13    let mut levels = 0;
14    let mut size = 0;
15
16    while let Some(p) = parent {
17        if p.object_type() == ObjectType::Cache {
18            levels += 1;
19            // This should actually be size(), but there is a (compiler) bug? with the c-ffi unions
20            size += p.cache_attributes().unwrap().size;
21        }
22        parent = p.parent();
23    }
24
25    println!("*** Logical processor 0 has {} caches totalling {} KB",
26             levels,
27             size / 1024);
28}