base.hh revision 5647
12SN/A/* 21762SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 32SN/A * All rights reserved. 42SN/A * 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt 292665Ssaidi@eecs.umich.edu * Nathan Binkert 302SN/A */ 312SN/A 321717SN/A#ifndef __CPU_BASE_HH__ 331717SN/A#define __CPU_BASE_HH__ 342SN/A 352SN/A#include <vector> 362SN/A 374182Sgblack@eecs.umich.edu#include "arch/isa_traits.hh" 38707SN/A#include "base/statistics.hh" 391858SN/A#include "config/full_system.hh" 4056SN/A#include "sim/eventq.hh" 414776Sgblack@eecs.umich.edu#include "sim/insttracer.hh" 422856Srdreslin@umich.edu#include "mem/mem_object.hh" 432SN/A 443520Sgblack@eecs.umich.edu#if FULL_SYSTEM 453520Sgblack@eecs.umich.edu#include "arch/interrupts.hh" 463520Sgblack@eecs.umich.edu#endif 473520Sgblack@eecs.umich.edu 485529Snate@binkert.orgclass BaseCPUParams; 492190SN/Aclass BranchPred; 502315SN/Aclass CheckerCPU; 512680Sktlim@umich.educlass ThreadContext; 522SN/Aclass System; 532856Srdreslin@umich.educlass Port; 542SN/A 554182Sgblack@eecs.umich.edunamespace TheISA 564182Sgblack@eecs.umich.edu{ 574182Sgblack@eecs.umich.edu class Predecoder; 584182Sgblack@eecs.umich.edu} 594182Sgblack@eecs.umich.edu 602356SN/Aclass CPUProgressEvent : public Event 612356SN/A{ 622356SN/A protected: 632356SN/A Tick interval; 642356SN/A Counter lastNumInst; 652356SN/A BaseCPU *cpu; 662356SN/A 672356SN/A public: 685606Snate@binkert.org CPUProgressEvent(BaseCPU *_cpu, Tick ival); 692356SN/A 702356SN/A void process(); 712356SN/A 725336Shines@cs.fsu.edu virtual const char *description() const; 732356SN/A}; 742356SN/A 752856Srdreslin@umich.educlass BaseCPU : public MemObject 762SN/A{ 771634SN/A protected: 781634SN/A // CPU's clock period in terms of the number of ticks of curTime. 791695SN/A Tick clock; 803814Ssaidi@eecs.umich.edu // @todo remove me after debugging with legion done 813814Ssaidi@eecs.umich.edu Tick instCnt; 821634SN/A 831634SN/A public: 842359SN/A// Tick currentTick; 851695SN/A inline Tick frequency() const { return Clock::Frequency / clock; } 865100Ssaidi@eecs.umich.edu inline Tick ticks(int numCycles) const { return clock * numCycles; } 871695SN/A inline Tick curCycle() const { return curTick / clock; } 885099Ssaidi@eecs.umich.edu inline Tick tickToCycles(Tick val) const { return val / clock; } 893814Ssaidi@eecs.umich.edu // @todo remove me after debugging with legion done 903814Ssaidi@eecs.umich.edu Tick instCount() { return instCnt; } 911634SN/A 923495Sktlim@umich.edu /** The next cycle the CPU should be scheduled, given a cache 933495Sktlim@umich.edu * access or quiesce event returning on this cycle. This function 943495Sktlim@umich.edu * may return curTick if the CPU should run on the current cycle. 953495Sktlim@umich.edu */ 963495Sktlim@umich.edu Tick nextCycle(); 973495Sktlim@umich.edu 983495Sktlim@umich.edu /** The next cycle the CPU should be scheduled, given a cache 993495Sktlim@umich.edu * access or quiesce event returning on the given Tick. This 1003495Sktlim@umich.edu * function may return curTick if the CPU should run on the 1013495Sktlim@umich.edu * current cycle. 1023495Sktlim@umich.edu * @param begin_tick The tick that the event is completing on. 1033495Sktlim@umich.edu */ 1043495Sktlim@umich.edu Tick nextCycle(Tick begin_tick); 1053495Sktlim@umich.edu 1061858SN/A#if FULL_SYSTEM 1072SN/A protected: 1083520Sgblack@eecs.umich.edu// uint64_t interrupts[TheISA::NumInterruptLevels]; 1093520Sgblack@eecs.umich.edu// uint64_t intstatus; 1105647Sgblack@eecs.umich.edu TheISA::Interrupts * interrupts; 1112SN/A 1122SN/A public: 1135645Sgblack@eecs.umich.edu TheISA::Interrupts * 1145645Sgblack@eecs.umich.edu getInterruptController() 1155645Sgblack@eecs.umich.edu { 1165647Sgblack@eecs.umich.edu return interrupts; 1175645Sgblack@eecs.umich.edu } 1185645Sgblack@eecs.umich.edu 1192SN/A virtual void post_interrupt(int int_num, int index); 1202SN/A virtual void clear_interrupt(int int_num, int index); 1212SN/A virtual void clear_interrupts(); 1222SN/A 1233521Sgblack@eecs.umich.edu bool check_interrupts(ThreadContext * tc) const 1245647Sgblack@eecs.umich.edu { return interrupts->check_interrupts(tc); } 1251917SN/A 1261917SN/A class ProfileEvent : public Event 1271917SN/A { 1281917SN/A private: 1291917SN/A BaseCPU *cpu; 1305536Srstrong@hp.com Tick interval; 1311917SN/A 1321917SN/A public: 1335536Srstrong@hp.com ProfileEvent(BaseCPU *cpu, Tick interval); 1341917SN/A void process(); 1351917SN/A }; 1361917SN/A ProfileEvent *profileEvent; 1372SN/A#endif 1382SN/A 1392SN/A protected: 1402680Sktlim@umich.edu std::vector<ThreadContext *> threadContexts; 1414182Sgblack@eecs.umich.edu std::vector<TheISA::Predecoder *> predecoders; 1422SN/A 1434776Sgblack@eecs.umich.edu Trace::InstTracer * tracer; 1444776Sgblack@eecs.umich.edu 1452SN/A public: 146393SN/A 1474776Sgblack@eecs.umich.edu /// Provide access to the tracer pointer 1484776Sgblack@eecs.umich.edu Trace::InstTracer * getTracer() { return tracer; } 1494776Sgblack@eecs.umich.edu 150393SN/A /// Notify the CPU that the indicated context is now active. The 151393SN/A /// delay parameter indicates the number of ticks to wait before 152393SN/A /// executing (typically 0 or 1). 153393SN/A virtual void activateContext(int thread_num, int delay) {} 154393SN/A 155393SN/A /// Notify the CPU that the indicated context is now suspended. 156393SN/A virtual void suspendContext(int thread_num) {} 157393SN/A 158393SN/A /// Notify the CPU that the indicated context is now deallocated. 159393SN/A virtual void deallocateContext(int thread_num) {} 160393SN/A 161393SN/A /// Notify the CPU that the indicated context is now halted. 162393SN/A virtual void haltContext(int thread_num) {} 1632SN/A 1644000Ssaidi@eecs.umich.edu /// Given a Thread Context pointer return the thread num 1654000Ssaidi@eecs.umich.edu int findContext(ThreadContext *tc); 1664000Ssaidi@eecs.umich.edu 1674000Ssaidi@eecs.umich.edu /// Given a thread num get tho thread context for it 1684000Ssaidi@eecs.umich.edu ThreadContext *getContext(int tn) { return threadContexts[tn]; } 1694000Ssaidi@eecs.umich.edu 1702SN/A public: 1715529Snate@binkert.org typedef BaseCPUParams Params; 1725529Snate@binkert.org const Params *params() const 1735529Snate@binkert.org { return reinterpret_cast<const Params *>(_params); } 1741400SN/A BaseCPU(Params *params); 1751191SN/A virtual ~BaseCPU(); 1762SN/A 1771129SN/A virtual void init(); 1781917SN/A virtual void startup(); 1792SN/A virtual void regStats(); 1802SN/A 1812103SN/A virtual void activateWhenReady(int tid) {}; 1822103SN/A 1832680Sktlim@umich.edu void registerThreadContexts(); 184180SN/A 1851492SN/A /// Prepare for another CPU to take over execution. When it is 1861492SN/A /// is ready (drained pipe) it signals the sampler. 1872798Sktlim@umich.edu virtual void switchOut(); 188180SN/A 189180SN/A /// Take over execution from the given CPU. Used for warm-up and 190180SN/A /// sampling. 1914192Sktlim@umich.edu virtual void takeOverFrom(BaseCPU *, Port *ic, Port *dc); 192180SN/A 193124SN/A /** 194124SN/A * Number of threads we're actually simulating (<= SMT_MAX_THREADS). 195124SN/A * This is a constant for the duration of the simulation. 196124SN/A */ 1972SN/A int number_of_threads; 1982SN/A 1995529Snate@binkert.org TheISA::CoreSpecific coreParams; //ISA-Specific Params That Set Up State in Core 2005529Snate@binkert.org 201124SN/A /** 202124SN/A * Vector of per-thread instruction-based event queues. Used for 203124SN/A * scheduling events based on number of instructions committed by 204124SN/A * a particular thread. 205124SN/A */ 206503SN/A EventQueue **comInstEventQueue; 2072SN/A 208124SN/A /** 209124SN/A * Vector of per-thread load-based event queues. Used for 210124SN/A * scheduling events based on number of loads committed by 211124SN/A *a particular thread. 212124SN/A */ 213124SN/A EventQueue **comLoadEventQueue; 214124SN/A 2152SN/A System *system; 216921SN/A 2173661Srdreslin@umich.edu Tick phase; 2183661Srdreslin@umich.edu 2192378SN/A#if FULL_SYSTEM 220921SN/A /** 221921SN/A * Serialize this object to the given output stream. 222921SN/A * @param os The stream to serialize to. 223921SN/A */ 224921SN/A virtual void serialize(std::ostream &os); 225921SN/A 226921SN/A /** 227921SN/A * Reconstruct the state of this object from a checkpoint. 228921SN/A * @param cp The checkpoint use. 229921SN/A * @param section The section name of this object 230921SN/A */ 231921SN/A virtual void unserialize(Checkpoint *cp, const std::string §ion); 232921SN/A 2332SN/A#endif 2342SN/A 235124SN/A /** 236124SN/A * Return pointer to CPU's branch predictor (NULL if none). 237124SN/A * @return Branch predictor pointer. 238124SN/A */ 2392SN/A virtual BranchPred *getBranchPred() { return NULL; }; 2402SN/A 241707SN/A virtual Counter totalInstructions() const { return 0; } 242707SN/A 2431191SN/A // Function tracing 2441191SN/A private: 2451191SN/A bool functionTracingEnabled; 2461191SN/A std::ostream *functionTraceStream; 2471191SN/A Addr currentFunctionStart; 2481191SN/A Addr currentFunctionEnd; 2491191SN/A Tick functionEntryTick; 2501191SN/A void enableFunctionTrace(); 2511191SN/A void traceFunctionsInternal(Addr pc); 2521191SN/A 2531191SN/A protected: 2541191SN/A void traceFunctions(Addr pc) 2551191SN/A { 2561191SN/A if (functionTracingEnabled) 2571191SN/A traceFunctionsInternal(pc); 2581191SN/A } 2591191SN/A 2602SN/A private: 2612SN/A static std::vector<BaseCPU *> cpuList; //!< Static global cpu list 2622SN/A 2632SN/A public: 2642SN/A static int numSimulatedCPUs() { return cpuList.size(); } 265707SN/A static Counter numSimulatedInstructions() 266707SN/A { 267707SN/A Counter total = 0; 268707SN/A 269707SN/A int size = cpuList.size(); 270707SN/A for (int i = 0; i < size; ++i) 271707SN/A total += cpuList[i]->totalInstructions(); 272707SN/A 273707SN/A return total; 274707SN/A } 275707SN/A 276707SN/A public: 277707SN/A // Number of CPU cycles simulated 278729SN/A Stats::Scalar<> numCycles; 2792SN/A}; 2802SN/A 2811717SN/A#endif // __CPU_BASE_HH__ 282