scheduler.cc revision 13245
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" 3612982Sgabeblack@google.com#include "systemc/ext/core/sc_main.hh" 3713182Sgabeblack@google.com#include "systemc/ext/utils/sc_report.hh" 3813182Sgabeblack@google.com#include "systemc/ext/utils/sc_report_handler.hh" 3913245Sgabeblack@google.com#include "systemc/utils/tracefile.hh" 4012953Sgabeblack@google.com 4112953Sgabeblack@google.comnamespace sc_gem5 4212953Sgabeblack@google.com{ 4312953Sgabeblack@google.com 4412954Sgabeblack@google.comScheduler::Scheduler() : 4512962Sgabeblack@google.com eq(nullptr), readyEvent(this, false, ReadyPriority), 4612961Sgabeblack@google.com pauseEvent(this, false, PausePriority), 4712961Sgabeblack@google.com stopEvent(this, false, StopPriority), 4813182Sgabeblack@google.com scMain(nullptr), _throwToScMain(nullptr), 4912987Sgabeblack@google.com starvationEvent(this, false, StarvationPriority), 5013203Sgabeblack@google.com _elaborationDone(false), _started(false), _stopNow(false), 5113203Sgabeblack@google.com _status(StatusOther), maxTickEvent(this, false, MaxTickPriority), 5213245Sgabeblack@google.com timeAdvancesEvent(this, false, TimeAdvancesPriority), _numCycles(0), 5313245Sgabeblack@google.com _changeStamp(0), _current(nullptr), initDone(false), runOnce(false) 5412954Sgabeblack@google.com{} 5512953Sgabeblack@google.com 5613072Sgabeblack@google.comScheduler::~Scheduler() 5713072Sgabeblack@google.com{ 5813072Sgabeblack@google.com // Clear out everything that belongs to us to make sure nobody tries to 5913072Sgabeblack@google.com // clear themselves out after the scheduler goes away. 6013076Sgabeblack@google.com clear(); 6113076Sgabeblack@google.com} 6213072Sgabeblack@google.com 6313076Sgabeblack@google.comvoid 6413076Sgabeblack@google.comScheduler::clear() 6513076Sgabeblack@google.com{ 6613072Sgabeblack@google.com // Delta notifications. 6713144Sgabeblack@google.com while (!deltas.empty()) 6813144Sgabeblack@google.com deltas.front()->deschedule(); 6913072Sgabeblack@google.com 7013072Sgabeblack@google.com // Timed notifications. 7113076Sgabeblack@google.com for (auto &tsp: timeSlots) { 7213076Sgabeblack@google.com TimeSlot *&ts = tsp.second; 7313144Sgabeblack@google.com while (!ts->events.empty()) 7413144Sgabeblack@google.com ts->events.front()->deschedule(); 7513088Sgabeblack@google.com deschedule(ts); 7613072Sgabeblack@google.com } 7713076Sgabeblack@google.com timeSlots.clear(); 7813072Sgabeblack@google.com 7913072Sgabeblack@google.com // gem5 events. 8013072Sgabeblack@google.com if (readyEvent.scheduled()) 8113088Sgabeblack@google.com deschedule(&readyEvent); 8213072Sgabeblack@google.com if (pauseEvent.scheduled()) 8313088Sgabeblack@google.com deschedule(&pauseEvent); 8413072Sgabeblack@google.com if (stopEvent.scheduled()) 8513088Sgabeblack@google.com deschedule(&stopEvent); 8613072Sgabeblack@google.com if (starvationEvent.scheduled()) 8713088Sgabeblack@google.com deschedule(&starvationEvent); 8813072Sgabeblack@google.com if (maxTickEvent.scheduled()) 8913088Sgabeblack@google.com deschedule(&maxTickEvent); 9013245Sgabeblack@google.com if (timeAdvancesEvent.scheduled()) 9113245Sgabeblack@google.com deschedule(&timeAdvancesEvent); 9213072Sgabeblack@google.com 9313072Sgabeblack@google.com Process *p; 9413072Sgabeblack@google.com while ((p = initList.getNext())) 9513072Sgabeblack@google.com p->popListNode(); 9613176Sgabeblack@google.com while ((p = readyListMethods.getNext())) 9713176Sgabeblack@google.com p->popListNode(); 9813176Sgabeblack@google.com while ((p = readyListThreads.getNext())) 9913072Sgabeblack@google.com p->popListNode(); 10013072Sgabeblack@google.com 10113072Sgabeblack@google.com Channel *c; 10213072Sgabeblack@google.com while ((c = updateList.getNext())) 10313072Sgabeblack@google.com c->popListNode(); 10413072Sgabeblack@google.com} 10513072Sgabeblack@google.com 10612953Sgabeblack@google.comvoid 10713067Sgabeblack@google.comScheduler::initPhase() 10812953Sgabeblack@google.com{ 10913194Sgabeblack@google.com for (Process *p = initList.getNext(); p; p = initList.getNext()) { 11012957Sgabeblack@google.com p->popListNode(); 11113180Sgabeblack@google.com 11213194Sgabeblack@google.com if (p->dontInitialize()) { 11313194Sgabeblack@google.com if (!p->hasStaticSensitivities() && !p->internal()) { 11413194Sgabeblack@google.com SC_REPORT_WARNING( 11513194Sgabeblack@google.com "(W558) disable() or dont_initialize() called on " 11613194Sgabeblack@google.com "process with no static sensitivity, it will be " 11713194Sgabeblack@google.com "orphaned", p->name()); 11813194Sgabeblack@google.com } 11913194Sgabeblack@google.com } else { 12013194Sgabeblack@google.com p->ready(); 12113180Sgabeblack@google.com } 12212957Sgabeblack@google.com } 12312957Sgabeblack@google.com 12413186Sgabeblack@google.com runUpdate(); 12513186Sgabeblack@google.com runDelta(); 12613067Sgabeblack@google.com 12712985Sgabeblack@google.com for (auto ets: eventsToSchedule) 12812985Sgabeblack@google.com eq->schedule(ets.first, ets.second); 12912985Sgabeblack@google.com eventsToSchedule.clear(); 13012985Sgabeblack@google.com 13113068Sgabeblack@google.com if (_started) { 13213096Sgabeblack@google.com if (!runToTime && starved()) 13313068Sgabeblack@google.com scheduleStarvationEvent(); 13413069Sgabeblack@google.com kernel->status(::sc_core::SC_RUNNING); 13513068Sgabeblack@google.com } 13612961Sgabeblack@google.com 13713067Sgabeblack@google.com initDone = true; 13813186Sgabeblack@google.com 13913186Sgabeblack@google.com status(StatusOther); 14013245Sgabeblack@google.com 14113245Sgabeblack@google.com scheduleTimeAdvancesEvent(); 14212957Sgabeblack@google.com} 14312957Sgabeblack@google.com 14412957Sgabeblack@google.comvoid 14512957Sgabeblack@google.comScheduler::reg(Process *p) 14612957Sgabeblack@google.com{ 14713067Sgabeblack@google.com if (initDone) { 14813194Sgabeblack@google.com // If not marked as dontInitialize, mark as ready. 14913194Sgabeblack@google.com if (!p->dontInitialize()) 15013194Sgabeblack@google.com p->ready(); 15112957Sgabeblack@google.com } else { 15212957Sgabeblack@google.com // Otherwise, record that this process should be initialized once we 15312957Sgabeblack@google.com // get there. 15412957Sgabeblack@google.com initList.pushLast(p); 15512957Sgabeblack@google.com } 15612957Sgabeblack@google.com} 15712957Sgabeblack@google.com 15812957Sgabeblack@google.comvoid 15912953Sgabeblack@google.comScheduler::yield() 16012953Sgabeblack@google.com{ 16113176Sgabeblack@google.com // Pull a process from the active list. 16213209Sgabeblack@google.com _current = getNextReady(); 16312953Sgabeblack@google.com if (!_current) { 16412953Sgabeblack@google.com // There are no more processes, so return control to evaluate. 16512953Sgabeblack@google.com Fiber::primaryFiber()->run(); 16612953Sgabeblack@google.com } else { 16712953Sgabeblack@google.com _current->popListNode(); 16812953Sgabeblack@google.com // Switch to whatever Fiber is supposed to run this process. All 16912953Sgabeblack@google.com // Fibers which aren't running should be parked at this line. 17012953Sgabeblack@google.com _current->fiber()->run(); 17112961Sgabeblack@google.com // If the current process needs to be manually started, start it. 17213093Sgabeblack@google.com if (_current && _current->needsStart()) { 17313093Sgabeblack@google.com _current->needsStart(false); 17413182Sgabeblack@google.com try { 17513182Sgabeblack@google.com _current->run(); 17613182Sgabeblack@google.com } catch (...) { 17713182Sgabeblack@google.com throwToScMain(); 17813182Sgabeblack@google.com } 17913093Sgabeblack@google.com } 18012953Sgabeblack@google.com } 18112995Sgabeblack@google.com if (_current && _current->excWrapper) { 18212995Sgabeblack@google.com // Make sure this isn't a method process. 18312995Sgabeblack@google.com assert(!_current->needsStart()); 18412995Sgabeblack@google.com auto ew = _current->excWrapper; 18512995Sgabeblack@google.com _current->excWrapper = nullptr; 18612995Sgabeblack@google.com ew->throw_it(); 18712995Sgabeblack@google.com } 18812953Sgabeblack@google.com} 18912953Sgabeblack@google.com 19012953Sgabeblack@google.comvoid 19112954Sgabeblack@google.comScheduler::ready(Process *p) 19212953Sgabeblack@google.com{ 19313154Sgabeblack@google.com if (_stopNow) 19413154Sgabeblack@google.com return; 19513154Sgabeblack@google.com 19613176Sgabeblack@google.com if (p->procKind() == ::sc_core::SC_METHOD_PROC_) 19713176Sgabeblack@google.com readyListMethods.pushLast(p); 19812954Sgabeblack@google.com else 19913176Sgabeblack@google.com readyListThreads.pushLast(p); 20012953Sgabeblack@google.com 20113244Sgabeblack@google.com if (!inEvaluate()) 20213244Sgabeblack@google.com scheduleReadyEvent(); 20312954Sgabeblack@google.com} 20412954Sgabeblack@google.com 20512954Sgabeblack@google.comvoid 20613133Sgabeblack@google.comScheduler::resume(Process *p) 20713133Sgabeblack@google.com{ 20813133Sgabeblack@google.com if (initDone) 20913133Sgabeblack@google.com ready(p); 21013133Sgabeblack@google.com else 21113133Sgabeblack@google.com initList.pushLast(p); 21213133Sgabeblack@google.com} 21313133Sgabeblack@google.com 21413133Sgabeblack@google.combool 21513176Sgabeblack@google.comlistContains(ListNode *list, ListNode *target) 21613176Sgabeblack@google.com{ 21713176Sgabeblack@google.com ListNode *n = list->nextListNode; 21813176Sgabeblack@google.com while (n != list) 21913176Sgabeblack@google.com if (n == target) 22013176Sgabeblack@google.com return true; 22113176Sgabeblack@google.com return false; 22213176Sgabeblack@google.com} 22313176Sgabeblack@google.com 22413176Sgabeblack@google.combool 22513133Sgabeblack@google.comScheduler::suspend(Process *p) 22613133Sgabeblack@google.com{ 22713176Sgabeblack@google.com bool was_ready; 22813133Sgabeblack@google.com if (initDone) { 22913194Sgabeblack@google.com // After initialization, check if we're on a ready list. 23013176Sgabeblack@google.com was_ready = (p->nextListNode != nullptr); 23113133Sgabeblack@google.com p->popListNode(); 23213133Sgabeblack@google.com } else { 23313194Sgabeblack@google.com // Nothing is ready before init. 23413194Sgabeblack@google.com was_ready = false; 23513133Sgabeblack@google.com } 23613176Sgabeblack@google.com return was_ready; 23713133Sgabeblack@google.com} 23813133Sgabeblack@google.com 23913133Sgabeblack@google.comvoid 24012954Sgabeblack@google.comScheduler::requestUpdate(Channel *c) 24112954Sgabeblack@google.com{ 24212954Sgabeblack@google.com updateList.pushLast(c); 24313244Sgabeblack@google.com if (!inEvaluate()) 24413244Sgabeblack@google.com scheduleReadyEvent(); 24512954Sgabeblack@google.com} 24612954Sgabeblack@google.com 24712954Sgabeblack@google.comvoid 24812954Sgabeblack@google.comScheduler::scheduleReadyEvent() 24912954Sgabeblack@google.com{ 25012954Sgabeblack@google.com // Schedule the evaluate and update phases. 25112954Sgabeblack@google.com if (!readyEvent.scheduled()) { 25213069Sgabeblack@google.com schedule(&readyEvent); 25312987Sgabeblack@google.com if (starvationEvent.scheduled()) 25413069Sgabeblack@google.com deschedule(&starvationEvent); 25512987Sgabeblack@google.com } 25612987Sgabeblack@google.com} 25712987Sgabeblack@google.com 25812987Sgabeblack@google.comvoid 25912987Sgabeblack@google.comScheduler::scheduleStarvationEvent() 26012987Sgabeblack@google.com{ 26112987Sgabeblack@google.com if (!starvationEvent.scheduled()) { 26213069Sgabeblack@google.com schedule(&starvationEvent); 26312987Sgabeblack@google.com if (readyEvent.scheduled()) 26413069Sgabeblack@google.com deschedule(&readyEvent); 26512954Sgabeblack@google.com } 26612954Sgabeblack@google.com} 26712954Sgabeblack@google.com 26812954Sgabeblack@google.comvoid 26912954Sgabeblack@google.comScheduler::runReady() 27012954Sgabeblack@google.com{ 27113245Sgabeblack@google.com scheduleTimeAdvancesEvent(); 27213245Sgabeblack@google.com 27313176Sgabeblack@google.com bool empty = readyListMethods.empty() && readyListThreads.empty(); 27413140Sgabeblack@google.com lastReadyTick = getCurTick(); 27512954Sgabeblack@google.com 27612954Sgabeblack@google.com // The evaluation phase. 27713245Sgabeblack@google.com status(StatusEvaluate); 27812953Sgabeblack@google.com do { 27913209Sgabeblack@google.com yield(); 28013209Sgabeblack@google.com } while (getNextReady()); 28112954Sgabeblack@google.com 28213140Sgabeblack@google.com if (!empty) { 28312954Sgabeblack@google.com _numCycles++; 28413140Sgabeblack@google.com _changeStamp++; 28513140Sgabeblack@google.com } 28612954Sgabeblack@google.com 28713244Sgabeblack@google.com if (_stopNow) { 28813244Sgabeblack@google.com status(StatusOther); 28913154Sgabeblack@google.com return; 29013244Sgabeblack@google.com } 29113154Sgabeblack@google.com 29213186Sgabeblack@google.com runUpdate(); 29313245Sgabeblack@google.com if (!traceFiles.empty()) 29413245Sgabeblack@google.com trace(true); 29513186Sgabeblack@google.com runDelta(); 29613061Sgabeblack@google.com 29713096Sgabeblack@google.com if (!runToTime && starved()) 29813096Sgabeblack@google.com scheduleStarvationEvent(); 29913096Sgabeblack@google.com 30013064Sgabeblack@google.com if (runOnce) 30113064Sgabeblack@google.com schedulePause(); 30213186Sgabeblack@google.com 30313186Sgabeblack@google.com status(StatusOther); 30412953Sgabeblack@google.com} 30512953Sgabeblack@google.com 30612953Sgabeblack@google.comvoid 30713186Sgabeblack@google.comScheduler::runUpdate() 30812953Sgabeblack@google.com{ 30913186Sgabeblack@google.com status(StatusUpdate); 31013186Sgabeblack@google.com 31113188Sgabeblack@google.com try { 31213188Sgabeblack@google.com Channel *channel = updateList.getNext(); 31313188Sgabeblack@google.com while (channel) { 31413188Sgabeblack@google.com channel->popListNode(); 31513188Sgabeblack@google.com channel->update(); 31613188Sgabeblack@google.com channel = updateList.getNext(); 31713188Sgabeblack@google.com } 31813188Sgabeblack@google.com } catch (...) { 31913188Sgabeblack@google.com throwToScMain(); 32012954Sgabeblack@google.com } 32112953Sgabeblack@google.com} 32212953Sgabeblack@google.com 32312961Sgabeblack@google.comvoid 32413186Sgabeblack@google.comScheduler::runDelta() 32513186Sgabeblack@google.com{ 32613186Sgabeblack@google.com status(StatusDelta); 32713188Sgabeblack@google.com 32813188Sgabeblack@google.com try { 32913188Sgabeblack@google.com while (!deltas.empty()) 33013188Sgabeblack@google.com deltas.front()->run(); 33113188Sgabeblack@google.com } catch (...) { 33213188Sgabeblack@google.com throwToScMain(); 33313188Sgabeblack@google.com } 33413186Sgabeblack@google.com} 33513186Sgabeblack@google.com 33613186Sgabeblack@google.comvoid 33712961Sgabeblack@google.comScheduler::pause() 33812961Sgabeblack@google.com{ 33913186Sgabeblack@google.com status(StatusPaused); 34012982Sgabeblack@google.com kernel->status(::sc_core::SC_PAUSED); 34113061Sgabeblack@google.com runOnce = false; 34213182Sgabeblack@google.com if (scMain && !scMain->finished()) 34313182Sgabeblack@google.com scMain->run(); 34412961Sgabeblack@google.com} 34512961Sgabeblack@google.com 34612961Sgabeblack@google.comvoid 34712961Sgabeblack@google.comScheduler::stop() 34812961Sgabeblack@google.com{ 34913186Sgabeblack@google.com status(StatusStopped); 35012982Sgabeblack@google.com kernel->stop(); 35113074Sgabeblack@google.com 35213076Sgabeblack@google.com clear(); 35313074Sgabeblack@google.com 35413061Sgabeblack@google.com runOnce = false; 35513182Sgabeblack@google.com if (scMain && !scMain->finished()) 35613182Sgabeblack@google.com scMain->run(); 35712961Sgabeblack@google.com} 35812961Sgabeblack@google.com 35912961Sgabeblack@google.comvoid 36012961Sgabeblack@google.comScheduler::start(Tick max_tick, bool run_to_time) 36112961Sgabeblack@google.com{ 36212961Sgabeblack@google.com // We should be running from sc_main. Keep track of that Fiber to return 36312961Sgabeblack@google.com // to later. 36412961Sgabeblack@google.com scMain = Fiber::currentFiber(); 36512961Sgabeblack@google.com 36612961Sgabeblack@google.com _started = true; 36713186Sgabeblack@google.com status(StatusOther); 36812987Sgabeblack@google.com runToTime = run_to_time; 36912961Sgabeblack@google.com 37012961Sgabeblack@google.com maxTick = max_tick; 37113140Sgabeblack@google.com lastReadyTick = getCurTick(); 37212961Sgabeblack@google.com 37313067Sgabeblack@google.com if (initDone) { 37413096Sgabeblack@google.com if (!runToTime && starved()) 37513068Sgabeblack@google.com scheduleStarvationEvent(); 37612982Sgabeblack@google.com kernel->status(::sc_core::SC_RUNNING); 37712982Sgabeblack@google.com } 37812961Sgabeblack@google.com 37913069Sgabeblack@google.com schedule(&maxTickEvent, maxTick); 38013245Sgabeblack@google.com scheduleTimeAdvancesEvent(); 38113069Sgabeblack@google.com 38212961Sgabeblack@google.com // Return to gem5 to let it run events, etc. 38312961Sgabeblack@google.com Fiber::primaryFiber()->run(); 38412961Sgabeblack@google.com 38512961Sgabeblack@google.com if (pauseEvent.scheduled()) 38613088Sgabeblack@google.com deschedule(&pauseEvent); 38712961Sgabeblack@google.com if (stopEvent.scheduled()) 38813088Sgabeblack@google.com deschedule(&stopEvent); 38912961Sgabeblack@google.com if (maxTickEvent.scheduled()) 39013088Sgabeblack@google.com deschedule(&maxTickEvent); 39112987Sgabeblack@google.com if (starvationEvent.scheduled()) 39213088Sgabeblack@google.com deschedule(&starvationEvent); 39313182Sgabeblack@google.com 39413182Sgabeblack@google.com if (_throwToScMain) { 39513182Sgabeblack@google.com const ::sc_core::sc_report *to_throw = _throwToScMain; 39613182Sgabeblack@google.com _throwToScMain = nullptr; 39713182Sgabeblack@google.com throw *to_throw; 39813182Sgabeblack@google.com } 39912961Sgabeblack@google.com} 40012961Sgabeblack@google.com 40112961Sgabeblack@google.comvoid 40213061Sgabeblack@google.comScheduler::oneCycle() 40313061Sgabeblack@google.com{ 40413061Sgabeblack@google.com runOnce = true; 40513095Sgabeblack@google.com scheduleReadyEvent(); 40613061Sgabeblack@google.com start(::MaxTick, false); 40713061Sgabeblack@google.com} 40813061Sgabeblack@google.com 40913061Sgabeblack@google.comvoid 41012961Sgabeblack@google.comScheduler::schedulePause() 41112961Sgabeblack@google.com{ 41212961Sgabeblack@google.com if (pauseEvent.scheduled()) 41312961Sgabeblack@google.com return; 41412961Sgabeblack@google.com 41513088Sgabeblack@google.com schedule(&pauseEvent); 41612961Sgabeblack@google.com} 41712961Sgabeblack@google.com 41812961Sgabeblack@google.comvoid 41913182Sgabeblack@google.comScheduler::throwToScMain(const ::sc_core::sc_report *r) 42013182Sgabeblack@google.com{ 42113182Sgabeblack@google.com if (!r) 42213182Sgabeblack@google.com r = reportifyException(); 42313182Sgabeblack@google.com _throwToScMain = r; 42413188Sgabeblack@google.com status(StatusOther); 42513182Sgabeblack@google.com scMain->run(); 42613182Sgabeblack@google.com} 42713182Sgabeblack@google.com 42813182Sgabeblack@google.comvoid 42912961Sgabeblack@google.comScheduler::scheduleStop(bool finish_delta) 43012961Sgabeblack@google.com{ 43112961Sgabeblack@google.com if (stopEvent.scheduled()) 43212961Sgabeblack@google.com return; 43312961Sgabeblack@google.com 43412961Sgabeblack@google.com if (!finish_delta) { 43513154Sgabeblack@google.com _stopNow = true; 43613076Sgabeblack@google.com // If we're not supposed to finish the delta cycle, flush all 43713076Sgabeblack@google.com // pending activity. 43813076Sgabeblack@google.com clear(); 43912961Sgabeblack@google.com } 44013088Sgabeblack@google.com schedule(&stopEvent); 44112961Sgabeblack@google.com} 44212961Sgabeblack@google.com 44313245Sgabeblack@google.comvoid 44413245Sgabeblack@google.comScheduler::trace(bool delta) 44513245Sgabeblack@google.com{ 44613245Sgabeblack@google.com for (auto tf: traceFiles) 44713245Sgabeblack@google.com tf->trace(delta); 44813245Sgabeblack@google.com} 44913245Sgabeblack@google.com 45012953Sgabeblack@google.comScheduler scheduler; 45112953Sgabeblack@google.com 45213182Sgabeblack@google.comnamespace { 45313182Sgabeblack@google.com 45413182Sgabeblack@google.comvoid 45513182Sgabeblack@google.comthrowingReportHandler(const ::sc_core::sc_report &r, 45613182Sgabeblack@google.com const ::sc_core::sc_actions &) 45713182Sgabeblack@google.com{ 45813182Sgabeblack@google.com throw r; 45913182Sgabeblack@google.com} 46013182Sgabeblack@google.com 46113182Sgabeblack@google.com} // anonymous namespace 46213182Sgabeblack@google.com 46313182Sgabeblack@google.comconst ::sc_core::sc_report * 46413182Sgabeblack@google.comreportifyException() 46513182Sgabeblack@google.com{ 46613182Sgabeblack@google.com ::sc_core::sc_report_handler_proc old_handler = 46713182Sgabeblack@google.com ::sc_core::sc_report_handler::get_handler(); 46813182Sgabeblack@google.com ::sc_core::sc_report_handler::set_handler(&throwingReportHandler); 46913182Sgabeblack@google.com 47013182Sgabeblack@google.com try { 47113182Sgabeblack@google.com try { 47213182Sgabeblack@google.com // Rethrow the current exception so we can catch it and throw an 47313182Sgabeblack@google.com // sc_report instead if it's not a type we recognize/can handle. 47413182Sgabeblack@google.com throw; 47513182Sgabeblack@google.com } catch (const ::sc_core::sc_report &) { 47613182Sgabeblack@google.com // It's already a sc_report, so nothing to do. 47713182Sgabeblack@google.com throw; 47813182Sgabeblack@google.com } catch (const ::sc_core::sc_unwind_exception &) { 47913182Sgabeblack@google.com panic("Kill/reset exception escaped a Process::run()"); 48013182Sgabeblack@google.com } catch (const std::exception &e) { 48113182Sgabeblack@google.com SC_REPORT_ERROR("uncaught exception", e.what()); 48213182Sgabeblack@google.com } catch (const char *msg) { 48313182Sgabeblack@google.com SC_REPORT_ERROR("uncaught exception", msg); 48413182Sgabeblack@google.com } catch (...) { 48513182Sgabeblack@google.com SC_REPORT_ERROR("uncaught exception", "UNKNOWN EXCEPTION"); 48613182Sgabeblack@google.com } 48713182Sgabeblack@google.com } catch (const ::sc_core::sc_report &r) { 48813182Sgabeblack@google.com ::sc_core::sc_report_handler::set_handler(old_handler); 48913182Sgabeblack@google.com return &r; 49013182Sgabeblack@google.com } 49113182Sgabeblack@google.com panic("No exception thrown in reportifyException."); 49213182Sgabeblack@google.com} 49313182Sgabeblack@google.com 49412953Sgabeblack@google.com} // namespace sc_gem5 495