diff --git a/cache_utils/Cargo.toml b/cache_utils/Cargo.toml index fb55fac..de8ed53 100644 --- a/cache_utils/Cargo.toml +++ b/cache_utils/Cargo.toml @@ -9,7 +9,7 @@ edition = "2018" [dependencies] polling_serial = { path = "../polling_serial", optional = true } vga_buffer = { path = "../vga_buffer", optional = true } -cpuid = { path = "../cpuid" } +cpuid = { path = "../cpuid", default-features = false } x86_64 = "0.9.2" static_assertions = "1.1.0" itertools = { version = "0.9.0", default-features = false } @@ -18,11 +18,11 @@ nix = { version = "0.17.0", optional = true } libc = { version = "0.2.69", optional = true } [features] -std = ["nix", "itertools/use_std", "libc"] +use_std = ["nix", "itertools/use_std", "libc", "cpuid/use_std"] no_std = ["polling_serial", "vga_buffer"] -default = ["std"] +default = ["use_std"] [[bin]] name = "cache_utils" -required-features = ["std"] +required-features = ["use_std"] diff --git a/cache_utils/src/frequency.rs b/cache_utils/src/frequency.rs index a27fcbc..75313e5 100644 --- a/cache_utils/src/frequency.rs +++ b/cache_utils/src/frequency.rs @@ -1,11 +1,11 @@ use crate::frequency::Error::{Unimplemented, UnsupportedPlatform}; use crate::rdtsc_fence; -#[cfg(all(target_os = "linux", feature = "std"))] +#[cfg(all(target_os = "linux", feature = "use_std"))] use libc::sched_getcpu; -#[cfg(all(target_os = "linux", feature = "std"))] +#[cfg(all(target_os = "linux", feature = "use_std"))] use std::convert::TryInto; -#[cfg(all(target_os = "linux", feature = "std"))] +#[cfg(all(target_os = "linux", feature = "use_std"))] use std::os::raw::{c_uint, c_ulong}; pub enum Error { @@ -14,13 +14,14 @@ pub enum Error { Unimplemented, } -#[cfg(all(target_os = "linux", feature = "std"))] #[link(name = "cpupower")] +#[cfg(all(target_os = "linux", feature = "use_std"))] extern "C" { //unsigned long cpufreq_get_freq_kernel(unsigned int cpu); fn cpufreq_get_freq_kernel(cpu: c_uint) -> c_ulong; } +#[cfg(all(target_os = "linux", feature = "use_std"))] pub fn get_freq_cpufreq_kernel() -> Result { // TODO Add memorization return match unsafe { sched_getcpu() }.try_into() { @@ -29,8 +30,15 @@ pub fn get_freq_cpufreq_kernel() -> Result { }; } +#[cfg(not(all(target_os = "linux", feature = "use_std")))] +pub fn get_freq_cpufreq_kernel() -> Result { + // TODO Add memorization + Err(UnsupportedPlatform) +} + + pub fn get_frequency() -> Result { - if cfg!(target_os = "linux") && cfg!(feature = "std") { + if cfg!(target_os = "linux") && cfg!(feature = "use_std") { return get_freq_cpufreq_kernel(); } diff --git a/cache_utils/src/lib.rs b/cache_utils/src/lib.rs index 9ccdfd5..2d09eff 100644 --- a/cache_utils/src/lib.rs +++ b/cache_utils/src/lib.rs @@ -6,8 +6,8 @@ use static_assertions::assert_cfg; assert_cfg!( all( - not(all(feature = "std", feature = "no_std")), - any(feature = "std", feature = "no_std") + not(all(feature = "use_std", feature = "no_std")), + any(feature = "use_std", feature = "no_std") ), "Choose std or no-std but not both" ); @@ -15,7 +15,7 @@ assert_cfg!( pub mod cache_info; pub mod calibration; pub mod complex_addressing; -#[cfg(feature = "std")] +#[cfg(feature = "use_std")] pub mod mmap; pub mod prefetcher; diff --git a/cache_utils/src/mmap.rs b/cache_utils/src/mmap.rs index b22b915..7727c60 100644 --- a/cache_utils/src/mmap.rs +++ b/cache_utils/src/mmap.rs @@ -1,4 +1,4 @@ -#![cfg(feature = "std")] +#![cfg(feature = "use_std")] use core::borrow::{Borrow, BorrowMut}; use core::ffi::c_void; diff --git a/cpuid/Cargo.toml b/cpuid/Cargo.toml index 8b5d86e..5403adc 100644 --- a/cpuid/Cargo.toml +++ b/cpuid/Cargo.toml @@ -11,12 +11,10 @@ itertools = { version = "0.9.0", default-features = false } #cstr_core = {version = "0.2.0", optional = true, features = ["alloc"] } [features] -std = ["itertools/use_std"] -no_std = [#"cstr_core/alloc" -] +use_std = ["itertools/use_std"] -default = ["std"] +default = ["use_std"] [[bin]] name = "cpuid" -required-features = ["std"] +required-features = ["use_std"] diff --git a/cpuid/src/lib.rs b/cpuid/src/lib.rs index 2fe5324..22ab735 100644 --- a/cpuid/src/lib.rs +++ b/cpuid/src/lib.rs @@ -1,4 +1,4 @@ -#![cfg_attr(feature = "no_std", no_std)] +#![cfg_attr(not(feature = "use_std"), no_std)] // TODO import x86 or x86_64 // TODO no_std