Skip to content

Commit

Permalink
Userspace dyn rep bench runs with both NrOS and DiNOS
Browse files Browse the repository at this point in the history
  • Loading branch information
hunhoffe committed Dec 6, 2023
1 parent b6a441c commit a0bee26
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 15 deletions.
20 changes: 16 additions & 4 deletions kernel/src/arch/x86_64/syscall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl<T: Arch86ProcessDispatch> ProcessDispatch<u64> for T {
Ok((0, 0))
}

fn allocate_physical(&self, page_size: u64, _affinity: u64) -> Result<(u64, u64), KError> {
fn allocate_physical(&self, page_size: u64, affinity: u64) -> Result<(u64, u64), KError> {
let page_size: usize = page_size.try_into().unwrap_or(0);
//let affinity: usize = arg3.try_into().unwrap_or(0);
// Validate input
Expand All @@ -227,25 +227,37 @@ impl<T: Arch86ProcessDispatch> ProcessDispatch<u64> for T {
}

let pcm = super::kcb::per_core_mem();
let orig_affinity = { pcm.physical_memory.borrow().affinity };
pcm.set_mem_affinity((affinity - 1) as atopology::NodeId)
.expect("Can't change affinity");

// Figure out what memory to allocate
let (bp, lp) = if page_size == BASE_PAGE_SIZE {
(1, 0)
} else {
(0, 1)
};
crate::memory::KernelAllocator::try_refill_tcache(bp, lp, MemType::Mem)?;
crate::memory::KernelAllocator::try_refill_tcache(bp, lp, MemType::Mem)
.expect("Failed to refill tcache");

// Allocate the page (need to make sure we drop pmanager again
// before we go to NR):
let frame = {
let mut pmanager = pcm.mem_manager();
if page_size == BASE_PAGE_SIZE {
pmanager.allocate_base_page()?
pmanager
.allocate_base_page()
.expect("Cannot allocate base page")
} else {
pmanager.allocate_large_page()?
pmanager
.allocate_large_page()
.expect("Cannot allocate large page")
}
};

pcm.set_mem_affinity(orig_affinity)
.expect("Can't change affinity");

// Associate memory with the process
let pid = current_pid()?;
let fid = NrProcess::<Ring3Process>::allocate_frame_to_process(pid, frame)?;
Expand Down
14 changes: 11 additions & 3 deletions kernel/tests/s11_rackscale_benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1073,13 +1073,17 @@ fn s11_rackscale_dynrep_userspace() {
let max_numa_nodes = machine.max_numa_nodes();
let cores_per_client = max_cores / max_numa_nodes;

let file_name = format!("rackscale_{}_dynrep_userspace.csv", transport.to_string(),);
let file_name = if cfg!(feature = "baseline") {
format!("nros_dynrep_userspace.csv")
} else {
format!("rackscale_{}_dynrep_userspace.csv", transport.to_string(),)
};
let _ignore = std::fs::remove_file(file_name.clone());

let built = BuildArgs::default()
.module("init")
.user_feature("test-dynrep")
.set_rackscale(true)
.set_rackscale(!cfg!(feature = "baseline"))
.kernel_feature("pages-4k")
.release()
.build();
Expand Down Expand Up @@ -1153,5 +1157,9 @@ fn s11_rackscale_dynrep_userspace() {
}
test.memory = 2 * 4096;
test.shmem_size = 1024 * 2;
test.run_rackscale();
if cfg!(feature = "baseline") {
test.run_baseline();
} else {
test.run_rackscale();
}
}
48 changes: 40 additions & 8 deletions usr/init/src/dynrep/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl Dispatch for HashTable {
}

fn run_bench(
mid: usize,
replica_id: usize,
core_id: usize,
ttkn: ThreadToken,
replica: Arc<NodeReplicated<HashTable>>,
Expand All @@ -101,26 +101,46 @@ fn run_bench(
ops += 1;
}
}
info!("dynhash,{},{},{},{}", mid, core_id, iterations, ops);
info!("dynhash,{},{},{},{}", replica_id, core_id, iterations, ops);
iterations += 1;
}
}

unsafe extern "C" fn bencher_trampoline(args: *mut u8) -> *mut u8 {
let current_gtid = vibrio::syscalls::System::core_id().expect("Can't get core id");
let mid = kpi::system::mid_from_gtid(current_gtid);
let replica_id = if mid == 0 {
let hwthreads = vibrio::syscalls::System::threads().expect("Cant get system topology");
let mut node_id = 0;
for hwthread in hwthreads.iter() {
if hwthread.id == current_gtid {
node_id = hwthread.node_id;
break;
}
}
node_id
} else {
mid - 1
};

let replica: Arc<NodeReplicated<HashTable>> =
Arc::from_raw(args as *const NodeReplicated<HashTable>);
let ttkn = replica.register(mid - 1).unwrap();

// TODO: change replica # here
log::info!(
"Registered thread {:?} with replica {:?}",
current_gtid,
replica_id
);
let ttkn = replica.register(replica_id).unwrap();

// Synchronize with all cores
POOR_MANS_BARRIER.fetch_sub(1, Ordering::Release);
while POOR_MANS_BARRIER.load(Ordering::Acquire) != 0 {
core::hint::spin_loop();
}

run_bench(mid, current_gtid, ttkn, replica.clone());
run_bench(replica_id, current_gtid, ttkn, replica.clone());
ptr::null_mut()
}

Expand All @@ -132,14 +152,25 @@ pub fn userspace_dynrep_test() {

// Figure out how many clients there are - this will determine how many max replicas we use
let mut nnodes = 0;
let mut nclients = 0;
for hwthread in hwthreads.iter() {
// mid == machine id, otherwise referred to as client id
let mid = kpi::system::mid_from_gtid(hwthread.id);
if mid > nnodes {
nnodes = mid;
if mid > nclients {
nclients = mid;
}
if hwthread.node_id > nnodes {
nnodes = hwthread.node_id;
}
}
log::info!("Found {:?} client machines", nnodes);
if nclients != 0 {
// running as DiNOS
log::info!("Found {:?} client machines", nclients);
nnodes = nclients;
} else {
// running as NrOS
log::info!("Found {:?} nodes", nnodes);
nnodes += 1;
}

// Create data structure, with as many replicas as there are clients (assuming 1 numa node per client)
// TODO: change this to change number of replicas
Expand Down Expand Up @@ -180,6 +211,7 @@ pub fn userspace_dynrep_test() {
move |_| {
let mut thandles = Vec::with_capacity(ncores);
POOR_MANS_BARRIER.store(ncores, Ordering::SeqCst);
log::info!("Set barrier to: {:?}", POOR_MANS_BARRIER);

for core_index in 0..ncores {
thandles.push(
Expand Down

0 comments on commit a0bee26

Please sign in to comment.