From e731642149c50955efb63b3f255a5112185976dd Mon Sep 17 00:00:00 2001
From: Gabe Black <gabeblack@google.com>
Date: Mon, 27 Aug 2018 23:18:18 -0700
Subject: [PATCH] systemc: Clamp the time of events to the present.

If systemc attempts to schedule an event in the past, schedule it for
right now instead. Still preserve the difference between delta and
timed events. This scheme doesn't really make a lot of sense (why not
just disallow scheduling events in the past?) but this will approximate
what I think the correct behavior is. What's probably supposed to
happen is that events in the past are executed from most past to most
present until they catch up with now, and then now advances as normal.
Our approach is simpler, but won't preserve ordering between multiple
events scheduled in the past.

Change-Id: I73c1e581c532530178458f044674613a4f4ea3be
Reviewed-on: https://gem5-review.googlesource.com/c/12277
Reviewed-by: Gabe Black <gabeblack@google.com>
Maintainer: Gabe Black <gabeblack@google.com>
---
 src/systemc/core/scheduler.hh | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/systemc/core/scheduler.hh b/src/systemc/core/scheduler.hh
index ff8434bef..2da8da470 100644
--- a/src/systemc/core/scheduler.hh
+++ b/src/systemc/core/scheduler.hh
@@ -215,6 +215,9 @@ class Scheduler
     schedule(ScEvent *event, const ::sc_core::sc_time &delay)
     {
         Tick tick = delayed(delay);
+        if (tick < getCurTick())
+            tick = getCurTick();
+
         event->schedule(tick);
 
         // Delta notification/timeout.
-- 
2.30.2