Skip to content

Commit 774264f

Browse files
committed
Support AIX operating system
The physical CPU number detection is done by dividing logical CPU number with SMT mode.
1 parent 3b6e5f0 commit 774264f

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/lib.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,12 @@ pub fn get_physical() -> usize {
110110
}
111111

112112

113-
#[cfg(not(any(target_os = "linux", target_os = "windows", target_os="macos", target_os="openbsd")))]
113+
#[cfg(not(any(
114+
target_os = "linux",
115+
target_os = "windows",
116+
target_os = "macos",
117+
target_os = "openbsd",
118+
target_os = "aix")))]
114119
#[inline]
115120
fn get_num_physical_cpus() -> usize {
116121
// Not implemented, fall back
@@ -327,11 +332,31 @@ fn get_num_physical_cpus() -> usize {
327332
cpus as usize
328333
}
329334

335+
#[cfg(target_os = "aix")]
336+
fn get_num_physical_cpus() -> usize {
337+
match get_smt_threads_aix() {
338+
Some(num) => get_num_cpus() / num,
339+
None => get_num_cpus(),
340+
}
341+
}
342+
343+
#[cfg(target_os = "aix")]
344+
fn get_smt_threads_aix() -> Option<usize> {
345+
let smt = unsafe {
346+
libc::getsystemcfg(libc::SC_SMT_TC)
347+
};
348+
if smt == u64::MAX {
349+
return None;
350+
}
351+
Some(smt as usize)
352+
}
353+
330354
#[cfg(any(
331355
target_os = "nacl",
332356
target_os = "macos",
333357
target_os = "ios",
334358
target_os = "android",
359+
target_os = "aix",
335360
target_os = "solaris",
336361
target_os = "illumos",
337362
target_os = "fuchsia")
@@ -413,6 +438,7 @@ fn get_num_cpus() -> usize {
413438
target_os = "macos",
414439
target_os = "ios",
415440
target_os = "android",
441+
target_os = "aix",
416442
target_os = "solaris",
417443
target_os = "illumos",
418444
target_os = "fuchsia",

0 commit comments

Comments
 (0)