mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
add l2 cache support (suspend/resume flushing)
also noted some performance benchmark improvements
This commit is contained in:
parent
47c1a98d13
commit
6c697de512
8 changed files with 178 additions and 8 deletions
|
|
@ -1068,10 +1068,103 @@ pub unsafe extern "C" fn rust_entry(arg_buffer: *const usize, signature: u32) ->
|
|||
boot_sequence(kab, signature);
|
||||
}
|
||||
|
||||
fn memtest() {
|
||||
let ram_ptr: *mut u32 = 0x4000_0000 as *mut u32;
|
||||
let sram_ptr: *mut u32 = 0x1000_0000 as *mut u32;
|
||||
use utralib::generated::*;
|
||||
|
||||
let mut sram_csr = CSR::new(utra::sram_ext::HW_SRAM_EXT_BASE as *mut u32);
|
||||
sram_csr.wfo(utra::sram_ext::READ_CONFIG_TRIGGER, 1);
|
||||
|
||||
// give some time for the status to read
|
||||
for i in 0..8 {
|
||||
unsafe { sram_ptr.add(i).write_volatile(i as u32) };
|
||||
}
|
||||
|
||||
println!("status: 0x{:08x}", sram_csr.rf(utra::sram_ext::CONFIG_STATUS_MODE));
|
||||
|
||||
for i in 0..(256*1024/4) {
|
||||
unsafe {
|
||||
ram_ptr.add(i).write_volatile( (0xACE0_0000 + i) as u32 );
|
||||
}
|
||||
}
|
||||
|
||||
let mut errcnt = 0;
|
||||
for i in 0..(256*1024/4) {
|
||||
unsafe {
|
||||
let rd = ram_ptr.add(i).read_volatile();
|
||||
if rd != (0xACE0_0000 + i) as u32 {
|
||||
if errcnt < 16 || ((errcnt % 256) == 0) {
|
||||
println!("* 0x{:08x}: e:0x{:08x} o:0x{:08x}", i*4, 0xACE0_0000 + i, rd);
|
||||
}
|
||||
errcnt += 1;
|
||||
} else if (i & 0x1FFF) == 8 {
|
||||
println!(" 0x{:08x}: e:0x{:08x} o:0x{:08x}", i*4, 0xACE0_0000 + i, rd);
|
||||
};
|
||||
}
|
||||
}
|
||||
// TRNG virtual memory mapping already set up, but we pump values out just to make sure
|
||||
// the pipeline is fresh. Simulations show this isn't necessary, but I feel paranoid;
|
||||
// I worry a subtle bug in the reset logic could leave deterministic values in the pipeline.
|
||||
for _k in 0..8 {
|
||||
let trng_csr = CSR::new(utra::trng_kernel::HW_TRNG_KERNEL_BASE as *mut u32);
|
||||
for i in 0x3E_0000..0x3F_0000 {
|
||||
while trng_csr.rf(utra::trng_kernel::URANDOM_VALID_URANDOM_VALID) == 0 {}
|
||||
unsafe {
|
||||
ram_ptr.add(i).write_volatile(trng_csr.rf(utra::trng_kernel::URANDOM_URANDOM));
|
||||
}
|
||||
}
|
||||
for i in 0x3D_0000..0x3E_0000 {
|
||||
unsafe {
|
||||
ram_ptr.add(i).write_volatile(ram_ptr.add(i + 0x10000).read_volatile());
|
||||
}
|
||||
}
|
||||
let basecnt = errcnt;
|
||||
println!("** take one **");
|
||||
for i in 0x3D_0000..0x3E_0000 {
|
||||
let rd1 = unsafe{ram_ptr.add(i).read_volatile()};
|
||||
let rd2 = unsafe{ram_ptr.add(i+0x10000).read_volatile()};
|
||||
if rd1 != rd2 {
|
||||
if errcnt < 16 + basecnt || ((errcnt % 256) == 0) {
|
||||
println!("* 0x{:08x}: rd1:0x{:08x} rd2:0x{:08x}", i*4, rd1, rd2);
|
||||
}
|
||||
errcnt += 1;
|
||||
} else if (i & 0x1FFF) == 12 {
|
||||
println!(" 0x{:08x}: rd1:0x{:08x} rd2:0x{:08x}", i*4, rd1, rd2);
|
||||
}
|
||||
}
|
||||
println!("** take two (check for read errors)**");
|
||||
let basecnt = errcnt;
|
||||
for i in 0x3D_0000..0x3E_0000 {
|
||||
let rd1 = unsafe{ram_ptr.add(i).read_volatile()};
|
||||
let rd2 = unsafe{ram_ptr.add(i+0x10000).read_volatile()};
|
||||
if rd1 != rd2 {
|
||||
if errcnt < 16 + basecnt || ((errcnt % 256) == 0) {
|
||||
println!("* 0x{:08x}: rd1:0x{:08x} rd2:0x{:08x}", i*4, rd1, rd2);
|
||||
}
|
||||
errcnt += 1;
|
||||
} else if (i & 0x1FFF) == 12 {
|
||||
println!(" 0x{:08x}: rd1:0x{:08x} rd2:0x{:08x}", i*4, rd1, rd2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if errcnt != 0 {
|
||||
println!("error count: {}", errcnt);
|
||||
println!("0x01000: {:08x}", unsafe{ ram_ptr.add(0x1000/4).read_volatile() });
|
||||
println!("0x00000: {:08x}", unsafe{ ram_ptr.add(0x0).read_volatile() });
|
||||
println!("0x0FFFC: {:08x}", unsafe{ ram_ptr.add(0xFFFC/4).read_volatile() });
|
||||
println!("0xfdff04: {:08x}", unsafe{ ram_ptr.add(0xfdff04/4).read_volatile() });
|
||||
}
|
||||
}
|
||||
|
||||
fn boot_sequence(args: KernelArguments, _signature: u32) -> ! {
|
||||
// Store the initial boot config on the stack. We don't know
|
||||
// where in heap this memory will go.
|
||||
#[allow(clippy::cast_ptr_alignment)] // This test only works on 32-bit systems
|
||||
if false {
|
||||
memtest();
|
||||
}
|
||||
let mut cfg = BootConfig {
|
||||
base_addr: args.base as *const usize,
|
||||
args,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<device schemaVersion="1.1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd" >
|
||||
<vendor>litex</vendor>
|
||||
<name>SOC</name>
|
||||
<description><![CDATA[Litex SoC 2021-07-03 18:21:53]]></description>
|
||||
<description><![CDATA[Litex SoC 2021-07-05 15:58:37]]></description>
|
||||
|
||||
<addressUnitBits>8</addressUnitBits>
|
||||
<width>32</width>
|
||||
|
|
@ -1222,10 +1222,10 @@ register to disable individual events.]]></description>
|
|||
<register>
|
||||
<name>GIT_GITREV</name>
|
||||
<description><![CDATA[First 32-bits of the git revision. This documentation was built from git rev
|
||||
``977355ba``, so this value is 2540918202, which should be enough to check out
|
||||
``afcc1323``, so this value is 2949387043, which should be enough to check out
|
||||
the exact git version used to build this firmware.]]></description>
|
||||
<addressOffset>0x0014</addressOffset>
|
||||
<resetValue>0x977355ba</resetValue>
|
||||
<resetValue>0xafcc1323</resetValue>
|
||||
<size>32</size>
|
||||
<fields>
|
||||
<field>
|
||||
|
|
@ -1242,7 +1242,7 @@ the exact git version used to build this firmware.]]></description>
|
|||
is ``1``, then the repository this was built from has one additional commit
|
||||
beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]></description>
|
||||
<addressOffset>0x0018</addressOffset>
|
||||
<resetValue>0x26</resetValue>
|
||||
<resetValue>0x2a</resetValue>
|
||||
<size>32</size>
|
||||
<fields>
|
||||
<field>
|
||||
|
|
@ -3467,7 +3467,7 @@ inject too fast.]]></description>
|
|||
<name>SEED1</name>
|
||||
<description><![CDATA[Bits 32-63 of `SEED_SEED`. Seed used for the build]]></description>
|
||||
<addressOffset>0x0000</addressOffset>
|
||||
<resetValue>0x698bb704</resetValue>
|
||||
<resetValue>0x6d48a16e</resetValue>
|
||||
<size>32</size>
|
||||
<fields>
|
||||
<field>
|
||||
|
|
@ -3482,7 +3482,7 @@ inject too fast.]]></description>
|
|||
<name>SEED0</name>
|
||||
<description><![CDATA[Bits 0-31 of `SEED_SEED`.]]></description>
|
||||
<addressOffset>0x0004</addressOffset>
|
||||
<resetValue>0x5d2ea7df</resetValue>
|
||||
<resetValue>0x71a7a0e3</resetValue>
|
||||
<size>32</size>
|
||||
<fields>
|
||||
<field>
|
||||
|
|
@ -3535,10 +3535,40 @@ inject too fast.]]></description>
|
|||
</field>
|
||||
</fields>
|
||||
</register>
|
||||
<register>
|
||||
<name>LOCKADDR</name>
|
||||
<description><![CDATA[address of the word to lock. Address locked on write, and cannot be undone.]]></description>
|
||||
<addressOffset>0x0008</addressOffset>
|
||||
<resetValue>0x00</resetValue>
|
||||
<size>32</size>
|
||||
<fields>
|
||||
<field>
|
||||
<name>lockaddr</name>
|
||||
<msb>7</msb>
|
||||
<bitRange>[7:0]</bitRange>
|
||||
<lsb>0</lsb>
|
||||
</field>
|
||||
</fields>
|
||||
</register>
|
||||
<register>
|
||||
<name>LOCKSTAT</name>
|
||||
<description><![CDATA[If set, the requested address word is locked and will always return 0.]]></description>
|
||||
<addressOffset>0x000c</addressOffset>
|
||||
<resetValue>0x00</resetValue>
|
||||
<size>32</size>
|
||||
<fields>
|
||||
<field>
|
||||
<name>lockstat</name>
|
||||
<msb>0</msb>
|
||||
<bitRange>[0:0]</bitRange>
|
||||
<lsb>0</lsb>
|
||||
</field>
|
||||
</fields>
|
||||
</register>
|
||||
</registers>
|
||||
<addressBlock>
|
||||
<offset>0</offset>
|
||||
<size>0x8</size>
|
||||
<size>0x10</size>
|
||||
<usage>registers</usage>
|
||||
</addressBlock>
|
||||
</peripheral>
|
||||
|
|
@ -6973,7 +7003,7 @@ of the PLL]]></description>
|
|||
<memoryRegion>
|
||||
<name>SRAM</name>
|
||||
<baseAddress>0x10000000</baseAddress>
|
||||
<size>0x00020000</size>
|
||||
<size>0x00004000</size>
|
||||
</memoryRegion>
|
||||
<memoryRegion>
|
||||
<name>VEXRISCV_DEBUG</name>
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -160,6 +160,9 @@ macro_rules! sha512_comms {
|
|||
panic!("Internal error in AcquireExclusive");
|
||||
}
|
||||
}
|
||||
} else if self.strategy == FallbackStrategy::SoftwareOnly {
|
||||
self.use_soft = true;
|
||||
self.in_progress = true;
|
||||
}
|
||||
}
|
||||
pub(crate) fn reset_hw(&mut self) {
|
||||
|
|
|
|||
|
|
@ -134,6 +134,10 @@ software: -151mA @ 100% CPU usage, 158.36us/block enc+dec AES128 (500 iters, 819
|
|||
|
||||
hardware: -148mA @ 100% CPU usage, 103.73us/block enc+dec AES256 (500 iters, 8192 len)
|
||||
software: -149mA @ 100% CPU usage, 217.95us/block enc+dec AES256 (500 iters, 8192 len)
|
||||
|
||||
with L2 cache on:
|
||||
hardware 92.24us/block enc+dec aes256 (500 iters, 8192 len)
|
||||
software 158.48us/block enc+dec aes256 (500 iters, 8192 len)
|
||||
*/
|
||||
pub fn benchmark_thread(sid0: usize, sid1: usize, sid2: usize, sid3: usize) {
|
||||
let sid = xous::SID::from_u32(sid0 as u32, sid1 as u32, sid2 as u32, sid3 as u32);
|
||||
|
|
|
|||
|
|
@ -159,6 +159,7 @@ pub fn benchmark_thread(sid0: usize, sid1: usize, sid2: usize, sid3: usize) {
|
|||
26ms/2xop (200 iters -hw) -- affine done in hardware
|
||||
|
||||
13.54ms/2xop (200 iters -hw) -- microcode pre-loaded, minimal registers transferred using MontgomeryJob call
|
||||
12.2ms/2xop (200 iters -hw) -- with L2 cache on
|
||||
*/
|
||||
Some(BenchOp::StartDh) => {
|
||||
let mut passes = 0;
|
||||
|
|
|
|||
|
|
@ -35,6 +35,9 @@ TEST_MAX_LEN = 1024 (fixed length) / TEST_ITERS = 1000: hw 7.257ms/hash, sw 11.6
|
|||
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
|
||||
|
||||
with L2 cache on:
|
||||
TEST_MAX_LEN = 8192 (fixed length) / TEST_ITERS = 1000: hw 13.798ms/hash, sw 29.034ms/hash
|
||||
|
||||
power consumption -
|
||||
4.1V system voltage
|
||||
159mA nominal
|
||||
|
|
|
|||
|
|
@ -79,6 +79,14 @@ mod implementation {
|
|||
reboot_csr.wfo(utra::reboot::SOC_RESET_SOC_RESET, 0xAC);
|
||||
}
|
||||
|
||||
// flush the L2 cache by writing 0's to a region of memory that matches the L2 cache size
|
||||
if let Some(cf) = sr.cacheflush {
|
||||
let cf_ptr = cf.as_ptr() as *mut u32;
|
||||
for i in 0..(cf.len() / 4) {
|
||||
unsafe {cf_ptr.add(i).write_volatile(0); }
|
||||
}
|
||||
}
|
||||
|
||||
// power the system down - this should result in an almost immediate loss of power
|
||||
sr.csr.wfo(utra::susres::POWERDOWN_POWERDOWN, 1);
|
||||
|
||||
|
|
@ -103,6 +111,8 @@ mod implementation {
|
|||
seed_csr: utralib::CSR<u32>,
|
||||
/// we also own the reboot facility
|
||||
reboot_csr: utralib::CSR<u32>,
|
||||
/// cache flushing memory raea
|
||||
cacheflush: Option<xous::MemoryRange>,
|
||||
}
|
||||
impl SusResHw {
|
||||
pub fn new() -> Self {
|
||||
|
|
@ -159,6 +169,7 @@ mod implementation {
|
|||
marker,
|
||||
seed_csr: CSR::new(seed_csr.as_mut_ptr() as *mut u32),
|
||||
reboot_csr: CSR::new(reboot_csr.as_mut_ptr() as *mut u32),
|
||||
cacheflush: None,
|
||||
};
|
||||
|
||||
// start the OS timer running
|
||||
|
|
@ -200,6 +211,26 @@ mod implementation {
|
|||
}
|
||||
|
||||
pub fn do_suspend(&mut self, forced: bool) {
|
||||
// allocate memory for the cache flush
|
||||
if self.cacheflush.is_none() {
|
||||
self.cacheflush = Some (
|
||||
xous::syscall::map_memory(
|
||||
None,
|
||||
None,
|
||||
128 * 1024, // this matches a 128k L2 cache
|
||||
xous::MemoryFlags::R | xous::MemoryFlags::W | xous::MemoryFlags::RESERVE,
|
||||
).expect("couldn't allocate RAM for cache flushing")
|
||||
);
|
||||
// the RESERVE flag should pre-allocate the pages, but for good measure
|
||||
// we write all the pages to make sure they are at a defined value
|
||||
if let Some(cf) = self.cacheflush {
|
||||
let cf_ptr = cf.as_ptr() as *mut u32;
|
||||
for i in 0..(cf.len() / 4) {
|
||||
unsafe {cf_ptr.add(i).write_volatile(0); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
println!("Stopping preemption");
|
||||
// stop pre-emption
|
||||
self.os_timer.wfo(utra::timer0::EN_EN, 0);
|
||||
|
|
@ -351,6 +382,11 @@ mod implementation {
|
|||
panic!("Can't resume because the ticktimer value was not saved properly before suspend!")
|
||||
};
|
||||
|
||||
// de-allocate the cache flush memory
|
||||
if let Some(cf) = self.cacheflush.take() {
|
||||
xous::syscall::unmap_memory(cf).expect("couldn't de-allocate cache flush region");
|
||||
}
|
||||
|
||||
if self.csr.rf(utra::susres::STATE_WAS_FORCED) == 0 {
|
||||
false
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue