Skip to content

Commit

Permalink
Wip.
Browse files Browse the repository at this point in the history
Signed-off-by: Gerd Zellweger <mail@gerdzellweger.com>
  • Loading branch information
gz committed Nov 16, 2023
1 parent c9d0886 commit 794d5d0
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 18 deletions.
9 changes: 0 additions & 9 deletions kernel/src/arch/x86_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,15 +514,6 @@ fn _start(argc: isize, _argv: *const *const u8) -> isize {
// Intialize PCI
crate::pci::init();

// Initialize processes
#[cfg(feature = "rackscale")]
if crate::CMDLINE
.get()
.map_or(false, |c| c.mode == crate::cmdline::Mode::Controller)
{
lazy_static::initialize(&process::PROCESS_TABLE);
}

#[cfg(not(feature = "rackscale"))]
{
lazy_static::initialize(&process::PROCESS_TABLE);
Expand Down
10 changes: 6 additions & 4 deletions kernel/src/arch/x86_64/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ lazy_static! {
pub(crate) static ref PROCESS_TABLE: ArrayVec<Arc<RwLock<NodeReplicated<NrProcess<Ring3Process>>>>, MAX_PROCESSES> = {
use crate::memory::shmem_affinity::mid_to_shmem_affinity;
use crate::arch::kcb::per_core_mem;
use crate::environment::NUM_MACHINES;

if !crate::CMDLINE
.get()
Expand Down Expand Up @@ -106,7 +107,7 @@ lazy_static! {

// Want at least one replica...
let num_replicas =
NonZeroUsize::new(core::cmp::max(1, atopology::MACHINE_TOPOLOGY.num_nodes())).unwrap();
NonZeroUsize::new(core::cmp::max(1, atopology::MACHINE_TOPOLOGY.num_nodes() * (*NUM_MACHINES))).unwrap();
let mut processes = ArrayVec::new();

for _pid in 0..MAX_PROCESSES {
Expand Down Expand Up @@ -1485,6 +1486,7 @@ impl Process for Ring3Process {
fn allocate_executors(
&mut self,
memory: Frame,
#[cfg(feature = "rackscale")] mid: kpi::system::MachineId,
) -> Result<usize, KError> {
let executor_space_requirement = Ring3Executor::EXECUTOR_SPACE_REQUIREMENT;
let executors_to_create = memory.size() / executor_space_requirement;
Expand Down Expand Up @@ -1536,11 +1538,11 @@ impl Process for Ring3Process {
memory.affinity,
))?;

#[cfg(not(feature = "rackscale"))]
let index = memory.affinity as usize;

//TODO: xxx
//#[cfg(feature = "rackscale")]
//let index = self.get_executor_index(memory.affinity, mid);
#[cfg(feature = "rackscale")]
let index = self.get_executor_index(memory.affinity, mid);

// TODO(error-handling): Needs to properly unwind on alloc errors
// (e.g., have something that frees vcpu mem etc. on drop())
Expand Down
3 changes: 3 additions & 0 deletions kernel/src/arch/x86_64/rackscale/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ pub(crate) fn run() {

// TODO(dynrep): here is the point where we have all the memory regions and
// could create NodeReplicated instances for each client.
// Initialize processes
use crate::arch::process::PROCESS_TABLE;
lazy_static::initialize(&PROCESS_TABLE);

#[cfg(feature = "test-controller-shmem-alloc")]
{
Expand Down
5 changes: 5 additions & 0 deletions kernel/src/memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ impl KernelAllocator {
use crate::arch::rackscale::get_shmem_frames::rpc_get_shmem_frames;
use crate::arch::rackscale::CLIENT_STATE;

if needed_base_pages == 0 && needed_large_pages == 0 {
return Ok(());
}

// We only request at large page granularity
let mut total_needed_large_pages = needed_large_pages;
let mut total_needed_base_pages = needed_base_pages;
Expand Down Expand Up @@ -415,6 +419,7 @@ impl KernelAllocator {
}
frames
} else {
log::info!("try-refill-shmem needed_base_pages={needed_base_pages} needed_large_pages={needed_large_pages} total_needed_base_pages={total_needed_base_pages} total_needed_large_pages={total_needed_large_pages}");
rpc_get_shmem_frames(None, total_needed_large_pages)?
};

Expand Down
20 changes: 18 additions & 2 deletions kernel/src/nrproc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@ pub(crate) enum ProcessOpMut {
/// Remove a physical frame previosuly allocated to the process (returns a Frame).
ReleaseFrameFromProcess(FrameId),

#[cfg(feature = "rackscale")]
DispatcherAllocation(Frame, kpi::system::MachineId),

#[cfg(not(feature = "rackscale"))]
DispatcherAllocation(Frame),

MemMapFrame(VAddr, Frame, MapAction),
MemMapDevice(Frame, MapAction),
MemMapFrameId(VAddr, FrameId, MapAction),
Expand Down Expand Up @@ -388,11 +392,16 @@ impl<P: Process> NrProcess<P> {
pub(crate) fn allocate_dispatchers(pid: Pid, frame: Frame) -> Result<usize, KError> {
debug_assert!(pid < MAX_PROCESSES, "Invalid PID");

#[cfg(feature = "rackscale")]
let mid = *crate::environment::MACHINE_ID;
let response = PROCESS_TABLE[pid].read(*crate::environment::MT_ID).execute_mut(
#[cfg(not(feature = "rackscale"))]
ProcessOpMut::DispatcherAllocation(frame),
#[cfg(feature = "rackscale")]
ProcessOpMut::DispatcherAllocation(frame, mid),
PROCESS_TOKEN.get().unwrap()[pid],
);

match response {
Ok(ProcessResult::ExecutorsCreated(how_many)) => Ok(how_many),
Err(e) => Err(e),
Expand Down Expand Up @@ -545,11 +554,18 @@ where
Ok(ProcessResult::Ok)
}

#[cfg(not(feature = "rackscale"))]
ProcessOpMut::DispatcherAllocation(frame) => {
let how_many = self.process.allocate_executors(frame)?;
Ok(ProcessResult::ExecutorsCreated(how_many))
}

#[cfg(feature = "rackscale")]
ProcessOpMut::DispatcherAllocation(frame, mid) => {
let how_many = self.process.allocate_executors(frame, mid)?;
Ok(ProcessResult::ExecutorsCreated(how_many))
}

ProcessOpMut::MemMapFrame(base, frame, action) => {
crate::memory::KernelAllocator::try_refill_tcache(7, 0, MemType::Mem)?;
self.process.vspace_mut().map_frame(base, frame, action)?;
Expand Down
3 changes: 2 additions & 1 deletion kernel/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub(crate) trait Process: FrameManagement + Clone {
affinity: atopology::NodeId,
) -> Result<(), alloc::collections::TryReserveError>;

fn allocate_executors(&mut self, frame: Frame) -> Result<usize, KError>;
fn allocate_executors(&mut self, frame: Frame, #[cfg(feature = "rackscale")] mid: kpi::system::MachineId) -> Result<usize, KError>;

fn vspace_mut(&mut self) -> &mut Self::A;

Expand Down Expand Up @@ -287,6 +287,7 @@ impl elfloader::ElfLoader for DataSecAllocator {
}
};

log::info!("DataSecAllocator::allocate");
let shmem_frames = rpc_get_shmem_frames(Some(self.pid), large_pages)
.expect("Failed to get shmem frames for elf loading");

Expand Down
5 changes: 3 additions & 2 deletions kernel/tests/s06_rackscale_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn rackscale_userspace_smoke_test(transport: RackscaleTransport) {
"test-upcall",
"test-scheduler",
"test-syscalls",
//"test-dynamic-replication"
"test-dynamic-replication"
])
.set_rackscale(true)
.release()
Expand All @@ -58,7 +58,7 @@ fn rackscale_userspace_smoke_test(transport: RackscaleTransport) {
*output += proc.exp_string("map_test OK")?.as_str();
*output += proc.exp_string("alloc_test OK")?.as_str();
*output += proc.exp_string("scheduler_test OK")?.as_str();
//*output += proc.exp_string("dynamic_replication OK")?.as_str();
*output += proc.exp_string("dynamic_replication OK")?.as_str();
Ok(())
}

Expand All @@ -67,6 +67,7 @@ fn rackscale_userspace_smoke_test(transport: RackscaleTransport) {
test_run.transport = transport;
test_run.wait_for_client = true;
test_run.shmem_size *= 2;
test_run.num_clients = 3;
test_run.run_rackscale();
}

Expand Down

0 comments on commit 794d5d0

Please sign in to comment.