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
34 * Declaration of a simple coherence policy.
37 #ifndef __SIMPLE_COHERENCE_HH__
38 #define __SIMPLE_COHERENCE_HH__
42 #include "mem/packet.hh"
43 #include "mem/cache/cache_blk.hh"
44 #include "mem/cache/miss/mshr_queue.hh"
45 #include "mem/cache/coherence/coherence_protocol.hh"
50 * A simple MP coherence policy. This policy assumes an atomic bus and only one
56 /** Pointer to the parent cache. */
58 /** Pointer to the coherence protocol. */
59 CoherenceProtocol *protocol;
63 * Construct and initialize this coherence policy.
64 * @param _protocol The coherence protocol to use.
66 SimpleCoherence(CoherenceProtocol *_protocol)
72 * Set the pointer to the parent cache.
73 * @param _cache The parent cache.
75 void setCache(BaseCache *_cache)
81 * Register statistics.
82 * @param name The name to prepend to stat descriptions.
84 void regStats(const std::string &name)
89 * This policy does not forward invalidates, return NULL.
98 * Was the CSHR request was sent successfully?
99 * @param pkt The request.
100 * @param success True if the request was sent successfully.
102 void sendResult(PacketPtr &pkt, MSHR* cshr, bool success)
110 * Return the proper state given the current state and the bus response.
111 * @param pkt The bus response.
112 * @param current The current block state.
113 * @return The new state.
115 CacheBlk::State getNewState(PacketPtr &pkt, CacheBlk::State current)
117 return protocol->getNewState(pkt, current);
121 * Handle snooped bus requests.
122 * @param pkt The snooped bus request.
123 * @param blk The cache block corresponding to the request, if any.
124 * @param mshr The MSHR corresponding to the request, if any.
125 * @param new_state Return the new state for the block.
127 bool handleBusRequest(PacketPtr &pkt, CacheBlk *blk, MSHR *mshr,
128 CacheBlk::State &new_state)
130 // assert(mshr == NULL);
131 //Got rid of, there could be an MSHR, but it can't be in service
134 if (pkt->cmd != Packet::Writeback) {
135 return protocol->handleBusRequest(cache, pkt, blk, mshr,
138 else { //It is a writeback, must be ownership protocol, just keep state
139 new_state = blk->status;
146 * Get the proper bus command for the given command and status.
147 * @param cmd The request's command.
148 * @param state The current state of the cache block.
149 * @return The proper bus command, as determined by the protocol.
151 Packet::Command getBusCmd(Packet::Command &cmd, CacheBlk::State state)
153 if (cmd == Packet::Writeback) return Packet::Writeback;
154 return protocol->getBusCmd(cmd, state);
158 * Return true if this coherence policy can handle fast cache writes.
160 bool allowFastWrites() { return false; }
162 bool hasProtocol() { return true; }
164 void propogateInvalidate(PacketPtr pkt, bool isTiming)
166 //For now we do nothing, asssumes simple coherence is top level of cache
171 #endif //__SIMPLE_COHERENCE_HH__