From 0867e8961e27c39214c004ffa8cac763c6c60600 Mon Sep 17 00:00:00 2001 From: GuillaumeDIDIER Date: Mon, 20 Jul 2020 13:44:12 +0200 Subject: [PATCH] Detect correct number of physical core per socket --- cache_utils/src/bin/two_thread_cal.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cache_utils/src/bin/two_thread_cal.rs b/cache_utils/src/bin/two_thread_cal.rs index da15700..8be51b5 100644 --- a/cache_utils/src/bin/two_thread_cal.rs +++ b/cache_utils/src/bin/two_thread_cal.rs @@ -9,6 +9,8 @@ use nix::sched::{sched_getaffinity, CpuSet}; use nix::unistd::Pid; use core::arch::x86_64 as arch_x86; +use std::process::Command; +use std::str::from_utf8; unsafe fn multiple_access(p: *const u8) { maccess::(p); @@ -26,6 +28,24 @@ const SIZE: usize = 2 << 20; fn main() { // Grab a slice of memory + + let core_per_socket_out = Command::new("sh") + .arg("-c") + .arg("lscpu | grep socket | cut -b 22-") + .output() + .expect("Failed to detect cpu count"); + //println!("{:#?}", core_per_socket_str); + + let core_per_socket_str = from_utf8(&core_per_socket_out.stdout).unwrap(); + + //println!("Number of cores per socket: {}", cps_str); + + let core_per_socket: i32 = core_per_socket_str[0..(core_per_socket_str.len() - 1)] + .parse() + .unwrap_or(0); + + println!("Number of cores per socket: {}", core_per_socket); + let m = MMappedMemory::new(SIZE); let array = m.slice();