Struct TopologyObject

Source
#[repr(C)]
pub struct TopologyObject { /* private fields */ }

Implementations§

Source§

impl TopologyObject

Source

pub fn object_type(&self) -> ObjectType

The type of the object.

Examples found in repository?
examples/processor_cache.rs (line 17)
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}
Source

pub fn memory(&self) -> &TopologyObjectMemory

The memory attributes of the object.

Source

pub fn os_index(&self) -> u32

The OS-provided physical index number.

It is not guaranteed unique across the entire machine, except for PUs and NUMA nodes.

Examples found in repository?
examples/walk_tree.rs (line 15)
13fn print_children(topo: &Topology, obj: &TopologyObject, depth: usize) {
14    let padding = std::iter::repeat(" ").take(depth).collect::<String>();
15    println!("{}{}: #{}", padding, obj, obj.os_index());
16
17    for i in 0..obj.arity() {
18        print_children(topo, obj.children()[i as usize], depth + 1);
19    }
20}
Source

pub fn name(&self) -> String

The name of the object, if set.

Source

pub fn depth(&self) -> u32

Vertical index in the hierarchy.

If the topology is symmetric, this is equal to the parent depth plus one, and also equal to the number of parent/child links from the root object to here.

Source

pub fn logical_index(&self) -> u32

Horizontal index in the whole list of similar objects, hence guaranteed unique across the entire machine.

Could be a “cousin_rank” since it’s the rank within the “cousin” list below.

Source

pub fn sibling_rank(&self) -> u32

This objects index in the parents children list.

Source

pub fn arity(&self) -> u32

The number of direct children.

Examples found in repository?
examples/walk_tree.rs (line 17)
13fn print_children(topo: &Topology, obj: &TopologyObject, depth: usize) {
14    let padding = std::iter::repeat(" ").take(depth).collect::<String>();
15    println!("{}{}: #{}", padding, obj, obj.os_index());
16
17    for i in 0..obj.arity() {
18        print_children(topo, obj.children()[i as usize], depth + 1);
19    }
20}
Source

pub fn symmetric_subtree(&self) -> bool

Set if the subtree of objects below this object is symmetric, which means all children and their children have identical subtrees.

Source

pub fn children(&self) -> Vec<&TopologyObject>

All direct children of this object.

Examples found in repository?
examples/walk_tree.rs (line 18)
13fn print_children(topo: &Topology, obj: &TopologyObject, depth: usize) {
14    let padding = std::iter::repeat(" ").take(depth).collect::<String>();
15    println!("{}{}: #{}", padding, obj, obj.os_index());
16
17    for i in 0..obj.arity() {
18        print_children(topo, obj.children()[i as usize], depth + 1);
19    }
20}
Source

pub fn next_cousin(&self) -> Option<&TopologyObject>

Next object of same type and depth.

Source

pub fn prev_cousin(&self) -> Option<&TopologyObject>

Previous object of same type and depth.

Source

pub fn first_child(&self) -> Option<&TopologyObject>

First child of the next depth.

Source

pub fn last_child(&self) -> Option<&TopologyObject>

Last child of the next depth.

Source

pub fn parent(&self) -> Option<&TopologyObject>

Last child of the next depth.

Examples found in repository?
examples/processor_cache.rs (line 12)
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}
Source

pub fn prev_sibling(&self) -> Option<&TopologyObject>

Previous object below the same parent.

Source

pub fn next_sibling(&self) -> Option<&TopologyObject>

Next object below the same parent.

Source

pub fn cpuset(&self) -> Option<CpuSet>

CPUs covered by this object.

This is the set of CPUs for which there are PU objects in the topology under this object, i.e. which are known to be physically contained in this object and known how (the children path between this object and the PU objects).

