From f3e70815f99bcca7611f6ac18d65cfe9965d23ad Mon Sep 17 00:00:00 2001 From: Qiu Chaofan Date: Wed, 17 May 2023 02:28:28 +0800 Subject: [PATCH] Support AIX operating system (#123) The physical CPU number detection is done by dividing logical CPU number with SMT mode. --- src/lib.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 20474af..fa1267c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 @@ -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 { + 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") @@ -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",