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
;
138 END_DECLARE_SIM_OBJECT_PARAMS(BaseCache
)
141 BEGIN_INIT_SIM_OBJECT_PARAMS(BaseCache
)
143 INIT_PARAM(size
, "capacity in bytes"),
144 INIT_PARAM(assoc
, "associativity"),
145 INIT_PARAM(block_size
, "block size in bytes"),
146 INIT_PARAM(latency
, "hit latency in CPU cycles"),
147 INIT_PARAM(mshrs
, "number of MSHRs (max outstanding requests)"),
148 INIT_PARAM(tgts_per_mshr
, "max number of accesses per MSHR"),
149 INIT_PARAM_DFLT(write_buffers
, "number of write buffers", 8),
150 INIT_PARAM_DFLT(prioritizeRequests
, "always service demand misses first",
152 INIT_PARAM_DFLT(protocol
, "coherence protocol to use in the cache", NULL
),
153 INIT_PARAM_DFLT(trace_addr
, "address to trace", 0),
155 INIT_PARAM_DFLT(hash_delay
, "time in cycles of hash access",1),
156 #if defined(USE_CACHE_IIC)
157 INIT_PARAM_DFLT(repl
, "replacement policy",NULL
),
159 INIT_PARAM_DFLT(compressed_bus
,
160 "This cache connects to a compressed memory",
162 INIT_PARAM_DFLT(store_compressed
, "Store compressed data in the cache",
164 INIT_PARAM_DFLT(adaptive_compression
, "Use an adaptive compression scheme",
166 INIT_PARAM_DFLT(compression_latency
,
167 "Latency in cycles of compression algorithm",
169 INIT_PARAM_DFLT(subblock_size
,
170 "Size of subblock in IIC used for compression",
172 INIT_PARAM_DFLT(max_miss_count
,
173 "The number of misses to handle before calling exit",
175 INIT_PARAM_DFLT(addr_range
, "The address range in bytes",
176 vector
<Range
<Addr
> >(1,RangeIn((Addr
)0, MaxAddr
))),
177 // INIT_PARAM_DFLT(mem_trace, "Memory trace to write accesses to", NULL),
178 INIT_PARAM_DFLT(split
, "Whether this is a partitioned cache", false),
179 INIT_PARAM_DFLT(split_size
, "the number of \"ways\" belonging to the LRU partition", 0),
180 INIT_PARAM_DFLT(lifo
, "whether you are using a LIFO repl. policy", false),
181 INIT_PARAM_DFLT(two_queue
, "whether the lifo should have two queue replacement", false),
182 INIT_PARAM_DFLT(prefetch_miss
, "wheter you are using the hardware prefetcher from Miss stream", false),
183 INIT_PARAM_DFLT(prefetch_access
, "wheter you are using the hardware prefetcher from Access stream", false),
184 INIT_PARAM_DFLT(prefetcher_size
, "Number of entries in the harware prefetch queue", 100),
185 INIT_PARAM_DFLT(prefetch_past_page
, "Allow prefetches to cross virtual page boundaries", false),
186 INIT_PARAM_DFLT(prefetch_serial_squash
, "Squash prefetches with a later time on a subsequent miss", false),
187 INIT_PARAM_DFLT(prefetch_latency
, "Latency of the prefetcher", 10),
188 INIT_PARAM_DFLT(prefetch_degree
, "Degree of the prefetch depth", 1),
189 INIT_PARAM_DFLT(prefetch_policy
, "Type of prefetcher to use", "none"),
190 INIT_PARAM_DFLT(prefetch_cache_check_push
, "Check if in cash on push or pop of prefetch queue", true),
191 INIT_PARAM_DFLT(prefetch_use_cpu_id
, "Use the CPU ID to seperate calculations of prefetches", true),
192 INIT_PARAM_DFLT(prefetch_data_accesses_only
, "Only prefetch on data not on instruction accesses", false)
193 END_INIT_SIM_OBJECT_PARAMS(BaseCache
)
196 #define BUILD_CACHE(TAGS, tags, c) \
198 BasePrefetcher *pf; \
199 if (pf_policy == "tagged") { \
200 BUILD_TAGGED_PREFETCHER(TAGS); \
202 else if (pf_policy == "stride") { \
203 BUILD_STRIDED_PREFETCHER(TAGS); \
205 else if (pf_policy == "ghb") { \
206 BUILD_GHB_PREFETCHER(TAGS); \
209 BUILD_NULL_PREFETCHER(TAGS); \
211 Cache<TAGS, c>::Params params(tags, mq, coh, base_params, \
212 pf, prefetch_access, latency, \
215 adaptive_compression, \
217 compAlg, compression_latency, \
219 Cache<TAGS, c> *retval = \
220 new Cache<TAGS, c>(getInstanceName(), params); \
224 #define BUILD_CACHE_PANIC(x) do { \
225 panic("%s not compiled into M5", x); \
228 #define BUILD_COMPRESSED_CACHE(TAGS, tags, c) \
230 CompressionAlgorithm *compAlg; \
231 if (compressed_bus || store_compressed) { \
232 compAlg = new LZSSCompression(); \
234 compAlg = new NullCompression(); \
236 BUILD_CACHE(TAGS, tags, c); \
239 #if defined(USE_CACHE_FALRU)
240 #define BUILD_FALRU_CACHE(c) do { \
241 FALRU *tags = new FALRU(block_size, size, latency); \
242 BUILD_COMPRESSED_CACHE(FALRU, tags, c); \
245 #define BUILD_FALRU_CACHE(c) BUILD_CACHE_PANIC("falru cache")
248 #if defined(USE_CACHE_LRU)
249 #define BUILD_LRU_CACHE(c) do { \
250 LRU *tags = new LRU(numSets, block_size, assoc, latency); \
251 BUILD_COMPRESSED_CACHE(LRU, tags, c); \
254 #define BUILD_LRU_CACHE(c) BUILD_CACHE_PANIC("lru cache")
257 #if defined(USE_CACHE_SPLIT)
258 #define BUILD_SPLIT_CACHE(c) do { \
259 Split *tags = new Split(numSets, block_size, assoc, split_size, lifo, \
260 two_queue, latency); \
261 BUILD_COMPRESSED_CACHE(Split, tags, c); \
264 #define BUILD_SPLIT_CACHE(c) BUILD_CACHE_PANIC("split cache")
267 #if defined(USE_CACHE_SPLIT_LIFO)
268 #define BUILD_SPLIT_LIFO_CACHE(c) do { \
269 SplitLIFO *tags = new SplitLIFO(block_size, size, assoc, \
270 latency, two_queue, -1); \
271 BUILD_COMPRESSED_CACHE(SplitLIFO, tags, c); \
274 #define BUILD_SPLIT_LIFO_CACHE(c) BUILD_CACHE_PANIC("lifo cache")
277 #if defined(USE_CACHE_IIC)
278 #define BUILD_IIC_CACHE(c) do { \
279 IIC *tags = new IIC(iic_params); \
280 BUILD_COMPRESSED_CACHE(IIC, tags, c); \
283 #define BUILD_IIC_CACHE(c) BUILD_CACHE_PANIC("iic")
286 #define BUILD_CACHES(c) do { \
287 if (repl == NULL) { \
288 if (numSets == 1) { \
289 BUILD_FALRU_CACHE(c); \
291 if (split == true) { \
292 BUILD_SPLIT_CACHE(c); \
293 } else if (lifo == true) { \
294 BUILD_SPLIT_LIFO_CACHE(c); \
296 BUILD_LRU_CACHE(c); \
300 BUILD_IIC_CACHE(c); \
304 #define BUILD_COHERENCE(b) do { \
305 if (protocol == NULL) { \
306 UniCoherence *coh = new UniCoherence(); \
307 BUILD_CACHES(UniCoherence); \
309 SimpleCoherence *coh = new SimpleCoherence(protocol); \
310 BUILD_CACHES(SimpleCoherence); \
314 #if defined(USE_TAGGED)
315 #define BUILD_TAGGED_PREFETCHER(t) \
316 pf = new TaggedPrefetcher(prefetcher_size, \
317 !prefetch_past_page, \
318 prefetch_serial_squash, \
319 prefetch_cache_check_push, \
320 prefetch_data_accesses_only, \
324 #define BUILD_TAGGED_PREFETCHER(t) BUILD_CACHE_PANIC("Tagged Prefetcher")
327 #if defined(USE_STRIDED)
328 #define BUILD_STRIDED_PREFETCHER(t) \
329 pf = new StridePrefetcher(prefetcher_size, \
330 !prefetch_past_page, \
331 prefetch_serial_squash, \
332 prefetch_cache_check_push, \
333 prefetch_data_accesses_only, \
338 #define BUILD_STRIDED_PREFETCHER(t) BUILD_CACHE_PANIC("Stride Prefetcher")
342 #define BUILD_GHB_PREFETCHER(t) \
343 pf = new GHBPrefetcher(prefetcher_size, \
344 !prefetch_past_page, \
345 prefetch_serial_squash, \
346 prefetch_cache_check_push, \
347 prefetch_data_accesses_only, \
352 #define BUILD_GHB_PREFETCHER(t) BUILD_CACHE_PANIC("GHB Prefetcher")
355 #if defined(USE_TAGGED)
356 #define BUILD_NULL_PREFETCHER(t) \
357 pf = new TaggedPrefetcher(prefetcher_size, \
358 !prefetch_past_page, \
359 prefetch_serial_squash, \
360 prefetch_cache_check_push, \
361 prefetch_data_accesses_only, \
365 #define BUILD_NULL_PREFETCHER(t) BUILD_CACHE_PANIC("NULL Prefetcher (uses Tagged)")
368 CREATE_SIM_OBJECT(BaseCache
)
370 string name
= getInstanceName();
371 int numSets
= size
/ (assoc
* block_size
);
372 string pf_policy
= prefetch_policy
;
373 if (subblock_size
== 0) {
374 subblock_size
= block_size
;
377 // Build BaseCache param object
378 BaseCache::Params
base_params(addr_range
, latency
,
379 block_size
, max_miss_count
);
381 //Warnings about prefetcher policy
382 if (pf_policy
== "none" && (prefetch_miss
|| prefetch_access
)) {
383 panic("With no prefetcher, you shouldn't prefetch from"
384 " either miss or access stream\n");
386 if ((pf_policy
== "tagged" || pf_policy
== "stride" ||
387 pf_policy
== "ghb") && !(prefetch_miss
|| prefetch_access
)) {
388 warn("With this prefetcher you should chose a prefetch"
389 " stream (miss or access)\nNo Prefetching will occur\n");
391 if ((pf_policy
== "tagged" || pf_policy
== "stride" ||
392 pf_policy
== "ghb") && prefetch_miss
&& prefetch_access
) {
393 panic("Can't do prefetches from both miss and access"
396 if (pf_policy
!= "tagged" && pf_policy
!= "stride" &&
397 pf_policy
!= "ghb" && pf_policy
!= "none") {
398 panic("Unrecognized form of a prefetcher: %s, try using"
399 "['none','stride','tagged','ghb']\n", pf_policy
);
402 #if defined(USE_CACHE_IIC)
404 IIC::Params iic_params
;
405 iic_params
.size
= size
;
406 iic_params
.numSets
= numSets
;
407 iic_params
.blkSize
= block_size
;
408 iic_params
.assoc
= assoc
;
409 iic_params
.hashDelay
= hash_delay
;
410 iic_params
.hitLatency
= latency
;
411 iic_params
.rp
= repl
;
412 iic_params
.subblockSize
= subblock_size
;
414 const void *repl
= NULL
;
417 if (mshrs
== 1 /*|| out_bus->doEvents() == false*/) {
418 BlockingBuffer
*mq
= new BlockingBuffer(true);
419 BUILD_COHERENCE(BlockingBuffer
);
421 MissQueue
*mq
= new MissQueue(mshrs
, tgts_per_mshr
, write_buffers
,
422 true, prefetch_miss
);
423 BUILD_COHERENCE(MissQueue
);
428 REGISTER_SIM_OBJECT("BaseCache", BaseCache
)
431 #endif //DOXYGEN_SHOULD_SKIP_THIS