lsq.hh revision 2727
12292SN/A/* 22329SN/A * Copyright (c) 2004-2006 The Regents of The University of Michigan 32292SN/A * All rights reserved. 42292SN/A * 52292SN/A * Redistribution and use in source and binary forms, with or without 62292SN/A * modification, are permitted provided that the following conditions are 72292SN/A * met: redistributions of source code must retain the above copyright 82292SN/A * notice, this list of conditions and the following disclaimer; 92292SN/A * redistributions in binary form must reproduce the above copyright 102292SN/A * notice, this list of conditions and the following disclaimer in the 112292SN/A * documentation and/or other materials provided with the distribution; 122292SN/A * neither the name of the copyright holders nor the names of its 132292SN/A * contributors may be used to endorse or promote products derived from 142292SN/A * this software without specific prior written permission. 152292SN/A * 162292SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172292SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182292SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192292SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202292SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212292SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222292SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232292SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242292SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252292SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262292SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272689Sktlim@umich.edu * 282689Sktlim@umich.edu * Authors: Korey Sewell 292292SN/A */ 302292SN/A 312292SN/A#ifndef __CPU_O3_LSQ_HH__ 322292SN/A#define __CPU_O3_LSQ_HH__ 332292SN/A 342292SN/A#include <map> 352292SN/A#include <queue> 362292SN/A 372292SN/A#include "config/full_system.hh" 382292SN/A#include "cpu/inst_seq.hh" 392292SN/A#include "cpu/o3/lsq_unit.hh" 402669Sktlim@umich.edu#include "mem/port.hh" 412292SN/A#include "sim/sim_object.hh" 422292SN/A 432292SN/Atemplate <class Impl> 442292SN/Aclass LSQ { 452292SN/A public: 462292SN/A typedef typename Impl::Params Params; 472292SN/A typedef typename Impl::FullCPU FullCPU; 482292SN/A typedef typename Impl::DynInstPtr DynInstPtr; 492292SN/A typedef typename Impl::CPUPol::IEW IEW; 502292SN/A typedef typename Impl::CPUPol::LSQUnit LSQUnit; 512292SN/A 522348SN/A /** SMT policy. */ 532292SN/A enum LSQPolicy { 542292SN/A Dynamic, 552292SN/A Partitioned, 562292SN/A Threshold 572292SN/A }; 582292SN/A 592292SN/A /** Constructs an LSQ with the given parameters. */ 602292SN/A LSQ(Params *params); 612292SN/A 622292SN/A /** Returns the name of the LSQ. */ 632292SN/A std::string name() const; 642292SN/A 652727Sktlim@umich.edu /** Registers statistics of each LSQ unit. */ 662727Sktlim@umich.edu void regStats(); 672727Sktlim@umich.edu 682292SN/A /** Sets the pointer to the list of active threads. */ 692292SN/A void setActiveThreads(std::list<unsigned> *at_ptr); 702292SN/A /** Sets the CPU pointer. */ 712292SN/A void setCPU(FullCPU *cpu_ptr); 722292SN/A /** Sets the IEW stage pointer. */ 732292SN/A void setIEW(IEW *iew_ptr); 742348SN/A /** Switches out the LSQ. */ 752307SN/A void switchOut(); 762348SN/A /** Takes over execution from another CPU's thread. */ 772307SN/A void takeOverFrom(); 782307SN/A 792292SN/A /** Number of entries needed for the given amount of threads.*/ 802292SN/A int entryAmount(int num_threads); 812292SN/A void removeEntries(unsigned tid); 822292SN/A /** Reset the max entries for each thread. */ 832292SN/A void resetEntries(); 842292SN/A /** Resize the max entries for a thread. */ 852292SN/A void resizeEntries(unsigned size, unsigned tid); 862292SN/A 872292SN/A /** Ticks the LSQ. */ 882292SN/A void tick(); 892292SN/A /** Ticks a specific LSQ Unit. */ 902329SN/A void tick(unsigned tid) 912329SN/A { thread[tid].tick(); } 922292SN/A 932292SN/A /** Inserts a load into the LSQ. */ 942292SN/A void insertLoad(DynInstPtr &load_inst); 952292SN/A /** Inserts a store into the LSQ. */ 962292SN/A void insertStore(DynInstPtr &store_inst); 972292SN/A 982292SN/A /** Executes a load. */ 992292SN/A Fault executeLoad(DynInstPtr &inst); 1002292SN/A 1012292SN/A /** Executes a store. */ 1022292SN/A Fault executeStore(DynInstPtr &inst); 1032292SN/A 1042292SN/A /** 1052292SN/A * Commits loads up until the given sequence number for a specific thread. 1062292SN/A */ 1072329SN/A void commitLoads(InstSeqNum &youngest_inst, unsigned tid) 1082329SN/A { thread[tid].commitLoads(youngest_inst); } 1092329SN/A 1102292SN/A /** 1112292SN/A * Commits stores up until the given sequence number for a specific thread. 1122292SN/A */ 1132329SN/A void commitStores(InstSeqNum &youngest_inst, unsigned tid) 1142329SN/A { thread[tid].commitStores(youngest_inst); } 1152292SN/A 1162292SN/A /** 1172292SN/A * Attempts to write back stores until all cache ports are used or the 1182292SN/A * interface becomes blocked. 1192292SN/A */ 1202292SN/A void writebackStores(); 1212292SN/A /** Same as above, but only for one thread. */ 1222292SN/A void writebackStores(unsigned tid); 1232292SN/A 1242292SN/A /** 1252292SN/A * Squash instructions from a thread until the specified sequence number. 1262292SN/A */ 1272329SN/A void squash(const InstSeqNum &squashed_num, unsigned tid) 1282329SN/A { thread[tid].squash(squashed_num); } 1292292SN/A 1302292SN/A /** Returns whether or not there was a memory ordering violation. */ 1312292SN/A bool violation(); 1322292SN/A /** 1332292SN/A * Returns whether or not there was a memory ordering violation for a 1342292SN/A * specific thread. 1352292SN/A */ 1362329SN/A bool violation(unsigned tid) 1372329SN/A { return thread[tid].violation(); } 1382292SN/A 1392292SN/A /** Returns if a load is blocked due to the memory system for a specific 1402292SN/A * thread. 1412292SN/A */ 1422329SN/A bool loadBlocked(unsigned tid) 1432329SN/A { return thread[tid].loadBlocked(); } 1442292SN/A 1452292SN/A bool isLoadBlockedHandled(unsigned tid) 1462292SN/A { return thread[tid].isLoadBlockedHandled(); } 1472292SN/A 1482292SN/A void setLoadBlockedHandled(unsigned tid) 1492292SN/A { thread[tid].setLoadBlockedHandled(); } 1502292SN/A 1512292SN/A /** Gets the instruction that caused the memory ordering violation. */ 1522329SN/A DynInstPtr getMemDepViolator(unsigned tid) 1532329SN/A { return thread[tid].getMemDepViolator(); } 1542292SN/A 1552292SN/A /** Returns the head index of the load queue for a specific thread. */ 1562329SN/A int getLoadHead(unsigned tid) 1572329SN/A { return thread[tid].getLoadHead(); } 1582329SN/A 1592292SN/A /** Returns the sequence number of the head of the load queue. */ 1602292SN/A InstSeqNum getLoadHeadSeqNum(unsigned tid) 1612292SN/A { 1622292SN/A return thread[tid].getLoadHeadSeqNum(); 1632292SN/A } 1642292SN/A 1652292SN/A /** Returns the head index of the store queue. */ 1662329SN/A int getStoreHead(unsigned tid) 1672329SN/A { return thread[tid].getStoreHead(); } 1682329SN/A 1692292SN/A /** Returns the sequence number of the head of the store queue. */ 1702292SN/A InstSeqNum getStoreHeadSeqNum(unsigned tid) 1712292SN/A { 1722292SN/A return thread[tid].getStoreHeadSeqNum(); 1732292SN/A } 1742292SN/A 1752292SN/A /** Returns the number of instructions in all of the queues. */ 1762292SN/A int getCount(); 1772292SN/A /** Returns the number of instructions in the queues of one thread. */ 1782329SN/A int getCount(unsigned tid) 1792329SN/A { return thread[tid].getCount(); } 1802292SN/A 1812292SN/A /** Returns the total number of loads in the load queue. */ 1822292SN/A int numLoads(); 1832292SN/A /** Returns the total number of loads for a single thread. */ 1842329SN/A int numLoads(unsigned tid) 1852329SN/A { return thread[tid].numLoads(); } 1862292SN/A 1872292SN/A /** Returns the total number of stores in the store queue. */ 1882292SN/A int numStores(); 1892292SN/A /** Returns the total number of stores for a single thread. */ 1902329SN/A int numStores(unsigned tid) 1912329SN/A { return thread[tid].numStores(); } 1922292SN/A 1932292SN/A /** Returns the total number of loads that are ready. */ 1942292SN/A int numLoadsReady(); 1952292SN/A /** Returns the number of loads that are ready for a single thread. */ 1962329SN/A int numLoadsReady(unsigned tid) 1972329SN/A { return thread[tid].numLoadsReady(); } 1982292SN/A 1992292SN/A /** Returns the number of free entries. */ 2002292SN/A unsigned numFreeEntries(); 2012292SN/A /** Returns the number of free entries for a specific thread. */ 2022292SN/A unsigned numFreeEntries(unsigned tid); 2032292SN/A 2042292SN/A /** Returns if the LSQ is full (either LQ or SQ is full). */ 2052292SN/A bool isFull(); 2062292SN/A /** 2072292SN/A * Returns if the LSQ is full for a specific thread (either LQ or SQ is 2082292SN/A * full). 2092292SN/A */ 2102292SN/A bool isFull(unsigned tid); 2112292SN/A 2122292SN/A /** Returns if any of the LQs are full. */ 2132292SN/A bool lqFull(); 2142292SN/A /** Returns if the LQ of a given thread is full. */ 2152292SN/A bool lqFull(unsigned tid); 2162292SN/A 2172292SN/A /** Returns if any of the SQs are full. */ 2182292SN/A bool sqFull(); 2192292SN/A /** Returns if the SQ of a given thread is full. */ 2202292SN/A bool sqFull(unsigned tid); 2212292SN/A 2222292SN/A /** 2232292SN/A * Returns if the LSQ is stalled due to a memory operation that must be 2242292SN/A * replayed. 2252292SN/A */ 2262292SN/A bool isStalled(); 2272292SN/A /** 2282292SN/A * Returns if the LSQ of a specific thread is stalled due to a memory 2292292SN/A * operation that must be replayed. 2302292SN/A */ 2312292SN/A bool isStalled(unsigned tid); 2322292SN/A 2332292SN/A /** Returns whether or not there are any stores to write back to memory. */ 2342292SN/A bool hasStoresToWB(); 2352329SN/A 2362292SN/A /** Returns whether or not a specific thread has any stores to write back 2372292SN/A * to memory. 2382292SN/A */ 2392329SN/A bool hasStoresToWB(unsigned tid) 2402329SN/A { return thread[tid].hasStoresToWB(); } 2412329SN/A 2422292SN/A /** Returns the number of stores a specific thread has to write back. */ 2432329SN/A int numStoresToWB(unsigned tid) 2442329SN/A { return thread[tid].numStoresToWB(); } 2452292SN/A 2462292SN/A /** Returns if the LSQ will write back to memory this cycle. */ 2472292SN/A bool willWB(); 2482292SN/A /** Returns if the LSQ of a specific thread will write back to memory this 2492292SN/A * cycle. 2502292SN/A */ 2512329SN/A bool willWB(unsigned tid) 2522329SN/A { return thread[tid].willWB(); } 2532292SN/A 2542292SN/A /** Debugging function to print out all instructions. */ 2552292SN/A void dumpInsts(); 2562292SN/A /** Debugging function to print out instructions from a specific thread. */ 2572329SN/A void dumpInsts(unsigned tid) 2582329SN/A { thread[tid].dumpInsts(); } 2592292SN/A 2602292SN/A /** Executes a read operation, using the load specified at the load index. */ 2612292SN/A template <class T> 2622669Sktlim@umich.edu Fault read(RequestPtr req, T &data, int load_idx); 2632292SN/A 2642292SN/A /** Executes a store operation, using the store specified at the store 2652292SN/A * index. 2662292SN/A */ 2672292SN/A template <class T> 2682669Sktlim@umich.edu Fault write(RequestPtr req, T &data, int store_idx); 2692292SN/A 2702292SN/A private: 2712292SN/A /** The LSQ policy for SMT mode. */ 2722292SN/A LSQPolicy lsqPolicy; 2732292SN/A 2742292SN/A /** The LSQ units for individual threads. */ 2752292SN/A LSQUnit thread[Impl::MaxThreads]; 2762292SN/A 2772292SN/A /** The CPU pointer. */ 2782292SN/A FullCPU *cpu; 2792292SN/A 2802292SN/A /** The IEW stage pointer. */ 2812292SN/A IEW *iewStage; 2822292SN/A 2832292SN/A /** List of Active Threads in System. */ 2842292SN/A std::list<unsigned> *activeThreads; 2852292SN/A 2862292SN/A /** Total Size of LQ Entries. */ 2872292SN/A unsigned LQEntries; 2882292SN/A /** Total Size of SQ Entries. */ 2892292SN/A unsigned SQEntries; 2902292SN/A 2912292SN/A /** Max LQ Size - Used to Enforce Sharing Policies. */ 2922292SN/A unsigned maxLQEntries; 2932292SN/A 2942292SN/A /** Max SQ Size - Used to Enforce Sharing Policies. */ 2952292SN/A unsigned maxSQEntries; 2962292SN/A 2972292SN/A /** Number of Threads. */ 2982292SN/A unsigned numThreads; 2992292SN/A}; 3002292SN/A 3012292SN/Atemplate <class Impl> 3022292SN/Atemplate <class T> 3032292SN/AFault 3042669Sktlim@umich.eduLSQ<Impl>::read(RequestPtr req, T &data, int load_idx) 3052292SN/A{ 3062669Sktlim@umich.edu unsigned tid = req->getThreadNum(); 3072292SN/A 3082292SN/A return thread[tid].read(req, data, load_idx); 3092292SN/A} 3102292SN/A 3112292SN/Atemplate <class Impl> 3122292SN/Atemplate <class T> 3132292SN/AFault 3142669Sktlim@umich.eduLSQ<Impl>::write(RequestPtr req, T &data, int store_idx) 3152292SN/A{ 3162669Sktlim@umich.edu unsigned tid = req->getThreadNum(); 3172292SN/A 3182292SN/A return thread[tid].write(req, data, store_idx); 3192292SN/A} 3202292SN/A 3212292SN/A#endif // __CPU_O3_LSQ_HH__ 322