Skip to content

Commit

Permalink
Outline Nr hashmap in Dinos userspace.
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitbhrdwj committed Dec 5, 2023
1 parent e8bb646 commit 5766582
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 13 deletions.
19 changes: 17 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions kernel/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use log::{debug, info, trace};
use crate::arch::kcb::per_core_mem;
use crate::arch::memory::{paddr_to_kernel_vaddr, BASE_PAGE_SIZE, LARGE_PAGE_SIZE};
use crate::arch::process::{current_pid, with_user_space_access_enabled, ArchProcess};
use crate::arch::MAX_CORES;
//use crate::arch::MAX_CORES;
use crate::cmdline::CommandLineArguments;
use crate::error::{KError, KResult};
use crate::fs::fd::FileDescriptorEntry;
Expand Down Expand Up @@ -52,7 +52,7 @@ pub(crate) type Eid = usize;
pub(crate) const MAX_PROCESSES: usize = 1;

/// How many registered "named" frames a process can have.
pub(crate) const MAX_FRAMES_PER_PROCESS: usize = MAX_CORES;
pub(crate) const MAX_FRAMES_PER_PROCESS: usize = 1023;

/// How many writable sections a process can have (part of the ELF file).
pub(crate) const MAX_WRITEABLE_SECTIONS_PER_PROCESS: usize = 4;
Expand Down
4 changes: 2 additions & 2 deletions kernel/tests/s11_rackscale_benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ fn s11_rackscale_dynrep_userspace() {
//test.client_timeout *= 2;

// TODO: may need to increase shmem size in the future?
//test.shmem_size = 1024 * 2;
test.shmem_size = 1024 * 2;

test.use_affinity_shmem = cfg!(feature = "affinity-shmem");
test.use_qemu_huge_pages = cfg!(feature = "affinity-shmem");
Expand All @@ -1147,7 +1147,7 @@ fn s11_rackscale_dynrep_userspace() {
//test.num_clients = 3;

// TODO: may need to increase memory in the future
//test.memory = 2*4096;
test.memory = 2*4096;

// TODO: may need to increase cores per client in the future
test.cores_per_client = 1;
Expand Down
1 change: 1 addition & 0 deletions usr/init/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ path = "src/init.rs"
lineup = { path = "../../lib/lineup" }
vibrio = { path = "../../lib/vibrio" }
kpi = { path = "../../lib/kpi" }
nr2 = { git="https://github.com/gz/node-replication.git", branch="nr-dymanic-replication" }
arrayvec = { version = "0.7.0", default-features = false }
proptest = { git = "https://github.com/gz/proptest.git", branch = "x86-asm", default-features = false, features = ['alloc', 'hardware-rng'] }
rawtime = "0.0.10"
Expand Down
2 changes: 1 addition & 1 deletion usr/init/src/dynrep/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use core::{
};

pub const BASE: u64 = 0x0510_0000_0000;
pub const MAX_FRAMES: u64 = 180;
pub const MAX_FRAMES: u64 = 600;

#[derive(Clone, Copy)]
pub struct MyAllocator;
Expand Down
62 changes: 56 additions & 6 deletions usr/init/src/dynrep/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,66 @@
use log::info;
use hashbrown::{hash_map::DefaultHashBuilder, HashMap};

use alloc::sync::Arc;
use core::num::NonZeroUsize;
use nr2::nr::{NodeReplicated, rwlock::RwLock, Dispatch};

mod allocator;
use allocator::MyAllocator;

pub const NUM_ENTRIES: u64 = 10_000_000;
pub const NUM_ENTRIES: u64 = 50_000_000;

pub fn userspace_dynrep_test() {
let allocator = MyAllocator::default();
let mut h = HashMap::<u64, u64, DefaultHashBuilder, MyAllocator>::with_capacity_in(NUM_ENTRIES as usize, allocator);
for i in 0..NUM_ENTRIES {
h.insert(i, i + 1);
#[derive(Clone)]
struct HashTable {
map: HashMap<u64, u64, DefaultHashBuilder, MyAllocator>,
}

impl Default for HashTable {
fn default() -> Self {
let allocator = MyAllocator::default();
let map = HashMap::<u64, u64, DefaultHashBuilder, MyAllocator>::with_capacity_in(NUM_ENTRIES as usize, allocator);
HashTable { map }
}
}

enum OpRd {
Get(u64),
}

#[derive(PartialEq, Clone)]
enum OpWr {
Put(u64, u64),
}

impl Dispatch for HashTable {
type ReadOperation<'a> = OpRd;
type WriteOperation = OpWr;
type Response = Result<Option<u64>, ()>;

fn dispatch<'a>(&self, op: Self::ReadOperation<'a>) -> Self::Response {
match op {
OpRd::Get(key) => {
let val = self.map.get(&key);
Ok(val.copied())
}
}
}

fn dispatch_mut(&mut self, op: Self::WriteOperation) -> Self::Response {
match op {
OpWr::Put(key, val) => {
let resp = self.map.insert(key, val);
Ok(resp)
}
}
}
}

pub fn userspace_dynrep_test() {
let replicas = NonZeroUsize::new(1).unwrap();
let nrht = NodeReplicated::<HashTable>::new(replicas, |_| { 0 }).unwrap();
let ttkn = nrht.register(0).unwrap();
nrht.execute(OpRd::Get(0), ttkn).unwrap();

info!("dynrep_test OK");
}

0 comments on commit 5766582

Please sign in to comment.