mmtk/scheduler/
affinity.rs

1use super::worker::ThreadId;
2use crate::util::options::AffinityKind;
3use crate::util::os::*;
4
5impl AffinityKind {
6    /// Resolve affinity of GC thread. Has a side-effect of calling into the kernel to set the
7    /// thread affinity. Note that we assume that each GC thread is equivalent to an OS or hardware
8    /// thread.
9    pub fn resolve_affinity(&self, thread: ThreadId) {
10        match self {
11            AffinityKind::OsDefault => {}
12            AffinityKind::AllInSet(cpuset) => {
13                // Bind the current thread to all the cores in the set
14                debug!("Set affinity for thread {} to cpuset {:?}", thread, cpuset);
15                OS::bind_current_thread_to_cpuset(cpuset.as_slice());
16            }
17            AffinityKind::RoundRobin(cpuset) => {
18                let cpu = cpuset[thread % cpuset.len()];
19                debug!("Set affinity for thread {} to core {}", thread, cpu);
20                OS::bind_current_thread_to_core(cpu);
21            }
22        }
23    }
24}