Examples found in repository?
examples/bind_threads.rs (line 76)
73fn cpuset_for_core(topology: &Topology, idx: usize) -> CpuSet {
74    let cores = (*topology).objects_with_type(&ObjectType::Core).unwrap();
75    match cores.get(idx) {
76        Some(val) => val.cpuset().unwrap(),
77        None => panic!("No Core found with id {}", idx),
78    }
79}
More examples
Hide additional examples
examples/bind_to_last_core.rs (line 23)
19fn main() {
20    let mut topo = Topology::new();
21
22    // Grab last core and exctract its CpuSet
23    let mut cpuset = last_core(&mut topo).cpuset().unwrap();
24
25    //  Get only one logical processor (in case the core is SMT/hyper-threaded).
26    cpuset.singlify();
27
28    // Print the current cpu binding before explicit setting
29    println!("Cpu Binding before explicit bind: {:?}",
30             topo.get_cpubind(CPUBIND_PROCESS));
31    println!("Cpu Location before explicit bind: {:?}",
32             topo.get_cpu_location(CPUBIND_PROCESS));
33
34    // Try to bind all threads of the current (possibly multithreaded) process.
35    match topo.set_cpubind(cpuset, CPUBIND_PROCESS) {
36        Ok(_) => println!("Correctly bound to last core"),
37        Err(e) => println!("Failed to bind: {:?}", e),
38    }
39
40    // Print the current cpu binding after explicit setting
41    println!("Cpu Binding after explicit bind: {:?}",
42             topo.get_cpubind(CPUBIND_PROCESS));
43    println!("Cpu Location after explicit bind: {:?}",
44             topo.get_cpu_location(CPUBIND_PROCESS));
45}
examples/bind_process.rs (line 21)
12fn main() {
13    let mut topo = Topology::new();
14
15    // load the current pid through libc
16    let pid = get_pid();
17
18    println!("Binding Process with PID {:?}", pid);
19
20    // Grab last core and exctract its CpuSet
21    let mut cpuset = last_core(&mut topo).cpuset().unwrap();
22
23    // Get only one logical processor (in case the core is SMT/hyper-threaded).
24    cpuset.singlify();
25
26    println!("Before Bind: {:?}",
27             topo.get_cpubind_for_process(pid, CPUBIND_PROCESS)
28                 .unwrap());
29
30    // Last CPU Location for this PID (not implemented on all systems)
31    if let Some(l) = topo.get_cpu_location_for_process(pid, CPUBIND_PROCESS) {
32        println!("Last Known CPU Location: {:?}", l);
33    }
34
35    // Bind to one core.
36    topo.set_cpubind_for_process(pid, cpuset, CPUBIND_PROCESS)
37        .unwrap();
38
39    println!("After Bind: {:?}",
40             topo.get_cpubind_for_process(pid, CPUBIND_PROCESS)
41                 .unwrap());
42
43    // Last CPU Location for this PID (not implemented on all systems)
44    if let Some(l) = topo.get_cpu_location_for_process(pid, CPUBIND_PROCESS) {
45        println!("Last Known CPU Location: {:?}", l);
46    }
47}
Source

pub fn complete_cpuset(&self) -> Option<CpuSet>

The complete CPU set of logical processors of this object.

This includes not only the same as the cpuset field, but also the CPUs for which topology information is unknown or incomplete, and the CPUs that are ignored when the HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM flag is not set. Thus no corresponding PU object may be found in the topology, because the precise position is undefined. It is however known that it would be somewhere under this object.

Source

pub fn online_cpuset(&self) -> Option<CpuSet>

The CPU set of online logical processors.

This includes the CPUs contained in this object that are online, i.e. draw power and can execute threads. It may however not be allowed to bind to them due to administration rules, see allowed_cpuset.

Source

pub fn allowed_cpuset(&self) -> Option<CpuSet>

The CPU set of allowed logical processors.

This includes the CPUs contained in this object which are allowed for binding, i.e. passing them to the hwloc binding functions should not return permission errors. This is usually restricted by administration rules. Some of them may however be offline so binding to them may still not be possible, see online_cpuset.

Source

pub fn nodeset(&self) -> Option<NodeSet>

NUMA nodes covered by this object or containing this object.

This is the set of NUMA nodes for which there are NODE objects in the topology under or containing it and known how (the children path between this object and the NODE objects).

In the end, these nodes are those that are close to the current object. If the HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM configuration flag is set, some of these nodes may not be allowed for allocation, see allowed_nodeset.

If there are no NUMA nodes in the machine, all the memory is close to this object, so the nodeset is full.

Source

pub fn complete_nodeset(&self) -> Option<NodeSet>

The complete NUMA node set of this object,.

This includes not only the same as the nodeset field, but also the NUMA nodes for which topology information is unknown or incomplete, and the nodes that are ignored when the HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM flag is not set. Thus no corresponding NODE object may be found in the topology, because the precise position is undefined. It is however known that it would be somewhere under this object.

If there are no NUMA nodes in the machine, all the memory is close to this object, so complete_nodeset is full.

Source

pub fn allowed_nodeset(&self) -> Option<NodeSet>

The set of allowed NUMA memory nodes.

This includes the NUMA memory nodes contained in this object which are allowed for memory allocation, i.e. passing them to NUMA node-directed memory allocation should not return permission errors. This is usually restricted by administration rules.

If there are no NUMA nodes in the machine, all the memory is close to this object, so allowed_nodeset is full.

Source

pub fn cache_attributes(&self) -> Option<&TopologyObjectCacheAttributes>

Examples found in repository?
examples/processor_cache.rs (line 20)
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}

Trait Implementations§

Source§

impl Display for TopologyObject

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.