diff --git a/Cargo.lock b/Cargo.lock index 4aae386..8dec534 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,79 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "core_affinity" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a034b3a7b624016c6e13f5df875747cc25f884156aad2abd12b6c46797971342" +dependencies = [ + "libc", + "num_cpus", + "winapi", +] + +[[package]] +name = "hermit-abi" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" + +[[package]] +name = "libc" +version = "0.2.182" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112" + [[package]] name = "lpmd-rewrite" version = "0.1.0" +dependencies = [ + "core_affinity", + "raw-cpuid", +] + +[[package]] +name = "num_cpus" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91df4bbde75afed763b708b7eee1e8e7651e02d97f6d5dd763e89367e957b23b" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "raw-cpuid" +version = "10.6.1" +source = "git+https://github.com/oxidecomputer/rust-cpuid.git#e86d96ba1e63a4c4ecfc521e9fc7a312db0e0c17" +dependencies = [ + "bitflags", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 3fcc692..b0bab27 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,3 +4,5 @@ version = "0.1.0" edition = "2024" [dependencies] +core_affinity = "0.8.3" +raw-cpuid = { git = "https://github.com/oxidecomputer/rust-cpuid.git", version = "10.6.1" } diff --git a/src/cpu.rs b/src/cpu.rs new file mode 100644 index 0000000..f59b207 --- /dev/null +++ b/src/cpu.rs @@ -0,0 +1,44 @@ +use std::{ + collections::HashMap, + string, + sync::{Arc, Mutex}, +}; + +use core_affinity::*; +use std::thread; + +pub struct Cpu { + pub cores: HashMap, +} + +struct CpuCore {} + +enum CoreType { + P, // Performence + E, // Efficent + L, // Low power +} + +impl Cpu { + pub fn new() -> Cpu { + let cpu = Arc::new(Mutex::new(Cpu { + cores: HashMap::new(), + })); + let _ = core_ids + .into_iter() + .map(|id| { + thread::spawn(move || { + // Pin this thread to a single CPU core. + let res = core_affinity::set_for_current(id); + if !res { + return; + } + }) + }) + .collect::>(); + + for handle in handles.into_iter() { + handle.join().unwrap(); + } + } +} diff --git a/src/main.rs b/src/main.rs index e1f8699..03e1203 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,8 @@ +use raw_cpuid::*; +mod cpu; + fn main() { + let a = cpuid!(26, 0); + println!("{:?}", a); println!("Hello, world!"); - meow }