cpu.hh revision 13601:f5c84915eb7f
1/* 2 * Copyright (c) 2011-2013, 2016-2019 ARM Limited 3 * Copyright (c) 2013 Advanced Micro Devices, Inc. 4 * All rights reserved 5 * 6 * The license below extends only to copyright in the software and shall 7 * not be construed as granting a license to any other intellectual 8 * property including but not limited to intellectual property relating 9 * to a hardware implementation of the functionality of the software 10 * licensed hereunder. You may use the software subject to the license 11 * terms below provided that you ensure that this notice is replicated 12 * unmodified and in its entirety in all distributions of the software, 13 * modified or unmodified, in source code or in binary form. 14 * 15 * Copyright (c) 2004-2005 The Regents of The University of Michigan 16 * Copyright (c) 2011 Regents of the University of California 17 * All rights reserved. 18 * 19 * Redistribution and use in source and binary forms, with or without 20 * modification, are permitted provided that the following conditions are 21 * met: redistributions of source code must retain the above copyright 22 * notice, this list of conditions and the following disclaimer; 23 * redistributions in binary form must reproduce the above copyright 24 * notice, this list of conditions and the following disclaimer in the 25 * documentation and/or other materials provided with the distribution; 26 * neither the name of the copyright holders nor the names of its 27 * contributors may be used to endorse or promote products derived from 28 * this software without specific prior written permission. 29 * 30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 34 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 35 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 36 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 37 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 38 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 40 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 41 * 42 * Authors: Kevin Lim 43 * Korey Sewell 44 * Rick Strong 45 */ 46 47#ifndef __CPU_O3_CPU_HH__ 48#define __CPU_O3_CPU_HH__ 49 50#include <iostream> 51#include <list> 52#include <queue> 53#include <set> 54#include <vector> 55 56#include "arch/generic/types.hh" 57#include "arch/types.hh" 58#include "base/statistics.hh" 59#include "config/the_isa.hh" 60#include "cpu/o3/comm.hh" 61#include "cpu/o3/cpu_policy.hh" 62#include "cpu/o3/scoreboard.hh" 63#include "cpu/o3/thread_state.hh" 64#include "cpu/activity.hh" 65#include "cpu/base.hh" 66#include "cpu/simple_thread.hh" 67#include "cpu/timebuf.hh" 68//#include "cpu/o3/thread_context.hh" 69#include "params/DerivO3CPU.hh" 70#include "sim/process.hh" 71 72template <class> 73class Checker; 74class ThreadContext; 75template <class> 76class O3ThreadContext; 77 78class Checkpoint; 79class MemObject; 80class Process; 81 82struct BaseCPUParams; 83 84class BaseO3CPU : public BaseCPU 85{ 86 //Stuff that's pretty ISA independent will go here. 87 public: 88 BaseO3CPU(BaseCPUParams *params); 89 90 void regStats(); 91}; 92 93/** 94 * FullO3CPU class, has each of the stages (fetch through commit) 95 * within it, as well as all of the time buffers between stages. The 96 * tick() function for the CPU is defined here. 97 */ 98template <class Impl> 99class FullO3CPU : public BaseO3CPU 100{ 101 public: 102 // Typedefs from the Impl here. 103 typedef typename Impl::CPUPol CPUPolicy; 104 typedef typename Impl::DynInstPtr DynInstPtr; 105 typedef typename Impl::O3CPU O3CPU; 106 107 using VecElem = TheISA::VecElem; 108 using VecRegContainer = TheISA::VecRegContainer; 109 110 typedef O3ThreadState<Impl> ImplState; 111 typedef O3ThreadState<Impl> Thread; 112 113 typedef typename std::list<DynInstPtr>::iterator ListIt; 114 115 friend class O3ThreadContext<Impl>; 116 117 public: 118 enum Status { 119 Running, 120 Idle, 121 Halted, 122 Blocked, 123 SwitchedOut 124 }; 125 126 BaseTLB *itb; 127 BaseTLB *dtb; 128 using LSQRequest = typename LSQ<Impl>::LSQRequest; 129 130 /** Overall CPU status. */ 131 Status _status; 132 133 private: 134 135 /** 136 * IcachePort class for instruction fetch. 137 */ 138 class IcachePort : public MasterPort 139 { 140 protected: 141 /** Pointer to fetch. */ 142 DefaultFetch<Impl> *fetch; 143 144 public: 145 /** Default constructor. */ 146 IcachePort(DefaultFetch<Impl> *_fetch, FullO3CPU<Impl>* _cpu) 147 : MasterPort(_cpu->name() + ".icache_port", _cpu), fetch(_fetch) 148 { } 149 150 protected: 151 152 /** Timing version of receive. Handles setting fetch to the 153 * proper status to start fetching. */ 154 virtual bool recvTimingResp(PacketPtr pkt); 155 156 /** Handles doing a retry of a failed fetch. */ 157 virtual void recvReqRetry(); 158 }; 159 160 /** 161 * DcachePort class for the load/store queue. 162 */ 163 class DcachePort : public MasterPort 164 { 165 protected: 166 167 /** Pointer to LSQ. */ 168 LSQ<Impl> *lsq; 169 FullO3CPU<Impl> *cpu; 170 171 public: 172 /** Default constructor. */ 173 DcachePort(LSQ<Impl> *_lsq, FullO3CPU<Impl>* _cpu) 174 : MasterPort(_cpu->name() + ".dcache_port", _cpu), lsq(_lsq), 175 cpu(_cpu) 176 { } 177 178 protected: 179 180 /** Timing version of receive. Handles writing back and 181 * completing the load or store that has returned from 182 * memory. */ 183 virtual bool recvTimingResp(PacketPtr pkt); 184 virtual void recvTimingSnoopReq(PacketPtr pkt); 185 186 virtual void recvFunctionalSnoop(PacketPtr pkt) 187 { 188 // @todo: Is there a need for potential invalidation here? 189 } 190 191 /** Handles doing a retry of the previous send. */ 192 virtual void recvReqRetry(); 193 194 /** 195 * As this CPU requires snooping to maintain the load store queue 196 * change the behaviour from the base CPU port. 197 * 198 * @return true since we have to snoop 199 */ 200 virtual bool isSnooping() const { return true; } 201 }; 202 203 /** The tick event used for scheduling CPU ticks. */ 204 EventFunctionWrapper tickEvent; 205 206 /** Schedule tick event, regardless of its current state. */ 207 void scheduleTickEvent(Cycles delay) 208 { 209 if (tickEvent.squashed()) 210 reschedule(tickEvent, clockEdge(delay)); 211 else if (!tickEvent.scheduled()) 212 schedule(tickEvent, clockEdge(delay)); 213 } 214 215 /** Unschedule tick event, regardless of its current state. */ 216 void unscheduleTickEvent() 217 { 218 if (tickEvent.scheduled()) 219 tickEvent.squash(); 220 } 221 222 /** 223 * Check if the pipeline has drained and signal drain done. 224 * 225 * This method checks if a drain has been requested and if the CPU 226 * has drained successfully (i.e., there are no instructions in 227 * the pipeline). If the CPU has drained, it deschedules the tick 228 * event and signals the drain manager. 229 * 230 * @return False if a drain hasn't been requested or the CPU 231 * hasn't drained, true otherwise. 232 */ 233 bool tryDrain(); 234 235 /** 236 * Perform sanity checks after a drain. 237 * 238 * This method is called from drain() when it has determined that 239 * the CPU is fully drained when gem5 is compiled with the NDEBUG 240 * macro undefined. The intention of this method is to do more 241 * extensive tests than the isDrained() method to weed out any 242 * draining bugs. 243 */ 244 void drainSanityCheck() const; 245 246 /** Check if a system is in a drained state. */ 247 bool isDrained() const; 248 249 public: 250 /** Constructs a CPU with the given parameters. */ 251 FullO3CPU(DerivO3CPUParams *params); 252 /** Destructor. */ 253 ~FullO3CPU(); 254 255 /** Registers statistics. */ 256 void regStats() override; 257 258 ProbePointArg<PacketPtr> *ppInstAccessComplete; 259 ProbePointArg<std::pair<DynInstPtr, PacketPtr> > *ppDataAccessComplete; 260 261 /** Register probe points. */ 262 void regProbePoints() override; 263 264 void demapPage(Addr vaddr, uint64_t asn) 265 { 266 this->itb->demapPage(vaddr, asn); 267 this->dtb->demapPage(vaddr, asn); 268 } 269 270 void demapInstPage(Addr vaddr, uint64_t asn) 271 { 272 this->itb->demapPage(vaddr, asn); 273 } 274 275 void demapDataPage(Addr vaddr, uint64_t asn) 276 { 277 this->dtb->demapPage(vaddr, asn); 278 } 279 280 /** Ticks CPU, calling tick() on each stage, and checking the overall 281 * activity to see if the CPU should deschedule itself. 282 */ 283 void tick(); 284 285 /** Initialize the CPU */ 286 void init() override; 287 288 void startup() override; 289 290 /** Returns the Number of Active Threads in the CPU */ 291 int numActiveThreads() 292 { return activeThreads.size(); } 293 294 /** Add Thread to Active Threads List */ 295 void activateThread(ThreadID tid); 296 297 /** Remove Thread from Active Threads List */ 298 void deactivateThread(ThreadID tid); 299 300 /** Setup CPU to insert a thread's context */ 301 void insertThread(ThreadID tid); 302 303 /** Remove all of a thread's context from CPU */ 304 void removeThread(ThreadID tid); 305 306 /** Count the Total Instructions Committed in the CPU. */ 307 Counter totalInsts() const override; 308 309 /** Count the Total Ops (including micro ops) committed in the CPU. */ 310 Counter totalOps() const override; 311 312 /** Add Thread to Active Threads List. */ 313 void activateContext(ThreadID tid) override; 314 315 /** Remove Thread from Active Threads List */ 316 void suspendContext(ThreadID tid) override; 317 318 /** Remove Thread from Active Threads List && 319 * Remove Thread Context from CPU. 320 */ 321 void haltContext(ThreadID tid) override; 322 323 /** Update The Order In Which We Process Threads. */ 324 void updateThreadPriority(); 325 326 /** Is the CPU draining? */ 327 bool isDraining() const { return drainState() == DrainState::Draining; } 328 329 void serializeThread(CheckpointOut &cp, ThreadID tid) const override; 330 void unserializeThread(CheckpointIn &cp, ThreadID tid) override; 331 332 public: 333 /** Executes a syscall. 334 * @todo: Determine if this needs to be virtual. 335 */ 336 void syscall(int64_t callnum, ThreadID tid, Fault *fault); 337 338 /** Starts draining the CPU's pipeline of all instructions in 339 * order to stop all memory accesses. */ 340 DrainState drain() override; 341 342 /** Resumes execution after a drain. */ 343 void drainResume() override; 344 345 /** 346 * Commit has reached a safe point to drain a thread. 347 * 348 * Commit calls this method to inform the pipeline that it has 349 * reached a point where it is not executed microcode and is about 350 * to squash uncommitted instructions to fully drain the pipeline. 351 */ 352 void commitDrained(ThreadID tid); 353 354 /** Switches out this CPU. */ 355 void switchOut() override; 356 357 /** Takes over from another CPU. */ 358 void takeOverFrom(BaseCPU *oldCPU) override; 359 360 void verifyMemoryMode() const override; 361 362 /** Get the current instruction sequence number, and increment it. */ 363 InstSeqNum getAndIncrementInstSeq() 364 { return globalSeqNum++; } 365 366 /** Traps to handle given fault. */ 367 void trap(const Fault &fault, ThreadID tid, const StaticInstPtr &inst); 368 369 /** HW return from error interrupt. */ 370 Fault hwrei(ThreadID tid); 371 372 bool simPalCheck(int palFunc, ThreadID tid); 373 374 /** Check if a change in renaming is needed for vector registers. 375 * The vecMode variable is updated and propagated to rename maps. 376 * 377 * @param tid ThreadID 378 * @param freelist list of free registers 379 */ 380 void switchRenameMode(ThreadID tid, UnifiedFreeList* freelist); 381 382 /** Returns the Fault for any valid interrupt. */ 383 Fault getInterrupts(); 384 385 /** Processes any an interrupt fault. */ 386 void processInterrupts(const Fault &interrupt); 387 388 /** Halts the CPU. */ 389 void halt() { panic("Halt not implemented!\n"); } 390 391 /** Register accessors. Index refers to the physical register index. */ 392 393 /** Reads a miscellaneous register. */ 394 RegVal readMiscRegNoEffect(int misc_reg, ThreadID tid) const; 395 396 /** Reads a misc. register, including any side effects the read 397 * might have as defined by the architecture. 398 */ 399 RegVal readMiscReg(int misc_reg, ThreadID tid); 400 401 /** Sets a miscellaneous register. */ 402 void setMiscRegNoEffect(int misc_reg, RegVal val, ThreadID tid); 403 404 /** Sets a misc. register, including any side effects the write 405 * might have as defined by the architecture. 406 */ 407 void setMiscReg(int misc_reg, RegVal val, ThreadID tid); 408 409 RegVal readIntReg(PhysRegIdPtr phys_reg); 410 411 RegVal readFloatRegBits(PhysRegIdPtr phys_reg); 412 413 const VecRegContainer& readVecReg(PhysRegIdPtr reg_idx) const; 414 415 /** 416 * Read physical vector register for modification. 417 */ 418 VecRegContainer& getWritableVecReg(PhysRegIdPtr reg_idx); 419 420 /** Returns current vector renaming mode */ 421 Enums::VecRegRenameMode vecRenameMode() const { return vecMode; } 422 423 /** Sets the current vector renaming mode */ 424 void vecRenameMode(Enums::VecRegRenameMode vec_mode) 425 { vecMode = vec_mode; } 426 427 /** 428 * Read physical vector register lane 429 */ 430 template<typename VecElem, int LaneIdx> 431 VecLaneT<VecElem, true> 432 readVecLane(PhysRegIdPtr phys_reg) const 433 { 434 vecRegfileReads++; 435 return regFile.readVecLane<VecElem, LaneIdx>(phys_reg); 436 } 437 438 /** 439 * Read physical vector register lane 440 */ 441 template<typename VecElem> 442 VecLaneT<VecElem, true> 443 readVecLane(PhysRegIdPtr phys_reg) const 444 { 445 vecRegfileReads++; 446 return regFile.readVecLane<VecElem>(phys_reg); 447 } 448 449 /** Write a lane of the destination vector register. */ 450 template<typename LD> 451 void 452 setVecLane(PhysRegIdPtr phys_reg, const LD& val) 453 { 454 vecRegfileWrites++; 455 return regFile.setVecLane(phys_reg, val); 456 } 457 458 const VecElem& readVecElem(PhysRegIdPtr reg_idx) const; 459 460 TheISA::CCReg readCCReg(PhysRegIdPtr phys_reg); 461 462 void setIntReg(PhysRegIdPtr phys_reg, RegVal val); 463 464 void setFloatRegBits(PhysRegIdPtr phys_reg, RegVal val); 465 466 void setVecReg(PhysRegIdPtr reg_idx, const VecRegContainer& val); 467 468 void setVecElem(PhysRegIdPtr reg_idx, const VecElem& val); 469 470 void setCCReg(PhysRegIdPtr phys_reg, TheISA::CCReg val); 471 472 RegVal readArchIntReg(int reg_idx, ThreadID tid); 473 474 RegVal readArchFloatRegBits(int reg_idx, ThreadID tid); 475 476 const VecRegContainer& readArchVecReg(int reg_idx, ThreadID tid) const; 477 /** Read architectural vector register for modification. */ 478 VecRegContainer& getWritableArchVecReg(int reg_idx, ThreadID tid); 479 480 /** Read architectural vector register lane. */ 481 template<typename VecElem> 482 VecLaneT<VecElem, true> 483 readArchVecLane(int reg_idx, int lId, ThreadID tid) const 484 { 485 PhysRegIdPtr phys_reg = commitRenameMap[tid].lookup( 486 RegId(VecRegClass, reg_idx)); 487 return readVecLane<VecElem>(phys_reg); 488 } 489 490 491 /** Write a lane of the destination vector register. */ 492 template<typename LD> 493 void 494 setArchVecLane(int reg_idx, int lId, ThreadID tid, const LD& val) 495 { 496 PhysRegIdPtr phys_reg = commitRenameMap[tid].lookup( 497 RegId(VecRegClass, reg_idx)); 498 setVecLane(phys_reg, val); 499 } 500 501 const VecElem& readArchVecElem(const RegIndex& reg_idx, 502 const ElemIndex& ldx, ThreadID tid) const; 503 504 TheISA::CCReg readArchCCReg(int reg_idx, ThreadID tid); 505 506 /** Architectural register accessors. Looks up in the commit 507 * rename table to obtain the true physical index of the 508 * architected register first, then accesses that physical 509 * register. 510 */ 511 void setArchIntReg(int reg_idx, RegVal val, ThreadID tid); 512 513 void setArchFloatRegBits(int reg_idx, RegVal val, ThreadID tid); 514 515 void setArchVecReg(int reg_idx, const VecRegContainer& val, ThreadID tid); 516 517 void setArchVecElem(const RegIndex& reg_idx, const ElemIndex& ldx, 518 const VecElem& val, ThreadID tid); 519 520 void setArchCCReg(int reg_idx, TheISA::CCReg val, ThreadID tid); 521 522 /** Sets the commit PC state of a specific thread. */ 523 void pcState(const TheISA::PCState &newPCState, ThreadID tid); 524 525 /** Reads the commit PC state of a specific thread. */ 526 TheISA::PCState pcState(ThreadID tid); 527 528 /** Reads the commit PC of a specific thread. */ 529 Addr instAddr(ThreadID tid); 530 531 /** Reads the commit micro PC of a specific thread. */ 532 MicroPC microPC(ThreadID tid); 533 534 /** Reads the next PC of a specific thread. */ 535 Addr nextInstAddr(ThreadID tid); 536 537 /** Initiates a squash of all in-flight instructions for a given 538 * thread. The source of the squash is an external update of 539 * state through the TC. 540 */ 541 void squashFromTC(ThreadID tid); 542 543 /** Function to add instruction onto the head of the list of the 544 * instructions. Used when new instructions are fetched. 545 */ 546 ListIt addInst(const DynInstPtr &inst); 547 548 /** Function to tell the CPU that an instruction has completed. */ 549 void instDone(ThreadID tid, const DynInstPtr &inst); 550 551 /** Remove an instruction from the front end of the list. There's 552 * no restriction on location of the instruction. 553 */ 554 void removeFrontInst(const DynInstPtr &inst); 555 556 /** Remove all instructions that are not currently in the ROB. 557 * There's also an option to not squash delay slot instructions.*/ 558 void removeInstsNotInROB(ThreadID tid); 559 560 /** Remove all instructions younger than the given sequence number. */ 561 void removeInstsUntil(const InstSeqNum &seq_num, ThreadID tid); 562 563 /** Removes the instruction pointed to by the iterator. */ 564 inline void squashInstIt(const ListIt &instIt, ThreadID tid); 565 566 /** Cleans up all instructions on the remove list. */ 567 void cleanUpRemovedInsts(); 568 569 /** Debug function to print all instructions on the list. */ 570 void dumpInsts(); 571 572 public: 573#ifndef NDEBUG 574 /** Count of total number of dynamic instructions in flight. */ 575 int instcount; 576#endif 577 578 /** List of all the instructions in flight. */ 579 std::list<DynInstPtr> instList; 580 581 /** List of all the instructions that will be removed at the end of this 582 * cycle. 583 */ 584 std::queue<ListIt> removeList; 585 586#ifdef DEBUG 587 /** Debug structure to keep track of the sequence numbers still in 588 * flight. 589 */ 590 std::set<InstSeqNum> snList; 591#endif 592 593 /** Records if instructions need to be removed this cycle due to 594 * being retired or squashed. 595 */ 596 bool removeInstsThisCycle; 597 598 protected: 599 /** The fetch stage. */ 600 typename CPUPolicy::Fetch fetch; 601 602 /** The decode stage. */ 603 typename CPUPolicy::Decode decode; 604 605 /** The dispatch stage. */ 606 typename CPUPolicy::Rename rename; 607 608 /** The issue/execute/writeback stages. */ 609 typename CPUPolicy::IEW iew; 610 611 /** The commit stage. */ 612 typename CPUPolicy::Commit commit; 613 614 /** The rename mode of the vector registers */ 615 Enums::VecRegRenameMode vecMode; 616 617 /** The register file. */ 618 PhysRegFile regFile; 619 620 /** The free list. */ 621 typename CPUPolicy::FreeList freeList; 622 623 /** The rename map. */ 624 typename CPUPolicy::RenameMap renameMap[Impl::MaxThreads]; 625 626 /** The commit rename map. */ 627 typename CPUPolicy::RenameMap commitRenameMap[Impl::MaxThreads]; 628 629 /** The re-order buffer. */ 630 typename CPUPolicy::ROB rob; 631 632 /** Active Threads List */ 633 std::list<ThreadID> activeThreads; 634 635 /** Integer Register Scoreboard */ 636 Scoreboard scoreboard; 637 638 std::vector<TheISA::ISA *> isa; 639 640 /** Instruction port. Note that it has to appear after the fetch stage. */ 641 IcachePort icachePort; 642 643 /** Data port. Note that it has to appear after the iew stages */ 644 DcachePort dcachePort; 645 646 public: 647 /** Enum to give each stage a specific index, so when calling 648 * activateStage() or deactivateStage(), they can specify which stage 649 * is being activated/deactivated. 650 */ 651 enum StageIdx { 652 FetchIdx, 653 DecodeIdx, 654 RenameIdx, 655 IEWIdx, 656 CommitIdx, 657 NumStages }; 658 659 /** Typedefs from the Impl to get the structs that each of the 660 * time buffers should use. 661 */ 662 typedef typename CPUPolicy::TimeStruct TimeStruct; 663 664 typedef typename CPUPolicy::FetchStruct FetchStruct; 665 666 typedef typename CPUPolicy::DecodeStruct DecodeStruct; 667 668 typedef typename CPUPolicy::RenameStruct RenameStruct; 669 670 typedef typename CPUPolicy::IEWStruct IEWStruct; 671 672 /** The main time buffer to do backwards communication. */ 673 TimeBuffer<TimeStruct> timeBuffer; 674 675 /** The fetch stage's instruction queue. */ 676 TimeBuffer<FetchStruct> fetchQueue; 677 678 /** The decode stage's instruction queue. */ 679 TimeBuffer<DecodeStruct> decodeQueue; 680 681 /** The rename stage's instruction queue. */ 682 TimeBuffer<RenameStruct> renameQueue; 683 684 /** The IEW stage's instruction queue. */ 685 TimeBuffer<IEWStruct> iewQueue; 686 687 private: 688 /** The activity recorder; used to tell if the CPU has any 689 * activity remaining or if it can go to idle and deschedule 690 * itself. 691 */ 692 ActivityRecorder activityRec; 693 694 public: 695 /** Records that there was time buffer activity this cycle. */ 696 void activityThisCycle() { activityRec.activity(); } 697 698 /** Changes a stage's status to active within the activity recorder. */ 699 void activateStage(const StageIdx idx) 700 { activityRec.activateStage(idx); } 701 702 /** Changes a stage's status to inactive within the activity recorder. */ 703 void deactivateStage(const StageIdx idx) 704 { activityRec.deactivateStage(idx); } 705 706 /** Wakes the CPU, rescheduling the CPU if it's not already active. */ 707 void wakeCPU(); 708 709 virtual void wakeup(ThreadID tid) override; 710 711 /** Gets a free thread id. Use if thread ids change across system. */ 712 ThreadID getFreeTid(); 713 714 public: 715 /** Returns a pointer to a thread context. */ 716 ThreadContext * 717 tcBase(ThreadID tid) 718 { 719 return thread[tid]->getTC(); 720 } 721 722 /** The global sequence number counter. */ 723 InstSeqNum globalSeqNum;//[Impl::MaxThreads]; 724 725 /** Pointer to the checker, which can dynamically verify 726 * instruction results at run time. This can be set to NULL if it 727 * is not being used. 728 */ 729 Checker<Impl> *checker; 730 731 /** Pointer to the system. */ 732 System *system; 733 734 /** Pointers to all of the threads in the CPU. */ 735 std::vector<Thread *> thread; 736 737 /** Threads Scheduled to Enter CPU */ 738 std::list<int> cpuWaitList; 739 740 /** The cycle that the CPU was last running, used for statistics. */ 741 Cycles lastRunningCycle; 742 743 /** The cycle that the CPU was last activated by a new thread*/ 744 Tick lastActivatedCycle; 745 746 /** Mapping for system thread id to cpu id */ 747 std::map<ThreadID, unsigned> threadMap; 748 749 /** Available thread ids in the cpu*/ 750 std::vector<ThreadID> tids; 751 752 /** CPU pushRequest function, forwards request to LSQ. */ 753 Fault pushRequest(const DynInstPtr& inst, bool isLoad, uint8_t *data, 754 unsigned int size, Addr addr, Request::Flags flags, 755 uint64_t *res) 756 { 757 return iew.ldstQueue.pushRequest(inst, isLoad, data, size, addr, 758 flags, res); 759 } 760 761 /** CPU read function, forwards read to LSQ. */ 762 Fault read(LSQRequest* req, int load_idx) 763 { 764 return this->iew.ldstQueue.read(req, load_idx); 765 } 766 767 /** CPU write function, forwards write to LSQ. */ 768 Fault write(LSQRequest* req, uint8_t *data, int store_idx) 769 { 770 return this->iew.ldstQueue.write(req, data, store_idx); 771 } 772 773 /** Used by the fetch unit to get a hold of the instruction port. */ 774 MasterPort &getInstPort() override { return icachePort; } 775 776 /** Get the dcache port (used to find block size for translations). */ 777 MasterPort &getDataPort() override { return dcachePort; } 778 779 /** Stat for total number of times the CPU is descheduled. */ 780 Stats::Scalar timesIdled; 781 /** Stat for total number of cycles the CPU spends descheduled. */ 782 Stats::Scalar idleCycles; 783 /** Stat for total number of cycles the CPU spends descheduled due to a 784 * quiesce operation or waiting for an interrupt. */ 785 Stats::Scalar quiesceCycles; 786 /** Stat for the number of committed instructions per thread. */ 787 Stats::Vector committedInsts; 788 /** Stat for the number of committed ops (including micro ops) per thread. */ 789 Stats::Vector committedOps; 790 /** Stat for the CPI per thread. */ 791 Stats::Formula cpi; 792 /** Stat for the total CPI. */ 793 Stats::Formula totalCpi; 794 /** Stat for the IPC per thread. */ 795 Stats::Formula ipc; 796 /** Stat for the total IPC. */ 797 Stats::Formula totalIpc; 798 799 //number of integer register file accesses 800 Stats::Scalar intRegfileReads; 801 Stats::Scalar intRegfileWrites; 802 //number of float register file accesses 803 Stats::Scalar fpRegfileReads; 804 Stats::Scalar fpRegfileWrites; 805 //number of vector register file accesses 806 mutable Stats::Scalar vecRegfileReads; 807 Stats::Scalar vecRegfileWrites; 808 //number of CC register file accesses 809 Stats::Scalar ccRegfileReads; 810 Stats::Scalar ccRegfileWrites; 811 //number of misc 812 Stats::Scalar miscRegfileReads; 813 Stats::Scalar miscRegfileWrites; 814}; 815 816#endif // __CPU_O3_CPU_HH__ 817