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 "enums/Prefetch.hh"
40 #include "mem/config/cache.hh"
41 #include "mem/config/prefetch.hh"
42 #include "mem/cache/base.hh"
43 #include "mem/cache/cache.hh"
45 #include "params/BaseCache.hh"
48 #if defined(USE_CACHE_LRU)
49 #include "mem/cache/tags/lru.hh"
52 #if defined(USE_CACHE_FALRU)
53 #include "mem/cache/tags/fa_lru.hh"
56 #if defined(USE_CACHE_IIC)
57 #include "mem/cache/tags/iic.hh"
62 #include "mem/cache/prefetch/ghb.hh"
64 #if defined(USE_TAGGED)
65 #include "mem/cache/prefetch/tagged.hh"
67 #if defined(USE_STRIDED)
68 #include "mem/cache/prefetch/stride.hh"
73 using namespace TheISA
;
75 #define BUILD_CACHE(TAGS, tags) \
78 if (prefetch_policy == Enums::tagged) { \
79 BUILD_TAGGED_PREFETCHER(TAGS); \
81 else if (prefetch_policy == Enums::stride) { \
82 BUILD_STRIDED_PREFETCHER(TAGS); \
84 else if (prefetch_policy == Enums::ghb) { \
85 BUILD_GHB_PREFETCHER(TAGS); \
88 BUILD_NULL_PREFETCHER(TAGS); \
90 Cache<TAGS> *retval = \
91 new Cache<TAGS>(this, tags, pf); \
95 #define BUILD_CACHE_PANIC(x) do { \
96 panic("%s not compiled into M5", x); \
99 #if defined(USE_CACHE_FALRU)
100 #define BUILD_FALRU_CACHE do { \
101 FALRU *tags = new FALRU(block_size, size, latency); \
102 BUILD_CACHE(FALRU, tags); \
105 #define BUILD_FALRU_CACHE BUILD_CACHE_PANIC("falru cache")
108 #if defined(USE_CACHE_LRU)
109 #define BUILD_LRU_CACHE do { \
110 LRU *tags = new LRU(numSets, block_size, assoc, latency); \
111 BUILD_CACHE(LRU, tags); \
114 #define BUILD_LRU_CACHE BUILD_CACHE_PANIC("lru cache")
117 #if defined(USE_CACHE_IIC)
118 #define BUILD_IIC_CACHE do { \
119 IIC *tags = new IIC(iic_params); \
120 BUILD_CACHE(IIC, tags); \
123 #define BUILD_IIC_CACHE BUILD_CACHE_PANIC("iic")
126 #define BUILD_CACHES do { \
127 if (repl == NULL) { \
128 if (numSets == 1) { \
138 #define BUILD_COHERENCE(b) do { \
141 #if defined(USE_TAGGED)
142 #define BUILD_TAGGED_PREFETCHER(t) \
143 pf = new TaggedPrefetcher(this)
145 #define BUILD_TAGGED_PREFETCHER(t) BUILD_CACHE_PANIC("Tagged Prefetcher")
148 #if defined(USE_STRIDED)
149 #define BUILD_STRIDED_PREFETCHER(t) \
150 pf = new StridePrefetcher(this)
152 #define BUILD_STRIDED_PREFETCHER(t) BUILD_CACHE_PANIC("Stride Prefetcher")
156 #define BUILD_GHB_PREFETCHER(t) \
157 pf = new GHBPrefetcher(this)
159 #define BUILD_GHB_PREFETCHER(t) BUILD_CACHE_PANIC("GHB Prefetcher")
162 #if defined(USE_TAGGED)
163 #define BUILD_NULL_PREFETCHER(t) \
164 pf = new TaggedPrefetcher(this)
166 #define BUILD_NULL_PREFETCHER(t) BUILD_CACHE_PANIC("NULL Prefetcher (uses Tagged)")
170 BaseCacheParams::create()
172 int numSets
= size
/ (assoc
* block_size
);
173 if (subblock_size
== 0) {
174 subblock_size
= block_size
;
177 //Warnings about prefetcher policy
178 if (prefetch_policy
== Enums::none
) {
179 if (prefetch_miss
|| prefetch_access
)
180 panic("With no prefetcher, you shouldn't prefetch from"
181 " either miss or access stream\n");
184 if (prefetch_policy
== Enums::tagged
|| prefetch_policy
== Enums::stride
||
185 prefetch_policy
== Enums::ghb
) {
187 if (!prefetch_miss
&& !prefetch_access
)
188 warn("With this prefetcher you should chose a prefetch"
189 " stream (miss or access)\nNo Prefetching will occur\n");
191 if (prefetch_miss
&& prefetch_access
)
192 panic("Can't do prefetches from both miss and access stream");
195 #if defined(USE_CACHE_IIC)
197 IIC::Params iic_params
;
198 iic_params
.size
= size
;
199 iic_params
.numSets
= numSets
;
200 iic_params
.blkSize
= block_size
;
201 iic_params
.assoc
= assoc
;
202 iic_params
.hashDelay
= hash_delay
;
203 iic_params
.hitLatency
= latency
;
204 iic_params
.rp
= repl
;
205 iic_params
.subblockSize
= subblock_size
;
207 const void *repl
= NULL
;