scheduler.cc revision 13182
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" 3912953Sgabeblack@google.com 4012953Sgabeblack@google.comnamespace sc_gem5 4112953Sgabeblack@google.com{ 4212953Sgabeblack@google.com 4312954Sgabeblack@google.comScheduler::Scheduler() : 4412962Sgabeblack@google.com eq(nullptr), readyEvent(this, false, ReadyPriority), 4512961Sgabeblack@google.com pauseEvent(this, false, PausePriority), 4612961Sgabeblack@google.com stopEvent(this, false, StopPriority), 4713182Sgabeblack@google.com scMain(nullptr), _throwToScMain(nullptr), 4812987Sgabeblack@google.com starvationEvent(this, false, StarvationPriority), 4913154Sgabeblack@google.com _started(false), _paused(false), _stopped(false), _stopNow(false), 5012961Sgabeblack@google.com maxTickEvent(this, false, MaxTickPriority), 5113140Sgabeblack@google.com _numCycles(0), _changeStamp(0), _current(nullptr), initDone(false), 5213176Sgabeblack@google.com runOnce(false), readyList(nullptr) 5312954Sgabeblack@google.com{} 5412953Sgabeblack@google.com 5513072Sgabeblack@google.comScheduler::~Scheduler() 5613072Sgabeblack@google.com{ 5713072Sgabeblack@google.com // Clear out everything that belongs to us to make sure nobody tries to 5813072Sgabeblack@google.com // clear themselves out after the scheduler goes away. 5913076Sgabeblack@google.com clear(); 6013076Sgabeblack@google.com} 6113072Sgabeblack@google.com 6213076Sgabeblack@google.comvoid 6313076Sgabeblack@google.comScheduler::clear() 6413076Sgabeblack@google.com{ 6513072Sgabeblack@google.com // Delta notifications. 6613144Sgabeblack@google.com while (!deltas.empty()) 6713144Sgabeblack@google.com deltas.front()->deschedule(); 6813072Sgabeblack@google.com 6913072Sgabeblack@google.com // Timed notifications. 7013076Sgabeblack@google.com for (auto &tsp: timeSlots) { 7113076Sgabeblack@google.com TimeSlot *&ts = tsp.second; 7213144Sgabeblack@google.com while (!ts->events.empty()) 7313144Sgabeblack@google.com ts->events.front()->deschedule(); 7413088Sgabeblack@google.com deschedule(ts); 7513072Sgabeblack@google.com } 7613076Sgabeblack@google.com timeSlots.clear(); 7713072Sgabeblack@google.com 7813072Sgabeblack@google.com // gem5 events. 7913072Sgabeblack@google.com if (readyEvent.scheduled()) 8013088Sgabeblack@google.com deschedule(&readyEvent); 8113072Sgabeblack@google.com if (pauseEvent.scheduled()) 8213088Sgabeblack@google.com deschedule(&pauseEvent); 8313072Sgabeblack@google.com if (stopEvent.scheduled()) 8413088Sgabeblack@google.com deschedule(&stopEvent); 8513072Sgabeblack@google.com if (starvationEvent.scheduled()) 8613088Sgabeblack@google.com deschedule(&starvationEvent); 8713072Sgabeblack@google.com if (maxTickEvent.scheduled()) 8813088Sgabeblack@google.com deschedule(&maxTickEvent); 8913072Sgabeblack@google.com 9013072Sgabeblack@google.com Process *p; 9113072Sgabeblack@google.com while ((p = toFinalize.getNext())) 9213072Sgabeblack@google.com p->popListNode(); 9313072Sgabeblack@google.com while ((p = initList.getNext())) 9413072Sgabeblack@google.com p->popListNode(); 9513176Sgabeblack@google.com while ((p = readyListMethods.getNext())) 9613176Sgabeblack@google.com p->popListNode(); 9713176Sgabeblack@google.com while ((p = readyListThreads.getNext())) 9813072Sgabeblack@google.com p->popListNode(); 9913072Sgabeblack@google.com 10013072Sgabeblack@google.com Channel *c; 10113072Sgabeblack@google.com while ((c = updateList.getNext())) 10213072Sgabeblack@google.com c->popListNode(); 10313072Sgabeblack@google.com} 10413072Sgabeblack@google.com 10512953Sgabeblack@google.comvoid 10613067Sgabeblack@google.comScheduler::initPhase() 10712953Sgabeblack@google.com{ 10812957Sgabeblack@google.com for (Process *p = toFinalize.getNext(); p; p = toFinalize.getNext()) { 10912957Sgabeblack@google.com p->finalize(); 11012957Sgabeblack@google.com p->popListNode(); 11113180Sgabeblack@google.com 11213180Sgabeblack@google.com if (!p->hasStaticSensitivities() && !p->internal()) { 11313180Sgabeblack@google.com SC_REPORT_WARNING( 11413180Sgabeblack@google.com "(W558) disable() or dont_initialize() called on process " 11513180Sgabeblack@google.com "with no static sensitivity, it will be orphaned", 11613180Sgabeblack@google.com p->name()); 11713180Sgabeblack@google.com } 11812957Sgabeblack@google.com } 11912957Sgabeblack@google.com 12012957Sgabeblack@google.com for (Process *p = initList.getNext(); p; p = initList.getNext()) { 12112957Sgabeblack@google.com p->finalize(); 12212996Sgabeblack@google.com p->popListNode(); 12312959Sgabeblack@google.com p->ready(); 12412957Sgabeblack@google.com } 12512957Sgabeblack@google.com 12613067Sgabeblack@google.com update(); 12713067Sgabeblack@google.com 12813144Sgabeblack@google.com while (!deltas.empty()) 12913144Sgabeblack@google.com deltas.front()->run(); 13013067Sgabeblack@google.com 13112985Sgabeblack@google.com for (auto ets: eventsToSchedule) 13212985Sgabeblack@google.com eq->schedule(ets.first, ets.second); 13312985Sgabeblack@google.com eventsToSchedule.clear(); 13412985Sgabeblack@google.com 13513068Sgabeblack@google.com if (_started) { 13613096Sgabeblack@google.com if (!runToTime && starved()) 13713068Sgabeblack@google.com scheduleStarvationEvent(); 13813069Sgabeblack@google.com kernel->status(::sc_core::SC_RUNNING); 13913068Sgabeblack@google.com } 14012961Sgabeblack@google.com 14113067Sgabeblack@google.com initDone = true; 14212957Sgabeblack@google.com} 14312957Sgabeblack@google.com 14412957Sgabeblack@google.comvoid 14512957Sgabeblack@google.comScheduler::reg(Process *p) 14612957Sgabeblack@google.com{ 14713067Sgabeblack@google.com if (initDone) { 14812957Sgabeblack@google.com // If we're past initialization, finalize static sensitivity. 14912957Sgabeblack@google.com p->finalize(); 15012957Sgabeblack@google.com // Mark the process as ready. 15112959Sgabeblack@google.com p->ready(); 15212957Sgabeblack@google.com } else { 15312957Sgabeblack@google.com // Otherwise, record that this process should be initialized once we 15412957Sgabeblack@google.com // get there. 15512957Sgabeblack@google.com initList.pushLast(p); 15612957Sgabeblack@google.com } 15712957Sgabeblack@google.com} 15812957Sgabeblack@google.com 15912957Sgabeblack@google.comvoid 16012957Sgabeblack@google.comScheduler::dontInitialize(Process *p) 16112957Sgabeblack@google.com{ 16213067Sgabeblack@google.com if (initDone) { 16312957Sgabeblack@google.com // Pop this process off of the ready list. 16412957Sgabeblack@google.com p->popListNode(); 16512957Sgabeblack@google.com } else { 16612957Sgabeblack@google.com // Push this process onto the list of processes which still need 16712957Sgabeblack@google.com // their static sensitivity to be finalized. That implicitly pops it 16812957Sgabeblack@google.com // off the list of processes to be initialized/marked ready. 16912957Sgabeblack@google.com toFinalize.pushLast(p); 17012957Sgabeblack@google.com } 17112953Sgabeblack@google.com} 17212953Sgabeblack@google.com 17312953Sgabeblack@google.comvoid 17412953Sgabeblack@google.comScheduler::yield() 17512953Sgabeblack@google.com{ 17613176Sgabeblack@google.com // Pull a process from the active list. 17713176Sgabeblack@google.com _current = readyList->getNext(); 17812953Sgabeblack@google.com if (!_current) { 17912953Sgabeblack@google.com // There are no more processes, so return control to evaluate. 18012953Sgabeblack@google.com Fiber::primaryFiber()->run(); 18112953Sgabeblack@google.com } else { 18212953Sgabeblack@google.com _current->popListNode(); 18312953Sgabeblack@google.com // Switch to whatever Fiber is supposed to run this process. All 18412953Sgabeblack@google.com // Fibers which aren't running should be parked at this line. 18512953Sgabeblack@google.com _current->fiber()->run(); 18612961Sgabeblack@google.com // If the current process needs to be manually started, start it. 18713093Sgabeblack@google.com if (_current && _current->needsStart()) { 18813093Sgabeblack@google.com _current->needsStart(false); 18913182Sgabeblack@google.com try { 19013182Sgabeblack@google.com _current->run(); 19113182Sgabeblack@google.com } catch (...) { 19213182Sgabeblack@google.com throwToScMain(); 19313182Sgabeblack@google.com } 19413093Sgabeblack@google.com } 19512953Sgabeblack@google.com } 19612995Sgabeblack@google.com if (_current && _current->excWrapper) { 19712995Sgabeblack@google.com // Make sure this isn't a method process. 19812995Sgabeblack@google.com assert(!_current->needsStart()); 19912995Sgabeblack@google.com auto ew = _current->excWrapper; 20012995Sgabeblack@google.com _current->excWrapper = nullptr; 20112995Sgabeblack@google.com ew->throw_it(); 20212995Sgabeblack@google.com } 20312953Sgabeblack@google.com} 20412953Sgabeblack@google.com 20512953Sgabeblack@google.comvoid 20612954Sgabeblack@google.comScheduler::ready(Process *p) 20712953Sgabeblack@google.com{ 20813154Sgabeblack@google.com if (_stopNow) 20913154Sgabeblack@google.com return; 21013154Sgabeblack@google.com 21113176Sgabeblack@google.com if (p->procKind() == ::sc_core::SC_METHOD_PROC_) 21213176Sgabeblack@google.com readyListMethods.pushLast(p); 21312954Sgabeblack@google.com else 21413176Sgabeblack@google.com readyListThreads.pushLast(p); 21512953Sgabeblack@google.com 21612954Sgabeblack@google.com scheduleReadyEvent(); 21712954Sgabeblack@google.com} 21812954Sgabeblack@google.com 21912954Sgabeblack@google.comvoid 22013133Sgabeblack@google.comScheduler::resume(Process *p) 22113133Sgabeblack@google.com{ 22213133Sgabeblack@google.com if (initDone) 22313133Sgabeblack@google.com ready(p); 22413133Sgabeblack@google.com else 22513133Sgabeblack@google.com initList.pushLast(p); 22613133Sgabeblack@google.com} 22713133Sgabeblack@google.com 22813133Sgabeblack@google.combool 22913176Sgabeblack@google.comlistContains(ListNode *list, ListNode *target) 23013176Sgabeblack@google.com{ 23113176Sgabeblack@google.com ListNode *n = list->nextListNode; 23213176Sgabeblack@google.com while (n != list) 23313176Sgabeblack@google.com if (n == target) 23413176Sgabeblack@google.com return true; 23513176Sgabeblack@google.com return false; 23613176Sgabeblack@google.com} 23713176Sgabeblack@google.com 23813176Sgabeblack@google.combool 23913133Sgabeblack@google.comScheduler::suspend(Process *p) 24013133Sgabeblack@google.com{ 24113176Sgabeblack@google.com bool was_ready; 24213133Sgabeblack@google.com if (initDone) { 24313133Sgabeblack@google.com // After initialization, the only list we can be on is the ready list. 24413176Sgabeblack@google.com was_ready = (p->nextListNode != nullptr); 24513133Sgabeblack@google.com p->popListNode(); 24613133Sgabeblack@google.com } else { 24713176Sgabeblack@google.com // Check the ready lists to see if we find this process. 24813176Sgabeblack@google.com was_ready = listContains(&readyListMethods, p) || 24913176Sgabeblack@google.com listContains(&readyListThreads, p); 25013133Sgabeblack@google.com if (was_ready) 25113133Sgabeblack@google.com toFinalize.pushLast(p); 25213133Sgabeblack@google.com } 25313176Sgabeblack@google.com return was_ready; 25413133Sgabeblack@google.com} 25513133Sgabeblack@google.com 25613133Sgabeblack@google.comvoid 25712954Sgabeblack@google.comScheduler::requestUpdate(Channel *c) 25812954Sgabeblack@google.com{ 25912954Sgabeblack@google.com updateList.pushLast(c); 26013069Sgabeblack@google.com scheduleReadyEvent(); 26112954Sgabeblack@google.com} 26212954Sgabeblack@google.com 26312954Sgabeblack@google.comvoid 26412954Sgabeblack@google.comScheduler::scheduleReadyEvent() 26512954Sgabeblack@google.com{ 26612954Sgabeblack@google.com // Schedule the evaluate and update phases. 26712954Sgabeblack@google.com if (!readyEvent.scheduled()) { 26813069Sgabeblack@google.com schedule(&readyEvent); 26912987Sgabeblack@google.com if (starvationEvent.scheduled()) 27013069Sgabeblack@google.com deschedule(&starvationEvent); 27112987Sgabeblack@google.com } 27212987Sgabeblack@google.com} 27312987Sgabeblack@google.com 27412987Sgabeblack@google.comvoid 27512987Sgabeblack@google.comScheduler::scheduleStarvationEvent() 27612987Sgabeblack@google.com{ 27712987Sgabeblack@google.com if (!starvationEvent.scheduled()) { 27813069Sgabeblack@google.com schedule(&starvationEvent); 27912987Sgabeblack@google.com if (readyEvent.scheduled()) 28013069Sgabeblack@google.com deschedule(&readyEvent); 28112954Sgabeblack@google.com } 28212954Sgabeblack@google.com} 28312954Sgabeblack@google.com 28412954Sgabeblack@google.comvoid 28512954Sgabeblack@google.comScheduler::runReady() 28612954Sgabeblack@google.com{ 28713176Sgabeblack@google.com bool empty = readyListMethods.empty() && readyListThreads.empty(); 28813140Sgabeblack@google.com lastReadyTick = getCurTick(); 28912954Sgabeblack@google.com 29012954Sgabeblack@google.com // The evaluation phase. 29112953Sgabeblack@google.com do { 29213176Sgabeblack@google.com // We run methods and threads in two seperate passes to emulate how 29313176Sgabeblack@google.com // Accellera orders things, but without having to scan through a 29413176Sgabeblack@google.com // unified list to find the next process of the correct type. 29513176Sgabeblack@google.com readyList = &readyListMethods; 29613176Sgabeblack@google.com while (!readyListMethods.empty()) 29713176Sgabeblack@google.com yield(); 29813176Sgabeblack@google.com 29913176Sgabeblack@google.com readyList = &readyListThreads; 30013176Sgabeblack@google.com while (!readyListThreads.empty()) 30113176Sgabeblack@google.com yield(); 30213176Sgabeblack@google.com 30313176Sgabeblack@google.com // We already know that readyListThreads is empty at this point. 30413176Sgabeblack@google.com } while (!readyListMethods.empty()); 30512954Sgabeblack@google.com 30613140Sgabeblack@google.com if (!empty) { 30712954Sgabeblack@google.com _numCycles++; 30813140Sgabeblack@google.com _changeStamp++; 30913140Sgabeblack@google.com } 31012954Sgabeblack@google.com 31113154Sgabeblack@google.com if (_stopNow) 31213154Sgabeblack@google.com return; 31313154Sgabeblack@google.com 31412954Sgabeblack@google.com // The update phase. 31512954Sgabeblack@google.com update(); 31612954Sgabeblack@google.com 31713063Sgabeblack@google.com // The delta phase. 31813144Sgabeblack@google.com while (!deltas.empty()) 31913144Sgabeblack@google.com deltas.front()->run(); 32013061Sgabeblack@google.com 32113096Sgabeblack@google.com if (!runToTime && starved()) 32213096Sgabeblack@google.com scheduleStarvationEvent(); 32313096Sgabeblack@google.com 32413064Sgabeblack@google.com if (runOnce) 32513064Sgabeblack@google.com schedulePause(); 32612953Sgabeblack@google.com} 32712953Sgabeblack@google.com 32812953Sgabeblack@google.comvoid 32912953Sgabeblack@google.comScheduler::update() 33012953Sgabeblack@google.com{ 33112954Sgabeblack@google.com Channel *channel = updateList.getNext(); 33212954Sgabeblack@google.com while (channel) { 33312954Sgabeblack@google.com channel->popListNode(); 33412954Sgabeblack@google.com channel->update(); 33512954Sgabeblack@google.com channel = updateList.getNext(); 33612954Sgabeblack@google.com } 33712953Sgabeblack@google.com} 33812953Sgabeblack@google.com 33912961Sgabeblack@google.comvoid 34012961Sgabeblack@google.comScheduler::pause() 34112961Sgabeblack@google.com{ 34212961Sgabeblack@google.com _paused = true; 34312982Sgabeblack@google.com kernel->status(::sc_core::SC_PAUSED); 34413061Sgabeblack@google.com runOnce = false; 34513182Sgabeblack@google.com if (scMain && !scMain->finished()) 34613182Sgabeblack@google.com scMain->run(); 34712961Sgabeblack@google.com} 34812961Sgabeblack@google.com 34912961Sgabeblack@google.comvoid 35012961Sgabeblack@google.comScheduler::stop() 35112961Sgabeblack@google.com{ 35212961Sgabeblack@google.com _stopped = true; 35312982Sgabeblack@google.com kernel->stop(); 35413074Sgabeblack@google.com 35513076Sgabeblack@google.com clear(); 35613074Sgabeblack@google.com 35713061Sgabeblack@google.com runOnce = false; 35813182Sgabeblack@google.com if (scMain && !scMain->finished()) 35913182Sgabeblack@google.com scMain->run(); 36012961Sgabeblack@google.com} 36112961Sgabeblack@google.com 36212961Sgabeblack@google.comvoid 36312961Sgabeblack@google.comScheduler::start(Tick max_tick, bool run_to_time) 36412961Sgabeblack@google.com{ 36512961Sgabeblack@google.com // We should be running from sc_main. Keep track of that Fiber to return 36612961Sgabeblack@google.com // to later. 36712961Sgabeblack@google.com scMain = Fiber::currentFiber(); 36812961Sgabeblack@google.com 36912961Sgabeblack@google.com _started = true; 37012961Sgabeblack@google.com _paused = false; 37112961Sgabeblack@google.com _stopped = false; 37212987Sgabeblack@google.com runToTime = run_to_time; 37312961Sgabeblack@google.com 37412961Sgabeblack@google.com maxTick = max_tick; 37513140Sgabeblack@google.com lastReadyTick = getCurTick(); 37612961Sgabeblack@google.com 37713067Sgabeblack@google.com if (initDone) { 37813096Sgabeblack@google.com if (!runToTime && starved()) 37913068Sgabeblack@google.com scheduleStarvationEvent(); 38012982Sgabeblack@google.com kernel->status(::sc_core::SC_RUNNING); 38112982Sgabeblack@google.com } 38212961Sgabeblack@google.com 38313069Sgabeblack@google.com schedule(&maxTickEvent, maxTick); 38413069Sgabeblack@google.com 38512961Sgabeblack@google.com // Return to gem5 to let it run events, etc. 38612961Sgabeblack@google.com Fiber::primaryFiber()->run(); 38712961Sgabeblack@google.com 38812961Sgabeblack@google.com if (pauseEvent.scheduled()) 38913088Sgabeblack@google.com deschedule(&pauseEvent); 39012961Sgabeblack@google.com if (stopEvent.scheduled()) 39113088Sgabeblack@google.com deschedule(&stopEvent); 39212961Sgabeblack@google.com if (maxTickEvent.scheduled()) 39313088Sgabeblack@google.com deschedule(&maxTickEvent); 39412987Sgabeblack@google.com if (starvationEvent.scheduled()) 39513088Sgabeblack@google.com deschedule(&starvationEvent); 39613182Sgabeblack@google.com 39713182Sgabeblack@google.com if (_throwToScMain) { 39813182Sgabeblack@google.com const ::sc_core::sc_report *to_throw = _throwToScMain; 39913182Sgabeblack@google.com _throwToScMain = nullptr; 40013182Sgabeblack@google.com throw *to_throw; 40113182Sgabeblack@google.com } 40212961Sgabeblack@google.com} 40312961Sgabeblack@google.com 40412961Sgabeblack@google.comvoid 40513061Sgabeblack@google.comScheduler::oneCycle() 40613061Sgabeblack@google.com{ 40713061Sgabeblack@google.com runOnce = true; 40813095Sgabeblack@google.com scheduleReadyEvent(); 40913061Sgabeblack@google.com start(::MaxTick, false); 41013061Sgabeblack@google.com} 41113061Sgabeblack@google.com 41213061Sgabeblack@google.comvoid 41312961Sgabeblack@google.comScheduler::schedulePause() 41412961Sgabeblack@google.com{ 41512961Sgabeblack@google.com if (pauseEvent.scheduled()) 41612961Sgabeblack@google.com return; 41712961Sgabeblack@google.com 41813088Sgabeblack@google.com schedule(&pauseEvent); 41912961Sgabeblack@google.com} 42012961Sgabeblack@google.com 42112961Sgabeblack@google.comvoid 42213182Sgabeblack@google.comScheduler::throwToScMain(const ::sc_core::sc_report *r) 42313182Sgabeblack@google.com{ 42413182Sgabeblack@google.com if (!r) 42513182Sgabeblack@google.com r = reportifyException(); 42613182Sgabeblack@google.com _throwToScMain = r; 42713182Sgabeblack@google.com scMain->run(); 42813182Sgabeblack@google.com} 42913182Sgabeblack@google.com 43013182Sgabeblack@google.comvoid 43112961Sgabeblack@google.comScheduler::scheduleStop(bool finish_delta) 43212961Sgabeblack@google.com{ 43312961Sgabeblack@google.com if (stopEvent.scheduled()) 43412961Sgabeblack@google.com return; 43512961Sgabeblack@google.com 43612961Sgabeblack@google.com if (!finish_delta) { 43713154Sgabeblack@google.com _stopNow = true; 43813076Sgabeblack@google.com // If we're not supposed to finish the delta cycle, flush all 43913076Sgabeblack@google.com // pending activity. 44013076Sgabeblack@google.com clear(); 44112961Sgabeblack@google.com } 44213088Sgabeblack@google.com schedule(&stopEvent); 44312961Sgabeblack@google.com} 44412961Sgabeblack@google.com 44512953Sgabeblack@google.comScheduler scheduler; 44612953Sgabeblack@google.com 44713182Sgabeblack@google.comnamespace { 44813182Sgabeblack@google.com 44913182Sgabeblack@google.comvoid 45013182Sgabeblack@google.comthrowingReportHandler(const ::sc_core::sc_report &r, 45113182Sgabeblack@google.com const ::sc_core::sc_actions &) 45213182Sgabeblack@google.com{ 45313182Sgabeblack@google.com throw r; 45413182Sgabeblack@google.com} 45513182Sgabeblack@google.com 45613182Sgabeblack@google.com} // anonymous namespace 45713182Sgabeblack@google.com 45813182Sgabeblack@google.comconst ::sc_core::sc_report * 45913182Sgabeblack@google.comreportifyException() 46013182Sgabeblack@google.com{ 46113182Sgabeblack@google.com ::sc_core::sc_report_handler_proc old_handler = 46213182Sgabeblack@google.com ::sc_core::sc_report_handler::get_handler(); 46313182Sgabeblack@google.com ::sc_core::sc_report_handler::set_handler(&throwingReportHandler); 46413182Sgabeblack@google.com 46513182Sgabeblack@google.com try { 46613182Sgabeblack@google.com try { 46713182Sgabeblack@google.com // Rethrow the current exception so we can catch it and throw an 46813182Sgabeblack@google.com // sc_report instead if it's not a type we recognize/can handle. 46913182Sgabeblack@google.com throw; 47013182Sgabeblack@google.com } catch (const ::sc_core::sc_report &) { 47113182Sgabeblack@google.com // It's already a sc_report, so nothing to do. 47213182Sgabeblack@google.com throw; 47313182Sgabeblack@google.com } catch (const ::sc_core::sc_unwind_exception &) { 47413182Sgabeblack@google.com panic("Kill/reset exception escaped a Process::run()"); 47513182Sgabeblack@google.com } catch (const std::exception &e) { 47613182Sgabeblack@google.com SC_REPORT_ERROR("uncaught exception", e.what()); 47713182Sgabeblack@google.com } catch (const char *msg) { 47813182Sgabeblack@google.com SC_REPORT_ERROR("uncaught exception", msg); 47913182Sgabeblack@google.com } catch (...) { 48013182Sgabeblack@google.com SC_REPORT_ERROR("uncaught exception", "UNKNOWN EXCEPTION"); 48113182Sgabeblack@google.com } 48213182Sgabeblack@google.com } catch (const ::sc_core::sc_report &r) { 48313182Sgabeblack@google.com ::sc_core::sc_report_handler::set_handler(old_handler); 48413182Sgabeblack@google.com return &r; 48513182Sgabeblack@google.com } 48613182Sgabeblack@google.com panic("No exception thrown in reportifyException."); 48713182Sgabeblack@google.com} 48813182Sgabeblack@google.com 48912953Sgabeblack@google.com} // namespace sc_gem5 490