#[repr(C)]pub struct TopologyObject { /* private fields */ }Implementations§
Source§impl TopologyObject
impl TopologyObject
Sourcepub fn object_type(&self) -> ObjectType
pub fn object_type(&self) -> ObjectType
The type of the object.
Examples found in repository?
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}Sourcepub fn memory(&self) -> &TopologyObjectMemory
pub fn memory(&self) -> &TopologyObjectMemory
The memory attributes of the object.
Sourcepub fn os_index(&self) -> u32
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.
Sourcepub fn depth(&self) -> u32
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.
Sourcepub fn logical_index(&self) -> u32
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.
Sourcepub fn sibling_rank(&self) -> u32
pub fn sibling_rank(&self) -> u32
This objects index in the parents children list.
Sourcepub fn symmetric_subtree(&self) -> bool
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.
Sourcepub fn children(&self) -> Vec<&TopologyObject>
pub fn children(&self) -> Vec<&TopologyObject>
All direct children of this object.
Sourcepub fn next_cousin(&self) -> Option<&TopologyObject>
pub fn next_cousin(&self) -> Option<&TopologyObject>
Next object of same type and depth.
Sourcepub fn prev_cousin(&self) -> Option<&TopologyObject>
pub fn prev_cousin(&self) -> Option<&TopologyObject>
Previous object of same type and depth.
Sourcepub fn first_child(&self) -> Option<&TopologyObject>
pub fn first_child(&self) -> Option<&TopologyObject>
First child of the next depth.
Sourcepub fn last_child(&self) -> Option<&TopologyObject>
pub fn last_child(&self) -> Option<&TopologyObject>
Last child of the next depth.
Sourcepub fn parent(&self) -> Option<&TopologyObject>
pub fn parent(&self) -> Option<&TopologyObject>
Last child of the next depth.
Examples found in repository?
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}Sourcepub fn prev_sibling(&self) -> Option<&TopologyObject>
pub fn prev_sibling(&self) -> Option<&TopologyObject>
Previous object below the same parent.
Sourcepub fn next_sibling(&self) -> Option<&TopologyObject>
pub fn next_sibling(&self) -> Option<&TopologyObject>
Next object below the same parent.
Sourcepub fn cpuset(&self) -> Option<CpuSet>
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?
More examples
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}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}Sourcepub fn complete_cpuset(&self) -> Option<CpuSet>
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.
Sourcepub fn online_cpuset(&self) -> Option<CpuSet>
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.
Sourcepub fn allowed_cpuset(&self) -> Option<CpuSet>
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.
Sourcepub fn nodeset(&self) -> Option<NodeSet>
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.
Sourcepub fn complete_nodeset(&self) -> Option<NodeSet>
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.
Sourcepub fn allowed_nodeset(&self) -> Option<NodeSet>
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.
Sourcepub fn cache_attributes(&self) -> Option<&TopologyObjectCacheAttributes>
pub fn cache_attributes(&self) -> Option<&TopologyObjectCacheAttributes>
Examples found in repository?
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}