mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
remove dependency of xous-names on ticktimer; use d11ctimeout instead
this allows susres to manage ticktimer and have secured namespace integration
This commit is contained in:
parent
85211bb57d
commit
a4678ee95c
2 changed files with 44 additions and 11 deletions
|
|
@ -13,7 +13,6 @@ num-derive = {version = "0.3", default-features = false}
|
||||||
num-traits = {version = "0.2", default-features = false}
|
num-traits = {version = "0.2", default-features = false}
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
log-server = {path = "../log-server"}
|
log-server = {path = "../log-server"}
|
||||||
ticktimer-server = {path = "../ticktimer-server"}
|
|
||||||
xous = {path = "../../xous-rs"}
|
xous = {path = "../../xous-rs"}
|
||||||
xous-ipc = {path = "../../xous-ipc"}
|
xous-ipc = {path = "../../xous-ipc"}
|
||||||
rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]}
|
rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]}
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,52 @@ use xous_ipc::{String, Buffer};
|
||||||
|
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
|
|
||||||
const FAIL_TIMEOUT_MS: u64 = 100;
|
#[cfg(target_os = "none")]
|
||||||
|
mod implementation {
|
||||||
|
use utralib::generated::*;
|
||||||
|
|
||||||
|
pub struct D11cTimeout {
|
||||||
|
d11t_csr: utralib::CSR<u32>,
|
||||||
|
}
|
||||||
|
impl D11cTimeout {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
let csr = xous::syscall::map_memory(
|
||||||
|
xous::MemoryAddress::new(utra::d11ctime::HW_D11CTIME_BASE),
|
||||||
|
None,
|
||||||
|
4096,
|
||||||
|
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||||
|
)
|
||||||
|
.expect("couldn't map D11cTimeout CSR range");
|
||||||
|
|
||||||
|
D11cTimeout {
|
||||||
|
d11t_csr: CSR::new(csr.as_mut_ptr() as *mut u32),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn deterministic_busy_wait(&self) {
|
||||||
|
let phase = self.d11t_csr.rf(utra::d11ctime::HEARTBEAT_BEAT);
|
||||||
|
while phase == self.d11t_csr.rf(utra::d11ctime::HEARTBEAT_BEAT) {
|
||||||
|
xous::yield_slice();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "none"))]
|
||||||
|
mod implementation {
|
||||||
|
pub struct D11cTimeout {}
|
||||||
|
impl D11cTimeout {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
D11cTimeout {}
|
||||||
|
}
|
||||||
|
pub fn deterministic_busy_wait(&self) {
|
||||||
|
// don't do anything for hosted mode
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[xous::xous_main]
|
#[xous::xous_main]
|
||||||
fn xmain() -> ! {
|
fn xmain() -> ! {
|
||||||
|
use implementation::*;
|
||||||
let debug1 = false;
|
let debug1 = false;
|
||||||
log_server::init_wait().unwrap();
|
log_server::init_wait().unwrap();
|
||||||
log::set_max_level(log::LevelFilter::Info);
|
log::set_max_level(log::LevelFilter::Info);
|
||||||
|
|
@ -28,7 +69,7 @@ fn xmain() -> ! {
|
||||||
let name_server = xous::create_server_with_address(b"xous-name-server")
|
let name_server = xous::create_server_with_address(b"xous-name-server")
|
||||||
.expect("Couldn't create xousnames-server");
|
.expect("Couldn't create xousnames-server");
|
||||||
|
|
||||||
let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer");
|
let d11ctimeout = D11cTimeout::new();
|
||||||
|
|
||||||
// this limits the number of available servers to be requested to 128...!
|
// this limits the number of available servers to be requested to 128...!
|
||||||
let mut name_table = FnvIndexMap::<_, _, U128>::new();
|
let mut name_table = FnvIndexMap::<_, _, U128>::new();
|
||||||
|
|
@ -57,15 +98,8 @@ fn xmain() -> ! {
|
||||||
|
|
||||||
response = api::Return::SID(new_sid.into());
|
response = api::Return::SID(new_sid.into());
|
||||||
} else {
|
} else {
|
||||||
// compute the next interval, rounded to a multiple of FAIL_TIMEOUT_MS to reduce timing side channels
|
|
||||||
let target_time: u64 = ((ticktimer.elapsed_ms()
|
|
||||||
/ FAIL_TIMEOUT_MS)
|
|
||||||
+ 1)
|
|
||||||
* FAIL_TIMEOUT_MS;
|
|
||||||
info!("request failed, waiting for deterministic timeout");
|
info!("request failed, waiting for deterministic timeout");
|
||||||
while ticktimer.elapsed_ms() < target_time {
|
d11ctimeout.deterministic_busy_wait();
|
||||||
xous::yield_slice();
|
|
||||||
}
|
|
||||||
info!("deterministic timeout done");
|
info!("deterministic timeout done");
|
||||||
response = api::Return::Failure
|
response = api::Return::Failure
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue