cpu.hh revision 12127:4207df055b0d
113172Sgiacomo.travaglini@arm.com/* 210259SAndrew.Bardsley@arm.com * Copyright (c) 2011-2013, 2016 ARM Limited 310259SAndrew.Bardsley@arm.com * Copyright (c) 2013 Advanced Micro Devices, Inc. 410259SAndrew.Bardsley@arm.com * All rights reserved 510259SAndrew.Bardsley@arm.com * 610259SAndrew.Bardsley@arm.com * The license below extends only to copyright in the software and shall 710259SAndrew.Bardsley@arm.com * not be construed as granting a license to any other intellectual 810259SAndrew.Bardsley@arm.com * property including but not limited to intellectual property relating 910259SAndrew.Bardsley@arm.com * to a hardware implementation of the functionality of the software 1010259SAndrew.Bardsley@arm.com * licensed hereunder. You may use the software subject to the license 1110259SAndrew.Bardsley@arm.com * terms below provided that you ensure that this notice is replicated 1210259SAndrew.Bardsley@arm.com * unmodified and in its entirety in all distributions of the software, 1310259SAndrew.Bardsley@arm.com * modified or unmodified, in source code or in binary form. 1410259SAndrew.Bardsley@arm.com * 1510259SAndrew.Bardsley@arm.com * Copyright (c) 2004-2005 The Regents of The University of Michigan 1610259SAndrew.Bardsley@arm.com * Copyright (c) 2011 Regents of the University of California 1710259SAndrew.Bardsley@arm.com * All rights reserved. 1810259SAndrew.Bardsley@arm.com * 1910259SAndrew.Bardsley@arm.com * Redistribution and use in source and binary forms, with or without 2010259SAndrew.Bardsley@arm.com * modification, are permitted provided that the following conditions are 2110259SAndrew.Bardsley@arm.com * met: redistributions of source code must retain the above copyright 2210259SAndrew.Bardsley@arm.com * notice, this list of conditions and the following disclaimer; 2310259SAndrew.Bardsley@arm.com * redistributions in binary form must reproduce the above copyright 2410259SAndrew.Bardsley@arm.com * notice, this list of conditions and the following disclaimer in the 2510259SAndrew.Bardsley@arm.com * documentation and/or other materials provided with the distribution; 2610259SAndrew.Bardsley@arm.com * neither the name of the copyright holders nor the names of its 2710259SAndrew.Bardsley@arm.com * contributors may be used to endorse or promote products derived from 2810259SAndrew.Bardsley@arm.com * this software without specific prior written permission. 2910259SAndrew.Bardsley@arm.com * 3010259SAndrew.Bardsley@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 3110259SAndrew.Bardsley@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3210259SAndrew.Bardsley@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 3310259SAndrew.Bardsley@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3410259SAndrew.Bardsley@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3510259SAndrew.Bardsley@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3610259SAndrew.Bardsley@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3710259SAndrew.Bardsley@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3810259SAndrew.Bardsley@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3910259SAndrew.Bardsley@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 4010259SAndrew.Bardsley@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 4110259SAndrew.Bardsley@arm.com * 4210259SAndrew.Bardsley@arm.com * Authors: Kevin Lim 4312563Sgabeblack@google.com * Korey Sewell 4412563Sgabeblack@google.com * Rick Strong 4510259SAndrew.Bardsley@arm.com */ 4610259SAndrew.Bardsley@arm.com 4710259SAndrew.Bardsley@arm.com#ifndef __CPU_O3_CPU_HH__ 4810259SAndrew.Bardsley@arm.com#define __CPU_O3_CPU_HH__ 4913665Sandreas.sandberg@arm.com 5013665Sandreas.sandberg@arm.com#include <iostream> 5113665Sandreas.sandberg@arm.com#include <list> 5213665Sandreas.sandberg@arm.com#include <queue> 5310259SAndrew.Bardsley@arm.com#include <set> 5413665Sandreas.sandberg@arm.com#include <vector> 5510259SAndrew.Bardsley@arm.com 5610259SAndrew.Bardsley@arm.com#include "arch/generic/types.hh" 5710259SAndrew.Bardsley@arm.com#include "arch/types.hh" 5810259SAndrew.Bardsley@arm.com#include "base/statistics.hh" 5910259SAndrew.Bardsley@arm.com#include "config/the_isa.hh" 6010259SAndrew.Bardsley@arm.com#include "cpu/o3/comm.hh" 6110259SAndrew.Bardsley@arm.com#include "cpu/o3/cpu_policy.hh" 6210259SAndrew.Bardsley@arm.com#include "cpu/o3/scoreboard.hh" 6310259SAndrew.Bardsley@arm.com#include "cpu/o3/thread_state.hh" 6410259SAndrew.Bardsley@arm.com#include "cpu/activity.hh" 6510259SAndrew.Bardsley@arm.com#include "cpu/base.hh" 6610259SAndrew.Bardsley@arm.com#include "cpu/simple_thread.hh" 6710259SAndrew.Bardsley@arm.com#include "cpu/timebuf.hh" 6810259SAndrew.Bardsley@arm.com//#include "cpu/o3/thread_context.hh" 6910259SAndrew.Bardsley@arm.com#include "params/DerivO3CPU.hh" 7010259SAndrew.Bardsley@arm.com#include "sim/process.hh" 7110259SAndrew.Bardsley@arm.com 7210259SAndrew.Bardsley@arm.comtemplate <class> 7310259SAndrew.Bardsley@arm.comclass Checker; 7410259SAndrew.Bardsley@arm.comclass ThreadContext; 7510259SAndrew.Bardsley@arm.comtemplate <class> 7610259SAndrew.Bardsley@arm.comclass O3ThreadContext; 7710259SAndrew.Bardsley@arm.com 7810259SAndrew.Bardsley@arm.comclass Checkpoint; 7910259SAndrew.Bardsley@arm.comclass MemObject; 8010259SAndrew.Bardsley@arm.comclass Process; 8110259SAndrew.Bardsley@arm.com 8210259SAndrew.Bardsley@arm.comstruct BaseCPUParams; 8310259SAndrew.Bardsley@arm.com 8410259SAndrew.Bardsley@arm.comclass BaseO3CPU : public BaseCPU 8510259SAndrew.Bardsley@arm.com{ 8610259SAndrew.Bardsley@arm.com //Stuff that's pretty ISA independent will go here. 8710259SAndrew.Bardsley@arm.com public: 8810259SAndrew.Bardsley@arm.com BaseO3CPU(BaseCPUParams *params); 8910259SAndrew.Bardsley@arm.com 9010259SAndrew.Bardsley@arm.com void regStats(); 9110259SAndrew.Bardsley@arm.com}; 9210259SAndrew.Bardsley@arm.com 9310259SAndrew.Bardsley@arm.com/** 9410259SAndrew.Bardsley@arm.com * FullO3CPU class, has each of the stages (fetch through commit) 9510259SAndrew.Bardsley@arm.com * within it, as well as all of the time buffers between stages. The 9610259SAndrew.Bardsley@arm.com * tick() function for the CPU is defined here. 9710259SAndrew.Bardsley@arm.com */ 9810259SAndrew.Bardsley@arm.comtemplate <class Impl> 9910259SAndrew.Bardsley@arm.comclass FullO3CPU : public BaseO3CPU 10010259SAndrew.Bardsley@arm.com{ 10110259SAndrew.Bardsley@arm.com public: 10210259SAndrew.Bardsley@arm.com // Typedefs from the Impl here. 10310259SAndrew.Bardsley@arm.com typedef typename Impl::CPUPol CPUPolicy; 10410259SAndrew.Bardsley@arm.com typedef typename Impl::DynInstPtr DynInstPtr; 10510259SAndrew.Bardsley@arm.com typedef typename Impl::O3CPU O3CPU; 10610259SAndrew.Bardsley@arm.com 10710259SAndrew.Bardsley@arm.com using VecElem = TheISA::VecElem; 10810259SAndrew.Bardsley@arm.com using VecRegContainer = TheISA::VecRegContainer; 10910259SAndrew.Bardsley@arm.com 11010259SAndrew.Bardsley@arm.com typedef O3ThreadState<Impl> ImplState; 11110259SAndrew.Bardsley@arm.com typedef O3ThreadState<Impl> Thread; 11210259SAndrew.Bardsley@arm.com 11310259SAndrew.Bardsley@arm.com typedef typename std::list<DynInstPtr>::iterator ListIt; 11410259SAndrew.Bardsley@arm.com 11510259SAndrew.Bardsley@arm.com friend class O3ThreadContext<Impl>; 11610259SAndrew.Bardsley@arm.com 11710259SAndrew.Bardsley@arm.com public: 11810259SAndrew.Bardsley@arm.com enum Status { 11910259SAndrew.Bardsley@arm.com Running, 12010259SAndrew.Bardsley@arm.com Idle, 12110259SAndrew.Bardsley@arm.com Halted, 12210259SAndrew.Bardsley@arm.com Blocked, 12310259SAndrew.Bardsley@arm.com SwitchedOut 12410259SAndrew.Bardsley@arm.com }; 12510259SAndrew.Bardsley@arm.com 12610259SAndrew.Bardsley@arm.com TheISA::TLB * itb; 12710259SAndrew.Bardsley@arm.com TheISA::TLB * dtb; 12810259SAndrew.Bardsley@arm.com 12910259SAndrew.Bardsley@arm.com /** Overall CPU status. */ 13010259SAndrew.Bardsley@arm.com Status _status; 13110259SAndrew.Bardsley@arm.com 13210259SAndrew.Bardsley@arm.com private: 13310259SAndrew.Bardsley@arm.com 13410259SAndrew.Bardsley@arm.com /** 13510259SAndrew.Bardsley@arm.com * IcachePort class for instruction fetch. 13610259SAndrew.Bardsley@arm.com */ 13710259SAndrew.Bardsley@arm.com class IcachePort : public MasterPort 13810259SAndrew.Bardsley@arm.com { 13910259SAndrew.Bardsley@arm.com protected: 14010259SAndrew.Bardsley@arm.com /** Pointer to fetch. */ 14110259SAndrew.Bardsley@arm.com DefaultFetch<Impl> *fetch; 14210259SAndrew.Bardsley@arm.com 14310259SAndrew.Bardsley@arm.com public: 14410259SAndrew.Bardsley@arm.com /** Default constructor. */ 14510259SAndrew.Bardsley@arm.com IcachePort(DefaultFetch<Impl> *_fetch, FullO3CPU<Impl>* _cpu) 14610259SAndrew.Bardsley@arm.com : MasterPort(_cpu->name() + ".icache_port", _cpu), fetch(_fetch) 14711683Sfernando.endo2@gmail.com { } 14811683Sfernando.endo2@gmail.com 14910259SAndrew.Bardsley@arm.com protected: 15010259SAndrew.Bardsley@arm.com 15110259SAndrew.Bardsley@arm.com /** Timing version of receive. Handles setting fetch to the 15210259SAndrew.Bardsley@arm.com * proper status to start fetching. */ 15313172Sgiacomo.travaglini@arm.com virtual bool recvTimingResp(PacketPtr pkt); 15413172Sgiacomo.travaglini@arm.com 15513172Sgiacomo.travaglini@arm.com /** Handles doing a retry of a failed fetch. */ 15610259SAndrew.Bardsley@arm.com virtual void recvReqRetry(); 15710259SAndrew.Bardsley@arm.com }; 15810259SAndrew.Bardsley@arm.com 15910259SAndrew.Bardsley@arm.com /** 16010259SAndrew.Bardsley@arm.com * DcachePort class for the load/store queue. 16111683Sfernando.endo2@gmail.com */ 16211683Sfernando.endo2@gmail.com class DcachePort : public MasterPort 16310259SAndrew.Bardsley@arm.com { 16410259SAndrew.Bardsley@arm.com protected: 16510259SAndrew.Bardsley@arm.com 16610259SAndrew.Bardsley@arm.com /** Pointer to LSQ. */ 16710259SAndrew.Bardsley@arm.com LSQ<Impl> *lsq; 16810259SAndrew.Bardsley@arm.com FullO3CPU<Impl> *cpu; 16910259SAndrew.Bardsley@arm.com 17010259SAndrew.Bardsley@arm.com public: 17110259SAndrew.Bardsley@arm.com /** Default constructor. */ 17210259SAndrew.Bardsley@arm.com DcachePort(LSQ<Impl> *_lsq, FullO3CPU<Impl>* _cpu) 17310259SAndrew.Bardsley@arm.com : MasterPort(_cpu->name() + ".dcache_port", _cpu), lsq(_lsq), 17410259SAndrew.Bardsley@arm.com cpu(_cpu) 17510259SAndrew.Bardsley@arm.com { } 17610259SAndrew.Bardsley@arm.com 17711567Smitch.hayenga@arm.com protected: 17811567Smitch.hayenga@arm.com 17910259SAndrew.Bardsley@arm.com /** Timing version of receive. Handles writing back and 18010259SAndrew.Bardsley@arm.com * completing the load or store that has returned from 18110259SAndrew.Bardsley@arm.com * memory. */ 18210259SAndrew.Bardsley@arm.com virtual bool recvTimingResp(PacketPtr pkt); 18310259SAndrew.Bardsley@arm.com virtual void recvTimingSnoopReq(PacketPtr pkt); 18410259SAndrew.Bardsley@arm.com 18510259SAndrew.Bardsley@arm.com virtual void recvFunctionalSnoop(PacketPtr pkt) 18610259SAndrew.Bardsley@arm.com { 18710259SAndrew.Bardsley@arm.com // @todo: Is there a need for potential invalidation here? 18810259SAndrew.Bardsley@arm.com } 18910259SAndrew.Bardsley@arm.com 19010259SAndrew.Bardsley@arm.com /** Handles doing a retry of the previous send. */ 19110259SAndrew.Bardsley@arm.com virtual void recvReqRetry(); 19210259SAndrew.Bardsley@arm.com 19310259SAndrew.Bardsley@arm.com /** 19410259SAndrew.Bardsley@arm.com * As this CPU requires snooping to maintain the load store queue 19511567Smitch.hayenga@arm.com * change the behaviour from the base CPU port. 19611567Smitch.hayenga@arm.com * 19710259SAndrew.Bardsley@arm.com * @return true since we have to snoop 19810259SAndrew.Bardsley@arm.com */ 19910259SAndrew.Bardsley@arm.com virtual bool isSnooping() const { return true; } 20010259SAndrew.Bardsley@arm.com }; 20110259SAndrew.Bardsley@arm.com 20210259SAndrew.Bardsley@arm.com /** The tick event used for scheduling CPU ticks. */ 20310259SAndrew.Bardsley@arm.com EventFunctionWrapper tickEvent; 20410259SAndrew.Bardsley@arm.com 20510259SAndrew.Bardsley@arm.com /** Schedule tick event, regardless of its current state. */ 20610259SAndrew.Bardsley@arm.com void scheduleTickEvent(Cycles delay) 20710259SAndrew.Bardsley@arm.com { 20810259SAndrew.Bardsley@arm.com if (tickEvent.squashed()) 20910259SAndrew.Bardsley@arm.com reschedule(tickEvent, clockEdge(delay)); 21010259SAndrew.Bardsley@arm.com else if (!tickEvent.scheduled()) 21110259SAndrew.Bardsley@arm.com schedule(tickEvent, clockEdge(delay)); 21210259SAndrew.Bardsley@arm.com } 21310259SAndrew.Bardsley@arm.com 21410259SAndrew.Bardsley@arm.com /** Unschedule tick event, regardless of its current state. */ 21510259SAndrew.Bardsley@arm.com void unscheduleTickEvent() 21610259SAndrew.Bardsley@arm.com { 21710259SAndrew.Bardsley@arm.com if (tickEvent.scheduled()) 21810259SAndrew.Bardsley@arm.com tickEvent.squash(); 21910259SAndrew.Bardsley@arm.com } 22010259SAndrew.Bardsley@arm.com 22110259SAndrew.Bardsley@arm.com /** 22210259SAndrew.Bardsley@arm.com * Check if the pipeline has drained and signal drain done. 22310259SAndrew.Bardsley@arm.com * 22410259SAndrew.Bardsley@arm.com * This method checks if a drain has been requested and if the CPU 22510259SAndrew.Bardsley@arm.com * has drained successfully (i.e., there are no instructions in 22610259SAndrew.Bardsley@arm.com * the pipeline). If the CPU has drained, it deschedules the tick 22710259SAndrew.Bardsley@arm.com * event and signals the drain manager. 22810259SAndrew.Bardsley@arm.com * 22910259SAndrew.Bardsley@arm.com * @return False if a drain hasn't been requested or the CPU 23010259SAndrew.Bardsley@arm.com * hasn't drained, true otherwise. 23110259SAndrew.Bardsley@arm.com */ 23210259SAndrew.Bardsley@arm.com bool tryDrain(); 23310259SAndrew.Bardsley@arm.com 23410259SAndrew.Bardsley@arm.com /** 23510259SAndrew.Bardsley@arm.com * Perform sanity checks after a drain. 23610259SAndrew.Bardsley@arm.com * 23710259SAndrew.Bardsley@arm.com * This method is called from drain() when it has determined that 23810259SAndrew.Bardsley@arm.com * the CPU is fully drained when gem5 is compiled with the NDEBUG 23910259SAndrew.Bardsley@arm.com * macro undefined. The intention of this method is to do more 24010259SAndrew.Bardsley@arm.com * extensive tests than the isDrained() method to weed out any 24110259SAndrew.Bardsley@arm.com * draining bugs. 24210259SAndrew.Bardsley@arm.com */ 24310259SAndrew.Bardsley@arm.com void drainSanityCheck() const; 24410259SAndrew.Bardsley@arm.com 24510259SAndrew.Bardsley@arm.com /** Check if a system is in a drained state. */ 24610259SAndrew.Bardsley@arm.com bool isDrained() const; 24710259SAndrew.Bardsley@arm.com 24810259SAndrew.Bardsley@arm.com public: 24910259SAndrew.Bardsley@arm.com /** Constructs a CPU with the given parameters. */ 25010259SAndrew.Bardsley@arm.com FullO3CPU(DerivO3CPUParams *params); 25110259SAndrew.Bardsley@arm.com /** Destructor. */ 25210259SAndrew.Bardsley@arm.com ~FullO3CPU(); 25310259SAndrew.Bardsley@arm.com 25410259SAndrew.Bardsley@arm.com /** Registers statistics. */ 25510259SAndrew.Bardsley@arm.com void regStats() override; 25610259SAndrew.Bardsley@arm.com 25710259SAndrew.Bardsley@arm.com ProbePointArg<PacketPtr> *ppInstAccessComplete; 25810259SAndrew.Bardsley@arm.com ProbePointArg<std::pair<DynInstPtr, PacketPtr> > *ppDataAccessComplete; 25910259SAndrew.Bardsley@arm.com 26010259SAndrew.Bardsley@arm.com /** Register probe points. */ 26110259SAndrew.Bardsley@arm.com void regProbePoints() override; 26210259SAndrew.Bardsley@arm.com 26310259SAndrew.Bardsley@arm.com void demapPage(Addr vaddr, uint64_t asn) 26410259SAndrew.Bardsley@arm.com { 26510259SAndrew.Bardsley@arm.com this->itb->demapPage(vaddr, asn); 26610259SAndrew.Bardsley@arm.com this->dtb->demapPage(vaddr, asn); 26710259SAndrew.Bardsley@arm.com } 26810259SAndrew.Bardsley@arm.com 26910259SAndrew.Bardsley@arm.com void demapInstPage(Addr vaddr, uint64_t asn) 27010259SAndrew.Bardsley@arm.com { 27110259SAndrew.Bardsley@arm.com this->itb->demapPage(vaddr, asn); 27210259SAndrew.Bardsley@arm.com } 27310259SAndrew.Bardsley@arm.com 27410259SAndrew.Bardsley@arm.com void demapDataPage(Addr vaddr, uint64_t asn) 27510259SAndrew.Bardsley@arm.com { 27610259SAndrew.Bardsley@arm.com this->dtb->demapPage(vaddr, asn); 27710259SAndrew.Bardsley@arm.com } 27810785Sgope@wisc.edu 27910259SAndrew.Bardsley@arm.com /** Ticks CPU, calling tick() on each stage, and checking the overall 28010259SAndrew.Bardsley@arm.com * activity to see if the CPU should deschedule itself. 28110259SAndrew.Bardsley@arm.com */ 28212563Sgabeblack@google.com void tick(); 28310259SAndrew.Bardsley@arm.com 284 /** Initialize the CPU */ 285 void init() override; 286 287 void startup() override; 288 289 /** Returns the Number of Active Threads in the CPU */ 290 int numActiveThreads() 291 { return activeThreads.size(); } 292 293 /** Add Thread to Active Threads List */ 294 void activateThread(ThreadID tid); 295 296 /** Remove Thread from Active Threads List */ 297 void deactivateThread(ThreadID tid); 298 299 /** Setup CPU to insert a thread's context */ 300 void insertThread(ThreadID tid); 301 302 /** Remove all of a thread's context from CPU */ 303 void removeThread(ThreadID tid); 304 305 /** Count the Total Instructions Committed in the CPU. */ 306 Counter totalInsts() const override; 307 308 /** Count the Total Ops (including micro ops) committed in the CPU. */ 309 Counter totalOps() const override; 310 311 /** Add Thread to Active Threads List. */ 312 void activateContext(ThreadID tid) override; 313 314 /** Remove Thread from Active Threads List */ 315 void suspendContext(ThreadID tid) override; 316 317 /** Remove Thread from Active Threads List && 318 * Remove Thread Context from CPU. 319 */ 320 void haltContext(ThreadID tid) override; 321 322 /** Update The Order In Which We Process Threads. */ 323 void updateThreadPriority(); 324 325 /** Is the CPU draining? */ 326 bool isDraining() const { return drainState() == DrainState::Draining; } 327 328 void serializeThread(CheckpointOut &cp, ThreadID tid) const override; 329 void unserializeThread(CheckpointIn &cp, ThreadID tid) override; 330 331 public: 332 /** Executes a syscall. 333 * @todo: Determine if this needs to be virtual. 334 */ 335 void syscall(int64_t callnum, ThreadID tid, Fault *fault); 336 337 /** Starts draining the CPU's pipeline of all instructions in 338 * order to stop all memory accesses. */ 339 DrainState drain() override; 340 341 /** Resumes execution after a drain. */ 342 void drainResume() override; 343 344 /** 345 * Commit has reached a safe point to drain a thread. 346 * 347 * Commit calls this method to inform the pipeline that it has 348 * reached a point where it is not executed microcode and is about 349 * to squash uncommitted instructions to fully drain the pipeline. 350 */ 351 void commitDrained(ThreadID tid); 352 353 /** Switches out this CPU. */ 354 void switchOut() override; 355 356 /** Takes over from another CPU. */ 357 void takeOverFrom(BaseCPU *oldCPU) override; 358 359 void verifyMemoryMode() const override; 360 361 /** Get the current instruction sequence number, and increment it. */ 362 InstSeqNum getAndIncrementInstSeq() 363 { return globalSeqNum++; } 364 365 /** Traps to handle given fault. */ 366 void trap(const Fault &fault, ThreadID tid, const StaticInstPtr &inst); 367 368 /** HW return from error interrupt. */ 369 Fault hwrei(ThreadID tid); 370 371 bool simPalCheck(int palFunc, ThreadID tid); 372 373 /** Returns the Fault for any valid interrupt. */ 374 Fault getInterrupts(); 375 376 /** Processes any an interrupt fault. */ 377 void processInterrupts(const Fault &interrupt); 378 379 /** Halts the CPU. */ 380 void halt() { panic("Halt not implemented!\n"); } 381 382 /** Register accessors. Index refers to the physical register index. */ 383 384 /** Reads a miscellaneous register. */ 385 TheISA::MiscReg readMiscRegNoEffect(int misc_reg, ThreadID tid) const; 386 387 /** Reads a misc. register, including any side effects the read 388 * might have as defined by the architecture. 389 */ 390 TheISA::MiscReg readMiscReg(int misc_reg, ThreadID tid); 391 392 /** Sets a miscellaneous register. */ 393 void setMiscRegNoEffect(int misc_reg, const TheISA::MiscReg &val, 394 ThreadID tid); 395 396 /** Sets a misc. register, including any side effects the write 397 * might have as defined by the architecture. 398 */ 399 void setMiscReg(int misc_reg, const TheISA::MiscReg &val, 400 ThreadID tid); 401 402 uint64_t readIntReg(PhysRegIdPtr phys_reg); 403 404 TheISA::FloatReg readFloatReg(PhysRegIdPtr phys_reg); 405 406 TheISA::FloatRegBits readFloatRegBits(PhysRegIdPtr phys_reg); 407 408 const VecRegContainer& readVecReg(PhysRegIdPtr reg_idx) const; 409 410 /** 411 * Read physical vector register for modification. 412 */ 413 VecRegContainer& getWritableVecReg(PhysRegIdPtr reg_idx); 414 415 /** 416 * Read physical vector register lane 417 */ 418 template<typename VecElem, int LaneIdx> 419 VecLaneT<VecElem, true> 420 readVecLane(PhysRegIdPtr phys_reg) const 421 { 422 vecRegfileReads++; 423 return regFile.readVecLane<VecElem, LaneIdx>(phys_reg); 424 } 425 426 /** 427 * Read physical vector register lane 428 */ 429 template<typename VecElem> 430 VecLaneT<VecElem, true> 431 readVecLane(PhysRegIdPtr phys_reg) const 432 { 433 vecRegfileReads++; 434 return regFile.readVecLane<VecElem>(phys_reg); 435 } 436 437 /** Write a lane of the destination vector register. */ 438 template<typename LD> 439 void 440 setVecLane(PhysRegIdPtr phys_reg, const LD& val) 441 { 442 vecRegfileWrites++; 443 return regFile.setVecLane(phys_reg, val); 444 } 445 446 const VecElem& readVecElem(PhysRegIdPtr reg_idx) const; 447 448 TheISA::CCReg readCCReg(PhysRegIdPtr phys_reg); 449 450 void setIntReg(PhysRegIdPtr phys_reg, uint64_t val); 451 452 void setFloatReg(PhysRegIdPtr phys_reg, TheISA::FloatReg val); 453 454 void setFloatRegBits(PhysRegIdPtr phys_reg, TheISA::FloatRegBits val); 455 456 void setVecReg(PhysRegIdPtr reg_idx, const VecRegContainer& val); 457 458 void setVecElem(PhysRegIdPtr reg_idx, const VecElem& val); 459 460 void setCCReg(PhysRegIdPtr phys_reg, TheISA::CCReg val); 461 462 uint64_t readArchIntReg(int reg_idx, ThreadID tid); 463 464 float readArchFloatReg(int reg_idx, ThreadID tid); 465 466 uint64_t readArchFloatRegInt(int reg_idx, ThreadID tid); 467 468 const VecRegContainer& readArchVecReg(int reg_idx, ThreadID tid) const; 469 /** Read architectural vector register for modification. */ 470 VecRegContainer& getWritableArchVecReg(int reg_idx, ThreadID tid); 471 472 /** Read architectural vector register lane. */ 473 template<typename VecElem> 474 VecLaneT<VecElem, true> 475 readArchVecLane(int reg_idx, int lId, ThreadID tid) const 476 { 477 PhysRegIdPtr phys_reg = commitRenameMap[tid].lookup( 478 RegId(VecRegClass, reg_idx)); 479 return readVecLane<VecElem>(phys_reg); 480 } 481 482 483 /** Write a lane of the destination vector register. */ 484 template<typename LD> 485 void 486 setArchVecLane(int reg_idx, int lId, ThreadID tid, const LD& val) 487 { 488 PhysRegIdPtr phys_reg = commitRenameMap[tid].lookup( 489 RegId(VecRegClass, reg_idx)); 490 setVecLane(phys_reg, val); 491 } 492 493 const VecElem& readArchVecElem(const RegIndex& reg_idx, 494 const ElemIndex& ldx, ThreadID tid) const; 495 496 TheISA::CCReg readArchCCReg(int reg_idx, ThreadID tid); 497 498 /** Architectural register accessors. Looks up in the commit 499 * rename table to obtain the true physical index of the 500 * architected register first, then accesses that physical 501 * register. 502 */ 503 void setArchIntReg(int reg_idx, uint64_t val, ThreadID tid); 504 505 void setArchFloatReg(int reg_idx, float val, ThreadID tid); 506 507 void setArchFloatRegInt(int reg_idx, uint64_t val, ThreadID tid); 508 509 void setArchVecReg(int reg_idx, const VecRegContainer& val, ThreadID tid); 510 511 void setArchVecElem(const RegIndex& reg_idx, const ElemIndex& ldx, 512 const VecElem& val, ThreadID tid); 513 514 void setArchCCReg(int reg_idx, TheISA::CCReg val, ThreadID tid); 515 516 /** Sets the commit PC state of a specific thread. */ 517 void pcState(const TheISA::PCState &newPCState, ThreadID tid); 518 519 /** Reads the commit PC state of a specific thread. */ 520 TheISA::PCState pcState(ThreadID tid); 521 522 /** Reads the commit PC of a specific thread. */ 523 Addr instAddr(ThreadID tid); 524 525 /** Reads the commit micro PC of a specific thread. */ 526 MicroPC microPC(ThreadID tid); 527 528 /** Reads the next PC of a specific thread. */ 529 Addr nextInstAddr(ThreadID tid); 530 531 /** Initiates a squash of all in-flight instructions for a given 532 * thread. The source of the squash is an external update of 533 * state through the TC. 534 */ 535 void squashFromTC(ThreadID tid); 536 537 /** Function to add instruction onto the head of the list of the 538 * instructions. Used when new instructions are fetched. 539 */ 540 ListIt addInst(DynInstPtr &inst); 541 542 /** Function to tell the CPU that an instruction has completed. */ 543 void instDone(ThreadID tid, DynInstPtr &inst); 544 545 /** Remove an instruction from the front end of the list. There's 546 * no restriction on location of the instruction. 547 */ 548 void removeFrontInst(DynInstPtr &inst); 549 550 /** Remove all instructions that are not currently in the ROB. 551 * There's also an option to not squash delay slot instructions.*/ 552 void removeInstsNotInROB(ThreadID tid); 553 554 /** Remove all instructions younger than the given sequence number. */ 555 void removeInstsUntil(const InstSeqNum &seq_num, ThreadID tid); 556 557 /** Removes the instruction pointed to by the iterator. */ 558 inline void squashInstIt(const ListIt &instIt, ThreadID tid); 559 560 /** Cleans up all instructions on the remove list. */ 561 void cleanUpRemovedInsts(); 562 563 /** Debug function to print all instructions on the list. */ 564 void dumpInsts(); 565 566 public: 567#ifndef NDEBUG 568 /** Count of total number of dynamic instructions in flight. */ 569 int instcount; 570#endif 571 572 /** List of all the instructions in flight. */ 573 std::list<DynInstPtr> instList; 574 575 /** List of all the instructions that will be removed at the end of this 576 * cycle. 577 */ 578 std::queue<ListIt> removeList; 579 580#ifdef DEBUG 581 /** Debug structure to keep track of the sequence numbers still in 582 * flight. 583 */ 584 std::set<InstSeqNum> snList; 585#endif 586 587 /** Records if instructions need to be removed this cycle due to 588 * being retired or squashed. 589 */ 590 bool removeInstsThisCycle; 591 592 protected: 593 /** The fetch stage. */ 594 typename CPUPolicy::Fetch fetch; 595 596 /** The decode stage. */ 597 typename CPUPolicy::Decode decode; 598 599 /** The dispatch stage. */ 600 typename CPUPolicy::Rename rename; 601 602 /** The issue/execute/writeback stages. */ 603 typename CPUPolicy::IEW iew; 604 605 /** The commit stage. */ 606 typename CPUPolicy::Commit commit; 607 608 /** The rename mode of the vector registers */ 609 Enums::VecRegRenameMode vecMode; 610 611 /** The register file. */ 612 PhysRegFile regFile; 613 614 /** The free list. */ 615 typename CPUPolicy::FreeList freeList; 616 617 /** The rename map. */ 618 typename CPUPolicy::RenameMap renameMap[Impl::MaxThreads]; 619 620 /** The commit rename map. */ 621 typename CPUPolicy::RenameMap commitRenameMap[Impl::MaxThreads]; 622 623 /** The re-order buffer. */ 624 typename CPUPolicy::ROB rob; 625 626 /** Active Threads List */ 627 std::list<ThreadID> activeThreads; 628 629 /** Integer Register Scoreboard */ 630 Scoreboard scoreboard; 631 632 std::vector<TheISA::ISA *> isa; 633 634 /** Instruction port. Note that it has to appear after the fetch stage. */ 635 IcachePort icachePort; 636 637 /** Data port. Note that it has to appear after the iew stages */ 638 DcachePort dcachePort; 639 640 public: 641 /** Enum to give each stage a specific index, so when calling 642 * activateStage() or deactivateStage(), they can specify which stage 643 * is being activated/deactivated. 644 */ 645 enum StageIdx { 646 FetchIdx, 647 DecodeIdx, 648 RenameIdx, 649 IEWIdx, 650 CommitIdx, 651 NumStages }; 652 653 /** Typedefs from the Impl to get the structs that each of the 654 * time buffers should use. 655 */ 656 typedef typename CPUPolicy::TimeStruct TimeStruct; 657 658 typedef typename CPUPolicy::FetchStruct FetchStruct; 659 660 typedef typename CPUPolicy::DecodeStruct DecodeStruct; 661 662 typedef typename CPUPolicy::RenameStruct RenameStruct; 663 664 typedef typename CPUPolicy::IEWStruct IEWStruct; 665 666 /** The main time buffer to do backwards communication. */ 667 TimeBuffer<TimeStruct> timeBuffer; 668 669 /** The fetch stage's instruction queue. */ 670 TimeBuffer<FetchStruct> fetchQueue; 671 672 /** The decode stage's instruction queue. */ 673 TimeBuffer<DecodeStruct> decodeQueue; 674 675 /** The rename stage's instruction queue. */ 676 TimeBuffer<RenameStruct> renameQueue; 677 678 /** The IEW stage's instruction queue. */ 679 TimeBuffer<IEWStruct> iewQueue; 680 681 private: 682 /** The activity recorder; used to tell if the CPU has any 683 * activity remaining or if it can go to idle and deschedule 684 * itself. 685 */ 686 ActivityRecorder activityRec; 687 688 public: 689 /** Records that there was time buffer activity this cycle. */ 690 void activityThisCycle() { activityRec.activity(); } 691 692 /** Changes a stage's status to active within the activity recorder. */ 693 void activateStage(const StageIdx idx) 694 { activityRec.activateStage(idx); } 695 696 /** Changes a stage's status to inactive within the activity recorder. */ 697 void deactivateStage(const StageIdx idx) 698 { activityRec.deactivateStage(idx); } 699 700 /** Wakes the CPU, rescheduling the CPU if it's not already active. */ 701 void wakeCPU(); 702 703 virtual void wakeup(ThreadID tid) override; 704 705 /** Gets a free thread id. Use if thread ids change across system. */ 706 ThreadID getFreeTid(); 707 708 public: 709 /** Returns a pointer to a thread context. */ 710 ThreadContext * 711 tcBase(ThreadID tid) 712 { 713 return thread[tid]->getTC(); 714 } 715 716 /** The global sequence number counter. */ 717 InstSeqNum globalSeqNum;//[Impl::MaxThreads]; 718 719 /** Pointer to the checker, which can dynamically verify 720 * instruction results at run time. This can be set to NULL if it 721 * is not being used. 722 */ 723 Checker<Impl> *checker; 724 725 /** Pointer to the system. */ 726 System *system; 727 728 /** Pointers to all of the threads in the CPU. */ 729 std::vector<Thread *> thread; 730 731 /** Threads Scheduled to Enter CPU */ 732 std::list<int> cpuWaitList; 733 734 /** The cycle that the CPU was last running, used for statistics. */ 735 Cycles lastRunningCycle; 736 737 /** The cycle that the CPU was last activated by a new thread*/ 738 Tick lastActivatedCycle; 739 740 /** Mapping for system thread id to cpu id */ 741 std::map<ThreadID, unsigned> threadMap; 742 743 /** Available thread ids in the cpu*/ 744 std::vector<ThreadID> tids; 745 746 /** CPU read function, forwards read to LSQ. */ 747 Fault read(RequestPtr &req, RequestPtr &sreqLow, RequestPtr &sreqHigh, 748 int load_idx) 749 { 750 return this->iew.ldstQueue.read(req, sreqLow, sreqHigh, load_idx); 751 } 752 753 /** CPU write function, forwards write to LSQ. */ 754 Fault write(RequestPtr &req, RequestPtr &sreqLow, RequestPtr &sreqHigh, 755 uint8_t *data, int store_idx) 756 { 757 return this->iew.ldstQueue.write(req, sreqLow, sreqHigh, 758 data, store_idx); 759 } 760 761 /** Used by the fetch unit to get a hold of the instruction port. */ 762 MasterPort &getInstPort() override { return icachePort; } 763 764 /** Get the dcache port (used to find block size for translations). */ 765 MasterPort &getDataPort() override { return dcachePort; } 766 767 /** Stat for total number of times the CPU is descheduled. */ 768 Stats::Scalar timesIdled; 769 /** Stat for total number of cycles the CPU spends descheduled. */ 770 Stats::Scalar idleCycles; 771 /** Stat for total number of cycles the CPU spends descheduled due to a 772 * quiesce operation or waiting for an interrupt. */ 773 Stats::Scalar quiesceCycles; 774 /** Stat for the number of committed instructions per thread. */ 775 Stats::Vector committedInsts; 776 /** Stat for the number of committed ops (including micro ops) per thread. */ 777 Stats::Vector committedOps; 778 /** Stat for the CPI per thread. */ 779 Stats::Formula cpi; 780 /** Stat for the total CPI. */ 781 Stats::Formula totalCpi; 782 /** Stat for the IPC per thread. */ 783 Stats::Formula ipc; 784 /** Stat for the total IPC. */ 785 Stats::Formula totalIpc; 786 787 //number of integer register file accesses 788 Stats::Scalar intRegfileReads; 789 Stats::Scalar intRegfileWrites; 790 //number of float register file accesses 791 Stats::Scalar fpRegfileReads; 792 Stats::Scalar fpRegfileWrites; 793 //number of vector register file accesses 794 mutable Stats::Scalar vecRegfileReads; 795 Stats::Scalar vecRegfileWrites; 796 //number of CC register file accesses 797 Stats::Scalar ccRegfileReads; 798 Stats::Scalar ccRegfileWrites; 799 //number of misc 800 Stats::Scalar miscRegfileReads; 801 Stats::Scalar miscRegfileWrites; 802}; 803 804#endif // __CPU_O3_CPU_HH__ 805