From d3545a774a176543a1e841337aa9deba5c14c8e6 Mon Sep 17 00:00:00 2001 From: mwojcik Date: Fri, 18 Oct 2024 13:51:48 +0800 Subject: [PATCH] subkernels: pass now_mu when calling subkernels --- src/libboard_artiq/src/drtioaux_proto.rs | 4 ++++ src/libksupport/src/kernel/mod.rs | 1 + src/libksupport/src/kernel/subkernel.rs | 3 ++- src/runtime/src/comms.rs | 3 ++- src/runtime/src/rtio_mgt.rs | 2 ++ src/runtime/src/subkernel.rs | 3 ++- src/satman/src/main.rs | 3 ++- src/satman/src/subkernel.rs | 7 +++++-- 8 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/libboard_artiq/src/drtioaux_proto.rs b/src/libboard_artiq/src/drtioaux_proto.rs index 6232260..acea1d7 100644 --- a/src/libboard_artiq/src/drtioaux_proto.rs +++ b/src/libboard_artiq/src/drtioaux_proto.rs @@ -255,6 +255,7 @@ pub enum Packet { destination: u8, id: u32, run: bool, + timestamp: u64, }, SubkernelLoadRunReply { destination: u8, @@ -514,6 +515,7 @@ impl Packet { destination: reader.read_u8()?, id: reader.read_u32()?, run: reader.read_bool()?, + timestamp: reader.read_u64()?, }, 0xc5 => Packet::SubkernelLoadRunReply { destination: reader.read_u8()?, @@ -877,12 +879,14 @@ impl Packet { destination, id, run, + timestamp, } => { writer.write_u8(0xc4)?; writer.write_u8(source)?; writer.write_u8(destination)?; writer.write_u32(id)?; writer.write_bool(run)?; + writer.write_u64(timestamp)?; } Packet::SubkernelLoadRunReply { destination, succeeded } => { writer.write_u8(0xc5)?; diff --git a/src/libksupport/src/kernel/mod.rs b/src/libksupport/src/kernel/mod.rs index 8a8d48d..69ccd8d 100644 --- a/src/libksupport/src/kernel/mod.rs +++ b/src/libksupport/src/kernel/mod.rs @@ -80,6 +80,7 @@ pub enum Message { id: u32, destination: u8, run: bool, + timestamp: u64, }, #[cfg(has_drtio)] SubkernelLoadRunReply { diff --git a/src/libksupport/src/kernel/subkernel.rs b/src/libksupport/src/kernel/subkernel.rs index 66adb46..ed02188 100644 --- a/src/libksupport/src/kernel/subkernel.rs +++ b/src/libksupport/src/kernel/subkernel.rs @@ -3,7 +3,7 @@ use alloc::vec::Vec; use cslice::CSlice; use super::{Message, SubkernelStatus, KERNEL_CHANNEL_0TO1, KERNEL_CHANNEL_1TO0}; -use crate::{artiq_raise, eh_artiq, rpc::send_args}; +use crate::{artiq_raise, eh_artiq, rpc::send_args, rtio::now_mu}; pub extern "C" fn load_run(id: u32, destination: u8, run: bool) { unsafe { @@ -14,6 +14,7 @@ pub extern "C" fn load_run(id: u32, destination: u8, run: bool) { id: id, destination: destination, run: run, + timestamp: now_mu() as u64, }); } match unsafe { KERNEL_CHANNEL_0TO1.as_mut().unwrap() }.recv() { diff --git a/src/runtime/src/comms.rs b/src/runtime/src/comms.rs index 0e21c98..8aa0ea9 100644 --- a/src/runtime/src/comms.rs +++ b/src/runtime/src/comms.rs @@ -405,8 +405,9 @@ async fn handle_run_kernel( id, destination: _, run, + timestamp } => { - let succeeded = match subkernel::load(aux_mutex, routing_table, timer, id, run).await { + let succeeded = match subkernel::load(aux_mutex, routing_table, timer, id, run, timestamp).await { Ok(()) => true, Err(e) => { error!("Error loading subkernel: {:?}", e); diff --git a/src/runtime/src/rtio_mgt.rs b/src/runtime/src/rtio_mgt.rs index 53a3b8b..f62fe75 100644 --- a/src/runtime/src/rtio_mgt.rs +++ b/src/runtime/src/rtio_mgt.rs @@ -792,6 +792,7 @@ pub mod drtio { id: u32, destination: u8, run: bool, + timestamp: u64, ) -> Result<(), Error> { let linkno = routing_table.0[destination as usize][0] - 1; let reply = aux_transact( @@ -803,6 +804,7 @@ pub mod drtio { source: 0, destination: destination, run: run, + timestamp, }, timer, ) diff --git a/src/runtime/src/subkernel.rs b/src/runtime/src/subkernel.rs index e1a1afc..1b47c36 100644 --- a/src/runtime/src/subkernel.rs +++ b/src/runtime/src/subkernel.rs @@ -100,12 +100,13 @@ pub async fn load( timer: GlobalTimer, id: u32, run: bool, + timestamp: u64, ) -> Result<(), Error> { if let Some(subkernel) = SUBKERNELS.async_lock().await.get_mut(&id) { if subkernel.state != SubkernelState::Uploaded { return Err(Error::IncorrectState); } - drtio::subkernel_load(aux_mutex, routing_table, timer, id, subkernel.destination, run).await?; + drtio::subkernel_load(aux_mutex, routing_table, timer, id, subkernel.destination, run, timestamp).await?; if run { subkernel.state = SubkernelState::Running; } diff --git a/src/satman/src/main.rs b/src/satman/src/main.rs index aebd9d6..6db698c 100644 --- a/src/satman/src/main.rs +++ b/src/satman/src/main.rs @@ -826,6 +826,7 @@ fn process_aux_packet( destination: _destination, id, run, + timestamp, } => { forward!( router, @@ -844,7 +845,7 @@ fn process_aux_packet( // cannot run kernel while DDMA is running succeeded = false; } else { - succeeded |= kernel_manager.run(source, id).is_ok(); + succeeded |= kernel_manager.run(source, id, timestamp).is_ok(); } } router.send( diff --git a/src/satman/src/subkernel.rs b/src/satman/src/subkernel.rs index 83d0c38..a49e29a 100644 --- a/src/satman/src/subkernel.rs +++ b/src/satman/src/subkernel.rs @@ -8,7 +8,7 @@ use core_io::{Error as IoError, Write}; use cslice::AsCSlice; use dma::{Error as DmaError, Manager as DmaManager}; use io::{Cursor, ProtoWrite}; -use ksupport::{eh_artiq, kernel, rpc}; +use ksupport::{eh_artiq, kernel, rpc, rtio}; use libboard_artiq::{drtio_routing::RoutingTable, drtioaux, drtioaux_proto::{PayloadStatus, MASTER_PAYLOAD_MAX_SIZE}, @@ -349,7 +349,7 @@ impl<'a> Manager<'_> { } } - pub fn run(&mut self, source: u8, id: u32) -> Result<(), Error> { + pub fn run(&mut self, source: u8, id: u32, timestamp: u64) -> Result<(), Error> { if self.session.kernel_state != KernelState::Loaded || self.session.id != id { self.load(id)?; } @@ -359,6 +359,7 @@ impl<'a> Manager<'_> { csr::cri_con::selected_write(2); } + rtio::at_mu(timestamp as i64); self.control.tx.send(kernel::Message::StartRequest); Ok(()) } @@ -812,6 +813,7 @@ impl<'a> Manager<'_> { id, destination: sk_destination, run, + timestamp, } => { self.session.kernel_state = KernelState::SubkernelAwaitLoad; router.route( @@ -820,6 +822,7 @@ impl<'a> Manager<'_> { destination: sk_destination, id: id, run: run, + timestamp, }, routing_table, rank,