kernel.cc revision 13053:a7a320144bc1
110249Sstephan.diestelhorst@arm.com/* 210249Sstephan.diestelhorst@arm.com * Copyright 2018 Google, Inc. 310249Sstephan.diestelhorst@arm.com * 410249Sstephan.diestelhorst@arm.com * Redistribution and use in source and binary forms, with or without 510249Sstephan.diestelhorst@arm.com * modification, are permitted provided that the following conditions are 610249Sstephan.diestelhorst@arm.com * met: redistributions of source code must retain the above copyright 710249Sstephan.diestelhorst@arm.com * notice, this list of conditions and the following disclaimer; 810249Sstephan.diestelhorst@arm.com * redistributions in binary form must reproduce the above copyright 910249Sstephan.diestelhorst@arm.com * notice, this list of conditions and the following disclaimer in the 1010249Sstephan.diestelhorst@arm.com * documentation and/or other materials provided with the distribution; 1110249Sstephan.diestelhorst@arm.com * neither the name of the copyright holders nor the names of its 1210249Sstephan.diestelhorst@arm.com * contributors may be used to endorse or promote products derived from 1310249Sstephan.diestelhorst@arm.com * this software without specific prior written permission. 1410249Sstephan.diestelhorst@arm.com * 1510249Sstephan.diestelhorst@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1610249Sstephan.diestelhorst@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1710249Sstephan.diestelhorst@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1810249Sstephan.diestelhorst@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1910249Sstephan.diestelhorst@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2010249Sstephan.diestelhorst@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2110249Sstephan.diestelhorst@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2210249Sstephan.diestelhorst@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2310249Sstephan.diestelhorst@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2410249Sstephan.diestelhorst@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2510249Sstephan.diestelhorst@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2610249Sstephan.diestelhorst@arm.com * 2710249Sstephan.diestelhorst@arm.com * Authors: Gabe Black 2810249Sstephan.diestelhorst@arm.com */ 2910249Sstephan.diestelhorst@arm.com 3010249Sstephan.diestelhorst@arm.com#include "systemc/core/kernel.hh" 3110249Sstephan.diestelhorst@arm.com 3210249Sstephan.diestelhorst@arm.com#include "base/logging.hh" 3310249Sstephan.diestelhorst@arm.com#include "systemc/core/module.hh" 3410249Sstephan.diestelhorst@arm.com#include "systemc/core/scheduler.hh" 3510249Sstephan.diestelhorst@arm.com 3610249Sstephan.diestelhorst@arm.comnamespace sc_gem5 3710249Sstephan.diestelhorst@arm.com{ 3810249Sstephan.diestelhorst@arm.com 3910249Sstephan.diestelhorst@arm.comnamespace 4010249Sstephan.diestelhorst@arm.com{ 4110249Sstephan.diestelhorst@arm.com 4211793Sbrandon.potter@amd.combool stopAfterCallbacks = false; 4311793Sbrandon.potter@amd.combool startComplete = false; 4410249Sstephan.diestelhorst@arm.combool endComplete = false; 4510249Sstephan.diestelhorst@arm.com 4610249Sstephan.diestelhorst@arm.comsc_core::sc_status _status = sc_core::SC_ELABORATION; 4712334Sgabeblack@google.com 4811800Sbrandon.potter@amd.com} // anonymous namespace 4910249Sstephan.diestelhorst@arm.com 5010249Sstephan.diestelhorst@arm.combool Kernel::startOfSimulationComplete() { return startComplete; } 5110249Sstephan.diestelhorst@arm.combool Kernel::endOfSimulationComplete() { return endComplete; } 5211800Sbrandon.potter@amd.com 5310249Sstephan.diestelhorst@arm.comsc_core::sc_status Kernel::status() { return _status; } 5410249Sstephan.diestelhorst@arm.comvoid Kernel::status(sc_core::sc_status s) { _status = s; } 5510249Sstephan.diestelhorst@arm.com 5610249Sstephan.diestelhorst@arm.comKernel::Kernel(Params *params) : 5710249Sstephan.diestelhorst@arm.com SimObject(params), t0Event(this, false, EventBase::Default_Pri - 1) 5810249Sstephan.diestelhorst@arm.com{ 5910249Sstephan.diestelhorst@arm.com // Install ourselves as the scheduler's event manager. 6010249Sstephan.diestelhorst@arm.com ::sc_gem5::scheduler.setEventQueue(eventQueue()); 6110249Sstephan.diestelhorst@arm.com} 6210249Sstephan.diestelhorst@arm.com 6310249Sstephan.diestelhorst@arm.comvoid 6410249Sstephan.diestelhorst@arm.comKernel::init() 6510249Sstephan.diestelhorst@arm.com{ 6610249Sstephan.diestelhorst@arm.com status(::sc_core::SC_BEFORE_END_OF_ELABORATION); 6710249Sstephan.diestelhorst@arm.com for (auto m: sc_gem5::allModules) { 6810249Sstephan.diestelhorst@arm.com callbackModule(m); 6911321Ssteve.reinhardt@amd.com m->sc_mod()->before_end_of_elaboration(); 7010249Sstephan.diestelhorst@arm.com } 7110249Sstephan.diestelhorst@arm.com callbackModule(nullptr); 7210249Sstephan.diestelhorst@arm.com 7310249Sstephan.diestelhorst@arm.com if (stopAfterCallbacks) 7410249Sstephan.diestelhorst@arm.com stopWork(); 7510249Sstephan.diestelhorst@arm.com} 7610249Sstephan.diestelhorst@arm.com 7710249Sstephan.diestelhorst@arm.comvoid 7810249Sstephan.diestelhorst@arm.comKernel::regStats() 7910249Sstephan.diestelhorst@arm.com{ 8010249Sstephan.diestelhorst@arm.com for (auto m: sc_gem5::allModules) 8110249Sstephan.diestelhorst@arm.com for (auto p: m->ports) 8210249Sstephan.diestelhorst@arm.com p->_gem5Finalize(); 8310249Sstephan.diestelhorst@arm.com 8410249Sstephan.diestelhorst@arm.com status(::sc_core::SC_END_OF_ELABORATION); 8510249Sstephan.diestelhorst@arm.com for (auto m: sc_gem5::allModules) 8610249Sstephan.diestelhorst@arm.com m->sc_mod()->end_of_elaboration(); 8710395Sstephan.diestelhorst@arm.com 8810395Sstephan.diestelhorst@arm.com if (stopAfterCallbacks) 8910395Sstephan.diestelhorst@arm.com stopWork(); 9010249Sstephan.diestelhorst@arm.com} 9110249Sstephan.diestelhorst@arm.com 9210249Sstephan.diestelhorst@arm.comvoid 9310249Sstephan.diestelhorst@arm.comKernel::startup() 9410249Sstephan.diestelhorst@arm.com{ 9510249Sstephan.diestelhorst@arm.com status(::sc_core::SC_START_OF_SIMULATION); 9610395Sstephan.diestelhorst@arm.com for (auto m: sc_gem5::allModules) 9710395Sstephan.diestelhorst@arm.com m->sc_mod()->start_of_simulation(); 9810395Sstephan.diestelhorst@arm.com 9910395Sstephan.diestelhorst@arm.com startComplete = true; 10010395Sstephan.diestelhorst@arm.com 10110395Sstephan.diestelhorst@arm.com if (stopAfterCallbacks) 10210395Sstephan.diestelhorst@arm.com stopWork(); 10310395Sstephan.diestelhorst@arm.com 10410395Sstephan.diestelhorst@arm.com kernel->status(::sc_core::SC_RUNNING); 10510395Sstephan.diestelhorst@arm.com 10610395Sstephan.diestelhorst@arm.com schedule(t0Event, curTick()); 10710249Sstephan.diestelhorst@arm.com // Run update once before the event queue starts. 10810249Sstephan.diestelhorst@arm.com ::sc_gem5::scheduler.update(); 10910249Sstephan.diestelhorst@arm.com} 11010249Sstephan.diestelhorst@arm.com 11110249Sstephan.diestelhorst@arm.comvoid 11210249Sstephan.diestelhorst@arm.comKernel::stop() 11310249Sstephan.diestelhorst@arm.com{ 11410249Sstephan.diestelhorst@arm.com if (status() < ::sc_core::SC_RUNNING) 11510249Sstephan.diestelhorst@arm.com stopAfterCallbacks = true; 11610249Sstephan.diestelhorst@arm.com else 11710249Sstephan.diestelhorst@arm.com stopWork(); 11810249Sstephan.diestelhorst@arm.com} 11910249Sstephan.diestelhorst@arm.com 12010249Sstephan.diestelhorst@arm.comvoid 12110249Sstephan.diestelhorst@arm.comKernel::stopWork() 12210249Sstephan.diestelhorst@arm.com{ 12310249Sstephan.diestelhorst@arm.com status(::sc_core::SC_END_OF_SIMULATION); 12410249Sstephan.diestelhorst@arm.com for (auto m: sc_gem5::allModules) 12510249Sstephan.diestelhorst@arm.com m->sc_mod()->end_of_simulation(); 12610249Sstephan.diestelhorst@arm.com 12710249Sstephan.diestelhorst@arm.com endComplete = true; 12810249Sstephan.diestelhorst@arm.com 12910249Sstephan.diestelhorst@arm.com status(::sc_core::SC_STOPPED); 13010249Sstephan.diestelhorst@arm.com 13110249Sstephan.diestelhorst@arm.com if (stopAfterCallbacks) 13210249Sstephan.diestelhorst@arm.com fatal("Simulation called sc_stop during elaboration.\n"); 13310249Sstephan.diestelhorst@arm.com} 13410249Sstephan.diestelhorst@arm.com 13510249Sstephan.diestelhorst@arm.comvoid 13610249Sstephan.diestelhorst@arm.comKernel::t0Handler() 13710249Sstephan.diestelhorst@arm.com{ 13810249Sstephan.diestelhorst@arm.com // Now that the event queue has started, mark all the processes that 13910249Sstephan.diestelhorst@arm.com // need to be initialized as ready to run. 14010249Sstephan.diestelhorst@arm.com // 14110249Sstephan.diestelhorst@arm.com // This event has greater priority than delta notifications and so will 14210249Sstephan.diestelhorst@arm.com // happen before them, honoring the ordering for the initialization phase 14310249Sstephan.diestelhorst@arm.com // in the spec. The delta phase will happen at normal priority, and then 14410249Sstephan.diestelhorst@arm.com // the event which runs the processes which is at a lower priority. 14510249Sstephan.diestelhorst@arm.com ::sc_gem5::scheduler.prepareForInit(); 14610249Sstephan.diestelhorst@arm.com 14710249Sstephan.diestelhorst@arm.com status(::sc_core::SC_RUNNING); 14810249Sstephan.diestelhorst@arm.com} 14910249Sstephan.diestelhorst@arm.com 15010249Sstephan.diestelhorst@arm.comKernel *kernel; 15110249Sstephan.diestelhorst@arm.com 15210249Sstephan.diestelhorst@arm.com} // namespace sc_gem5 15310249Sstephan.diestelhorst@arm.com 15410249Sstephan.diestelhorst@arm.comsc_gem5::Kernel * 15510249Sstephan.diestelhorst@arm.comSystemC_KernelParams::create() 15610249Sstephan.diestelhorst@arm.com{ 15710249Sstephan.diestelhorst@arm.com panic_if(sc_gem5::kernel, 15810249Sstephan.diestelhorst@arm.com "Only one systemc kernel object may be defined.\n"); 15910249Sstephan.diestelhorst@arm.com sc_gem5::kernel = new sc_gem5::Kernel(this); 16010249Sstephan.diestelhorst@arm.com return sc_gem5::kernel; 16110249Sstephan.diestelhorst@arm.com} 16210249Sstephan.diestelhorst@arm.com