mshr_queue.hh revision 2991
1/* 2 * Copyright (c) 2003-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Erik Hallnor 29 */ 30 31/** @file 32 * Declaration of a structure to manage MSHRs. 33 */ 34 35#ifndef __MSHR_QUEUE_HH__ 36#define __MSHR_QUEUE_HH__ 37 38#include <vector> 39#include "mem/cache/miss/mshr.hh" 40 41/** 42 * A Class for maintaining a list of pending and allocated memory pktuests. 43 */ 44class MSHRQueue { 45 private: 46 /** MSHR storage. */ 47 MSHR* registers; 48 /** Holds pointers to all allocated MSHRs. */ 49 MSHR::List allocatedList; 50 /** Holds pointers to MSHRs that haven't been sent to the bus. */ 51 MSHR::List pendingList; 52 /** Holds non allocated MSHRs. */ 53 MSHR::List freeList; 54 55 // Parameters 56 /** 57 * The total number of MSHRs in this queue. This number is set as the 58 * number of MSHRs pktuested plus (numReserve - 1). This allows for 59 * the same number of effective MSHRs while still maintaining the reserve. 60 */ 61 const int numMSHRs; 62 63 /** 64 * The number of MSHRs to hold in reserve. This is needed because copy 65 * operations can allocate upto 4 MSHRs at one time. 66 */ 67 const int numReserve; 68 69 public: 70 /** 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