mshr_queue.hh revision 9725:0d4ee33078bb
113771Sgabeblack@google.com/* 213771Sgabeblack@google.com * Copyright (c) 2012-2013 ARM Limited 313771Sgabeblack@google.com * All rights reserved. 413771Sgabeblack@google.com * 513771Sgabeblack@google.com * The license below extends only to copyright in the software and shall 613771Sgabeblack@google.com * not be construed as granting a license to any other intellectual 713771Sgabeblack@google.com * property including but not limited to intellectual property relating 813771Sgabeblack@google.com * to a hardware implementation of the functionality of the software 913771Sgabeblack@google.com * licensed hereunder. You may use the software subject to the license 1013771Sgabeblack@google.com * terms below provided that you ensure that this notice is replicated 1113771Sgabeblack@google.com * unmodified and in its entirety in all distributions of the software, 1213771Sgabeblack@google.com * modified or unmodified, in source code or in binary form. 1313771Sgabeblack@google.com * 1413771Sgabeblack@google.com * Copyright (c) 2003-2005 The Regents of The University of Michigan 1513771Sgabeblack@google.com * All rights reserved. 1613771Sgabeblack@google.com * 1713771Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 1813771Sgabeblack@google.com * modification, are permitted provided that the following conditions are 1913771Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 2013771Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 2113771Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 2213771Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 2313771Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 2413771Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 2513771Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 2613771Sgabeblack@google.com * this software without specific prior written permission. 2713771Sgabeblack@google.com * 2813771Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2913771Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3013771Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 3113771Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3213771Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3313771Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3413771Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3513771Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3613771Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3713771Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3813771Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3913771Sgabeblack@google.com * 4013771Sgabeblack@google.com * Authors: Erik Hallnor 4113771Sgabeblack@google.com * Andreas Sandberg 4213771Sgabeblack@google.com */ 4313771Sgabeblack@google.com 4413771Sgabeblack@google.com/** @file 4513771Sgabeblack@google.com * Declaration of a structure to manage MSHRs. 4613771Sgabeblack@google.com */ 4713771Sgabeblack@google.com 4813771Sgabeblack@google.com#ifndef __MEM__CACHE__MISS__MSHR_QUEUE_HH__ 4913771Sgabeblack@google.com#define __MEM__CACHE__MISS__MSHR_QUEUE_HH__ 5013771Sgabeblack@google.com 5113771Sgabeblack@google.com#include <vector> 5213771Sgabeblack@google.com 5313771Sgabeblack@google.com#include "mem/cache/mshr.hh" 5413771Sgabeblack@google.com#include "mem/packet.hh" 5513771Sgabeblack@google.com#include "sim/drain.hh" 5613771Sgabeblack@google.com 5713771Sgabeblack@google.com/** 5813771Sgabeblack@google.com * A Class for maintaining a list of pending and allocated memory requests. 5913771Sgabeblack@google.com */ 6013771Sgabeblack@google.comclass MSHRQueue : public Drainable 6113771Sgabeblack@google.com{ 6213771Sgabeblack@google.com private: 6313771Sgabeblack@google.com /** Local label (for functional print requests) */ 6413771Sgabeblack@google.com const std::string label; 6513771Sgabeblack@google.com 6613782Sgabeblack@google.com // Parameters 6713771Sgabeblack@google.com /** 6813771Sgabeblack@google.com * The total number of entries in this queue. This number is set as the 6913771Sgabeblack@google.com * number of entries requested plus (numReserve - 1). This allows for 7013771Sgabeblack@google.com * the same number of effective entries while still maintaining the reserve. 7113771Sgabeblack@google.com */ 7213771Sgabeblack@google.com const int numEntries; 7313771Sgabeblack@google.com 7413771Sgabeblack@google.com /** 7514189Sgabeblack@google.com * The number of entries to hold in reserve. This is needed because copy 7614189Sgabeblack@google.com * operations can allocate upto 4 entries at one time. 7714189Sgabeblack@google.com */ 7814189Sgabeblack@google.com const int numReserve; 7914189Sgabeblack@google.com 8014189Sgabeblack@google.com /** MSHR storage. */ 8114189Sgabeblack@google.com std::vector<MSHR> registers; 8213782Sgabeblack@google.com /** Holds pointers to all allocated entries. */ 8313782Sgabeblack@google.com MSHR::List allocatedList; 8413782Sgabeblack@google.com /** Holds pointers to entries that haven't been sent to the bus. */ 8513782Sgabeblack@google.com MSHR::List readyList; 8613771Sgabeblack@google.com /** Holds non allocated entries. */ 8713771Sgabeblack@google.com MSHR::List freeList; 8813771Sgabeblack@google.com 8913771Sgabeblack@google.com /** Drain manager to inform of a completed drain */ 9013771Sgabeblack@google.com DrainManager *drainManager; 9113771Sgabeblack@google.com 9213771Sgabeblack@google.com MSHR::Iterator addToReadyList(MSHR *mshr); 9313771Sgabeblack@google.com 9413771Sgabeblack@google.com 9513771Sgabeblack@google.com public: 9613771Sgabeblack@google.com /** The number of allocated entries. */ 9713771Sgabeblack@google.com int allocated; 9813771Sgabeblack@google.com /** The number of entries that have been forwarded to the bus. */ 9913771Sgabeblack@google.com int inServiceEntries; 10013771Sgabeblack@google.com /** The index of this queue within the cache (MSHR queue vs. write 10113771Sgabeblack@google.com * buffer). */ 10214189Sgabeblack@google.com const int index; 10314189Sgabeblack@google.com 10414189Sgabeblack@google.com /** 10513771Sgabeblack@google.com * Create a queue with a given number of entries. 10613771Sgabeblack@google.com * @param num_entrys The number of entries in this queue. 10713771Sgabeblack@google.com * @param reserve The minimum number of entries needed to satisfy 10813771Sgabeblack@google.com * any access. 10913771Sgabeblack@google.com */ 11013771Sgabeblack@google.com MSHRQueue(const std::string &_label, int num_entries, int reserve, 11113782Sgabeblack@google.com int index); 11214189Sgabeblack@google.com 11314189Sgabeblack@google.com /** 11414189Sgabeblack@google.com * Find the first MSHR that matches the provided address. 11514189Sgabeblack@google.com * @param addr The address to find. 11614189Sgabeblack@google.com * @return Pointer to the matching MSHR, null if not found. 11714189Sgabeblack@google.com */ 11813782Sgabeblack@google.com MSHR *findMatch(Addr addr) const; 11913782Sgabeblack@google.com 12014189Sgabeblack@google.com /** 12114189Sgabeblack@google.com * Find and return all the matching entries in the provided vector. 12214189Sgabeblack@google.com * @param addr The address to find. 12314189Sgabeblack@google.com * @param matches The vector to return pointers to the matching entries. 12414189Sgabeblack@google.com * @return True if any matches are found, false otherwise. 12514189Sgabeblack@google.com * @todo Typedef the vector?? 12613782Sgabeblack@google.com */ 12713782Sgabeblack@google.com bool findMatches(Addr addr, std::vector<MSHR*>& matches) const; 12813782Sgabeblack@google.com 12914190Sgabeblack@google.com /** 13014190Sgabeblack@google.com * Find any pending requests that overlap the given request. 13114190Sgabeblack@google.com * @param pkt The request to find. 13214190Sgabeblack@google.com * @return A pointer to the earliest matching MSHR. 13314190Sgabeblack@google.com */ 13414190Sgabeblack@google.com MSHR *findPending(Addr addr, int size) const; 13514190Sgabeblack@google.com 13614190Sgabeblack@google.com bool checkFunctional(PacketPtr pkt, Addr blk_addr); 13714190Sgabeblack@google.com 13814190Sgabeblack@google.com /** 13914190Sgabeblack@google.com * Allocates a new MSHR for the request and size. This places the request 14014190Sgabeblack@google.com * as the first target in the MSHR. 14114190Sgabeblack@google.com * @param pkt The request to handle. 14214190Sgabeblack@google.com * @param size The number in bytes to fetch from memory. 14314190Sgabeblack@google.com * @return The a pointer to the MSHR allocated. 14414190Sgabeblack@google.com * 14514190Sgabeblack@google.com * @pre There are free entries. 14614190Sgabeblack@google.com */ 14714190Sgabeblack@google.com MSHR *allocate(Addr addr, int size, PacketPtr &pkt, 14813771Sgabeblack@google.com Tick when, Counter order); 14913771Sgabeblack@google.com 15014191Sgabeblack@google.com /** 15114191Sgabeblack@google.com * Removes the given MSHR from the queue. This places the MSHR on the 15214191Sgabeblack@google.com * free list. 15314191Sgabeblack@google.com * @param mshr 15414191Sgabeblack@google.com */ 15514191Sgabeblack@google.com void deallocate(MSHR *mshr); 15614191Sgabeblack@google.com 15713771Sgabeblack@google.com /** 158 * Remove a MSHR from the queue. Returns an iterator into the 159 * allocatedList for faster squash implementation. 160 * @param mshr The MSHR to remove. 161 * @return An iterator to the next entry in the allocatedList. 162 */ 163 MSHR::Iterator deallocateOne(MSHR *mshr); 164 165 /** 166 * Moves the MSHR to the front of the pending list if it is not 167 * in service. 168 * @param mshr The entry to move. 169 */ 170 void moveToFront(MSHR *mshr); 171 172 /** 173 * Mark the given MSHR as in service. This removes the MSHR from the 174 * readyList. Deallocates the MSHR if it does not expect a response. 175 * @param mshr The MSHR to mark in service. 176 */ 177 void markInService(MSHR *mshr, PacketPtr pkt); 178 179 /** 180 * Mark an in service entry as pending, used to resend a request. 181 * @param mshr The MSHR to resend. 182 */ 183 void markPending(MSHR *mshr); 184 185 /** 186 * Squash outstanding requests with the given thread number. If a request 187 * is in service, just squashes the targets. 188 * @param threadNum The thread to squash. 189 */ 190 void squash(int threadNum); 191 192 /** 193 * Returns true if the pending list is not empty. 194 * @return True if there are outstanding requests. 195 */ 196 bool havePending() const 197 { 198 return !readyList.empty(); 199 } 200 201 /** 202 * Returns true if there are no free entries. 203 * @return True if this queue is full. 204 */ 205 bool isFull() const 206 { 207 return (allocated > numEntries - numReserve); 208 } 209 210 /** 211 * Returns the MSHR at the head of the readyList. 212 * @return The next request to service. 213 */ 214 MSHR *getNextMSHR() const 215 { 216 if (readyList.empty() || readyList.front()->readyTime > curTick()) { 217 return NULL; 218 } 219 return readyList.front(); 220 } 221 222 Tick nextMSHRReadyTime() const 223 { 224 return readyList.empty() ? MaxTick : readyList.front()->readyTime; 225 } 226 227 unsigned int drain(DrainManager *dm); 228}; 229 230#endif //__MEM__CACHE__MISS__MSHR_QUEUE_HH__ 231