scheduler.cc revision 13702
112953Sgabeblack@google.com/* 212953Sgabeblack@google.com * Copyright 2018 Google, Inc. 312953Sgabeblack@google.com * 412953Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 512953Sgabeblack@google.com * modification, are permitted provided that the following conditions are 612953Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 712953Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 812953Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 912953Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1012953Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1112953Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1212953Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1312953Sgabeblack@google.com * this software without specific prior written permission. 1412953Sgabeblack@google.com * 1512953Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1612953Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1712953Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1812953Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1912953Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2012953Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2112953Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2212953Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2312953Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2412953Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2512953Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2612953Sgabeblack@google.com * 2712953Sgabeblack@google.com * Authors: Gabe Black 2812953Sgabeblack@google.com */ 2912953Sgabeblack@google.com 3012953Sgabeblack@google.com#include "systemc/core/scheduler.hh" 3112953Sgabeblack@google.com 3212953Sgabeblack@google.com#include "base/fiber.hh" 3312954Sgabeblack@google.com#include "base/logging.hh" 3412954Sgabeblack@google.com#include "sim/eventq.hh" 3512982Sgabeblack@google.com#include "systemc/core/kernel.hh" 3613403Sgabeblack@google.com#include "systemc/core/sc_main_fiber.hh" 3713317Sgabeblack@google.com#include "systemc/ext/core/messages.hh" 3812982Sgabeblack@google.com#include "systemc/ext/core/sc_main.hh" 3913182Sgabeblack@google.com#include "systemc/ext/utils/sc_report.hh" 4013182Sgabeblack@google.com#include "systemc/ext/utils/sc_report_handler.hh" 4113312Sgabeblack@google.com#include "systemc/utils/report.hh" 4213245Sgabeblack@google.com#include "systemc/utils/tracefile.hh" 4312953Sgabeblack@google.com 4412953Sgabeblack@google.comnamespace sc_gem5 4512953Sgabeblack@google.com{ 4612953Sgabeblack@google.com 4712954Sgabeblack@google.comScheduler::Scheduler() : 4812962Sgabeblack@google.com eq(nullptr), readyEvent(this, false, ReadyPriority), 4912961Sgabeblack@google.com pauseEvent(this, false, PausePriority), 5013701Sgabeblack@google.com stopEvent(this, false, StopPriority), _throwUp(nullptr), 5112987Sgabeblack@google.com starvationEvent(this, false, StarvationPriority), 5213203Sgabeblack@google.com _elaborationDone(false), _started(false), _stopNow(false), 5313702Sgabeblack@google.com _status(StatusOther), maxTick(::MaxTick), 5413702Sgabeblack@google.com maxTickEvent(this, false, MaxTickPriority), 5513245Sgabeblack@google.com timeAdvancesEvent(this, false, TimeAdvancesPriority), _numCycles(0), 5613702Sgabeblack@google.com _changeStamp(0), _current(nullptr), initDone(false), runToTime(true), 5713702Sgabeblack@google.com runOnce(false) 5812954Sgabeblack@google.com{} 5912953Sgabeblack@google.com 6013072Sgabeblack@google.comScheduler::~Scheduler() 6113072Sgabeblack@google.com{ 6213072Sgabeblack@google.com // Clear out everything that belongs to us to make sure nobody tries to 6313072Sgabeblack@google.com // clear themselves out after the scheduler goes away. 6413076Sgabeblack@google.com clear(); 6513076Sgabeblack@google.com} 6613072Sgabeblack@google.com 6713076Sgabeblack@google.comvoid 6813076Sgabeblack@google.comScheduler::clear() 6913076Sgabeblack@google.com{ 7013072Sgabeblack@google.com // Delta notifications. 7113144Sgabeblack@google.com while (!deltas.empty()) 7213144Sgabeblack@google.com deltas.front()->deschedule(); 7313072Sgabeblack@google.com 7413072Sgabeblack@google.com // Timed notifications. 7513076Sgabeblack@google.com for (auto &tsp: timeSlots) { 7613076Sgabeblack@google.com TimeSlot *&ts = tsp.second; 7713144Sgabeblack@google.com while (!ts->events.empty()) 7813144Sgabeblack@google.com ts->events.front()->deschedule(); 7913088Sgabeblack@google.com deschedule(ts); 8013072Sgabeblack@google.com } 8113076Sgabeblack@google.com timeSlots.clear(); 8213072Sgabeblack@google.com 8313072Sgabeblack@google.com // gem5 events. 8413072Sgabeblack@google.com if (readyEvent.scheduled()) 8513088Sgabeblack@google.com deschedule(&readyEvent); 8613072Sgabeblack@google.com if (pauseEvent.scheduled()) 8713088Sgabeblack@google.com deschedule(&pauseEvent); 8813072Sgabeblack@google.com if (stopEvent.scheduled()) 8913088Sgabeblack@google.com deschedule(&stopEvent); 9013072Sgabeblack@google.com if (starvationEvent.scheduled()) 9113088Sgabeblack@google.com deschedule(&starvationEvent); 9213072Sgabeblack@google.com if (maxTickEvent.scheduled()) 9313088Sgabeblack@google.com deschedule(&maxTickEvent); 9413245Sgabeblack@google.com if (timeAdvancesEvent.scheduled()) 9513245Sgabeblack@google.com deschedule(&timeAdvancesEvent); 9613072Sgabeblack@google.com 9713072Sgabeblack@google.com Process *p; 9813072Sgabeblack@google.com while ((p = initList.getNext())) 9913072Sgabeblack@google.com p->popListNode(); 10013176Sgabeblack@google.com while ((p = readyListMethods.getNext())) 10113176Sgabeblack@google.com p->popListNode(); 10213176Sgabeblack@google.com while ((p = readyListThreads.getNext())) 10313072Sgabeblack@google.com p->popListNode(); 10413072Sgabeblack@google.com 10513072Sgabeblack@google.com Channel *c; 10613072Sgabeblack@google.com while ((c = updateList.getNext())) 10713072Sgabeblack@google.com c->popListNode(); 10813072Sgabeblack@google.com} 10913072Sgabeblack@google.com 11012953Sgabeblack@google.comvoid 11113067Sgabeblack@google.comScheduler::initPhase() 11212953Sgabeblack@google.com{ 11313488Sgabeblack@google.com runUpdate(); 11413488Sgabeblack@google.com 11513194Sgabeblack@google.com for (Process *p = initList.getNext(); p; p = initList.getNext()) { 11612957Sgabeblack@google.com p->popListNode(); 11713180Sgabeblack@google.com 11813194Sgabeblack@google.com if (p->dontInitialize()) { 11913194Sgabeblack@google.com if (!p->hasStaticSensitivities() && !p->internal()) { 12013317Sgabeblack@google.com SC_REPORT_WARNING(sc_core::SC_ID_DISABLE_WILL_ORPHAN_PROCESS_, 12113317Sgabeblack@google.com p->name()); 12213194Sgabeblack@google.com } 12313194Sgabeblack@google.com } else { 12413194Sgabeblack@google.com p->ready(); 12513180Sgabeblack@google.com } 12612957Sgabeblack@google.com } 12712957Sgabeblack@google.com 12813186Sgabeblack@google.com runDelta(); 12913067Sgabeblack@google.com 13012985Sgabeblack@google.com for (auto ets: eventsToSchedule) 13112985Sgabeblack@google.com eq->schedule(ets.first, ets.second); 13212985Sgabeblack@google.com eventsToSchedule.clear(); 13312985Sgabeblack@google.com 13413068Sgabeblack@google.com if (_started) { 13513096Sgabeblack@google.com if (!runToTime && starved()) 13613068Sgabeblack@google.com scheduleStarvationEvent(); 13713069Sgabeblack@google.com kernel->status(::sc_core::SC_RUNNING); 13813068Sgabeblack@google.com } 13912961Sgabeblack@google.com 14013067Sgabeblack@google.com initDone = true; 14113186Sgabeblack@google.com 14213186Sgabeblack@google.com status(StatusOther); 14313245Sgabeblack@google.com 14413245Sgabeblack@google.com scheduleTimeAdvancesEvent(); 14512957Sgabeblack@google.com} 14612957Sgabeblack@google.com 14712957Sgabeblack@google.comvoid 14812957Sgabeblack@google.comScheduler::reg(Process *p) 14912957Sgabeblack@google.com{ 15013067Sgabeblack@google.com if (initDone) { 15113194Sgabeblack@google.com // If not marked as dontInitialize, mark as ready. 15213194Sgabeblack@google.com if (!p->dontInitialize()) 15313194Sgabeblack@google.com p->ready(); 15412957Sgabeblack@google.com } else { 15512957Sgabeblack@google.com // Otherwise, record that this process should be initialized once we 15612957Sgabeblack@google.com // get there. 15712957Sgabeblack@google.com initList.pushLast(p); 15812957Sgabeblack@google.com } 15912957Sgabeblack@google.com} 16012957Sgabeblack@google.com 16112957Sgabeblack@google.comvoid 16212953Sgabeblack@google.comScheduler::yield() 16312953Sgabeblack@google.com{ 16413176Sgabeblack@google.com // Pull a process from the active list. 16513209Sgabeblack@google.com _current = getNextReady(); 16612953Sgabeblack@google.com if (!_current) { 16712953Sgabeblack@google.com // There are no more processes, so return control to evaluate. 16812953Sgabeblack@google.com Fiber::primaryFiber()->run(); 16912953Sgabeblack@google.com } else { 17012953Sgabeblack@google.com _current->popListNode(); 17113328Sgabeblack@google.com _current->scheduled(false); 17212953Sgabeblack@google.com // Switch to whatever Fiber is supposed to run this process. All 17312953Sgabeblack@google.com // Fibers which aren't running should be parked at this line. 17412953Sgabeblack@google.com _current->fiber()->run(); 17512961Sgabeblack@google.com // If the current process needs to be manually started, start it. 17613093Sgabeblack@google.com if (_current && _current->needsStart()) { 17713093Sgabeblack@google.com _current->needsStart(false); 17813308Sgabeblack@google.com // If a process hasn't started yet, "resetting" it just starts it 17913308Sgabeblack@google.com // and signals its reset event. 18013308Sgabeblack@google.com if (_current->inReset()) 18113308Sgabeblack@google.com _current->resetEvent().notify(); 18213182Sgabeblack@google.com try { 18313182Sgabeblack@google.com _current->run(); 18413182Sgabeblack@google.com } catch (...) { 18513701Sgabeblack@google.com throwUp(); 18613182Sgabeblack@google.com } 18713093Sgabeblack@google.com } 18812953Sgabeblack@google.com } 18913259Sgabeblack@google.com if (_current && !_current->needsStart()) { 19013259Sgabeblack@google.com if (_current->excWrapper) { 19113259Sgabeblack@google.com auto ew = _current->excWrapper; 19213259Sgabeblack@google.com _current->excWrapper = nullptr; 19313259Sgabeblack@google.com ew->throw_it(); 19413260Sgabeblack@google.com } else if (_current->inReset()) { 19513259Sgabeblack@google.com _current->reset(false); 19613259Sgabeblack@google.com } 19712995Sgabeblack@google.com } 19812953Sgabeblack@google.com} 19912953Sgabeblack@google.com 20012953Sgabeblack@google.comvoid 20112954Sgabeblack@google.comScheduler::ready(Process *p) 20212953Sgabeblack@google.com{ 20313154Sgabeblack@google.com if (_stopNow) 20413154Sgabeblack@google.com return; 20513154Sgabeblack@google.com 20613328Sgabeblack@google.com p->scheduled(true); 20713328Sgabeblack@google.com 20813176Sgabeblack@google.com if (p->procKind() == ::sc_core::SC_METHOD_PROC_) 20913176Sgabeblack@google.com readyListMethods.pushLast(p); 21012954Sgabeblack@google.com else 21113176Sgabeblack@google.com readyListThreads.pushLast(p); 21212953Sgabeblack@google.com 21313244Sgabeblack@google.com if (!inEvaluate()) 21413244Sgabeblack@google.com scheduleReadyEvent(); 21512954Sgabeblack@google.com} 21612954Sgabeblack@google.com 21712954Sgabeblack@google.comvoid 21813133Sgabeblack@google.comScheduler::resume(Process *p) 21913133Sgabeblack@google.com{ 22013133Sgabeblack@google.com if (initDone) 22113133Sgabeblack@google.com ready(p); 22213133Sgabeblack@google.com else 22313133Sgabeblack@google.com initList.pushLast(p); 22413133Sgabeblack@google.com} 22513133Sgabeblack@google.com 22613133Sgabeblack@google.combool 22713176Sgabeblack@google.comlistContains(ListNode *list, ListNode *target) 22813176Sgabeblack@google.com{ 22913176Sgabeblack@google.com ListNode *n = list->nextListNode; 23013176Sgabeblack@google.com while (n != list) 23113176Sgabeblack@google.com if (n == target) 23213176Sgabeblack@google.com return true; 23313176Sgabeblack@google.com return false; 23413176Sgabeblack@google.com} 23513176Sgabeblack@google.com 23613176Sgabeblack@google.combool 23713133Sgabeblack@google.comScheduler::suspend(Process *p) 23813133Sgabeblack@google.com{ 23913176Sgabeblack@google.com bool was_ready; 24013133Sgabeblack@google.com if (initDone) { 24113194Sgabeblack@google.com // After initialization, check if we're on a ready list. 24213176Sgabeblack@google.com was_ready = (p->nextListNode != nullptr); 24313133Sgabeblack@google.com p->popListNode(); 24413133Sgabeblack@google.com } else { 24513194Sgabeblack@google.com // Nothing is ready before init. 24613194Sgabeblack@google.com was_ready = false; 24713133Sgabeblack@google.com } 24813176Sgabeblack@google.com return was_ready; 24913133Sgabeblack@google.com} 25013133Sgabeblack@google.com 25113133Sgabeblack@google.comvoid 25212954Sgabeblack@google.comScheduler::requestUpdate(Channel *c) 25312954Sgabeblack@google.com{ 25412954Sgabeblack@google.com updateList.pushLast(c); 25513244Sgabeblack@google.com if (!inEvaluate()) 25613244Sgabeblack@google.com scheduleReadyEvent(); 25712954Sgabeblack@google.com} 25812954Sgabeblack@google.com 25912954Sgabeblack@google.comvoid 26012954Sgabeblack@google.comScheduler::scheduleReadyEvent() 26112954Sgabeblack@google.com{ 26212954Sgabeblack@google.com // Schedule the evaluate and update phases. 26312954Sgabeblack@google.com if (!readyEvent.scheduled()) { 26413069Sgabeblack@google.com schedule(&readyEvent); 26512987Sgabeblack@google.com if (starvationEvent.scheduled()) 26613069Sgabeblack@google.com deschedule(&starvationEvent); 26712987Sgabeblack@google.com } 26812987Sgabeblack@google.com} 26912987Sgabeblack@google.com 27012987Sgabeblack@google.comvoid 27112987Sgabeblack@google.comScheduler::scheduleStarvationEvent() 27212987Sgabeblack@google.com{ 27312987Sgabeblack@google.com if (!starvationEvent.scheduled()) { 27413069Sgabeblack@google.com schedule(&starvationEvent); 27512987Sgabeblack@google.com if (readyEvent.scheduled()) 27613069Sgabeblack@google.com deschedule(&readyEvent); 27712954Sgabeblack@google.com } 27812954Sgabeblack@google.com} 27912954Sgabeblack@google.com 28012954Sgabeblack@google.comvoid 28112954Sgabeblack@google.comScheduler::runReady() 28212954Sgabeblack@google.com{ 28313245Sgabeblack@google.com scheduleTimeAdvancesEvent(); 28413245Sgabeblack@google.com 28513176Sgabeblack@google.com bool empty = readyListMethods.empty() && readyListThreads.empty(); 28613140Sgabeblack@google.com lastReadyTick = getCurTick(); 28712954Sgabeblack@google.com 28812954Sgabeblack@google.com // The evaluation phase. 28913245Sgabeblack@google.com status(StatusEvaluate); 29012953Sgabeblack@google.com do { 29113209Sgabeblack@google.com yield(); 29213209Sgabeblack@google.com } while (getNextReady()); 29313275Sgabeblack@google.com _current = nullptr; 29412954Sgabeblack@google.com 29513140Sgabeblack@google.com if (!empty) { 29612954Sgabeblack@google.com _numCycles++; 29713140Sgabeblack@google.com _changeStamp++; 29813140Sgabeblack@google.com } 29912954Sgabeblack@google.com 30013244Sgabeblack@google.com if (_stopNow) { 30113244Sgabeblack@google.com status(StatusOther); 30213154Sgabeblack@google.com return; 30313244Sgabeblack@google.com } 30413154Sgabeblack@google.com 30513186Sgabeblack@google.com runUpdate(); 30613245Sgabeblack@google.com if (!traceFiles.empty()) 30713245Sgabeblack@google.com trace(true); 30813186Sgabeblack@google.com runDelta(); 30913061Sgabeblack@google.com 31013096Sgabeblack@google.com if (!runToTime && starved()) 31113096Sgabeblack@google.com scheduleStarvationEvent(); 31213096Sgabeblack@google.com 31313064Sgabeblack@google.com if (runOnce) 31413064Sgabeblack@google.com schedulePause(); 31513186Sgabeblack@google.com 31613186Sgabeblack@google.com status(StatusOther); 31712953Sgabeblack@google.com} 31812953Sgabeblack@google.com 31912953Sgabeblack@google.comvoid 32013186Sgabeblack@google.comScheduler::runUpdate() 32112953Sgabeblack@google.com{ 32213186Sgabeblack@google.com status(StatusUpdate); 32313186Sgabeblack@google.com 32413188Sgabeblack@google.com try { 32513188Sgabeblack@google.com Channel *channel = updateList.getNext(); 32613188Sgabeblack@google.com while (channel) { 32713188Sgabeblack@google.com channel->popListNode(); 32813188Sgabeblack@google.com channel->update(); 32913188Sgabeblack@google.com channel = updateList.getNext(); 33013188Sgabeblack@google.com } 33113188Sgabeblack@google.com } catch (...) { 33213701Sgabeblack@google.com throwUp(); 33312954Sgabeblack@google.com } 33412953Sgabeblack@google.com} 33512953Sgabeblack@google.com 33612961Sgabeblack@google.comvoid 33713186Sgabeblack@google.comScheduler::runDelta() 33813186Sgabeblack@google.com{ 33913186Sgabeblack@google.com status(StatusDelta); 34013188Sgabeblack@google.com 34113188Sgabeblack@google.com try { 34213188Sgabeblack@google.com while (!deltas.empty()) 34313289Sgabeblack@google.com deltas.back()->run(); 34413188Sgabeblack@google.com } catch (...) { 34513701Sgabeblack@google.com throwUp(); 34613188Sgabeblack@google.com } 34713186Sgabeblack@google.com} 34813186Sgabeblack@google.com 34913186Sgabeblack@google.comvoid 35012961Sgabeblack@google.comScheduler::pause() 35112961Sgabeblack@google.com{ 35213186Sgabeblack@google.com status(StatusPaused); 35312982Sgabeblack@google.com kernel->status(::sc_core::SC_PAUSED); 35413061Sgabeblack@google.com runOnce = false; 35513403Sgabeblack@google.com if (scMainFiber.called() && !scMainFiber.finished()) 35613403Sgabeblack@google.com scMainFiber.run(); 35712961Sgabeblack@google.com} 35812961Sgabeblack@google.com 35912961Sgabeblack@google.comvoid 36012961Sgabeblack@google.comScheduler::stop() 36112961Sgabeblack@google.com{ 36213186Sgabeblack@google.com status(StatusStopped); 36312982Sgabeblack@google.com kernel->stop(); 36413074Sgabeblack@google.com 36513076Sgabeblack@google.com clear(); 36613074Sgabeblack@google.com 36713061Sgabeblack@google.com runOnce = false; 36813403Sgabeblack@google.com if (scMainFiber.called() && !scMainFiber.finished()) 36913403Sgabeblack@google.com scMainFiber.run(); 37012961Sgabeblack@google.com} 37112961Sgabeblack@google.com 37212961Sgabeblack@google.comvoid 37312961Sgabeblack@google.comScheduler::start(Tick max_tick, bool run_to_time) 37412961Sgabeblack@google.com{ 37512961Sgabeblack@google.com _started = true; 37613186Sgabeblack@google.com status(StatusOther); 37712987Sgabeblack@google.com runToTime = run_to_time; 37812961Sgabeblack@google.com 37912961Sgabeblack@google.com maxTick = max_tick; 38013140Sgabeblack@google.com lastReadyTick = getCurTick(); 38112961Sgabeblack@google.com 38213067Sgabeblack@google.com if (initDone) { 38313096Sgabeblack@google.com if (!runToTime && starved()) 38413068Sgabeblack@google.com scheduleStarvationEvent(); 38512982Sgabeblack@google.com kernel->status(::sc_core::SC_RUNNING); 38612982Sgabeblack@google.com } 38712961Sgabeblack@google.com 38813069Sgabeblack@google.com schedule(&maxTickEvent, maxTick); 38913245Sgabeblack@google.com scheduleTimeAdvancesEvent(); 39013069Sgabeblack@google.com 39112961Sgabeblack@google.com // Return to gem5 to let it run events, etc. 39212961Sgabeblack@google.com Fiber::primaryFiber()->run(); 39312961Sgabeblack@google.com 39412961Sgabeblack@google.com if (pauseEvent.scheduled()) 39513088Sgabeblack@google.com deschedule(&pauseEvent); 39612961Sgabeblack@google.com if (stopEvent.scheduled()) 39713088Sgabeblack@google.com deschedule(&stopEvent); 39812961Sgabeblack@google.com if (maxTickEvent.scheduled()) 39913088Sgabeblack@google.com deschedule(&maxTickEvent); 40012987Sgabeblack@google.com if (starvationEvent.scheduled()) 40113088Sgabeblack@google.com deschedule(&starvationEvent); 40213182Sgabeblack@google.com 40313701Sgabeblack@google.com if (_throwUp) { 40413701Sgabeblack@google.com const ::sc_core::sc_report *to_throw = _throwUp; 40513701Sgabeblack@google.com _throwUp = nullptr; 40613182Sgabeblack@google.com throw *to_throw; 40713182Sgabeblack@google.com } 40812961Sgabeblack@google.com} 40912961Sgabeblack@google.com 41012961Sgabeblack@google.comvoid 41113061Sgabeblack@google.comScheduler::oneCycle() 41213061Sgabeblack@google.com{ 41313061Sgabeblack@google.com runOnce = true; 41413095Sgabeblack@google.com scheduleReadyEvent(); 41513061Sgabeblack@google.com start(::MaxTick, false); 41613061Sgabeblack@google.com} 41713061Sgabeblack@google.com 41813061Sgabeblack@google.comvoid 41912961Sgabeblack@google.comScheduler::schedulePause() 42012961Sgabeblack@google.com{ 42112961Sgabeblack@google.com if (pauseEvent.scheduled()) 42212961Sgabeblack@google.com return; 42312961Sgabeblack@google.com 42413088Sgabeblack@google.com schedule(&pauseEvent); 42512961Sgabeblack@google.com} 42612961Sgabeblack@google.com 42712961Sgabeblack@google.comvoid 42813701Sgabeblack@google.comScheduler::throwUp() 42913182Sgabeblack@google.com{ 43013701Sgabeblack@google.com if (scMainFiber.called() && !scMainFiber.finished()) { 43113701Sgabeblack@google.com ::sc_core::sc_report report = reportifyException(); 43213701Sgabeblack@google.com _throwUp = &report; 43313701Sgabeblack@google.com status(StatusOther); 43413701Sgabeblack@google.com scMainFiber.run(); 43513701Sgabeblack@google.com } else { 43613701Sgabeblack@google.com reportHandlerProc(reportifyException(), 43713701Sgabeblack@google.com ::sc_core::sc_report_handler::get_catch_actions()); 43813701Sgabeblack@google.com } 43913182Sgabeblack@google.com} 44013182Sgabeblack@google.com 44113182Sgabeblack@google.comvoid 44212961Sgabeblack@google.comScheduler::scheduleStop(bool finish_delta) 44312961Sgabeblack@google.com{ 44412961Sgabeblack@google.com if (stopEvent.scheduled()) 44512961Sgabeblack@google.com return; 44612961Sgabeblack@google.com 44712961Sgabeblack@google.com if (!finish_delta) { 44813154Sgabeblack@google.com _stopNow = true; 44913076Sgabeblack@google.com // If we're not supposed to finish the delta cycle, flush all 45013076Sgabeblack@google.com // pending activity. 45113076Sgabeblack@google.com clear(); 45212961Sgabeblack@google.com } 45313088Sgabeblack@google.com schedule(&stopEvent); 45412961Sgabeblack@google.com} 45512961Sgabeblack@google.com 45613245Sgabeblack@google.comvoid 45713245Sgabeblack@google.comScheduler::trace(bool delta) 45813245Sgabeblack@google.com{ 45913245Sgabeblack@google.com for (auto tf: traceFiles) 46013245Sgabeblack@google.com tf->trace(delta); 46113245Sgabeblack@google.com} 46213245Sgabeblack@google.com 46312953Sgabeblack@google.comScheduler scheduler; 46413329Sgabeblack@google.comProcess *getCurrentProcess() { return scheduler.current(); } 46512953Sgabeblack@google.com 46613182Sgabeblack@google.comnamespace { 46713182Sgabeblack@google.com 46813182Sgabeblack@google.comvoid 46913182Sgabeblack@google.comthrowingReportHandler(const ::sc_core::sc_report &r, 47013182Sgabeblack@google.com const ::sc_core::sc_actions &) 47113182Sgabeblack@google.com{ 47213182Sgabeblack@google.com throw r; 47313182Sgabeblack@google.com} 47413182Sgabeblack@google.com 47513182Sgabeblack@google.com} // anonymous namespace 47613182Sgabeblack@google.com 47713264Sgabeblack@google.comconst ::sc_core::sc_report 47813182Sgabeblack@google.comreportifyException() 47913182Sgabeblack@google.com{ 48013312Sgabeblack@google.com ::sc_core::sc_report_handler_proc old_handler = reportHandlerProc; 48113182Sgabeblack@google.com ::sc_core::sc_report_handler::set_handler(&throwingReportHandler); 48213182Sgabeblack@google.com 48313182Sgabeblack@google.com try { 48413182Sgabeblack@google.com try { 48513182Sgabeblack@google.com // Rethrow the current exception so we can catch it and throw an 48613182Sgabeblack@google.com // sc_report instead if it's not a type we recognize/can handle. 48713182Sgabeblack@google.com throw; 48813182Sgabeblack@google.com } catch (const ::sc_core::sc_report &) { 48913182Sgabeblack@google.com // It's already a sc_report, so nothing to do. 49013182Sgabeblack@google.com throw; 49113182Sgabeblack@google.com } catch (const ::sc_core::sc_unwind_exception &) { 49213182Sgabeblack@google.com panic("Kill/reset exception escaped a Process::run()"); 49313182Sgabeblack@google.com } catch (const std::exception &e) { 49413317Sgabeblack@google.com SC_REPORT_ERROR( 49513317Sgabeblack@google.com sc_core::SC_ID_SIMULATION_UNCAUGHT_EXCEPTION_, e.what()); 49613182Sgabeblack@google.com } catch (const char *msg) { 49713317Sgabeblack@google.com SC_REPORT_ERROR( 49813317Sgabeblack@google.com sc_core::SC_ID_SIMULATION_UNCAUGHT_EXCEPTION_, msg); 49913182Sgabeblack@google.com } catch (...) { 50013317Sgabeblack@google.com SC_REPORT_ERROR( 50113317Sgabeblack@google.com sc_core::SC_ID_SIMULATION_UNCAUGHT_EXCEPTION_, 50213317Sgabeblack@google.com "UNKNOWN EXCEPTION"); 50313182Sgabeblack@google.com } 50413182Sgabeblack@google.com } catch (const ::sc_core::sc_report &r) { 50513182Sgabeblack@google.com ::sc_core::sc_report_handler::set_handler(old_handler); 50613264Sgabeblack@google.com return r; 50713182Sgabeblack@google.com } 50813182Sgabeblack@google.com panic("No exception thrown in reportifyException."); 50913182Sgabeblack@google.com} 51013182Sgabeblack@google.com 51112953Sgabeblack@google.com} // namespace sc_gem5 512