Skip to content

Commit

Permalink
fix: continue schedule after reconfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
dadada authored and sevenautumns committed Jan 14, 2025
1 parent 63cdb12 commit ac19a48
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 19 deletions.
6 changes: 4 additions & 2 deletions a653rs-router-linux/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use a653rs::bindings::ApexPartitionP4;
use a653rs::prelude::{Name, OperatingMode, Partition, PartitionExt, StartContext};
use a653rs::prelude::{ApexTimeP4Ext, Name, OperatingMode, Partition, PartitionExt, StartContext};
use a653rs_linux::partition::{ApexLinuxPartition, ApexLogger};
use a653rs_router::prelude::{RouterConfig, RouterState, VirtualLinksConfig};
use a653rs_router_linux::*;
Expand Down Expand Up @@ -54,7 +54,9 @@ impl Partition<Hypervisor> for RouterPartition {
extern "C" fn entry_point() {
let router = unsafe { ROUTER.as_ref() }.unwrap();
let cfg = unsafe { VL_CFG.as_ref() }.unwrap().clone();
let mut state = router.router::<INPUTS, OUTPUTS, MTU>(cfg).unwrap();
let mut state = router
.router::<INPUTS, OUTPUTS, MTU>(cfg, &Hypervisor::get_time().unwrap_duration())
.unwrap();
loop {
let res = state.forward::<MTU, _>(&ApexLinuxPartition);
#[cfg(feature = "log")]
Expand Down
6 changes: 4 additions & 2 deletions a653rs-router-tests/tests/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use a653rs::prelude::{Name, Partition, PartitionExt, StartContext};
use a653rs_router::prelude::{RouterConfig, RouterState, VirtualLinksConfig};
use a653rs_router_tests::{test_data::CFG, DummyHypervisor, DummyNetIntf};
use core::str::FromStr;
use std::process::exit;
use std::{process::exit, time::Duration};

const MTU: usize = 1_000;
const INPUTS: usize = 8;
Expand Down Expand Up @@ -51,7 +51,9 @@ impl Partition<DummyHypervisor> for RouterPartition {
extern "C" fn entry_point() {
let router = unsafe { ROUTER.as_ref() }.unwrap();
let cfg = unsafe { VL_CFG.as_ref() }.unwrap().clone();
let router = router.router::<INPUTS, OUTPUTS, MTU>(cfg).unwrap();
let router = router
.router::<INPUTS, OUTPUTS, MTU>(cfg, &Duration::from_secs(0))
.unwrap();
println!("{router:?}")
}

Expand Down
6 changes: 5 additions & 1 deletion a653rs-router-zynq7000/src/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,14 @@ impl Partition<XngHypervisor> for RouterPartition {
}

extern "C" fn entry_point() {
use a653rs::prelude::ApexTimeP4Ext;

info!("Running router entry_point");
let router = unsafe { ROUTER.as_ref() }.unwrap();
let cfg = unsafe { VL_CFG.as_ref() }.unwrap().clone();
let mut router = router.router::<INPUTS, OUTPUTS, MTU>(cfg).unwrap();
let mut router = router
.router::<INPUTS, OUTPUTS, MTU>(cfg, &XngHypervisor::get_time().unwrap_duration())
.unwrap();
loop {
let res = router.forward::<MTU, _>(&XngHypervisor);
#[cfg(feature = "log")]
Expand Down
5 changes: 4 additions & 1 deletion a653rs-router/src/partition.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::time::Duration;

use a653rs::{
bindings::{ApexProcessP4, ApexQueuingPortP4, ApexSamplingPortP4, StackSize},
prelude::{Name, StartContext},
Expand Down Expand Up @@ -80,7 +82,8 @@ where
pub fn router<const IN: usize, const OUT: usize, const BUF_LEN: usize>(
&self,
virtual_links_cfg: VirtualLinksConfig<IN, OUT>,
schedule_start: &Duration,
) -> Result<Router<IN, OUT>, Error> {
Router::try_new(virtual_links_cfg, &self.resources)
Router::try_new(virtual_links_cfg, &self.resources, schedule_start)
}
}
3 changes: 2 additions & 1 deletion a653rs-router/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,14 @@ impl<'a, const IN: usize, const OUT: usize> Router<'a, IN, OUT> {
>(
virtual_links_cfg: VirtualLinksConfig<IN, OUT>,
resources: &'a RouterResources<H, P, IFS, PORTS>,
schedule_start: &Duration,
) -> Result<Self, Error> {
let routes = RouteTable::<IN, OUT>::build(&virtual_links_cfg, resources)?;
let scheduler_cfg: Vec<(VirtualLinkId, Duration), IN> = virtual_links_cfg
.into_iter()
.map(|(id, cfg)| (*id, cfg.period))
.collect();
let scheduler = DeadlineRrScheduler::try_new(&scheduler_cfg)?;
let scheduler = DeadlineRrScheduler::try_new(&scheduler_cfg, schedule_start)?;
let router = Self { routes, scheduler };
Ok(router)
}
Expand Down
23 changes: 11 additions & 12 deletions a653rs-router/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ struct Window {
/// The next period is measured from the last time the start of the last
/// time the partition has been scheduled or from the beginning of time.
period: Duration,
/// The next instant at which this window should be scheduled.
next: Duration,
/// The last instant at which this window was scheduled.
last: Duration,
}

impl Window {
fn is_due(&self, current_time: &Duration) -> bool {
self.next <= *current_time
self.last + self.period <= *current_time
}
}

Expand All @@ -52,15 +52,18 @@ pub struct DeadlineRrScheduler<const SLOTS: usize> {

impl<const SLOTS: usize> DeadlineRrScheduler<SLOTS> {
/// Constructs a new DeadlineRrScheduler.
pub fn try_new(vls: &[(VirtualLinkId, Duration)]) -> Result<Self, RouterConfigError> {
pub fn try_new(
vls: &[(VirtualLinkId, Duration)],
start: &Duration,
) -> Result<Self, RouterConfigError> {
Ok(Self {
last_window: 0,
windows: vls
.iter()
.map(|(vl, period)| Window {
vl: *vl,
period: *period,
next: *period,
last: *start + *period,
})
.collect(),
})
Expand All @@ -79,19 +82,15 @@ impl<const SLOTS: usize> Scheduler for DeadlineRrScheduler<SLOTS> {
let next_window = (self.last_window + i) % self.windows.len();
let window = self.windows[next_window];
if window.is_due(current_time) {
// Check if clock skipped for some reason.
if let Some(t) = current_time.checked_sub(Duration::from_secs(15)) {
if t > window.next {
if t > window.last + window.period {
router_debug!("The system clock is {current_time:?} and this does not seem right. Ignoring this value.");
return None;
}
}
self.last_window = next_window;
let next = current_time
.checked_add(window.period)
.unwrap_or(*current_time);
self.windows[next_window].next = next;
router_trace!("Scheduled VL {}, next window at {:?}", window.vl, next);
self.windows[next_window].last = *current_time;
router_trace!("Scheduled VL {}", window.vl);
// Return the next window
return Some(window.vl);
}
Expand Down

0 comments on commit ac19a48

Please sign in to comment.