From f1376aebd0bc22d36d0e299146b86014a2af3a06 Mon Sep 17 00:00:00 2001 From: Erika Hunhoff Date: Thu, 10 Aug 2023 18:18:20 +0000 Subject: [PATCH] Update header size --- kernel/run.py | 2 +- .../arch/x86_64/rackscale/get_shmem_structure.rs | 6 +++--- kernel/src/arch/x86_64/rackscale/kernelrpc.rs | 4 ++-- lib/rpc/src/client.rs | 3 ++- lib/rpc/src/rpc.rs | 15 ++++++++------- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/kernel/run.py b/kernel/run.py index ff588750e..fb02aaaa9 100644 --- a/kernel/run.py +++ b/kernel/run.py @@ -57,7 +57,7 @@ def get_network_config(workers): NETWORK_CONFIG = get_network_config(MAX_WORKERS) NETWORK_INFRA_IP = '172.31.0.20/24' -DCM_SCHEDULER_VERSION = "1.1.14" +DCM_SCHEDULER_VERSION = "1.1.15" # # Important globals diff --git a/kernel/src/arch/x86_64/rackscale/get_shmem_structure.rs b/kernel/src/arch/x86_64/rackscale/get_shmem_structure.rs index 6f6537541..3c2a5f997 100644 --- a/kernel/src/arch/x86_64/rackscale/get_shmem_structure.rs +++ b/kernel/src/arch/x86_64/rackscale/get_shmem_structure.rs @@ -145,7 +145,7 @@ pub(crate) fn handle_get_shmem_structure( // Modify header and write into output buffer unsafe { encode(&logs, &mut payload) }.unwrap(); - hdr.msg_len = core::mem::size_of::<[u64; MAX_PROCESSES]>() as u64; + hdr.msg_len = core::mem::size_of::<[u64; MAX_PROCESSES]>() as MsgLen; } ShmemStructure::NrLog => { let log_clone = Arc::into_raw(Arc::clone(&NR_LOG)); @@ -155,7 +155,7 @@ pub(crate) fn handle_get_shmem_structure( // Modify header and write into output buffer unsafe { encode(&[log_paddr], &mut payload) }.unwrap(); - hdr.msg_len = core::mem::size_of::<[u64; 1]>() as u64; + hdr.msg_len = core::mem::size_of::<[u64; 1]>() as MsgLen; } ShmemStructure::WorkQueues => { let client_workqueue_clone = Arc::into_raw(Arc::clone(&RACKSCALE_CLIENT_WORKQUEUES)); @@ -168,7 +168,7 @@ pub(crate) fn handle_get_shmem_structure( // Modify header and write into output buffer unsafe { encode(&[arc_workqueue_paddr], &mut payload) }.unwrap(); - hdr.msg_len = core::mem::size_of::<[u64; 1]>() as u64; + hdr.msg_len = core::mem::size_of::<[u64; 1]>() as MsgLen; } } diff --git a/kernel/src/arch/x86_64/rackscale/kernelrpc.rs b/kernel/src/arch/x86_64/rackscale/kernelrpc.rs index ce26d763c..145669617 100644 --- a/kernel/src/arch/x86_64/rackscale/kernelrpc.rs +++ b/kernel/src/arch/x86_64/rackscale/kernelrpc.rs @@ -88,7 +88,7 @@ impl TryFrom for KernelRpc { } } -pub(crate) const KernelRpcRes_SIZE: u64 = core::mem::size_of::>() as u64; +pub(crate) const KernelRpcRes_SIZE: u16 = core::mem::size_of::>() as MsgLen; #[inline(always)] pub(crate) fn construct_error_ret(hdr: &mut RPCHeader, payload: &mut [u8], err: KError) { @@ -111,5 +111,5 @@ pub(crate) fn construct_ret_extra_data( unsafe { encode(&res, &mut payload) }.unwrap(); // Modify header and write into output buffer - hdr.msg_len = KernelRpcRes_SIZE + additional_data_len; + hdr.msg_len = KernelRpcRes_SIZE + additional_data_len as MsgLen; } diff --git a/lib/rpc/src/client.rs b/lib/rpc/src/client.rs index 3419d46ff..4dd0863b2 100644 --- a/lib/rpc/src/client.rs +++ b/lib/rpc/src/client.rs @@ -34,13 +34,14 @@ impl Client { ) -> Result<(), RPCError> { // Calculate total data_out len let data_in_len = data_in.iter().fold(0, |acc, x| acc + x.len()); + debug_assert!(data_in_len < MsgLen::MAX as usize); // Create request header and send message. It is safe to create a mutable reference here // because it is assumed there will only be one invocation of call() running at a time, and only // the client has access to this field. let mut hdr = &mut self.hdr; hdr.msg_type = rpc_id; - hdr.msg_len = data_in_len as u64; + hdr.msg_len = data_in_len as MsgLen; self.transport.send_msg(hdr, data_in)?; // Receive the response diff --git a/lib/rpc/src/rpc.rs b/lib/rpc/src/rpc.rs index 2921456c6..c0894ade0 100644 --- a/lib/rpc/src/rpc.rs +++ b/lib/rpc/src/rpc.rs @@ -23,17 +23,18 @@ pub enum RPCError { } unsafe_abomonate!(RPCError); -// TODO(efficiency): type could probably be u8, but this seems easier for alignment w/ DCM? -pub type RPCType = u64; -pub const RPC_TYPE_CONNECT: u64 = 0u64; +pub type RPCType = u8; +pub const RPC_TYPE_CONNECT: u8 = 0u8; +pub type MsgId = u8; +pub type MsgLen = u16; -#[derive(Debug, Default)] -#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +#[repr(C, packed)] pub struct RPCHeader { + pub msg_id: MsgId, pub msg_type: RPCType, - pub msg_len: u64, + pub msg_len: MsgLen, } - pub const HDR_LEN: usize = core::mem::size_of::(); impl RPCHeader {