mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
sha512 tests fully implemented, working through sus/res
note: sha512 will fail if a suspend is forced upon it!! but it will vociferously complain if this happens.
This commit is contained in:
parent
5526bc4100
commit
58edcc56f2
7 changed files with 50 additions and 8 deletions
|
|
@ -77,6 +77,17 @@ mod implementation {
|
|||
let sha = self.fifo.as_mut_ptr() as *mut u32;
|
||||
let sha_byte = self.fifo.as_mut_ptr() as *mut u8;
|
||||
|
||||
// this unsafe version is very slightly faster than the safe version below
|
||||
/*
|
||||
let src_bfr = buf.as_ptr() as *mut u32;
|
||||
for offset in 0 .. buf.len() / 4 {
|
||||
unsafe { sha.write_volatile(src_bfr.add(offset).read_volatile()); }
|
||||
}
|
||||
if (buf.len() % 4) != 0 {
|
||||
for index in (buf.len() - (buf.len() % 4))..buf.len() {
|
||||
unsafe{ sha_byte.write_volatile(buf[index]); }
|
||||
}
|
||||
} */
|
||||
for (_reg, chunk) in buf.chunks(4).enumerate() {
|
||||
let mut temp: [u8; 4] = Default::default();
|
||||
if chunk.len() == 4 {
|
||||
|
|
|
|||
|
|
@ -34,6 +34,14 @@ TEST_MAX_LEN = 512 (random length) / TEST_ITERS = 1000: hw 7.332ms/hash, sw 5.48
|
|||
TEST_MAX_LEN = 1024 (fixed length) / TEST_ITERS = 1000: hw 7.257ms/hash, sw 11.676ms/hash
|
||||
TEST_MAX_LEN = 8192 (random length) / TEST_ITERS = 1000: hw 10.528ms/hash, sw 40.631ms/hash
|
||||
TEST_MAX_LEN = 8192 (fixed length) / TEST_ITERS = 1000: hw 17.035ms/hash, sw 78.633ms/hash
|
||||
|
||||
power consumption -
|
||||
4.1V system voltage
|
||||
159mA nominal
|
||||
182mA while running hw benchmark (17.569ms/hash)
|
||||
~ 23mA for SHA hardware unit doing 8k fixed length hashes, ~14% extra power, 1.65mJ/hash
|
||||
172mA while running sw benchmark (78.525ms/hash) -> ~10mA excess power for software -> 3.22mJ/hash
|
||||
~50% power savings to use hardware hasher
|
||||
*/
|
||||
|
||||
pub fn benchmark_thread(sid0: usize, sid1: usize, sid2: usize, sid3: usize) {
|
||||
|
|
@ -211,6 +219,17 @@ impl<'a> ShellCmdApi<'a> for Sha {
|
|||
).unwrap();
|
||||
write!(ret, "Starting Sha512 software benchmark with {} iters, {} max_len, {} fixed_len", TEST_ITERS, TEST_MAX_LEN, TEST_FIXED_LEN).unwrap();
|
||||
}
|
||||
"susres" => {
|
||||
let start = env.ticktimer.elapsed_ms();
|
||||
self.start_time = Some(start);
|
||||
xous::send_message(self.benchmark_cid,
|
||||
xous::Message::new_scalar(BenchOp::StartSha512Hw.to_usize().unwrap(), 0, 0, 0, 0)
|
||||
).unwrap();
|
||||
let wait_time = (env.trng.get_u32().unwrap() % 2000) + 500; // at least half a second wait, up to 2 seconds
|
||||
env.ticktimer.sleep_ms(wait_time as _).unwrap();
|
||||
self.susres.initiate_suspend().unwrap();
|
||||
write!(ret, "Interrupted Sha512 hardware benchmark with a suspend/resume").unwrap();
|
||||
}
|
||||
_ => {
|
||||
write!(ret, "{}", helpstring).unwrap();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -258,7 +258,7 @@ pub(crate) const SERVER_NAME_SHELLCHAT: &str = "_Shell chat application_";
|
|||
#[xous::xous_main]
|
||||
fn xmain() -> ! {
|
||||
log_server::init_wait().unwrap();
|
||||
log::set_max_level(log::LevelFilter::Debug);
|
||||
log::set_max_level(log::LevelFilter::Info);
|
||||
info!("my PID is {}", xous::process::id());
|
||||
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
|
|
|
|||
|
|
@ -8,4 +8,6 @@ pub(crate) enum Opcode {
|
|||
|
||||
/// Suspend/resume callback
|
||||
SuspendResume,
|
||||
|
||||
Quit,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ pub struct Trng {
|
|||
impl Trng {
|
||||
pub fn new(xns: &xous_names::XousNames) -> Result<Self, xous::Error> {
|
||||
let conn = xns.request_connection_blocking(api::SERVER_NAME_TRNG).expect("Can't connect to TRNG server");
|
||||
REFCOUNT.store(REFCOUNT.load(Ordering::Relaxed) + 1, Ordering::Relaxed);
|
||||
Ok(Trng {
|
||||
conn
|
||||
})
|
||||
|
|
@ -39,10 +40,13 @@ impl Trng {
|
|||
}
|
||||
}
|
||||
|
||||
use core::sync::atomic::{AtomicU32, Ordering};
|
||||
static REFCOUNT: AtomicU32 = AtomicU32::new(0);
|
||||
impl Drop for Trng {
|
||||
fn drop(&mut self) {
|
||||
// de-allocate myself. It's unsafe because we are responsible to make sure nobody else is using the connection.
|
||||
unsafe{xous::disconnect(self.conn).unwrap();}
|
||||
|
||||
if REFCOUNT.load(Ordering::Relaxed) == 0 {
|
||||
unsafe{xous::disconnect(self.conn).unwrap();}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -400,9 +400,11 @@ fn xmain() -> ! {
|
|||
susres.suspend_until_resume(token).expect("couldn't execute suspend/resume");
|
||||
trng.resume();
|
||||
}),
|
||||
None => {
|
||||
log::error!("couldn't convert opcode");
|
||||
Some(api::Opcode::Quit) => {
|
||||
break
|
||||
},
|
||||
None => {
|
||||
log::error!("couldn't convert opcode, ignoring");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ pub struct XousNames {
|
|||
}
|
||||
impl XousNames {
|
||||
pub fn new() -> Result<Self, xous::Error> {
|
||||
REFCOUNT.store(REFCOUNT.load(Ordering::Relaxed) + 1, Ordering::Relaxed);
|
||||
let conn = xous::connect(xous::SID::from_bytes(b"xous-name-server").unwrap()).expect("Couldn't connect to XousNames");
|
||||
Ok(XousNames {
|
||||
conn,
|
||||
|
|
@ -88,10 +89,13 @@ impl XousNames {
|
|||
}
|
||||
}
|
||||
|
||||
use core::sync::atomic::{AtomicU32, Ordering};
|
||||
static REFCOUNT: AtomicU32 = AtomicU32::new(0);
|
||||
impl Drop for XousNames {
|
||||
fn drop(&mut self) {
|
||||
// de-allocate myself. It's unsafe because we are responsible to make sure nobody else is using the connection.
|
||||
unsafe{xous::disconnect(self.conn).unwrap();}
|
||||
|
||||
if REFCOUNT.load(Ordering::Relaxed) == 0 {
|
||||
unsafe{xous::disconnect(self.conn).unwrap();}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue