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 * Simobject instatiation of caches.
38 // Must be included first to determine which caches we want
39 #include "mem/config/cache.hh"
40 #include "mem/config/prefetch.hh"
42 #include "mem/cache/base_cache.hh"
43 #include "mem/cache/cache.hh"
45 #include "mem/cache/coherence/coherence_protocol.hh"
46 #include "sim/builder.hh"
49 #if defined(USE_CACHE_LRU)
50 #include "mem/cache/tags/lru.hh"
53 #if defined(USE_CACHE_FALRU)
54 #include "mem/cache/tags/fa_lru.hh"
57 #if defined(USE_CACHE_IIC)
58 #include "mem/cache/tags/iic.hh"
61 #if defined(USE_CACHE_SPLIT)
62 #include "mem/cache/tags/split.hh"
65 #if defined(USE_CACHE_SPLIT_LIFO)
66 #include "mem/cache/tags/split_lifo.hh"
69 // Compression Templates
70 #include "base/compression/null_compression.hh"
71 #include "base/compression/lzss_compression.hh"
73 // MissQueue Templates
74 #include "mem/cache/miss/miss_queue.hh"
75 #include "mem/cache/miss/blocking_buffer.hh"
77 // Coherence Templates
78 #include "mem/cache/coherence/uni_coherence.hh"
79 #include "mem/cache/coherence/simple_coherence.hh"
83 #include "mem/cache/prefetch/ghb_prefetcher.hh"
85 #if defined(USE_TAGGED)
86 #include "mem/cache/prefetch/tagged_prefetcher.hh"
88 #if defined(USE_STRIDED)
89 #include "mem/cache/prefetch/stride_prefetcher.hh"
94 using namespace TheISA
;
96 #ifndef DOXYGEN_SHOULD_SKIP_THIS
98 BEGIN_DECLARE_SIM_OBJECT_PARAMS(BaseCache
)
102 Param
<int> block_size
;
105 Param
<int> tgts_per_mshr
;
106 Param
<int> write_buffers
;
107 Param
<bool> prioritizeRequests
;
108 SimObjectParam
<CoherenceProtocol
*> protocol
;
109 Param
<Addr
> trace_addr
;
110 Param
<int> hash_delay
;
111 #if defined(USE_CACHE_IIC)
112 SimObjectParam
<Repl
*> repl
;
114 Param
<bool> compressed_bus
;
115 Param
<bool> store_compressed
;
116 Param
<bool> adaptive_compression
;
117 Param
<int> compression_latency
;
118 Param
<int> subblock_size
;
119 Param
<Counter
> max_miss_count
;
120 VectorParam
<Range
<Addr
> > addr_range
;
121 // SimObjectParam<MemTraceWriter *> mem_trace;
123 Param
<int> split_size
;
125 Param
<bool> two_queue
;
126 Param
<bool> prefetch_miss
;
127 Param
<bool> prefetch_access
;
128 Param
<int> prefetcher_size
;
129 Param
<bool> prefetch_past_page
;
130 Param
<bool> prefetch_serial_squash
;
131 Param
<Tick
> prefetch_latency
;
132 Param
<int> prefetch_degree
;
133 Param
<string
> prefetch_policy
;
134 Param
<bool> prefetch_cache_check_push
;
135 Param
<bool> prefetch_use_cpu_id
;
136 Param
<bool> prefetch_data_accesses_only
;
137 Param
<int> hit_latency
;
139 END_DECLARE_SIM_OBJECT_PARAMS(BaseCache
)
142 BEGIN_INIT_SIM_OBJECT_PARAMS(BaseCache
)
144 INIT_PARAM(size
, "capacity in bytes"),
145 INIT_PARAM(assoc
, "associativity"),
146 INIT_PARAM(block_size
, "block size in bytes"),
147 INIT_PARAM(latency
, "hit latency in CPU cycles"),
148 INIT_PARAM(mshrs
, "number of MSHRs (max outstanding requests)"),
149 INIT_PARAM(tgts_per_mshr
, "max number of accesses per MSHR"),
150 INIT_PARAM_DFLT(write_buffers
, "number of write buffers", 8),
151 INIT_PARAM_DFLT(prioritizeRequests
, "always service demand misses first",
153 INIT_PARAM_DFLT(protocol
, "coherence protocol to use in the cache", NULL
),
154 INIT_PARAM_DFLT(trace_addr
, "address to trace", 0),
156 INIT_PARAM_DFLT(hash_delay
, "time in cycles of hash access",1),
157 #if defined(USE_CACHE_IIC)
158 INIT_PARAM_DFLT(repl
, "replacement policy",NULL
),
160 INIT_PARAM_DFLT(compressed_bus
,
161 "This cache connects to a compressed memory",
163 INIT_PARAM_DFLT(store_compressed
, "Store compressed data in the cache",
165 INIT_PARAM_DFLT(adaptive_compression
, "Use an adaptive compression scheme",
167 INIT_PARAM_DFLT(compression_latency
,
168 "Latency in cycles of compression algorithm",
170 INIT_PARAM_DFLT(subblock_size
,
171 "Size of subblock in IIC used for compression",
173 INIT_PARAM_DFLT(max_miss_count
,
174 "The number of misses to handle before calling exit",
176 INIT_PARAM_DFLT(addr_range
, "The address range in bytes",
177 vector
<Range
<Addr
> >(1,RangeIn((Addr
)0, MaxAddr
))),
178 // INIT_PARAM_DFLT(mem_trace, "Memory trace to write accesses to", NULL),
179 INIT_PARAM_DFLT(split
, "Whether this is a partitioned cache", false),
180 INIT_PARAM_DFLT(split_size
, "the number of \"ways\" belonging to the LRU partition", 0),
181 INIT_PARAM_DFLT(lifo
, "whether you are using a LIFO repl. policy", false),
182 INIT_PARAM_DFLT(two_queue
, "whether the lifo should have two queue replacement", false),
183 INIT_PARAM_DFLT(prefetch_miss
, "wheter you are using the hardware prefetcher from Miss stream", false),
184 INIT_PARAM_DFLT(prefetch_access
, "wheter you are using the hardware prefetcher from Access stream", false),
185 INIT_PARAM_DFLT(prefetcher_size
, "Number of entries in the harware prefetch queue", 100),
186 INIT_PARAM_DFLT(prefetch_past_page
, "Allow prefetches to cross virtual page boundaries", false),
187 INIT_PARAM_DFLT(prefetch_serial_squash
, "Squash prefetches with a later time on a subsequent miss", false),
188 INIT_PARAM_DFLT(prefetch_latency
, "Latency of the prefetcher", 10),
189 INIT_PARAM_DFLT(prefetch_degree
, "Degree of the prefetch depth", 1),
190 INIT_PARAM_DFLT(prefetch_policy
, "Type of prefetcher to use", "none"),
191 INIT_PARAM_DFLT(prefetch_cache_check_push
, "Check if in cash on push or pop of prefetch queue", true),
192 INIT_PARAM_DFLT(prefetch_use_cpu_id
, "Use the CPU ID to seperate calculations of prefetches", true),
193 INIT_PARAM_DFLT(prefetch_data_accesses_only
, "Only prefetch on data not on instruction accesses", false),
194 INIT_PARAM_DFLT(hit_latency
, "Hit Latecny for a succesful access", 1)
195 END_INIT_SIM_OBJECT_PARAMS(BaseCache
)
198 #define BUILD_CACHE(TAGS, tags, c) \
200 BasePrefetcher *pf; \
201 if (pf_policy == "tagged") { \
202 BUILD_TAGGED_PREFETCHER(TAGS); \
204 else if (pf_policy == "stride") { \
205 BUILD_STRIDED_PREFETCHER(TAGS); \
207 else if (pf_policy == "ghb") { \
208 BUILD_GHB_PREFETCHER(TAGS); \
211 BUILD_NULL_PREFETCHER(TAGS); \
213 Cache<TAGS, c>::Params params(tags, mq, coh, base_params, \
214 pf, prefetch_access, hit_latency, \
217 adaptive_compression, \
219 compAlg, compression_latency, \
221 Cache<TAGS, c> *retval = \
222 new Cache<TAGS, c>(getInstanceName(), params); \
226 #define BUILD_CACHE_PANIC(x) do { \
227 panic("%s not compiled into M5", x); \
230 #define BUILD_COMPRESSED_CACHE(TAGS, tags, c) \
232 CompressionAlgorithm *compAlg; \
233 if (compressed_bus || store_compressed) { \
234 compAlg = new LZSSCompression(); \
236 compAlg = new NullCompression(); \
238 BUILD_CACHE(TAGS, tags, c); \
241 #if defined(USE_CACHE_FALRU)
242 #define BUILD_FALRU_CACHE(c) do { \
243 FALRU *tags = new FALRU(block_size, size, latency); \
244 BUILD_COMPRESSED_CACHE(FALRU, tags, c); \
247 #define BUILD_FALRU_CACHE(c) BUILD_CACHE_PANIC("falru cache")
250 #if defined(USE_CACHE_LRU)
251 #define BUILD_LRU_CACHE(c) do { \
252 LRU *tags = new LRU(numSets, block_size, assoc, latency); \
253 BUILD_COMPRESSED_CACHE(LRU, tags, c); \
256 #define BUILD_LRU_CACHE(c) BUILD_CACHE_PANIC("lru cache")
259 #if defined(USE_CACHE_SPLIT)
260 #define BUILD_SPLIT_CACHE(c) do { \
261 Split *tags = new Split(numSets, block_size, assoc, split_size, lifo, \
262 two_queue, latency); \
263 BUILD_COMPRESSED_CACHE(Split, tags, c); \
266 #define BUILD_SPLIT_CACHE(c) BUILD_CACHE_PANIC("split cache")
269 #if defined(USE_CACHE_SPLIT_LIFO)
270 #define BUILD_SPLIT_LIFO_CACHE(c) do { \
271 SplitLIFO *tags = new SplitLIFO(block_size, size, assoc, \
272 latency, two_queue, -1); \
273 BUILD_COMPRESSED_CACHE(SplitLIFO, tags, c); \
276 #define BUILD_SPLIT_LIFO_CACHE(c) BUILD_CACHE_PANIC("lifo cache")
279 #if defined(USE_CACHE_IIC)
280 #define BUILD_IIC_CACHE(c) do { \
281 IIC *tags = new IIC(iic_params); \
282 BUILD_COMPRESSED_CACHE(IIC, tags, c); \
285 #define BUILD_IIC_CACHE(c) BUILD_CACHE_PANIC("iic")
288 #define BUILD_CACHES(c) do { \
289 if (repl == NULL) { \
290 if (numSets == 1) { \
291 BUILD_FALRU_CACHE(c); \
293 if (split == true) { \
294 BUILD_SPLIT_CACHE(c); \
295 } else if (lifo == true) { \
296 BUILD_SPLIT_LIFO_CACHE(c); \
298 BUILD_LRU_CACHE(c); \
302 BUILD_IIC_CACHE(c); \
306 #define BUILD_COHERENCE(b) do { \
307 if (protocol == NULL) { \
308 UniCoherence *coh = new UniCoherence(); \
309 BUILD_CACHES(UniCoherence); \
311 SimpleCoherence *coh = new SimpleCoherence(protocol); \
312 BUILD_CACHES(SimpleCoherence); \
316 #if defined(USE_TAGGED)
317 #define BUILD_TAGGED_PREFETCHER(t) \
318 pf = new TaggedPrefetcher(prefetcher_size, \
319 !prefetch_past_page, \
320 prefetch_serial_squash, \
321 prefetch_cache_check_push, \
322 prefetch_data_accesses_only, \
326 #define BUILD_TAGGED_PREFETCHER(t) BUILD_CACHE_PANIC("Tagged Prefetcher")
329 #if defined(USE_STRIDED)
330 #define BUILD_STRIDED_PREFETCHER(t) \
331 pf = new StridePrefetcher(prefetcher_size, \
332 !prefetch_past_page, \
333 prefetch_serial_squash, \
334 prefetch_cache_check_push, \
335 prefetch_data_accesses_only, \
340 #define BUILD_STRIDED_PREFETCHER(t) BUILD_CACHE_PANIC("Stride Prefetcher")
344 #define BUILD_GHB_PREFETCHER(t) \
345 pf = new GHBPrefetcher(prefetcher_size, \
346 !prefetch_past_page, \
347 prefetch_serial_squash, \
348 prefetch_cache_check_push, \
349 prefetch_data_accesses_only, \
354 #define BUILD_GHB_PREFETCHER(t) BUILD_CACHE_PANIC("GHB Prefetcher")
357 #if defined(USE_TAGGED)
358 #define BUILD_NULL_PREFETCHER(t) \
359 pf = new TaggedPrefetcher(prefetcher_size, \
360 !prefetch_past_page, \
361 prefetch_serial_squash, \
362 prefetch_cache_check_push, \
363 prefetch_data_accesses_only, \
367 #define BUILD_NULL_PREFETCHER(t) BUILD_CACHE_PANIC("NULL Prefetcher (uses Tagged)")
370 CREATE_SIM_OBJECT(BaseCache
)
372 string name
= getInstanceName();
373 int numSets
= size
/ (assoc
* block_size
);
374 string pf_policy
= prefetch_policy
;
375 if (subblock_size
== 0) {
376 subblock_size
= block_size
;
379 // Build BaseCache param object
380 BaseCache::Params
base_params(addr_range
, latency
,
381 block_size
, max_miss_count
);
383 //Warnings about prefetcher policy
384 if (pf_policy
== "none" && (prefetch_miss
|| prefetch_access
)) {
385 panic("With no prefetcher, you shouldn't prefetch from"
386 " either miss or access stream\n");
388 if ((pf_policy
== "tagged" || pf_policy
== "stride" ||
389 pf_policy
== "ghb") && !(prefetch_miss
|| prefetch_access
)) {
390 warn("With this prefetcher you should chose a prefetch"
391 " stream (miss or access)\nNo Prefetching will occur\n");
393 if ((pf_policy
== "tagged" || pf_policy
== "stride" ||
394 pf_policy
== "ghb") && prefetch_miss
&& prefetch_access
) {
395 panic("Can't do prefetches from both miss and access"
398 if (pf_policy
!= "tagged" && pf_policy
!= "stride" &&
399 pf_policy
!= "ghb" && pf_policy
!= "none") {
400 panic("Unrecognized form of a prefetcher: %s, try using"
401 "['none','stride','tagged','ghb']\n", pf_policy
);
404 #if defined(USE_CACHE_IIC)
406 IIC::Params iic_params
;
407 iic_params
.size
= size
;
408 iic_params
.numSets
= numSets
;
409 iic_params
.blkSize
= block_size
;
410 iic_params
.assoc
= assoc
;
411 iic_params
.hashDelay
= hash_delay
;
412 iic_params
.hitLatency
= latency
;
413 iic_params
.rp
= repl
;
414 iic_params
.subblockSize
= subblock_size
;
416 const void *repl
= NULL
;
419 if (mshrs
== 1 /*|| out_bus->doEvents() == false*/) {
420 BlockingBuffer
*mq
= new BlockingBuffer(true);
421 BUILD_COHERENCE(BlockingBuffer
);
423 MissQueue
*mq
= new MissQueue(mshrs
, tgts_per_mshr
, write_buffers
,
424 true, prefetch_miss
);
425 BUILD_COHERENCE(MissQueue
);
430 REGISTER_SIM_OBJECT("BaseCache", BaseCache
)
433 #endif //DOXYGEN_SHOULD_SKIP_THIS