eq(nullptr), readyEvent(this, false, ReadyPriority),
pauseEvent(this, false, PausePriority),
stopEvent(this, false, StopPriority),
- scMain(nullptr), _started(false), _paused(false), _stopped(false),
+ scMain(nullptr),
+ starvationEvent(this, false, StarvationPriority),
+ _started(false), _paused(false), _stopped(false),
maxTickEvent(this, false, MaxTickPriority),
_numCycles(0), _current(nullptr), initReady(false)
{}
if (!readyEvent.scheduled()) {
panic_if(!eq, "Need to schedule ready, but no event manager.\n");
eq->schedule(&readyEvent, eq->getCurTick());
+ if (starvationEvent.scheduled())
+ eq->deschedule(&starvationEvent);
+ }
+}
+
+void
+Scheduler::scheduleStarvationEvent()
+{
+ if (!starvationEvent.scheduled()) {
+ panic_if(!eq, "Need to schedule starvation event, "
+ "but no event manager.\n");
+ eq->schedule(&starvationEvent, eq->getCurTick());
+ if (readyEvent.scheduled())
+ eq->deschedule(&readyEvent);
}
}
// The update phase.
update();
+ if (starved() && !runToTime)
+ scheduleStarvationEvent();
+
// The delta phase will happen naturally through the event queue.
}
_started = true;
_paused = false;
_stopped = false;
+ runToTime = run_to_time;
maxTick = max_tick;
+ if (starved() && !runToTime)
+ return;
+
if (initReady) {
kernel->status(::sc_core::SC_RUNNING);
eq->schedule(&maxTickEvent, maxTick);
eq->deschedule(&stopEvent);
if (maxTickEvent.scheduled())
eq->deschedule(&maxTickEvent);
+ if (starvationEvent.scheduled())
+ eq->deschedule(&starvationEvent);
}
void
auto it = pendingTicks.begin();
if (--it->second == 0)
pendingTicks.erase(it);
+
+ if (starved() && !runToTime)
+ scheduleStarvationEvent();
}
// Pending activity ignores gem5 activity, much like how a systemc
static Priority StopPriority = DefaultPriority - 1;
static Priority PausePriority = DefaultPriority + 1;
static Priority ReadyPriority = DefaultPriority + 2;
+ static Priority StarvationPriority = ReadyPriority;
static Priority MaxTickPriority = DefaultPriority + 3;
EventQueue *eq;
EventWrapper<Scheduler, &Scheduler::stop> stopEvent;
Fiber *scMain;
+ bool
+ starved()
+ {
+ return (readyList.empty() && updateList.empty() &&
+ (pendingTicks.empty() ||
+ pendingTicks.begin()->first > maxTick) &&
+ initList.empty());
+ }
+ EventWrapper<Scheduler, &Scheduler::pause> starvationEvent;
+ void scheduleStarvationEvent();
+
bool _started;
bool _paused;
bool _stopped;
Process *_current;
bool initReady;
+ bool runToTime;
ProcessList initList;
ProcessList toFinalize;