From 6772344053c4a0796c6bebcd3d9f2bd325bc29b3 Mon Sep 17 00:00:00 2001 From: mwojcik Date: Fri, 25 Mar 2022 17:23:28 +0800 Subject: [PATCH 1/4] implement get_destination_status --- src/runtime/src/comms.rs | 17 +++++++++++------ src/runtime/src/kernel/api.rs | 3 ++- src/runtime/src/kernel/mod.rs | 4 ++++ src/runtime/src/kernel/rtio.rs | 19 +++++++++++++++++++ src/runtime/src/rtio_acp.rs | 5 ----- src/runtime/src/rtio_csr.rs | 5 ----- 6 files changed, 36 insertions(+), 17 deletions(-) create mode 100644 src/runtime/src/kernel/rtio.rs diff --git a/src/runtime/src/comms.rs b/src/runtime/src/comms.rs index 23ba645..d33e618 100644 --- a/src/runtime/src/comms.rs +++ b/src/runtime/src/comms.rs @@ -159,7 +159,7 @@ async fn write_exception_string(stream: &TcpStream, s: CSlice<'static, u8>) -> R Ok(()) } -async fn handle_run_kernel(stream: Option<&TcpStream>, control: &Rc>) -> Result<()> { +async fn handle_run_kernel(stream: Option<&TcpStream>, control: &Rc>, up_destinations: &Rc>) -> Result<()> { control.borrow_mut().tx.async_send(kernel::Message::StartRequest).await; loop { let reply = control.borrow_mut().rx.async_recv().await; @@ -290,6 +290,10 @@ async fn handle_run_kernel(stream: Option<&TcpStream>, control: &Rc { + let result = up_destinations.borrow()[destination as usize]; + control.borrow_mut().tx.async_send(kernel::Message::UpDestinationsReply(result)).await; + } _ => { panic!("unexpected message from core1 while kernel was running: {:?}", reply); } @@ -331,7 +335,7 @@ async fn load_kernel(buffer: &Vec, control: &Rc>, s } } -async fn handle_connection(stream: &mut TcpStream, control: Rc>) -> Result<()> { +async fn handle_connection(stream: &mut TcpStream, control: Rc>, up_destinations: &Rc>) -> Result<()> { stream.set_ack_delay(None); if !expect(stream, b"ARTIQ coredev\n").await? { @@ -354,7 +358,7 @@ async fn handle_connection(stream: &mut TcpStream, control: Rc { - handle_run_kernel(Some(stream), &control).await?; + handle_run_kernel(Some(stream), &control, &up_destinations).await?; }, _ => { error!("unexpected request from host: {:?}", request); @@ -427,7 +431,7 @@ pub fn main(timer: GlobalTimer, cfg: Config) { info!("Loading startup kernel..."); if let Ok(()) = task::block_on(load_kernel(&buffer, &control, None)) { info!("Starting startup kernel..."); - let _ = task::block_on(handle_run_kernel(None, &control)); + let _ = task::block_on(handle_run_kernel(None, &control, &up_destinations)); info!("Startup kernel finished!"); } else { error!("Error loading startup kernel!"); @@ -452,13 +456,14 @@ pub fn main(timer: GlobalTimer, cfg: Config) { let idle_kernel = idle_kernel.clone(); let connection = connection.clone(); let terminate = terminate.clone(); + let up_destinations = up_destinations.clone(); // we make sure the value of terminate is 0 before we start let _ = terminate.try_wait(); task::spawn(async move { select_biased! { _ = (async { - let _ = handle_connection(&mut stream, control.clone()) + let _ = handle_connection(&mut stream, control.clone(), &up_destinations) .await .map_err(|e| warn!("connection terminated: {}", e)); if let Some(buffer) = &*idle_kernel { @@ -466,7 +471,7 @@ pub fn main(timer: GlobalTimer, cfg: Config) { let _ = load_kernel(&buffer, &control, None) .await.map_err(|_| warn!("error loading idle kernel")); info!("Running idle kernel"); - let _ = handle_run_kernel(None, &control) + let _ = handle_run_kernel(None, &control, &up_destinations) .await.map_err(|_| warn!("error running idle kernel")); info!("Idle kernel terminated"); } diff --git a/src/runtime/src/kernel/api.rs b/src/runtime/src/kernel/api.rs index 1c55d3e..7b4c01d 100644 --- a/src/runtime/src/kernel/api.rs +++ b/src/runtime/src/kernel/api.rs @@ -13,6 +13,7 @@ use crate::i2c; use super::rpc::{rpc_send, rpc_send_async, rpc_recv}; use super::dma; use super::cache; +use super::rtio as kernel_rtio; extern "C" { @@ -87,7 +88,7 @@ pub fn resolve(required: &[u8]) -> Option { // rtio api!(rtio_init = rtio::init), - api!(rtio_get_destination_status = rtio::get_destination_status), + api!(rtio_get_destination_status = kernel_rtio::get_destination_status), api!(rtio_get_counter = rtio::get_counter), api!(rtio_output = rtio::output), api!(rtio_output_wide = rtio::output_wide), diff --git a/src/runtime/src/kernel/mod.rs b/src/runtime/src/kernel/mod.rs index 300acc5..c12cdb9 100644 --- a/src/runtime/src/kernel/mod.rs +++ b/src/runtime/src/kernel/mod.rs @@ -7,6 +7,7 @@ use crate::eh_artiq; mod control; pub use control::Control; pub mod core1; +pub mod rtio; mod api; mod rpc; mod dma; @@ -47,6 +48,9 @@ pub enum Message { DmaEraseRequest(String), DmaGetRequest(String), DmaGetReply(Option<(Vec, i64)>), + + UpDestinationsRequest(i32), + UpDestinationsReply(bool), } static CHANNEL_0TO1: Mutex>> = Mutex::new(None); diff --git a/src/runtime/src/kernel/rtio.rs b/src/runtime/src/kernel/rtio.rs new file mode 100644 index 0000000..0e2b679 --- /dev/null +++ b/src/runtime/src/kernel/rtio.rs @@ -0,0 +1,19 @@ +use super::{KERNEL_CHANNEL_0TO1, KERNEL_CHANNEL_1TO0, Message}; + +pub extern fn get_destination_status(destination: i32) -> bool { + #[cfg(has_drtio)] + if destination > 0 && destination < 255 { + let reply = unsafe { + let core1_rx = KERNEL_CHANNEL_0TO1.as_mut().unwrap(); + let core1_tx = KERNEL_CHANNEL_1TO0.as_mut().unwrap(); + core1_tx.send(Message::UpDestinationsRequest(destination)); + core1_rx.recv() + }; + return match reply { + Message::UpDestinationsReply(true) => true, + _ => false + }; + } + + destination == 0 +} \ No newline at end of file diff --git a/src/runtime/src/rtio_acp.rs b/src/runtime/src/rtio_acp.rs index f7987e1..4c1f33b 100644 --- a/src/runtime/src/rtio_acp.rs +++ b/src/runtime/src/rtio_acp.rs @@ -57,11 +57,6 @@ pub extern fn init() { } } -pub extern fn get_destination_status(destination: i32) -> bool { - // TODO - destination == 0 -} - pub extern fn get_counter() -> i64 { unsafe { csr::rtio::counter_update_write(1); diff --git a/src/runtime/src/rtio_csr.rs b/src/runtime/src/rtio_csr.rs index 1edd606..761dcbe 100644 --- a/src/runtime/src/rtio_csr.rs +++ b/src/runtime/src/rtio_csr.rs @@ -25,11 +25,6 @@ pub extern fn init() { } } -pub extern fn get_destination_status(destination: i32) -> bool { - // TODO - destination == 0 -} - pub extern fn get_counter() -> i64 { unsafe { csr::rtio::counter_update_write(1); -- 2.42.0 From b80cb3b288adca5ea4d59f8556ab6781945ecf33 Mon Sep 17 00:00:00 2001 From: mwojcik Date: Fri, 25 Mar 2022 17:33:40 +0800 Subject: [PATCH 2/4] get_destination_status: panic on wrong reply --- src/runtime/src/kernel/rtio.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runtime/src/kernel/rtio.rs b/src/runtime/src/kernel/rtio.rs index 0e2b679..bf04755 100644 --- a/src/runtime/src/kernel/rtio.rs +++ b/src/runtime/src/kernel/rtio.rs @@ -10,8 +10,8 @@ pub extern fn get_destination_status(destination: i32) -> bool { core1_rx.recv() }; return match reply { - Message::UpDestinationsReply(true) => true, - _ => false + Message::UpDestinationsReply(x) => x, + _ => panic!("received unexpected reply to UpDestinationsRequest: {:?}", reply) }; } -- 2.42.0 From 8e3b4625605e0493661c9cebcb8ca5fe1c36b35d Mon Sep 17 00:00:00 2001 From: mwojcik Date: Fri, 25 Mar 2022 17:50:26 +0800 Subject: [PATCH 3/4] get_destination_status: move from rtio to core1.rs --- src/runtime/src/kernel/api.rs | 5 ++--- src/runtime/src/kernel/core1.rs | 18 ++++++++++++++++++ src/runtime/src/kernel/mod.rs | 1 - src/runtime/src/kernel/rtio.rs | 19 ------------------- 4 files changed, 20 insertions(+), 23 deletions(-) delete mode 100644 src/runtime/src/kernel/rtio.rs diff --git a/src/runtime/src/kernel/api.rs b/src/runtime/src/kernel/api.rs index 7b4c01d..e86c2c2 100644 --- a/src/runtime/src/kernel/api.rs +++ b/src/runtime/src/kernel/api.rs @@ -13,8 +13,7 @@ use crate::i2c; use super::rpc::{rpc_send, rpc_send_async, rpc_recv}; use super::dma; use super::cache; -use super::rtio as kernel_rtio; - +use super::core1::get_destination_status; extern "C" { fn vsnprintf_(buffer: *mut c_char, count: size_t, format: *const c_char, va: VaList) -> c_int; @@ -88,7 +87,7 @@ pub fn resolve(required: &[u8]) -> Option { // rtio api!(rtio_init = rtio::init), - api!(rtio_get_destination_status = kernel_rtio::get_destination_status), + api!(rtio_get_destination_status = get_destination_status), api!(rtio_get_counter = rtio::get_counter), api!(rtio_output = rtio::output), api!(rtio_output_wide = rtio::output_wide), diff --git a/src/runtime/src/kernel/core1.rs b/src/runtime/src/kernel/core1.rs index 72725d1..9107bc4 100644 --- a/src/runtime/src/kernel/core1.rs +++ b/src/runtime/src/kernel/core1.rs @@ -233,3 +233,21 @@ extern fn dl_unwind_find_exidx(pc: *const u32, len_ptr: *mut u32) -> *const u32 } start } + +pub extern fn get_destination_status(destination: i32) -> bool { + #[cfg(has_drtio)] + if destination > 0 && destination < 255 { + let reply = unsafe { + let core1_rx = KERNEL_CHANNEL_0TO1.as_mut().unwrap(); + let core1_tx = KERNEL_CHANNEL_1TO0.as_mut().unwrap(); + core1_tx.send(Message::UpDestinationsRequest(destination)); + core1_rx.recv() + }; + return match reply { + Message::UpDestinationsReply(x) => x, + _ => panic!("received unexpected reply to UpDestinationsRequest: {:?}", reply) + }; + } + + destination == 0 +} \ No newline at end of file diff --git a/src/runtime/src/kernel/mod.rs b/src/runtime/src/kernel/mod.rs index c12cdb9..f1770a3 100644 --- a/src/runtime/src/kernel/mod.rs +++ b/src/runtime/src/kernel/mod.rs @@ -7,7 +7,6 @@ use crate::eh_artiq; mod control; pub use control::Control; pub mod core1; -pub mod rtio; mod api; mod rpc; mod dma; diff --git a/src/runtime/src/kernel/rtio.rs b/src/runtime/src/kernel/rtio.rs deleted file mode 100644 index bf04755..0000000 --- a/src/runtime/src/kernel/rtio.rs +++ /dev/null @@ -1,19 +0,0 @@ -use super::{KERNEL_CHANNEL_0TO1, KERNEL_CHANNEL_1TO0, Message}; - -pub extern fn get_destination_status(destination: i32) -> bool { - #[cfg(has_drtio)] - if destination > 0 && destination < 255 { - let reply = unsafe { - let core1_rx = KERNEL_CHANNEL_0TO1.as_mut().unwrap(); - let core1_tx = KERNEL_CHANNEL_1TO0.as_mut().unwrap(); - core1_tx.send(Message::UpDestinationsRequest(destination)); - core1_rx.recv() - }; - return match reply { - Message::UpDestinationsReply(x) => x, - _ => panic!("received unexpected reply to UpDestinationsRequest: {:?}", reply) - }; - } - - destination == 0 -} \ No newline at end of file -- 2.42.0 From 8daaacee6879710160df7b5de2de41b1c18a156d Mon Sep 17 00:00:00 2001 From: mwojcik Date: Fri, 25 Mar 2022 17:55:13 +0800 Subject: [PATCH 4/4] get_destination_status: add rtio_ prefix --- src/runtime/src/kernel/api.rs | 4 ++-- src/runtime/src/kernel/core1.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/runtime/src/kernel/api.rs b/src/runtime/src/kernel/api.rs index e86c2c2..a44ab6e 100644 --- a/src/runtime/src/kernel/api.rs +++ b/src/runtime/src/kernel/api.rs @@ -13,7 +13,7 @@ use crate::i2c; use super::rpc::{rpc_send, rpc_send_async, rpc_recv}; use super::dma; use super::cache; -use super::core1::get_destination_status; +use super::core1::rtio_get_destination_status; extern "C" { fn vsnprintf_(buffer: *mut c_char, count: size_t, format: *const c_char, va: VaList) -> c_int; @@ -87,7 +87,7 @@ pub fn resolve(required: &[u8]) -> Option { // rtio api!(rtio_init = rtio::init), - api!(rtio_get_destination_status = get_destination_status), + api!(rtio_get_destination_status = rtio_get_destination_status), api!(rtio_get_counter = rtio::get_counter), api!(rtio_output = rtio::output), api!(rtio_output_wide = rtio::output_wide), diff --git a/src/runtime/src/kernel/core1.rs b/src/runtime/src/kernel/core1.rs index 9107bc4..1ebee9e 100644 --- a/src/runtime/src/kernel/core1.rs +++ b/src/runtime/src/kernel/core1.rs @@ -234,7 +234,7 @@ extern fn dl_unwind_find_exidx(pc: *const u32, len_ptr: *mut u32) -> *const u32 start } -pub extern fn get_destination_status(destination: i32) -> bool { +pub extern fn rtio_get_destination_status(destination: i32) -> bool { #[cfg(has_drtio)] if destination > 0 && destination < 255 { let reply = unsafe { -- 2.42.0