Skip to content

Commit

Permalink
Use getsystemcfg to get SMT threads
Browse files Browse the repository at this point in the history
  • Loading branch information
ecnelises committed Sep 29, 2022
1 parent 35c04d9 commit e9ef120
Showing 1 changed file with 4 additions and 48 deletions.
52 changes: 4 additions & 48 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,57 +342,13 @@ fn get_num_physical_cpus() -> usize {

#[cfg(target_os = "aix")]
fn get_smt_threads_aix() -> Option<usize> {
use std::mem;

const LPAR_INFO_FORMAT1: i32 = 1;

#[repr(C)]
struct lpar_info_format1 {
version: i32,
pad0: i32,
max_memory: u64,
min_memory: u64,
memory_region: u64,
dispatch_wheel_time: u64,
lpar_number: u32,
lpar_flags: u32,
max_pcpus_in_sys: u32,
min_vcpus: u32,
max_vcpus: u32,
min_lcpus: u32,
max_lcpus: u32,
minimum_capacity: u32,
maximum_capacity: u32,
capacity_increment: u32,
smt_threads: u16,
pad1: [u8; 2],
num_lpars: u32,
lpar_name: [u8; 256],
desired_capacity: u32,
desired_vcpus: u32,
desired_memory: u64,
servpar_id: u32,
true_max_memory: u64,
true_min_memory: u64,
ame_max_memory: u64,
ame_min_memory: u64,
spcm_status: u32,
spcm_max: u32,
}

extern "C" {
fn lpar_get_info(command: i32, buffer: *mut libc::c_void, size: usize) -> i32;
}

let mut lpar_info: lpar_info_format1 = unsafe { mem::zeroed() };
let info_size = mem::size_of::<lpar_info_format1>() as usize;
let ret = unsafe {
lpar_get_info(LPAR_INFO_FORMAT1, mem::transmute(&mut lpar_info), info_size)
let smt = unsafe {
libc::getsystemcfg(libc::SC_SMT_TC)
};
if ret != 0 {
if smt == u64::MAX {
return None;
}
Some(lpar_info.smt_threads as usize)
Some(smt as usize)
}

#[cfg(any(
Expand Down

0 comments on commit e9ef120

Please sign in to comment.