sc_module.hh revision 13372:28982dc45b17
111661Stushar@ece.gatech.edu/* 211661Stushar@ece.gatech.edu * Copyright (c) 2014 ARM Limited 311661Stushar@ece.gatech.edu * All rights reserved 411661Stushar@ece.gatech.edu * 511661Stushar@ece.gatech.edu * The license below extends only to copyright in the software and shall 611661Stushar@ece.gatech.edu * not be construed as granting a license to any other intellectual 711661Stushar@ece.gatech.edu * property including but not limited to intellectual property relating 811661Stushar@ece.gatech.edu * to a hardware implementation of the functionality of the software 911661Stushar@ece.gatech.edu * licensed hereunder. You may use the software subject to the license 1011661Stushar@ece.gatech.edu * terms below provided that you ensure that this notice is replicated 1111661Stushar@ece.gatech.edu * unmodified and in its entirety in all distributions of the software, 1211661Stushar@ece.gatech.edu * modified or unmodified, in source code or in binary form. 1311661Stushar@ece.gatech.edu * 1411661Stushar@ece.gatech.edu * Copyright (c) 2006 The Regents of The University of Michigan 1511661Stushar@ece.gatech.edu * Copyright (c) 2013 Advanced Micro Devices, Inc. 1611661Stushar@ece.gatech.edu * Copyright (c) 2013 Mark D. Hill and David A. Wood 1711661Stushar@ece.gatech.edu * All rights reserved. 1811661Stushar@ece.gatech.edu * 1911661Stushar@ece.gatech.edu * Redistribution and use in source and binary forms, with or without 2011661Stushar@ece.gatech.edu * modification, are permitted provided that the following conditions are 2111661Stushar@ece.gatech.edu * met: redistributions of source code must retain the above copyright 2211661Stushar@ece.gatech.edu * notice, this list of conditions and the following disclaimer; 2311661Stushar@ece.gatech.edu * redistributions in binary form must reproduce the above copyright 2411661Stushar@ece.gatech.edu * notice, this list of conditions and the following disclaimer in the 2511661Stushar@ece.gatech.edu * documentation and/or other materials provided with the distribution; 2611661Stushar@ece.gatech.edu * neither the name of the copyright holders nor the names of its 2711661Stushar@ece.gatech.edu * contributors may be used to endorse or promote products derived from 2811661Stushar@ece.gatech.edu * this software without specific prior written permission. 2911661Stushar@ece.gatech.edu * 3011661Stushar@ece.gatech.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 3111661Stushar@ece.gatech.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3211661Stushar@ece.gatech.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 3311661Stushar@ece.gatech.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3411661Stushar@ece.gatech.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3511661Stushar@ece.gatech.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3611661Stushar@ece.gatech.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3711661Stushar@ece.gatech.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3811661Stushar@ece.gatech.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3911661Stushar@ece.gatech.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 4011661Stushar@ece.gatech.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 4111661Stushar@ece.gatech.edu * 4211661Stushar@ece.gatech.edu * Authors: Nathan Binkert 4311661Stushar@ece.gatech.edu * Steve Reinhardt 4411661Stushar@ece.gatech.edu * Andrew Bardsley 4511661Stushar@ece.gatech.edu * Christian Menard 4611661Stushar@ece.gatech.edu */ 4711661Stushar@ece.gatech.edu 4811661Stushar@ece.gatech.edu/** 4911661Stushar@ece.gatech.edu * @file 5011661Stushar@ece.gatech.edu * 5111661Stushar@ece.gatech.edu * Defines an sc_module type to wrap a gem5 simulation. The 'evaluate' 5211661Stushar@ece.gatech.edu * thread on that module implements the gem5 event loop. 5311661Stushar@ece.gatech.edu * 5411661Stushar@ece.gatech.edu * This currently only supports a single event queue and strictly 5511661Stushar@ece.gatech.edu * cooperatively threaded SystemC threads and so there should be at 5611661Stushar@ece.gatech.edu * most one Gem5Module instantiated in any simulation. 5711661Stushar@ece.gatech.edu */ 5811661Stushar@ece.gatech.edu 5911661Stushar@ece.gatech.edu#ifndef __SIM_SC_MODULE_HH__ 6011661Stushar@ece.gatech.edu#define __SIM_SC_MODULE_HH__ 6111661Stushar@ece.gatech.edu 6211661Stushar@ece.gatech.edu#include <systemc> 6311661Stushar@ece.gatech.edu 6411661Stushar@ece.gatech.edu#include "sim/eventq.hh" 6511661Stushar@ece.gatech.edu#include "sim/sim_events.hh" 6611661Stushar@ece.gatech.edu 6711661Stushar@ece.gatech.edunamespace Gem5SystemC 6811661Stushar@ece.gatech.edu{ 6911661Stushar@ece.gatech.edu 7011661Stushar@ece.gatech.edu/** A SystemC module implementing the gem5 event queue. This object 7111661Stushar@ece.gatech.edu * doesn't actually own any of the simulation SimObjects (those need 7211661Stushar@ece.gatech.edu * to be administered separately) but it does control the event 7311661Stushar@ece.gatech.edu * queue. 7411661Stushar@ece.gatech.edu * 7511661Stushar@ece.gatech.edu * The event loop here services gem5 events in order at the current time 7611661Stushar@ece.gatech.edu * and then yielding to another SystemC thread. gem5 events are not 7711661Stushar@ece.gatech.edu * individually scheduled in SystemC. For this reason, asynchronous events 7811661Stushar@ece.gatech.edu * and function interaction (for example TLM) with gem5 from SystemC must 7911661Stushar@ece.gatech.edu * notify the module so that the yielding 'wait' can be interrupted. 8011661Stushar@ece.gatech.edu * From the point of view of another SystemC module calling into gem5, 8111661Stushar@ece.gatech.edu * curTick can lag SystemC time, be exactly the same time but *never* 8211661Stushar@ece.gatech.edu * lead SystemC time. 8311661Stushar@ece.gatech.edu * 8411661Stushar@ece.gatech.edu * This functionality is wrapped in an sc_module as its intended that 8511661Stushar@ece.gatech.edu * the a class representing top level simulation control should be derived 8611661Stushar@ece.gatech.edu * from this class. */ 8711661Stushar@ece.gatech.educlass Module : public sc_core::sc_channel 8811661Stushar@ece.gatech.edu{ 8911661Stushar@ece.gatech.edu protected: 9011661Stushar@ece.gatech.edu /** Event to trigger (via. ::notify) for event scheduling from 9111661Stushar@ece.gatech.edu * outside gem5 */ 9211661Stushar@ece.gatech.edu sc_core::sc_event externalSchedulingEvent; 9311661Stushar@ece.gatech.edu 9411661Stushar@ece.gatech.edu /** Event to trigger on exit of eventLoop */ 9511661Stushar@ece.gatech.edu sc_core::sc_event eventLoopExitEvent; 9611661Stushar@ece.gatech.edu 9711661Stushar@ece.gatech.edu /** Event to trigger to enter eventLoop */ 9811661Stushar@ece.gatech.edu sc_core::sc_event eventLoopEnterEvent; 9911661Stushar@ece.gatech.edu 10011661Stushar@ece.gatech.edu /** Expected exit time of last eventLoop sleep */ 10111661Stushar@ece.gatech.edu Tick wait_exit_time; 10211661Stushar@ece.gatech.edu 10311661Stushar@ece.gatech.edu /** Are we in Module::simulate? Used to mask events when not inside 10411661Stushar@ece.gatech.edu * the simulate loop */ 10511661Stushar@ece.gatech.edu bool in_simulate; 10611661Stushar@ece.gatech.edu 10711661Stushar@ece.gatech.edu /** Placeholder base class for a variant event queue if this becomes 10811661Stushar@ece.gatech.edu * useful */ 10911661Stushar@ece.gatech.edu class SCEventQueue : public EventQueue 11011661Stushar@ece.gatech.edu { 11111661Stushar@ece.gatech.edu protected: 11211661Stushar@ece.gatech.edu Module &module; 11311661Stushar@ece.gatech.edu 11411661Stushar@ece.gatech.edu public: 11511661Stushar@ece.gatech.edu SCEventQueue(const std::string &name, 11611661Stushar@ece.gatech.edu Module &module_) : EventQueue(name), module(module_) 11711661Stushar@ece.gatech.edu { } 11811661Stushar@ece.gatech.edu 11911661Stushar@ece.gatech.edu /** Signal module to wakeup */ 12011661Stushar@ece.gatech.edu void wakeup(Tick when); 12111661Stushar@ece.gatech.edu }; 12211661Stushar@ece.gatech.edu 12311661Stushar@ece.gatech.edu /** Service any async event marked up in the globals event_... */ 12411661Stushar@ece.gatech.edu void serviceAsyncEvent(); 12511661Stushar@ece.gatech.edu 12611661Stushar@ece.gatech.edu public: 12711661Stushar@ece.gatech.edu /** Simulate is a process */ 12811661Stushar@ece.gatech.edu SC_HAS_PROCESS(Module); 12911661Stushar@ece.gatech.edu 13011661Stushar@ece.gatech.edu Module(sc_core::sc_module_name name); 13111661Stushar@ece.gatech.edu 13211661Stushar@ece.gatech.edu /** Last exitEvent from eventLoop */ 13311661Stushar@ece.gatech.edu Event *exitEvent; 13411661Stushar@ece.gatech.edu 13511661Stushar@ece.gatech.edu /** Setup global event queues. Call this before any other event queues 13611661Stushar@ece.gatech.edu * are created */ 13711661Stushar@ece.gatech.edu static void setupEventQueues(Module &module); 13811661Stushar@ece.gatech.edu 13911661Stushar@ece.gatech.edu /** Catch gem5 time up with SystemC */ 14011661Stushar@ece.gatech.edu void catchup(); 14111661Stushar@ece.gatech.edu 14211661Stushar@ece.gatech.edu /** Notify an externalSchedulingEvent at the given time from the 14311661Stushar@ece.gatech.edu * current SystemC time */ 14411661Stushar@ece.gatech.edu void notify(sc_core::sc_time time_from_now = sc_core::SC_ZERO_TIME); 14511661Stushar@ece.gatech.edu 14611661Stushar@ece.gatech.edu /** Process an event triggered by externalSchedulingEvent and also 14711661Stushar@ece.gatech.edu * call eventLoop (to try and mop up any events at this time) if there 14811661Stushar@ece.gatech.edu * are any scheduled events */ 14911661Stushar@ece.gatech.edu void serviceExternalEvent(); 15011661Stushar@ece.gatech.edu 15111661Stushar@ece.gatech.edu /** Process gem5 events up until an exit event or there are no events 15211661Stushar@ece.gatech.edu * left. */ 15311661Stushar@ece.gatech.edu void eventLoop(); 15411661Stushar@ece.gatech.edu 15511661Stushar@ece.gatech.edu /** Run eventLoop up to num_cycles and return the final event */ 15611661Stushar@ece.gatech.edu GlobalSimLoopExitEvent *simulate(Tick num_cycles = MaxTick); 15711661Stushar@ece.gatech.edu}; 15811661Stushar@ece.gatech.edu 15911661Stushar@ece.gatech.edu/** There are assumptions throughout Gem5SystemC file that a tick is 1ps. 16011661Stushar@ece.gatech.edu * Make this the case */ 16111661Stushar@ece.gatech.eduvoid setTickFrequency(); 16211661Stushar@ece.gatech.edu 16311661Stushar@ece.gatech.edu} 16411661Stushar@ece.gatech.edu 16511661Stushar@ece.gatech.edu#endif // __SIM_SC_MODULE_HH__ 166