lsq.hh revision 9868
12292SN/A/* 29444SAndreas.Sandberg@ARM.com * Copyright (c) 2011-2012 ARM Limited 38707Sandreas.hansson@arm.com * All rights reserved 48707Sandreas.hansson@arm.com * 58707Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall 68707Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual 78707Sandreas.hansson@arm.com * property including but not limited to intellectual property relating 88707Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software 98707Sandreas.hansson@arm.com * licensed hereunder. You may use the software subject to the license 108707Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated 118707Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software, 128707Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form. 138707Sandreas.hansson@arm.com * 142329SN/A * Copyright (c) 2004-2006 The Regents of The University of Michigan 152292SN/A * All rights reserved. 162292SN/A * 172292SN/A * Redistribution and use in source and binary forms, with or without 182292SN/A * modification, are permitted provided that the following conditions are 192292SN/A * met: redistributions of source code must retain the above copyright 202292SN/A * notice, this list of conditions and the following disclaimer; 212292SN/A * redistributions in binary form must reproduce the above copyright 222292SN/A * notice, this list of conditions and the following disclaimer in the 232292SN/A * documentation and/or other materials provided with the distribution; 242292SN/A * neither the name of the copyright holders nor the names of its 252292SN/A * contributors may be used to endorse or promote products derived from 262292SN/A * this software without specific prior written permission. 272292SN/A * 282292SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 292292SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 302292SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 312292SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 322292SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 332292SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 342292SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 352292SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 362292SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 372292SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 382292SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392689Sktlim@umich.edu * 402689Sktlim@umich.edu * Authors: Korey Sewell 412292SN/A */ 422292SN/A 432292SN/A#ifndef __CPU_O3_LSQ_HH__ 442292SN/A#define __CPU_O3_LSQ_HH__ 452292SN/A 462292SN/A#include <map> 472292SN/A#include <queue> 482292SN/A 498229Snate@binkert.org#include "cpu/o3/lsq_unit.hh" 502292SN/A#include "cpu/inst_seq.hh" 512669Sktlim@umich.edu#include "mem/port.hh" 522292SN/A#include "sim/sim_object.hh" 532292SN/A 548737Skoansin.tan@gmail.comstruct DerivO3CPUParams; 555529Snate@binkert.org 562292SN/Atemplate <class Impl> 572292SN/Aclass LSQ { 582292SN/A public: 592733Sktlim@umich.edu typedef typename Impl::O3CPU O3CPU; 602292SN/A typedef typename Impl::DynInstPtr DynInstPtr; 612292SN/A typedef typename Impl::CPUPol::IEW IEW; 622292SN/A typedef typename Impl::CPUPol::LSQUnit LSQUnit; 632292SN/A 642348SN/A /** SMT policy. */ 652292SN/A enum LSQPolicy { 662292SN/A Dynamic, 672292SN/A Partitioned, 682292SN/A Threshold 692292SN/A }; 702292SN/A 712292SN/A /** Constructs an LSQ with the given parameters. */ 725529Snate@binkert.org LSQ(O3CPU *cpu_ptr, IEW *iew_ptr, DerivO3CPUParams *params); 739868Sjthestness@gmail.com ~LSQ() { 749868Sjthestness@gmail.com if (thread) delete [] thread; 759868Sjthestness@gmail.com } 762292SN/A 772292SN/A /** Returns the name of the LSQ. */ 782292SN/A std::string name() const; 792292SN/A 802727Sktlim@umich.edu /** Registers statistics of each LSQ unit. */ 812727Sktlim@umich.edu void regStats(); 822727Sktlim@umich.edu 832292SN/A /** Sets the pointer to the list of active threads. */ 846221Snate@binkert.org void setActiveThreads(std::list<ThreadID> *at_ptr); 859444SAndreas.Sandberg@ARM.com 869444SAndreas.Sandberg@ARM.com /** Perform sanity checks after a drain. */ 879444SAndreas.Sandberg@ARM.com void drainSanityCheck() const; 889444SAndreas.Sandberg@ARM.com /** Has the LSQ drained? */ 899444SAndreas.Sandberg@ARM.com bool isDrained() const; 902348SN/A /** Takes over execution from another CPU's thread. */ 912307SN/A void takeOverFrom(); 922307SN/A 932292SN/A /** Number of entries needed for the given amount of threads.*/ 946221Snate@binkert.org int entryAmount(ThreadID num_threads); 956221Snate@binkert.org void removeEntries(ThreadID tid); 962292SN/A /** Reset the max entries for each thread. */ 972292SN/A void resetEntries(); 982292SN/A /** Resize the max entries for a thread. */ 996221Snate@binkert.org void resizeEntries(unsigned size, ThreadID tid); 1002292SN/A 1012292SN/A /** Ticks the LSQ. */ 1022292SN/A void tick(); 1032292SN/A /** Ticks a specific LSQ Unit. */ 1046221Snate@binkert.org void tick(ThreadID tid) 1052329SN/A { thread[tid].tick(); } 1062292SN/A 1072292SN/A /** Inserts a load into the LSQ. */ 1082292SN/A void insertLoad(DynInstPtr &load_inst); 1092292SN/A /** Inserts a store into the LSQ. */ 1102292SN/A void insertStore(DynInstPtr &store_inst); 1112292SN/A 1122292SN/A /** Executes a load. */ 1132292SN/A Fault executeLoad(DynInstPtr &inst); 1142292SN/A 1152292SN/A /** Executes a store. */ 1162292SN/A Fault executeStore(DynInstPtr &inst); 1172292SN/A 1182292SN/A /** 1192292SN/A * Commits loads up until the given sequence number for a specific thread. 1202292SN/A */ 1216221Snate@binkert.org void commitLoads(InstSeqNum &youngest_inst, ThreadID tid) 1222329SN/A { thread[tid].commitLoads(youngest_inst); } 1232329SN/A 1242292SN/A /** 1252292SN/A * Commits stores up until the given sequence number for a specific thread. 1262292SN/A */ 1276221Snate@binkert.org void commitStores(InstSeqNum &youngest_inst, ThreadID tid) 1282329SN/A { thread[tid].commitStores(youngest_inst); } 1292292SN/A 1302292SN/A /** 1312292SN/A * Attempts to write back stores until all cache ports are used or the 1322292SN/A * interface becomes blocked. 1332292SN/A */ 1342292SN/A void writebackStores(); 1352292SN/A /** Same as above, but only for one thread. */ 1366221Snate@binkert.org void writebackStores(ThreadID tid); 1372292SN/A 1382292SN/A /** 1392292SN/A * Squash instructions from a thread until the specified sequence number. 1402292SN/A */ 1416221Snate@binkert.org void squash(const InstSeqNum &squashed_num, ThreadID tid) 1422329SN/A { thread[tid].squash(squashed_num); } 1432292SN/A 1442292SN/A /** Returns whether or not there was a memory ordering violation. */ 1452292SN/A bool violation(); 1462292SN/A /** 1472292SN/A * Returns whether or not there was a memory ordering violation for a 1482292SN/A * specific thread. 1492292SN/A */ 1506221Snate@binkert.org bool violation(ThreadID tid) 1512329SN/A { return thread[tid].violation(); } 1522292SN/A 1532292SN/A /** Returns if a load is blocked due to the memory system for a specific 1542292SN/A * thread. 1552292SN/A */ 1566221Snate@binkert.org bool loadBlocked(ThreadID tid) 1572329SN/A { return thread[tid].loadBlocked(); } 1582292SN/A 1596221Snate@binkert.org bool isLoadBlockedHandled(ThreadID tid) 1602292SN/A { return thread[tid].isLoadBlockedHandled(); } 1612292SN/A 1626221Snate@binkert.org void setLoadBlockedHandled(ThreadID tid) 1632292SN/A { thread[tid].setLoadBlockedHandled(); } 1642292SN/A 1652292SN/A /** Gets the instruction that caused the memory ordering violation. */ 1666221Snate@binkert.org DynInstPtr getMemDepViolator(ThreadID tid) 1672329SN/A { return thread[tid].getMemDepViolator(); } 1682292SN/A 1692292SN/A /** Returns the head index of the load queue for a specific thread. */ 1706221Snate@binkert.org int getLoadHead(ThreadID tid) 1712329SN/A { return thread[tid].getLoadHead(); } 1722329SN/A 1732292SN/A /** Returns the sequence number of the head of the load queue. */ 1746221Snate@binkert.org InstSeqNum getLoadHeadSeqNum(ThreadID tid) 1752292SN/A { 1762292SN/A return thread[tid].getLoadHeadSeqNum(); 1772292SN/A } 1782292SN/A 1792292SN/A /** Returns the head index of the store queue. */ 1806221Snate@binkert.org int getStoreHead(ThreadID tid) 1812329SN/A { return thread[tid].getStoreHead(); } 1822329SN/A 1832292SN/A /** Returns the sequence number of the head of the store queue. */ 1846221Snate@binkert.org InstSeqNum getStoreHeadSeqNum(ThreadID tid) 1852292SN/A { 1862292SN/A return thread[tid].getStoreHeadSeqNum(); 1872292SN/A } 1882292SN/A 1892292SN/A /** Returns the number of instructions in all of the queues. */ 1902292SN/A int getCount(); 1912292SN/A /** Returns the number of instructions in the queues of one thread. */ 1926221Snate@binkert.org int getCount(ThreadID tid) 1932329SN/A { return thread[tid].getCount(); } 1942292SN/A 1952292SN/A /** Returns the total number of loads in the load queue. */ 1962292SN/A int numLoads(); 1972292SN/A /** Returns the total number of loads for a single thread. */ 1986221Snate@binkert.org int numLoads(ThreadID tid) 1992329SN/A { return thread[tid].numLoads(); } 2002292SN/A 2012292SN/A /** Returns the total number of stores in the store queue. */ 2022292SN/A int numStores(); 2032292SN/A /** Returns the total number of stores for a single thread. */ 2046221Snate@binkert.org int numStores(ThreadID tid) 2052329SN/A { return thread[tid].numStores(); } 2062292SN/A 2072292SN/A /** Returns the number of free entries. */ 2082292SN/A unsigned numFreeEntries(); 2092292SN/A /** Returns the number of free entries for a specific thread. */ 2106221Snate@binkert.org unsigned numFreeEntries(ThreadID tid); 2112292SN/A 2122292SN/A /** Returns if the LSQ is full (either LQ or SQ is full). */ 2132292SN/A bool isFull(); 2142292SN/A /** 2152292SN/A * Returns if the LSQ is full for a specific thread (either LQ or SQ is 2162292SN/A * full). 2172292SN/A */ 2186221Snate@binkert.org bool isFull(ThreadID tid); 2192292SN/A 2209444SAndreas.Sandberg@ARM.com /** Returns if the LSQ is empty (both LQ and SQ are empty). */ 2219444SAndreas.Sandberg@ARM.com bool isEmpty() const; 2229444SAndreas.Sandberg@ARM.com /** Returns if all of the LQs are empty. */ 2239444SAndreas.Sandberg@ARM.com bool lqEmpty() const; 2249444SAndreas.Sandberg@ARM.com /** Returns if all of the SQs are empty. */ 2259444SAndreas.Sandberg@ARM.com bool sqEmpty() const; 2269444SAndreas.Sandberg@ARM.com 2272292SN/A /** Returns if any of the LQs are full. */ 2282292SN/A bool lqFull(); 2292292SN/A /** Returns if the LQ of a given thread is full. */ 2306221Snate@binkert.org bool lqFull(ThreadID tid); 2312292SN/A 2322292SN/A /** Returns if any of the SQs are full. */ 2332292SN/A bool sqFull(); 2342292SN/A /** Returns if the SQ of a given thread is full. */ 2356221Snate@binkert.org bool sqFull(ThreadID tid); 2362292SN/A 2372292SN/A /** 2382292SN/A * Returns if the LSQ is stalled due to a memory operation that must be 2392292SN/A * replayed. 2402292SN/A */ 2412292SN/A bool isStalled(); 2422292SN/A /** 2432292SN/A * Returns if the LSQ of a specific thread is stalled due to a memory 2442292SN/A * operation that must be replayed. 2452292SN/A */ 2466221Snate@binkert.org bool isStalled(ThreadID tid); 2472292SN/A 2482292SN/A /** Returns whether or not there are any stores to write back to memory. */ 2492292SN/A bool hasStoresToWB(); 2502329SN/A 2512292SN/A /** Returns whether or not a specific thread has any stores to write back 2522292SN/A * to memory. 2532292SN/A */ 2546221Snate@binkert.org bool hasStoresToWB(ThreadID tid) 2552329SN/A { return thread[tid].hasStoresToWB(); } 2562329SN/A 2572292SN/A /** Returns the number of stores a specific thread has to write back. */ 2586221Snate@binkert.org int numStoresToWB(ThreadID tid) 2592329SN/A { return thread[tid].numStoresToWB(); } 2602292SN/A 2612292SN/A /** Returns if the LSQ will write back to memory this cycle. */ 2622292SN/A bool willWB(); 2632292SN/A /** Returns if the LSQ of a specific thread will write back to memory this 2642292SN/A * cycle. 2652292SN/A */ 2666221Snate@binkert.org bool willWB(ThreadID tid) 2672329SN/A { return thread[tid].willWB(); } 2682292SN/A 2692907Sktlim@umich.edu /** Returns if the cache is currently blocked. */ 2709444SAndreas.Sandberg@ARM.com bool cacheBlocked() const 2716221Snate@binkert.org { return retryTid != InvalidThreadID; } 2722907Sktlim@umich.edu 2732907Sktlim@umich.edu /** Sets the retry thread id, indicating that one of the LSQUnits 2742907Sktlim@umich.edu * tried to access the cache but the cache was blocked. */ 2756221Snate@binkert.org void setRetryTid(ThreadID tid) 2762907Sktlim@umich.edu { retryTid = tid; } 2772907Sktlim@umich.edu 2782292SN/A /** Debugging function to print out all instructions. */ 2799440SAndreas.Sandberg@ARM.com void dumpInsts() const; 2802292SN/A /** Debugging function to print out instructions from a specific thread. */ 2819440SAndreas.Sandberg@ARM.com void dumpInsts(ThreadID tid) const 2822329SN/A { thread[tid].dumpInsts(); } 2832292SN/A 2846974Stjones1@inf.ed.ac.uk /** Executes a read operation, using the load specified at the load 2856974Stjones1@inf.ed.ac.uk * index. 2866974Stjones1@inf.ed.ac.uk */ 2876974Stjones1@inf.ed.ac.uk Fault read(RequestPtr req, RequestPtr sreqLow, RequestPtr sreqHigh, 2887520Sgblack@eecs.umich.edu uint8_t *data, int load_idx); 2892292SN/A 2902292SN/A /** Executes a store operation, using the store specified at the store 2916974Stjones1@inf.ed.ac.uk * index. 2922292SN/A */ 2936974Stjones1@inf.ed.ac.uk Fault write(RequestPtr req, RequestPtr sreqLow, RequestPtr sreqHigh, 2947520Sgblack@eecs.umich.edu uint8_t *data, int store_idx); 2952292SN/A 2968707Sandreas.hansson@arm.com /** 2978707Sandreas.hansson@arm.com * Retry the previous send that failed. 2988707Sandreas.hansson@arm.com */ 2998707Sandreas.hansson@arm.com void recvRetry(); 3008707Sandreas.hansson@arm.com 3018707Sandreas.hansson@arm.com /** 3028707Sandreas.hansson@arm.com * Handles writing back and completing the load or store that has 3038707Sandreas.hansson@arm.com * returned from memory. 3048707Sandreas.hansson@arm.com * 3058707Sandreas.hansson@arm.com * @param pkt Response packet from the memory sub-system 3068707Sandreas.hansson@arm.com */ 3078975Sandreas.hansson@arm.com bool recvTimingResp(PacketPtr pkt); 3088707Sandreas.hansson@arm.com 3098975Sandreas.hansson@arm.com void recvTimingSnoopReq(PacketPtr pkt); 3108948Sandreas.hansson@arm.com 3114329Sktlim@umich.edu /** The CPU pointer. */ 3124329Sktlim@umich.edu O3CPU *cpu; 3134329Sktlim@umich.edu 3144329Sktlim@umich.edu /** The IEW stage pointer. */ 3154329Sktlim@umich.edu IEW *iewStage; 3164329Sktlim@umich.edu 3172907Sktlim@umich.edu protected: 3182292SN/A /** The LSQ policy for SMT mode. */ 3192292SN/A LSQPolicy lsqPolicy; 3202292SN/A 3212292SN/A /** The LSQ units for individual threads. */ 3229868Sjthestness@gmail.com LSQUnit *thread; 3232292SN/A 3242292SN/A /** List of Active Threads in System. */ 3256221Snate@binkert.org std::list<ThreadID> *activeThreads; 3262292SN/A 3272292SN/A /** Total Size of LQ Entries. */ 3282292SN/A unsigned LQEntries; 3292292SN/A /** Total Size of SQ Entries. */ 3302292SN/A unsigned SQEntries; 3312292SN/A 3322292SN/A /** Max LQ Size - Used to Enforce Sharing Policies. */ 3332292SN/A unsigned maxLQEntries; 3342292SN/A 3352292SN/A /** Max SQ Size - Used to Enforce Sharing Policies. */ 3362292SN/A unsigned maxSQEntries; 3372292SN/A 3382292SN/A /** Number of Threads. */ 3396221Snate@binkert.org ThreadID numThreads; 3402907Sktlim@umich.edu 3412907Sktlim@umich.edu /** The thread id of the LSQ Unit that is currently waiting for a 3422907Sktlim@umich.edu * retry. */ 3436221Snate@binkert.org ThreadID retryTid; 3442292SN/A}; 3452292SN/A 3462292SN/Atemplate <class Impl> 3472292SN/AFault 3486974Stjones1@inf.ed.ac.ukLSQ<Impl>::read(RequestPtr req, RequestPtr sreqLow, RequestPtr sreqHigh, 3497520Sgblack@eecs.umich.edu uint8_t *data, int load_idx) 3502292SN/A{ 3516221Snate@binkert.org ThreadID tid = req->threadId(); 3522292SN/A 3536974Stjones1@inf.ed.ac.uk return thread[tid].read(req, sreqLow, sreqHigh, data, load_idx); 3542292SN/A} 3552292SN/A 3562292SN/Atemplate <class Impl> 3572292SN/AFault 3586974Stjones1@inf.ed.ac.ukLSQ<Impl>::write(RequestPtr req, RequestPtr sreqLow, RequestPtr sreqHigh, 3597520Sgblack@eecs.umich.edu uint8_t *data, int store_idx) 3602292SN/A{ 3616221Snate@binkert.org ThreadID tid = req->threadId(); 3622292SN/A 3636974Stjones1@inf.ed.ac.uk return thread[tid].write(req, sreqLow, sreqHigh, data, store_idx); 3642292SN/A} 3652292SN/A 3662292SN/A#endif // __CPU_O3_LSQ_HH__ 367