Was having difficulty with merging the cache, reverted to an early version and will...
[gem5.git] / src / mem / cache / coherence / simple_coherence.hh
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 /**
32 * @file
33 * Declaration of a simple coherence policy.
34 */
35
36 #ifndef __SIMPLE_COHERENCE_HH__
37 #define __SIMPLE_COHERENCE_HH__
38
39 #include <string>
40
41 #include "mem/packet.hh"
42 #include "mem/mem_cmd.hh"
43 #include "mem/cache/cache_blk.hh"
44 #include "mem/cache/miss/mshr_queue.hh"
45 #include "mem/cache/coherence/coherence_protocol.hh"
46
47 class BaseCache;
48
49 /**
50 * A simple MP coherence policy. This policy assumes an atomic bus and only one
51 * level of cache.
52 */
53 class SimpleCoherence
54 {
55 protected:
56 /** Pointer to the parent cache. */
57 BaseCache *cache;
58 /** Pointer to the coherence protocol. */
59 CoherenceProtocol *protocol;
60
61 public:
62 /**
63 * Construct and initialize this coherence policy.
64 * @param _protocol The coherence protocol to use.
65 */
66 SimpleCoherence(CoherenceProtocol *_protocol)
67 : protocol(_protocol)
68 {
69 }
70
71 /**
72 * Set the pointer to the parent cache.
73 * @param _cache The parent cache.
74 */
75 void setCache(BaseCache *_cache)
76 {
77 cache = _cache;
78 }
79
80 /**
81 * Register statistics.
82 * @param name The name to prepend to stat descriptions.
83 */
84 void regStats(const std::string &name)
85 {
86 }
87
88 /**
89 * This policy does not forward invalidates, return NULL.
90 * @return NULL.
91 */
92 Packet * getPacket()
93 {
94 return NULL;
95 }
96
97 /**
98 * Return the proper state given the current state and the bus response.
99 * @param req The bus response.
100 * @param current The current block state.
101 * @return The new state.
102 */
103 CacheBlk::State getNewState(Packet * &pkt, CacheBlk::State current)
104 {
105 return protocol->getNewState(pkt, current);
106 }
107
108 /**
109 * Handle snooped bus requests.
110 * @param req The snooped bus request.
111 * @param blk The cache block corresponding to the request, if any.
112 * @param mshr The MSHR corresponding to the request, if any.
113 * @param new_state Return the new state for the block.
114 */
115 bool handleBusRequest(Packet * &pkt, CacheBlk *blk, MSHR *mshr,
116 CacheBlk::State &new_state)
117 {
118 // assert(mshr == NULL);
119 //Got rid of, there could be an MSHR, but it can't be in service
120 if (blk != NULL)
121 {
122 if (pkt->cmd != Writeback) {
123 return protocol->handleBusRequest(cache, pkt, blk, mshr,
124 new_state);
125 }
126 else { //It is a writeback, must be ownership protocol, just keep state
127 new_state = blk->status;
128 }
129 }
130 return false;
131 }
132
133 /**
134 * Get the proper bus command for the given command and status.
135 * @param cmd The request's command.
136 * @param state The current state of the cache block.
137 * @return The proper bus command, as determined by the protocol.
138 */
139 Packet::Command getBusCmd(Packet::Command &cmd, CacheBlk::State state)
140 {
141 if (cmd == Writeback) return Writeback;
142 return protocol->getBusCmd(cmd, state);
143 }
144
145 /**
146 * Return true if this coherence policy can handle fast cache writes.
147 */
148 bool allowFastWrites() { return false; }
149
150 bool hasProtocol() { return true; }
151 };
152
153 #endif //__SIMPLE_COHERENCE_HH__
154
155
156
157
158
159
160
161