2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
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.
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.
28 * Authors: Erik Hallnor
33 * Declaration of a simple buffer for a blocking cache.
36 #ifndef __BLOCKING_BUFFER_HH__
37 #define __BLOCKING_BUFFER_HH__
41 #include "mem/cache/miss/mshr.hh"
42 #include "base/statistics.hh"
48 * Miss and writeback storage for a blocking cache.
60 /** Allocate on write misses. */
61 const bool writeAllocate;
63 /** Pointer to the parent cache. */
66 BasePrefetcher* prefetcher;
68 /** Block size of the parent cache. */
73 * @addtogroup CacheStatistics
76 /** Number of blocks written back per thread. */
77 Stats::Vector<> writebacks;
85 * Builds and initializes this buffer.
86 * @param write_allocate If true, treat write misses the same as reads.
88 BlockingBuffer(bool write_allocate)
89 : writeAllocate(write_allocate)
94 * Register statistics for this object.
95 * @param name The name of the parent cache.
97 void regStats(const std::string &name);
100 * Called by the parent cache to set the back pointer.
101 * @param _cache A pointer to the parent cache.
103 void setCache(BaseCache *_cache);
105 void setPrefetcher(BasePrefetcher *_prefetcher);
108 * Handle a cache miss properly. Requests the bus and marks the cache as
110 * @param pkt The request that missed in the cache.
111 * @param blk_size The block size of the cache.
112 * @param time The time the miss is detected.
114 void handleMiss(PacketPtr &pkt, int blk_size, Tick time);
117 * Fetch the block for the given address and buffer the given target.
118 * @param addr The address to fetch.
119 * @param asid The address space of the address.
120 * @param blk_size The block size of the cache.
121 * @param time The time the miss is detected.
122 * @param target The target for the fetch.
124 MSHR* fetchBlock(Addr addr, int blk_size, Tick time,
127 fatal("Unimplemented");
131 * Selects a outstanding request to service.
132 * @return The request to service, NULL if none found.
134 PacketPtr getPacket();
137 * Set the command to the given bus command.
138 * @param pkt The request to update.
139 * @param cmd The bus command to use.
141 void setBusCmd(PacketPtr &pkt, Packet::Command cmd);
144 * Restore the original command in case of a bus transmission error.
145 * @param pkt The request to reset.
147 void restoreOrigCmd(PacketPtr &pkt);
150 * Marks a request as in service (sent on the bus). This can have side
151 * effect since storage for no response commands is deallocated once they
152 * are successfully sent.
153 * @param pkt The request that was sent on the bus.
155 void markInService(PacketPtr &pkt, MSHR* mshr);
158 * Frees the resources of the request and unblock the cache.
159 * @param pkt The request that has been satisfied.
160 * @param time The time when the request is satisfied.
162 void handleResponse(PacketPtr &pkt, Tick time);
165 * Removes all outstanding requests for a given thread number. If a request
166 * has been sent to the bus, this function removes all of its targets.
167 * @param threadNum The thread number of the requests to squash.
169 void squash(int threadNum);
172 * Return the current number of outstanding misses.
173 * @return the number of outstanding misses.
177 return miss.getNumTargets();
181 * Searches for the supplied address in the miss "queue".
182 * @param addr The address to look for.
183 * @param asid The address space id.
184 * @return A pointer to miss if it matches.
186 MSHR* findMSHR(Addr addr)
188 if (miss.addr == addr && miss.pkt)
194 * Searches for the supplied address in the write buffer.
195 * @param addr The address to look for.
196 * @param asid The address space id.
197 * @param writes List of pointers to the matching writes.
198 * @return True if there is a matching write.
200 bool findWrites(Addr addr, std::vector<MSHR*>& writes)
202 if (wb.addr == addr && wb.pkt) {
203 writes.push_back(&wb);
212 * Perform a writeback of dirty data to the given address.
213 * @param addr The address to write to.
214 * @param asid The address space id.
215 * @param size The number of bytes to write.
216 * @param data The data to write, can be NULL.
217 * @param compressed True if the data is compressed.
219 void doWriteback(Addr addr,
220 int size, uint8_t *data, bool compressed);
223 * Perform a writeback request.
224 * @param pkt The writeback request.
226 void doWriteback(PacketPtr &pkt);
229 * Returns true if there are outstanding requests.
230 * @return True if there are outstanding requests.
234 return !miss.inService || !wb.inService;
238 * Add a target to the given MSHR. This assumes it is in the miss queue.
239 * @param mshr The mshr to add a target to.
240 * @param pkt The target to add.
242 void addTarget(MSHR *mshr, PacketPtr &pkt)
244 fatal("Shouldn't call this on a blocking buffer.");
248 * Dummy implmentation.
250 MSHR* allocateTargetList(Addr addr)
252 fatal("Unimplemented");
256 #endif // __BLOCKING_BUFFER_HH__