mmtk/util/os/process.rs
1use std::fmt::Display;
2use std::io::Result;
3
4/// Representation of a CPU core identifier.
5pub type CoreId = u16;
6/// Representation of number of CPU cores.
7pub type CoreNum = u16;
8
9/// Abstraction for OS process operations.
10pub trait OSProcess {
11 /// The process ID type for the OS.
12 type ProcessIDType: Display + Eq + Copy;
13 /// The thread ID type for the OS.
14 type ThreadIDType: Display + Eq + Copy;
15
16 /// Get the memory maps for the process. The returned string is a multi-line string.
17 /// Fallback: This is only used for debugging. For unimplemented cases, this function can return a placeholder Ok value.
18 fn get_process_memory_maps() -> Result<String>;
19
20 /// Get the process ID as a string.
21 /// Fallback: This is only used for debugging. For unimplemented cases, this function can return a placeholder Ok value.
22 fn get_process_id() -> Result<Self::ProcessIDType>;
23
24 //// Get the thread ID as a string.
25 /// Fallback: This is only used for debugging. For unimplemented cases, this function can return a placeholder Ok value.
26 fn get_thread_id() -> Result<Self::ThreadIDType>;
27
28 /// Return the total number of cores allocated to the program.
29 fn get_total_num_cpus() -> CoreNum;
30
31 /// Bind the current thread to the specified core.
32 fn bind_current_thread_to_core(core_id: CoreId);
33
34 /// Bind the current thread to the specified core set.
35 fn bind_current_thread_to_cpuset(core_ids: &[CoreId]);
36}