From e7752a3d6d17428b069e30fa6502a9638af4db9a Mon Sep 17 00:00:00 2001 From: pca006132 Date: Wed, 5 Aug 2020 15:54:45 +0800 Subject: [PATCH] runtime/kernel: fixes core0 memory leak. Fixes #85 --- default.nix | 2 +- src/Cargo.lock | 10 +++++----- src/runtime/src/kernel/control.rs | 10 ++++++++-- src/runtime/src/kernel/core1.rs | 2 ++ src/runtime/src/kernel/mod.rs | 2 ++ 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/default.nix b/default.nix index a06bbc6c..885e2dbe 100644 --- a/default.nix +++ b/default.nix @@ -14,7 +14,7 @@ let version = "0.1.0"; src = ./src; - cargoSha256 = "0da6smxhlq1z739g8pdhmkfiq7b8vjqapvskz58rzklh9scf2i99"; + cargoSha256 = "1lxjb37vl7s359r4801n7b73wnm3p28qlafl04vs9pznadcf6ar0"; nativeBuildInputs = [ pkgs.gnumake diff --git a/src/Cargo.lock b/src/Cargo.lock index 7cedaea3..e97e3c72 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -201,7 +201,7 @@ dependencies = [ [[package]] name = "libasync" version = "0.0.0" -source = "git+https://git.m-labs.hk/M-Labs/zc706.git#25c6d5eeaa6243724700e975e3935a5965c09a27" +source = "git+https://git.m-labs.hk/M-Labs/zc706.git#3958953ceb56aa81e33fb4f3d19ab7ee4c06d1ba" dependencies = [ "embedded-hal", "libcortex_a9", @@ -213,7 +213,7 @@ dependencies = [ [[package]] name = "libboard_zynq" version = "0.0.0" -source = "git+https://git.m-labs.hk/M-Labs/zc706.git#25c6d5eeaa6243724700e975e3935a5965c09a27" +source = "git+https://git.m-labs.hk/M-Labs/zc706.git#3958953ceb56aa81e33fb4f3d19ab7ee4c06d1ba" dependencies = [ "bit_field", "embedded-hal", @@ -237,7 +237,7 @@ dependencies = [ [[package]] name = "libcortex_a9" version = "0.0.0" -source = "git+https://git.m-labs.hk/M-Labs/zc706.git#25c6d5eeaa6243724700e975e3935a5965c09a27" +source = "git+https://git.m-labs.hk/M-Labs/zc706.git#3958953ceb56aa81e33fb4f3d19ab7ee4c06d1ba" dependencies = [ "bit_field", "libregister", @@ -252,7 +252,7 @@ checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a" [[package]] name = "libregister" version = "0.0.0" -source = "git+https://git.m-labs.hk/M-Labs/zc706.git#25c6d5eeaa6243724700e975e3935a5965c09a27" +source = "git+https://git.m-labs.hk/M-Labs/zc706.git#3958953ceb56aa81e33fb4f3d19ab7ee4c06d1ba" dependencies = [ "bit_field", "vcell", @@ -262,7 +262,7 @@ dependencies = [ [[package]] name = "libsupport_zynq" version = "0.0.0" -source = "git+https://git.m-labs.hk/M-Labs/zc706.git#25c6d5eeaa6243724700e975e3935a5965c09a27" +source = "git+https://git.m-labs.hk/M-Labs/zc706.git#3958953ceb56aa81e33fb4f3d19ab7ee4c06d1ba" dependencies = [ "compiler_builtins", "libboard_zynq", diff --git a/src/runtime/src/kernel/control.rs b/src/runtime/src/kernel/control.rs index 9a7d1a91..91fefa31 100644 --- a/src/runtime/src/kernel/control.rs +++ b/src/runtime/src/kernel/control.rs @@ -1,7 +1,7 @@ use libcortex_a9::sync_channel::{Sender, Receiver}; use libsupport_zynq::boot::Core1; -use super::{CHANNEL_0TO1, CHANNEL_1TO0, Message}; +use super::{CHANNEL_0TO1, CHANNEL_1TO0, INIT_LOCK, Message}; use crate::irq::restart_core1; use core::mem::{forget, replace}; @@ -39,7 +39,13 @@ impl Control { } pub fn restart(&mut self) { - restart_core1(); + { + INIT_LOCK.lock(); + restart_core1(); + unsafe { + self.tx.drop_elements(); + } + } let (core0_tx, core0_rx) = get_channels(); // dangling pointer here, so we forget it forget(replace(&mut self.tx, core0_tx)); diff --git a/src/runtime/src/kernel/core1.rs b/src/runtime/src/kernel/core1.rs index ac0632bf..15cf156b 100644 --- a/src/runtime/src/kernel/core1.rs +++ b/src/runtime/src/kernel/core1.rs @@ -18,6 +18,7 @@ use crate::eh_artiq; use super::{ api::resolve, rpc::rpc_send_async, + INIT_LOCK, CHANNEL_0TO1, CHANNEL_1TO0, KERNEL_CHANNEL_0TO1, KERNEL_CHANNEL_1TO0, KERNEL_IMAGE, @@ -147,6 +148,7 @@ pub fn main_core1() { let (mut core0_tx, mut core1_rx) = sync_channel!(Message, 4); let (mut core1_tx, core0_rx) = sync_channel!(Message, 4); unsafe { + INIT_LOCK.lock(); core0_tx.reset(); core1_tx.reset(); dma::init_dma_recorder(); diff --git a/src/runtime/src/kernel/mod.rs b/src/runtime/src/kernel/mod.rs index 6605fce3..ea3ecd54 100644 --- a/src/runtime/src/kernel/mod.rs +++ b/src/runtime/src/kernel/mod.rs @@ -54,3 +54,5 @@ static KERNEL_CHANNEL_1TO0: Mutex> static mut KERNEL_IMAGE: *const core1::KernelImage = ptr::null(); +static INIT_LOCK: Mutex<()> = Mutex::new(()); +