read idle kernel config after experiment end

This commit is contained in:
Simon Renblad 2024-08-06 13:43:34 +08:00
parent 78d6b7ddcf
commit ba3e38db11
2 changed files with 11 additions and 11 deletions

View File

@ -777,7 +777,6 @@ pub fn main(timer: GlobalTimer, cfg: Config) {
moninj::start(timer, &aux_mutex, &drtio_routing_table); moninj::start(timer, &aux_mutex, &drtio_routing_table);
let control: Rc<RefCell<kernel::Control>> = Rc::new(RefCell::new(kernel::Control::start())); let control: Rc<RefCell<kernel::Control>> = Rc::new(RefCell::new(kernel::Control::start()));
let idle_kernel = Rc::new(cfg.read("idle_kernel").ok());
if let Ok(buffer) = cfg.read("startup_kernel") { if let Ok(buffer) = cfg.read("startup_kernel") {
info!("Loading startup kernel..."); info!("Loading startup kernel...");
let routing_table = drtio_routing_table.borrow(); let routing_table = drtio_routing_table.borrow();
@ -804,14 +803,15 @@ pub fn main(timer: GlobalTimer, cfg: Config) {
} }
} }
mgmt::start(cfg); let cfg: Rc<Config> = Rc::new(cfg);
mgmt::start(cfg.clone());
task::spawn(async move { task::spawn(async move {
let connection = Rc::new(Semaphore::new(0, 1)); let connection = Rc::new(Semaphore::new(0, 1));
let terminate = Rc::new(Semaphore::new(0, 1)); let terminate = Rc::new(Semaphore::new(0, 1));
{ {
let control = control.clone(); let control = control.clone();
let idle_kernel = idle_kernel.clone(); let cfg = cfg.clone();
let connection = connection.clone(); let connection = connection.clone();
let terminate = terminate.clone(); let terminate = terminate.clone();
let up_destinations = up_destinations.clone(); let up_destinations = up_destinations.clone();
@ -819,9 +819,10 @@ pub fn main(timer: GlobalTimer, cfg: Config) {
let routing_table = drtio_routing_table.clone(); let routing_table = drtio_routing_table.clone();
task::spawn(async move { task::spawn(async move {
let routing_table = routing_table.borrow(); let routing_table = routing_table.borrow();
let idle_kernel = cfg.read("idle_kernel").ok();
select_biased! { select_biased! {
_ = (async { _ = (async {
if let Some(buffer) = &*idle_kernel { if let Some(buffer) = &idle_kernel {
load_and_run_idle_kernel(&buffer, &control, &up_destinations, &aux_mutex, &routing_table, timer).await; load_and_run_idle_kernel(&buffer, &control, &up_destinations, &aux_mutex, &routing_table, timer).await;
} }
}).fuse() => (), }).fuse() => (),
@ -841,7 +842,7 @@ pub fn main(timer: GlobalTimer, cfg: Config) {
} }
let control = control.clone(); let control = control.clone();
let idle_kernel = idle_kernel.clone(); let cfg = cfg.clone();
let connection = connection.clone(); let connection = connection.clone();
let terminate = terminate.clone(); let terminate = terminate.clone();
let up_destinations = up_destinations.clone(); let up_destinations = up_destinations.clone();
@ -852,12 +853,13 @@ pub fn main(timer: GlobalTimer, cfg: Config) {
let _ = terminate.try_wait(); let _ = terminate.try_wait();
task::spawn(async move { task::spawn(async move {
let routing_table = routing_table.borrow(); let routing_table = routing_table.borrow();
let idle_kernel = cfg.read("idle_kernel").ok();
select_biased! { select_biased! {
_ = (async { _ = (async {
let _ = handle_connection(&mut stream, control.clone(), &up_destinations, &aux_mutex, &routing_table, timer) let _ = handle_connection(&mut stream, control.clone(), &up_destinations, &aux_mutex, &routing_table, timer)
.await .await
.map_err(|e| warn!("connection terminated: {}", e)); .map_err(|e| warn!("connection terminated: {}", e));
if let Some(buffer) = &*idle_kernel { if let Some(buffer) = &idle_kernel {
load_and_run_idle_kernel(&buffer, &control, &up_destinations, &aux_mutex, &routing_table, timer).await; load_and_run_idle_kernel(&buffer, &control, &up_destinations, &aux_mutex, &routing_table, timer).await;
} }
}).fuse() => (), }).fuse() => (),
@ -913,8 +915,7 @@ pub fn soft_panic_main(timer: GlobalTimer, cfg: Config) -> ! {
}; };
Sockets::init(32); Sockets::init(32);
mgmt::start(Rc::new(cfg));
mgmt::start(cfg);
// getting eth settings disables the LED as it resets GPIO // getting eth settings disables the LED as it resets GPIO
// need to re-enable it here // need to re-enable it here

View File

@ -229,10 +229,9 @@ async fn handle_connection(stream: &mut TcpStream, pull_id: Rc<RefCell<u32>>, cf
} }
} }
pub fn start(cfg: Config) { pub fn start(cfg: Rc<Config>) {
task::spawn(async move { task::spawn(async move {
let pull_id = Rc::new(RefCell::new(0u32)); let pull_id = Rc::new(RefCell::new(0u32));
let cfg = Rc::new(cfg);
loop { loop {
let mut stream = TcpStream::accept(1380, 2048, 2048).await.unwrap(); let mut stream = TcpStream::accept(1380, 2048, 2048).await.unwrap();
let pull_id = pull_id.clone(); let pull_id = pull_id.clone();