Fix compile issues on non std platform

This commit is contained in:
Guillaume DIDIER 2020-05-28 10:01:22 +02:00
parent d102a755ce
commit 3726a2b14c
6 changed files with 25 additions and 19 deletions

View File

@ -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"]

View File

@ -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<u64, Error> {
// TODO Add memorization
return match unsafe { sched_getcpu() }.try_into() {
@ -29,8 +30,15 @@ pub fn get_freq_cpufreq_kernel() -> Result<u64, Error> {
};
}
#[cfg(not(all(target_os = "linux", feature = "use_std")))]
pub fn get_freq_cpufreq_kernel() -> Result<u64, Error> {
// TODO Add memorization
Err(UnsupportedPlatform)
}
pub fn get_frequency() -> Result<u64, Error> {
if cfg!(target_os = "linux") && cfg!(feature = "std") {
if cfg!(target_os = "linux") && cfg!(feature = "use_std") {
return get_freq_cpufreq_kernel();
}

View File

@ -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;

View File

@ -1,4 +1,4 @@
#![cfg(feature = "std")]
#![cfg(feature = "use_std")]
use core::borrow::{Borrow, BorrowMut};
use core::ffi::c_void;

View File

@ -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"]

View File

@ -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