mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
make determinism an optional feature
This commit is contained in:
parent
d4027fa8a2
commit
37b46fae98
4 changed files with 96 additions and 27 deletions
|
|
@ -54,4 +54,7 @@ u64_pa = []
|
||||||
# the page table when being updated in the case of a power loss, in exchange for more than doubling the time it
|
# the page table when being updated in the case of a power loss, in exchange for more than doubling the time it
|
||||||
# takes to update the page table.
|
# takes to update the page table.
|
||||||
mbbb = []
|
mbbb = []
|
||||||
default = ["mbbb"]
|
# selecting deterministic makes the allocation and page replacement algorithms deterministic. normally we don't want
|
||||||
|
# this but it's helpful for debugging.
|
||||||
|
deterministic = []
|
||||||
|
default = ["mbbb", "deterministic"]
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,19 @@ use core::ops::{Deref, DerefMut};
|
||||||
use core::mem::size_of;
|
use core::mem::size_of;
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
#[cfg(not(feature="deterministic"))]
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
#[cfg(feature="deterministic")]
|
||||||
|
use std::collections::BTreeSet;
|
||||||
use std::collections::BinaryHeap;
|
use std::collections::BinaryHeap;
|
||||||
use std::cmp::Reverse;
|
use std::cmp::Reverse;
|
||||||
use std::io::{Result, Error, ErrorKind};
|
use std::io::{Result, Error, ErrorKind};
|
||||||
|
|
||||||
|
#[cfg(not(feature="deterministic"))]
|
||||||
|
type FspaceSet = HashSet::<PhysPage>;
|
||||||
|
#[cfg(feature="deterministic")]
|
||||||
|
type FspaceSet = BTreeSet::<PhysPage>;
|
||||||
|
|
||||||
/// Implementation-specific PDDB structures: for Precursor/Xous OS pair
|
/// Implementation-specific PDDB structures: for Precursor/Xous OS pair
|
||||||
pub(crate) const MBBB_PAGES: usize = 10;
|
pub(crate) const MBBB_PAGES: usize = 10;
|
||||||
pub(crate) const FSCB_PAGES: usize = 16;
|
pub(crate) const FSCB_PAGES: usize = 16;
|
||||||
|
|
@ -72,7 +80,7 @@ pub(crate) struct PddbOs {
|
||||||
/// derived cipher for handling fastspace -- cache it, so we can save the time cost of constructing the cipher key schedule
|
/// derived cipher for handling fastspace -- cache it, so we can save the time cost of constructing the cipher key schedule
|
||||||
cipher_ecb: Option<Aes256>,
|
cipher_ecb: Option<Aes256>,
|
||||||
/// fast space cache
|
/// fast space cache
|
||||||
fspace_cache: HashSet<PhysPage>,
|
fspace_cache: FspaceSet,
|
||||||
/// memoize the location of the fscb log pages
|
/// memoize the location of the fscb log pages
|
||||||
fspace_log_addrs: Vec::<PageAlignedPa>,
|
fspace_log_addrs: Vec::<PageAlignedPa>,
|
||||||
/// memoize the current target offset for the next log entry
|
/// memoize the current target offset for the next log entry
|
||||||
|
|
@ -117,7 +125,7 @@ impl PddbOs {
|
||||||
data_phys_base: PageAlignedPa::from(fscb_phys_base.as_u32() + FSCB_PAGES as u32 * PAGE_SIZE as u32),
|
data_phys_base: PageAlignedPa::from(fscb_phys_base.as_u32() + FSCB_PAGES as u32 * PAGE_SIZE as u32),
|
||||||
system_basis_key: None,
|
system_basis_key: None,
|
||||||
cipher_ecb: None,
|
cipher_ecb: None,
|
||||||
fspace_cache: HashSet::<PhysPage>::new(),
|
fspace_cache: FspaceSet::new(),
|
||||||
fspace_log_addrs: Vec::<PageAlignedPa>::new(),
|
fspace_log_addrs: Vec::<PageAlignedPa>::new(),
|
||||||
fspace_log_next_addr: None,
|
fspace_log_next_addr: None,
|
||||||
fspace_log_len: 0,
|
fspace_log_len: 0,
|
||||||
|
|
@ -139,7 +147,7 @@ impl PddbOs {
|
||||||
data_phys_base: PageAlignedPa::from(fscb_phys_base.as_u32() + FSCB_PAGES as u32 * PAGE_SIZE as u32),
|
data_phys_base: PageAlignedPa::from(fscb_phys_base.as_u32() + FSCB_PAGES as u32 * PAGE_SIZE as u32),
|
||||||
system_basis_key: None,
|
system_basis_key: None,
|
||||||
cipher_ecb: None,
|
cipher_ecb: None,
|
||||||
fspace_cache: HashSet::<PhysPage>::new(),
|
fspace_cache: FspaceSet::new(),
|
||||||
fspace_log_addrs: Vec::<PageAlignedPa>::new(),
|
fspace_log_addrs: Vec::<PageAlignedPa>::new(),
|
||||||
fspace_log_next_addr: None,
|
fspace_log_next_addr: None,
|
||||||
fspace_log_len: 0,
|
fspace_log_len: 0,
|
||||||
|
|
@ -182,7 +190,7 @@ impl PddbOs {
|
||||||
#[cfg(not(any(target_os = "none", target_os = "xous")))]
|
#[cfg(not(any(target_os = "none", target_os = "xous")))]
|
||||||
/// used to reset the hardware structure for repeated runs of testing within a single invocation
|
/// used to reset the hardware structure for repeated runs of testing within a single invocation
|
||||||
pub fn test_reset(&mut self) {
|
pub fn test_reset(&mut self) {
|
||||||
self.fspace_cache = HashSet::<PhysPage>::new();
|
self.fspace_cache = FspaceSet::new();
|
||||||
self.fspace_log_addrs = Vec::<PageAlignedPa>::new();
|
self.fspace_log_addrs = Vec::<PageAlignedPa>::new();
|
||||||
self.system_basis_key = None;
|
self.system_basis_key = None;
|
||||||
self.cipher_ecb = None;
|
self.cipher_ecb = None;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ use super::{PAGE_SIZE, VPAGE_SIZE};
|
||||||
use crate::SpaceState;
|
use crate::SpaceState;
|
||||||
use bitfield::bitfield;
|
use bitfield::bitfield;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
|
use std::cmp::Ordering;
|
||||||
|
|
||||||
/// for the life of me, I can't figure out how to query the AES crate to give me the length of a 256-bit key.
|
/// for the life of me, I can't figure out how to query the AES crate to give me the length of a 256-bit key.
|
||||||
/// I mean, we know what it is, it's well-defined and never changes. But it'd just be nice to you know,
|
/// I mean, we know what it is, it's well-defined and never changes. But it'd just be nice to you know,
|
||||||
|
|
@ -52,6 +53,16 @@ impl PartialEq for PhysPage {
|
||||||
self.page_number() == other.page_number()
|
self.page_number() == other.page_number()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl Ord for PhysPage {
|
||||||
|
fn cmp(&self, other: &Self) -> Ordering {
|
||||||
|
self.page_number().cmp(&other.page_number())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl PartialOrd for PhysPage {
|
||||||
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||||
|
Some(self.cmp(other))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Storage for journal revisions.
|
/// Storage for journal revisions.
|
||||||
pub type JournalType = u32;
|
pub type JournalType = u32;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use rand::prelude::*;
|
||||||
use rand_chacha::ChaCha8Rng;
|
use rand_chacha::ChaCha8Rng;
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use core::sync::atomic::{AtomicU64, Ordering};
|
use core::sync::atomic::{AtomicU64, Ordering};
|
||||||
use std::collections::{BTreeSet, BTreeMap};
|
use std::collections::BTreeSet;
|
||||||
|
|
||||||
const UPPER_BOUND: usize = 9000;
|
const UPPER_BOUND: usize = 9000;
|
||||||
const LOWER_BOUND: usize = 12; // needs to be big enough to compute murmur3 hash + hold checksum
|
const LOWER_BOUND: usize = 12; // needs to be big enough to compute murmur3 hash + hold checksum
|
||||||
|
|
@ -91,11 +91,18 @@ pub(crate) fn delete_add_dict_consistency(hw: &mut PddbOs, basis_cache: &mut Bas
|
||||||
let (key_lower_bound, key_upper_bound) = maybe_key_sizes.unwrap_or((LOWER_BOUND, UPPER_BOUND - 4));
|
let (key_lower_bound, key_upper_bound) = maybe_key_sizes.unwrap_or((LOWER_BOUND, UPPER_BOUND - 4));
|
||||||
let extra_reserved = maybe_extra_reserved.unwrap_or(0);
|
let extra_reserved = maybe_extra_reserved.unwrap_or(0);
|
||||||
|
|
||||||
let dict_list_unord = basis_cache.dict_list(hw, None);
|
#[cfg(feature = "deterministic")]
|
||||||
let mut dict_list = BTreeSet::<String>::new();
|
let mut dict_list = BTreeSet::<String>::new();
|
||||||
for s in dict_list_unord {
|
#[cfg(feature = "deterministic")]
|
||||||
dict_list.insert(s);
|
{
|
||||||
|
let dict_list_unord = basis_cache.dict_list(hw, None);
|
||||||
|
for s in dict_list_unord {
|
||||||
|
dict_list.insert(s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(not(feature = "deterministic"))]
|
||||||
|
let dict_list = basis_cache.dict_list(hw, None);
|
||||||
|
|
||||||
let dict_start_index = dict_list.len();
|
let dict_start_index = dict_list.len();
|
||||||
for (evicted, evict_dict) in dict_list.iter().enumerate() {
|
for (evicted, evict_dict) in dict_list.iter().enumerate() {
|
||||||
if evicted < evict_count {
|
if evicted < evict_count {
|
||||||
|
|
@ -134,17 +141,27 @@ pub(crate) fn patch_test(hw: &mut PddbOs, basis_cache: &mut BasisCache,
|
||||||
let patch_offset = maybe_patch_offset.unwrap_or(5);
|
let patch_offset = maybe_patch_offset.unwrap_or(5);
|
||||||
let patch_data = maybe_patch_data.unwrap_or("patched!".to_string());
|
let patch_data = maybe_patch_data.unwrap_or("patched!".to_string());
|
||||||
|
|
||||||
let dict_list_unord = basis_cache.dict_list(hw, None);
|
#[cfg(feature = "deterministic")]
|
||||||
let mut dict_list = BTreeSet::<String>::new();
|
let mut dict_list = BTreeSet::<String>::new();
|
||||||
for s in dict_list_unord {
|
#[cfg(feature = "deterministic")]
|
||||||
dict_list.insert(s);
|
{
|
||||||
|
let dict_list_unord = basis_cache.dict_list(hw, None);
|
||||||
|
for s in dict_list_unord {
|
||||||
|
dict_list.insert(s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(not(feature = "deterministic"))]
|
||||||
|
let dict_list = basis_cache.dict_list(hw, None);
|
||||||
for dict in dict_list.iter() {
|
for dict in dict_list.iter() {
|
||||||
if let Ok(key_list_unord) = basis_cache.key_list(hw, dict, None) {
|
if let Ok(key_list_unord) = basis_cache.key_list(hw, dict, None) {
|
||||||
|
#[cfg(feature = "deterministic")]
|
||||||
let mut key_list = BTreeSet::<String>::new();
|
let mut key_list = BTreeSet::<String>::new();
|
||||||
|
#[cfg(feature = "deterministic")]
|
||||||
for s in key_list_unord {
|
for s in key_list_unord {
|
||||||
key_list.insert(s);
|
key_list.insert(s);
|
||||||
}
|
}
|
||||||
|
#[cfg(not(feature = "deterministic"))]
|
||||||
|
let key_list = key_list_unord;
|
||||||
for key in key_list.iter() {
|
for key in key_list.iter() {
|
||||||
// this actually does something a bit more complicated on a multi-basis system than you'd think:
|
// this actually does something a bit more complicated on a multi-basis system than you'd think:
|
||||||
// it will get the union of all key names, and then patch the *latest open basis* only with new data.
|
// it will get the union of all key names, and then patch the *latest open basis* only with new data.
|
||||||
|
|
@ -203,11 +220,17 @@ pub(crate) fn delete_pattern(hw: &mut PddbOs, basis_cache: &mut BasisCache,
|
||||||
let extra_reserved = maybe_extra_reserved.unwrap_or(0);
|
let extra_reserved = maybe_extra_reserved.unwrap_or(0);
|
||||||
|
|
||||||
let mut evicted_dicts = Vec::<String>::new();
|
let mut evicted_dicts = Vec::<String>::new();
|
||||||
let dict_list_unord = basis_cache.dict_list(hw, None);
|
#[cfg(feature = "deterministic")]
|
||||||
let mut dict_list = BTreeSet::<String>::new();
|
let mut dict_list = BTreeSet::<String>::new();
|
||||||
for s in dict_list_unord {
|
#[cfg(feature = "deterministic")]
|
||||||
dict_list.insert(s);
|
{
|
||||||
|
let dict_list_unord = basis_cache.dict_list(hw, None);
|
||||||
|
for s in dict_list_unord {
|
||||||
|
dict_list.insert(s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(not(feature = "deterministic"))]
|
||||||
|
let dict_list = basis_cache.dict_list(hw, None);
|
||||||
let mut evict_iter = 0;
|
let mut evict_iter = 0;
|
||||||
for (evicted, evict_dict) in dict_list.iter().enumerate() {
|
for (evicted, evict_dict) in dict_list.iter().enumerate() {
|
||||||
if evicted < evict_count {
|
if evicted < evict_count {
|
||||||
|
|
@ -230,11 +253,17 @@ pub(crate) fn delete_pattern(hw: &mut PddbOs, basis_cache: &mut BasisCache,
|
||||||
evicted_dicts.push(evict_dict.to_string());
|
evicted_dicts.push(evict_dict.to_string());
|
||||||
evict_iter += 1;
|
evict_iter += 1;
|
||||||
}
|
}
|
||||||
let dict_list_unord = basis_cache.dict_list(hw, None);
|
#[cfg(feature = "deterministic")]
|
||||||
let mut dict_list = BTreeSet::<String>::new();
|
let mut dict_list = BTreeSet::<String>::new();
|
||||||
for s in dict_list_unord {
|
#[cfg(feature = "deterministic")]
|
||||||
dict_list.insert(s);
|
{
|
||||||
|
let dict_list_unord = basis_cache.dict_list(hw, None);
|
||||||
|
for s in dict_list_unord {
|
||||||
|
dict_list.insert(s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(not(feature = "deterministic"))]
|
||||||
|
let dict_list = basis_cache.dict_list(hw, None);
|
||||||
for dict in dict_list.iter() {
|
for dict in dict_list.iter() {
|
||||||
let da = basis_cache.dict_attributes(hw, dict, None).unwrap();
|
let da = basis_cache.dict_attributes(hw, dict, None).unwrap();
|
||||||
log::debug!("{:?}", da);
|
log::debug!("{:?}", da);
|
||||||
|
|
@ -256,11 +285,17 @@ pub(crate) fn delete_pattern(hw: &mut PddbOs, basis_cache: &mut BasisCache,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let dict_list_unord = basis_cache.dict_list(hw, None);
|
#[cfg(feature = "deterministic")]
|
||||||
let mut dict_list = BTreeSet::<String>::new();
|
let mut dict_list = BTreeSet::<String>::new();
|
||||||
for s in dict_list_unord {
|
#[cfg(feature = "deterministic")]
|
||||||
dict_list.insert(s);
|
{
|
||||||
|
let dict_list_unord = basis_cache.dict_list(hw, None);
|
||||||
|
for s in dict_list_unord {
|
||||||
|
dict_list.insert(s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(not(feature = "deterministic"))]
|
||||||
|
let dict_list = basis_cache.dict_list(hw, None);
|
||||||
for dict in dict_list.iter() {
|
for dict in dict_list.iter() {
|
||||||
let da = basis_cache.dict_attributes(hw, dict, None).unwrap();
|
let da = basis_cache.dict_attributes(hw, dict, None).unwrap();
|
||||||
log::debug!("{:?}", da);
|
log::debug!("{:?}", da);
|
||||||
|
|
@ -271,11 +306,17 @@ pub(crate) fn delete_pattern(hw: &mut PddbOs, basis_cache: &mut BasisCache,
|
||||||
log::info!("all-basis sync done");
|
log::info!("all-basis sync done");
|
||||||
|
|
||||||
list_all(hw, basis_cache);
|
list_all(hw, basis_cache);
|
||||||
let dict_list_unord = basis_cache.dict_list(hw, None);
|
#[cfg(feature = "deterministic")]
|
||||||
let mut dict_list = BTreeSet::<String>::new();
|
let mut dict_list = BTreeSet::<String>::new();
|
||||||
for s in dict_list_unord {
|
#[cfg(feature = "deterministic")]
|
||||||
dict_list.insert(s);
|
{
|
||||||
|
let dict_list_unord = basis_cache.dict_list(hw, None);
|
||||||
|
for s in dict_list_unord {
|
||||||
|
dict_list.insert(s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(not(feature = "deterministic"))]
|
||||||
|
let dict_list = basis_cache.dict_list(hw, None);
|
||||||
for dict in dict_list.iter() {
|
for dict in dict_list.iter() {
|
||||||
let da = basis_cache.dict_attributes(hw, dict, None).unwrap();
|
let da = basis_cache.dict_attributes(hw, dict, None).unwrap();
|
||||||
log::info!("{:?}", da);
|
log::info!("{:?}", da);
|
||||||
|
|
@ -283,11 +324,17 @@ pub(crate) fn delete_pattern(hw: &mut PddbOs, basis_cache: &mut BasisCache,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn list_all(hw: &mut PddbOs, basis_cache: &mut BasisCache) {
|
pub(crate) fn list_all(hw: &mut PddbOs, basis_cache: &mut BasisCache) {
|
||||||
let dict_list_unord = basis_cache.dict_list(hw, None);
|
#[cfg(feature = "deterministic")]
|
||||||
let mut dict_list = BTreeSet::<String>::new();
|
let mut dict_list = BTreeSet::<String>::new();
|
||||||
for s in dict_list_unord {
|
#[cfg(feature = "deterministic")]
|
||||||
dict_list.insert(s);
|
{
|
||||||
|
let dict_list_unord = basis_cache.dict_list(hw, None);
|
||||||
|
for s in dict_list_unord {
|
||||||
|
dict_list.insert(s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(not(feature = "deterministic"))]
|
||||||
|
let dict_list = basis_cache.dict_list(hw, None);
|
||||||
|
|
||||||
// now list all the attributes of the basis
|
// now list all the attributes of the basis
|
||||||
for dict in dict_list.iter() {
|
for dict in dict_list.iter() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue