Skip to content

Commit

Permalink
Support AIX operating system (#123)
Browse files Browse the repository at this point in the history
The physical CPU number detection is done by dividing logical CPU number
with SMT mode.
  • Loading branch information
ecnelises authored May 16, 2023
1 parent edf035c commit f3e7081
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ pub fn get_physical() -> usize {
}


#[cfg(not(any(target_os = "linux", target_os = "windows", target_os="macos", target_os="openbsd")))]
#[cfg(not(any(
target_os = "linux",
target_os = "windows",
target_os = "macos",
target_os = "openbsd",
target_os = "aix")))]
#[inline]
fn get_num_physical_cpus() -> usize {
// Not implemented, fall back
Expand Down Expand Up @@ -327,11 +332,31 @@ fn get_num_physical_cpus() -> usize {
cpus as usize
}

#[cfg(target_os = "aix")]
fn get_num_physical_cpus() -> usize {
match get_smt_threads_aix() {
Some(num) => get_num_cpus() / num,
None => get_num_cpus(),
}
}

#[cfg(target_os = "aix")]
fn get_smt_threads_aix() -> Option<usize> {
let smt = unsafe {
libc::getsystemcfg(libc::SC_SMT_TC)
};
if smt == u64::MAX {
return None;
}
Some(smt as usize)
}

#[cfg(any(
target_os = "nacl",
target_os = "macos",
target_os = "ios",
target_os = "android",
target_os = "aix",
target_os = "solaris",
target_os = "illumos",
target_os = "fuchsia")
Expand Down Expand Up @@ -413,6 +438,7 @@ fn get_num_cpus() -> usize {
target_os = "macos",
target_os = "ios",
target_os = "android",
target_os = "aix",
target_os = "solaris",
target_os = "illumos",
target_os = "fuchsia",
Expand Down

0 comments on commit f3e7081

Please sign in to comment.