Commit 16a494fd authored by RILLING Louis's avatar RILLING Louis
Browse files

fake-vm: The coordinator sends absolute deadlines, not deltas

parent 2e2ed21a
Pipeline #186923 passed with stages
in 12 minutes and 22 seconds
......@@ -368,8 +368,11 @@ pub mod test_helpers {
// (clean stop) or just closing the connection (reported as an error without making the test
// fail)
pub fn recv_one_msg_actor(actor: &mut TestActor) -> TestResult<()> {
let mut deadline = Duration::from_micros(0);
let slice = Duration::from_micros(100);
loop {
actor.send(MsgIn::GoToDeadline(Duration::new(0, 100000)))?;
deadline += slice;
actor.send(MsgIn::GoToDeadline(deadline))?;
let msg = actor.recv()?;
match msg {
MsgOut::AtDeadline => (),
......@@ -390,7 +393,7 @@ pub mod test_helpers {
let mut next_deadline_micros = slice_micros;
while next_deadline_micros < delay_micros {
actor.send(MsgIn::GoToDeadline(Duration::from_micros(slice_micros)))?;
actor.send(MsgIn::GoToDeadline(Duration::from_micros(next_deadline_micros)))?;
loop {
match actor.recv()? {
MsgOut::AtDeadline => break,
......@@ -401,8 +404,7 @@ pub mod test_helpers {
next_deadline_micros += slice_micros;
}
let next_slice = delay_micros - (next_deadline_micros - slice_micros);
actor.send(MsgIn::GoToDeadline(Duration::from_micros(next_slice)))?;
actor.send(MsgIn::GoToDeadline(Duration::from_micros(delay_micros)))?;
let src = local_vsg_address!();
let dst = remote_vsg_address!();
actor.send(MsgIn::DeliverPacket(src, dst, buffer))?;
......
......@@ -129,10 +129,18 @@ impl TimerContext {
now
}
fn thaw_time_to_deadline(&self, freeze_time: Option<StdDuration>, time_to_deadline: StdDuration) -> Result<()> {
fn thaw_time_to_deadline(&self, freeze_time: Option<StdDuration>, deadline: StdDuration) -> Result<()> {
let mut next_deadline = self.next_deadline.lock().unwrap();
let next_deadline_val = *next_deadline;
*self.prev_deadline.lock().unwrap() = next_deadline_val;
*next_deadline = deadline;
deadline_handler_debug!("TimerContext::thaw_time_to_deadline() set next_deadline = {:?}", next_deadline);
// First call can be interrupted by the signal handler and deadlock
drop(next_deadline);
let now = clock::gettime(Self::CLOCK).unwrap();
deadline_handler_debug!("TimerContext::thaw_time_to_deadline() system time = {:?}", now);
let new_next_deadline_raw = now + time_to_deadline;
let new_next_deadline_raw = now + (deadline - next_deadline_val);
// DEBUG only
let mut next_deadline_raw = self.next_deadline_raw.lock().unwrap();
......@@ -161,14 +169,6 @@ impl TimerContext {
self.simulation_time.adjust(|_| -Duration::from_std(now).unwrap());
}
let mut next_deadline = self.next_deadline.lock().unwrap();
let next_deadline_val = *next_deadline;
*self.prev_deadline.lock().unwrap() = next_deadline_val;
*next_deadline = next_deadline_val + time_to_deadline;
deadline_handler_debug!("TimerContext::thaw_time_to_deadline() set next_deadline = {:?}", next_deadline);
// First call can be interrupted by the signal handler and deadlock
drop(next_deadline);
self.at_deadline.store(false, Ordering::Release);
// The first call of ::thaw_time_to_deadline() is not in signal handler context and can be
......@@ -178,9 +178,9 @@ impl TimerContext {
Ok(())
}
pub fn start(&self, time_to_deadline: StdDuration) -> Result<()> {
pub fn start(&self, deadline: StdDuration) -> Result<()> {
self.stopped.store(false, Ordering::Release);
let res = self.thaw_time_to_deadline(None, time_to_deadline);
let res = self.thaw_time_to_deadline(None, deadline);
if res.is_err() {
self.stopped.store(true, Ordering::Release);
}
......@@ -271,8 +271,8 @@ extern "C" fn deadline_handler(_: libc::c_int) {
if let Some(context) = CONTEXT.read().unwrap().upgrade() {
let freeze_time = context.timer_context.freeze_time();
match context.at_deadline() {
AfterDeadline::NextDeadline(time_to_deadline) => {
context.timer_context.thaw_time_to_deadline(Some(freeze_time), time_to_deadline).expect("thaw_time_to_deadline failed")
AfterDeadline::NextDeadline(deadline) => {
context.timer_context.thaw_time_to_deadline(Some(freeze_time), deadline).expect("thaw_time_to_deadline failed")
},
AfterDeadline::EndSimulation => context.timer_context.stopped.store(true, Ordering::Release),
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment