mshr_queue.hh revision 2991
15131Sgblack@eecs.umich.edu/* 25131Sgblack@eecs.umich.edu * Copyright (c) 2003-2005 The Regents of The University of Michigan 35131Sgblack@eecs.umich.edu * All rights reserved. 45131Sgblack@eecs.umich.edu * 55131Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 65131Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are 75131Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright 85131Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 95131Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 105131Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 115131Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution; 125131Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its 135131Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 145131Sgblack@eecs.umich.edu * this software without specific prior written permission. 155131Sgblack@eecs.umich.edu * 165131Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 175131Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 185131Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 195131Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 205131Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 215131Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 225131Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 235131Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 245131Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 255131Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 265131Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 275131Sgblack@eecs.umich.edu * 285131Sgblack@eecs.umich.edu * Authors: Erik Hallnor 295390Sgblack@eecs.umich.edu */ 305131Sgblack@eecs.umich.edu 315131Sgblack@eecs.umich.edu/** @file 325131Sgblack@eecs.umich.edu * Declaration of a structure to manage MSHRs. 338739Sgblack@eecs.umich.edu */ 345638Sgblack@eecs.umich.edu 355629Sgblack@eecs.umich.edu#ifndef __MSHR_QUEUE_HH__ 365131Sgblack@eecs.umich.edu#define __MSHR_QUEUE_HH__ 375637Sgblack@eecs.umich.edu 385637Sgblack@eecs.umich.edu#include <vector> 395637Sgblack@eecs.umich.edu#include "mem/cache/miss/mshr.hh" 405629Sgblack@eecs.umich.edu 415629Sgblack@eecs.umich.edu/** 428335Snate@binkert.org * A Class for maintaining a list of pending and allocated memory pktuests. 435630Sgblack@eecs.umich.edu */ 445630Sgblack@eecs.umich.educlass MSHRQueue { 455630Sgblack@eecs.umich.edu private: 468335Snate@binkert.org /** MSHR storage. */ 475633Sgblack@eecs.umich.edu MSHR* registers; 485636Sgblack@eecs.umich.edu /** Holds pointers to all allocated MSHRs. */ 495636Sgblack@eecs.umich.edu MSHR::List allocatedList; 508335Snate@binkert.org /** Holds pointers to MSHRs that haven't been sent to the bus. */ 515636Sgblack@eecs.umich.edu MSHR::List pendingList; 525818Sgblack@eecs.umich.edu /** Holds non allocated MSHRs. */ 535818Sgblack@eecs.umich.edu MSHR::List freeList; 548335Snate@binkert.org 555818Sgblack@eecs.umich.edu // Parameters 565831Sgblack@eecs.umich.edu /** 575831Sgblack@eecs.umich.edu * The total number of MSHRs in this queue. This number is set as the 588335Snate@binkert.org * number of MSHRs pktuested plus (numReserve - 1). This allows for 595831Sgblack@eecs.umich.edu * the same number of effective MSHRs while still maintaining the reserve. 605636Sgblack@eecs.umich.edu */ 615636Sgblack@eecs.umich.edu const int numMSHRs; 628335Snate@binkert.org 635636Sgblack@eecs.umich.edu /** 645643Sgblack@eecs.umich.edu * The number of MSHRs to hold in reserve. This is needed because copy 655643Sgblack@eecs.umich.edu * operations can allocate upto 4 MSHRs at one time. 668335Snate@binkert.org */ 675643Sgblack@eecs.umich.edu const int numReserve; 685633Sgblack@eecs.umich.edu 695633Sgblack@eecs.umich.edu public: 709807Sstever@gmail.com /** The number of allocated MSHRs. */ 71 int allocated; 72 /** The number of MSHRs that have been forwarded to the bus. */ 73 int inServiceMSHRs; 74 /** The number of targets waiting for response. */ 75 int allocatedTargets; 76 77 /** 78 * Create a queue with a given number of MSHRs. 79 * @param num_mshrs The number of MSHRs in this queue. 80 * @param reserve The minimum number of MSHRs needed to satisfy any access. 81 */ 82 MSHRQueue(int num_mshrs, int reserve = 1); 83 84 /** Destructor */ 85 ~MSHRQueue(); 86 87 /** 88 * Find the first MSHR that matches the provide address and asid. 89 * @param addr The address to find. 90 * @param asid The address space id. 91 * @return Pointer to the matching MSHR, null if not found. 92 */ 93 MSHR* findMatch(Addr addr) const; 94 95 /** 96 * Find and return all the matching MSHRs in the provided vector. 97 * @param addr The address to find. 98 * @param asid The address space ID. 99 * @param matches The vector to return pointers to the matching MSHRs. 100 * @return True if any matches are found, false otherwise. 101 * @todo Typedef the vector?? 102 */ 103 bool findMatches(Addr addr, std::vector<MSHR*>& matches) const; 104 105 /** 106 * Find any pending pktuests that overlap the given request. 107 * @param pkt The request to find. 108 * @return A pointer to the earliest matching MSHR. 109 */ 110 MSHR* findPending(Packet * &pkt) const; 111 112 /** 113 * Allocates a new MSHR for the pktuest and size. This places the request 114 * as the first target in the MSHR. 115 * @param pkt The request to handle. 116 * @param size The number in bytes to fetch from memory. 117 * @return The a pointer to the MSHR allocated. 118 * 119 * @pre There are free MSHRs. 120 */ 121 MSHR* allocate(Packet * &pkt, int size = 0); 122 123 /** 124 * Allocate a read pktuest for the given address, and places the given 125 * target on the target list. 126 * @param addr The address to fetch. 127 * @param asid The address space for the fetch. 128 * @param size The number of bytes to pktuest. 129 * @param target The first target for the pktuest. 130 * @return Pointer to the new MSHR. 131 */ 132 MSHR* allocateFetch(Addr addr, int size, Packet * &target); 133 134 /** 135 * Allocate a target list for the given address. 136 * @param addr The address to fetch. 137 * @param asid The address space for the fetch. 138 * @param size The number of bytes to pktuest. 139 * @return Pointer to the new MSHR. 140 */ 141 MSHR* allocateTargetList(Addr addr, int size); 142 143 /** 144 * Removes the given MSHR from the queue. This places the MSHR on the 145 * free list. 146 * @param mshr 147 */ 148 void deallocate(MSHR* mshr); 149 150 /** 151 * Allocates a target to the given MSHR. Used to keep track of the number 152 * of outstanding targets. 153 * @param mshr The MSHR to allocate the target to. 154 * @param pkt The target request. 155 */ 156 void allocateTarget(MSHR* mshr, Packet * &pkt) 157 { 158 mshr->allocateTarget(pkt); 159 allocatedTargets += 1; 160 } 161 162 /** 163 * Remove a MSHR from the queue. Returns an iterator into the allocatedList 164 * for faster squash implementation. 165 * @param mshr The MSHR to remove. 166 * @return An iterator to the next entry in the allocatedList. 167 */ 168 MSHR::Iterator deallocateOne(MSHR* mshr); 169 170 /** 171 * Moves the MSHR to the front of the pending list if it is not in service. 172 * @param mshr The mshr to move. 173 */ 174 void moveToFront(MSHR *mshr); 175 176 /** 177 * Mark the given MSHR as in service. This removes the MSHR from the 178 * pendingList. Deallocates the MSHR if it does not expect a response. 179 * @param mshr The MSHR to mark in service. 180 */ 181 void markInService(MSHR* mshr); 182 183 /** 184 * Mark an in service mshr as pending, used to resend a pktuest. 185 * @param mshr The MSHR to resend. 186 * @param cmd The command to resend. 187 */ 188 void markPending(MSHR* mshr, Packet::Command cmd); 189 190 /** 191 * Squash outstanding pktuests with the given thread number. If a request 192 * is in service, just squashes the targets. 193 * @param threadNum The thread to squash. 194 */ 195 void squash(int threadNum); 196 197 /** 198 * Returns true if the pending list is not empty. 199 * @return True if there are outstanding pktuests. 200 */ 201 bool havePending() const 202 { 203 return !pendingList.empty(); 204 } 205 206 /** 207 * Returns true if there are no free MSHRs. 208 * @return True if this queue is full. 209 */ 210 bool isFull() const 211 { 212 return (allocated > numMSHRs - numReserve); 213 } 214 215 /** 216 * Returns the pktuest at the head of the pendingList. 217 * @return The next pktuest to service. 218 */ 219 Packet * getReq() const 220 { 221 if (pendingList.empty()) { 222 return NULL; 223 } 224 MSHR* mshr = pendingList.front(); 225 return mshr->pkt; 226 } 227 228 /** 229 * Returns the number of outstanding targets. 230 * @return the number of allocated targets. 231 */ 232 int getAllocatedTargets() const 233 { 234 return allocatedTargets; 235 } 236 237}; 238 239#endif //__MSHR_QUEUE_HH__ 240