1/*
2 * Copyright 2018 Google, Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer;
8 * redistributions in binary form must reproduce the above copyright

--- 22 unchanged lines hidden (view full) ---

31
32#include "base/fiber.hh"
33#include "base/logging.hh"
34#include "sim/eventq.hh"
35#include "systemc/core/kernel.hh"
36#include "systemc/ext/core/sc_main.hh"
37#include "systemc/ext/utils/sc_report.hh"
38#include "systemc/ext/utils/sc_report_handler.hh"
39#include "systemc/utils/tracefile.hh"
40
41namespace sc_gem5
42{
43
44Scheduler::Scheduler() :
45 eq(nullptr), readyEvent(this, false, ReadyPriority),
46 pauseEvent(this, false, PausePriority),
47 stopEvent(this, false, StopPriority),
48 scMain(nullptr), _throwToScMain(nullptr),
49 starvationEvent(this, false, StarvationPriority),
50 _elaborationDone(false), _started(false), _stopNow(false),
51 _status(StatusOther), maxTickEvent(this, false, MaxTickPriority),
51 _numCycles(0), _changeStamp(0), _current(nullptr), initDone(false),
52 runOnce(false)
52 timeAdvancesEvent(this, false, TimeAdvancesPriority), _numCycles(0),
53 _changeStamp(0), _current(nullptr), initDone(false), runOnce(false)
54{}
55
56Scheduler::~Scheduler()
57{
58 // Clear out everything that belongs to us to make sure nobody tries to
59 // clear themselves out after the scheduler goes away.
60 clear();
61}

--- 20 unchanged lines hidden (view full) ---

82 if (pauseEvent.scheduled())
83 deschedule(&pauseEvent);
84 if (stopEvent.scheduled())
85 deschedule(&stopEvent);
86 if (starvationEvent.scheduled())
87 deschedule(&starvationEvent);
88 if (maxTickEvent.scheduled())
89 deschedule(&maxTickEvent);
90 if (timeAdvancesEvent.scheduled())
91 deschedule(&timeAdvancesEvent);
92
93 Process *p;
94 while ((p = initList.getNext()))
95 p->popListNode();
96 while ((p = readyListMethods.getNext()))
97 p->popListNode();
98 while ((p = readyListThreads.getNext()))
99 p->popListNode();

--- 32 unchanged lines hidden (view full) ---

132 if (!runToTime && starved())
133 scheduleStarvationEvent();
134 kernel->status(::sc_core::SC_RUNNING);
135 }
136
137 initDone = true;
138
139 status(StatusOther);
140
141 scheduleTimeAdvancesEvent();
142}
143
144void
145Scheduler::reg(Process *p)
146{
147 if (initDone) {
148 // If not marked as dontInitialize, mark as ready.
149 if (!p->dontInitialize())

--- 113 unchanged lines hidden (view full) ---

263 if (readyEvent.scheduled())
264 deschedule(&readyEvent);
265 }
266}
267
268void
269Scheduler::runReady()
270{
271 scheduleTimeAdvancesEvent();
272
273 bool empty = readyListMethods.empty() && readyListThreads.empty();
274 lastReadyTick = getCurTick();
275
276 // The evaluation phase.
277 status(StatusEvaluate);
278 do {
279 yield();
280 } while (getNextReady());
281
282 if (!empty) {
283 _numCycles++;
284 _changeStamp++;
285 }
286
287 if (_stopNow) {
288 status(StatusOther);
289 return;
290 }
291
292 runUpdate();
293 if (!traceFiles.empty())
294 trace(true);
295 runDelta();
296
297 if (!runToTime && starved())
298 scheduleStarvationEvent();
299
300 if (runOnce)
301 schedulePause();
302

--- 69 unchanged lines hidden (view full) ---

372
373 if (initDone) {
374 if (!runToTime && starved())
375 scheduleStarvationEvent();
376 kernel->status(::sc_core::SC_RUNNING);
377 }
378
379 schedule(&maxTickEvent, maxTick);
380 scheduleTimeAdvancesEvent();
381
382 // Return to gem5 to let it run events, etc.
383 Fiber::primaryFiber()->run();
384
385 if (pauseEvent.scheduled())
386 deschedule(&pauseEvent);
387 if (stopEvent.scheduled())
388 deschedule(&stopEvent);

--- 46 unchanged lines hidden (view full) ---

435 _stopNow = true;
436 // If we're not supposed to finish the delta cycle, flush all
437 // pending activity.
438 clear();
439 }
440 schedule(&stopEvent);
441}
442
443void
444Scheduler::trace(bool delta)
445{
446 for (auto tf: traceFiles)
447 tf->trace(delta);
448}
449
450Scheduler scheduler;
451
452namespace {
453
454void
455throwingReportHandler(const ::sc_core::sc_report &r,
456 const ::sc_core::sc_actions &)
457{

--- 37 unchanged lines hidden ---