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
33 * Definition of BaseCache functions.
36 #include "mem/cache/base_cache.hh"
38 #include "cpu/base.hh"
42 BaseCache::CachePort::CachePort(const std::string
&_name
, BaseCache
*_cache
,
44 : Port(_name
), cache(_cache
), isCpuSide(_isCpuSide
)
47 //Start ports at null if more than one is created we should panic
53 BaseCache::CachePort::recvStatusChange(Port::Status status
)
55 cache
->recvStatusChange(status
, isCpuSide
);
59 BaseCache::CachePort::getDeviceAddressRanges(AddrRangeList
&resp
,
62 cache
->getAddressRanges(resp
, snoop
);
66 BaseCache::CachePort::deviceBlockSize()
68 return cache
->getBlockSize();
72 BaseCache::CachePort::recvTiming(Packet
*pkt
)
74 return cache
->doTimingAccess(pkt
, this, isCpuSide
);
78 BaseCache::CachePort::recvAtomic(Packet
*pkt
)
80 return cache
->doAtomicAccess(pkt
, isCpuSide
);
84 BaseCache::CachePort::recvFunctional(Packet
*pkt
)
86 cache
->doFunctionalAccess(pkt
, isCpuSide
);
90 BaseCache::CachePort::setBlocked()
96 BaseCache::CachePort::clearBlocked()
102 BaseCache::getPort(const std::string
&if_name
, int idx
)
104 if(if_name
== "cpu_side")
106 if(cpuSidePort
!= NULL
)
107 panic("Already have a cpu side for this cache\n");
108 cpuSidePort
= new CachePort(name() + "-cpu_side_port", this, true);
111 else if(if_name
== "mem_side")
113 if(memSidePort
!= NULL
)
114 panic("Already have a mem side for this cache\n");
115 memSidePort
= new CachePort(name() + "-mem_side_port", this, false);
118 else panic("Port name %s unrecognized\n", if_name
);
122 BaseCache::regStats()
125 Packet::Command temp_cmd
= Packet::ReadReq
;
126 Packet
temp_pkt(&temp_req
, temp_cmd
, 0); //@todo FIx command strings so this isn't neccessary
128 using namespace Stats
;
131 for (int access_idx
= 0; access_idx
< NUM_MEM_CMDS
; ++access_idx
) {
132 Packet::Command cmd
= (Packet::Command
)access_idx
;
133 const string
&cstr
= temp_pkt
.cmdIdxToString(cmd
);
136 .init(maxThreadsPerCPU
)
137 .name(name() + "." + cstr
+ "_hits")
138 .desc("number of " + cstr
+ " hits")
139 .flags(total
| nozero
| nonan
)
144 .name(name() + ".demand_hits")
145 .desc("number of demand (read+write) hits")
148 demandHits
= hits
[Packet::ReadReq
] + hits
[Packet::WriteReq
];
151 .name(name() + ".overall_hits")
152 .desc("number of overall hits")
155 overallHits
= demandHits
+ hits
[Packet::SoftPFReq
] + hits
[Packet::HardPFReq
]
156 + hits
[Packet::Writeback
];
159 for (int access_idx
= 0; access_idx
< NUM_MEM_CMDS
; ++access_idx
) {
160 Packet::Command cmd
= (Packet::Command
)access_idx
;
161 const string
&cstr
= temp_pkt
.cmdIdxToString(cmd
);
164 .init(maxThreadsPerCPU
)
165 .name(name() + "." + cstr
+ "_misses")
166 .desc("number of " + cstr
+ " misses")
167 .flags(total
| nozero
| nonan
)
172 .name(name() + ".demand_misses")
173 .desc("number of demand (read+write) misses")
176 demandMisses
= misses
[Packet::ReadReq
] + misses
[Packet::WriteReq
];
179 .name(name() + ".overall_misses")
180 .desc("number of overall misses")
183 overallMisses
= demandMisses
+ misses
[Packet::SoftPFReq
] +
184 misses
[Packet::HardPFReq
] + misses
[Packet::Writeback
];
186 // Miss latency statistics
187 for (int access_idx
= 0; access_idx
< NUM_MEM_CMDS
; ++access_idx
) {
188 Packet::Command cmd
= (Packet::Command
)access_idx
;
189 const string
&cstr
= temp_pkt
.cmdIdxToString(cmd
);
191 missLatency
[access_idx
]
192 .init(maxThreadsPerCPU
)
193 .name(name() + "." + cstr
+ "_miss_latency")
194 .desc("number of " + cstr
+ " miss cycles")
195 .flags(total
| nozero
| nonan
)
200 .name(name() + ".demand_miss_latency")
201 .desc("number of demand (read+write) miss cycles")
204 demandMissLatency
= missLatency
[Packet::ReadReq
] + missLatency
[Packet::WriteReq
];
207 .name(name() + ".overall_miss_latency")
208 .desc("number of overall miss cycles")
211 overallMissLatency
= demandMissLatency
+ missLatency
[Packet::SoftPFReq
] +
212 missLatency
[Packet::HardPFReq
];
215 for (int access_idx
= 0; access_idx
< NUM_MEM_CMDS
; ++access_idx
) {
216 Packet::Command cmd
= (Packet::Command
)access_idx
;
217 const string
&cstr
= temp_pkt
.cmdIdxToString(cmd
);
220 .name(name() + "." + cstr
+ "_accesses")
221 .desc("number of " + cstr
+ " accesses(hits+misses)")
222 .flags(total
| nozero
| nonan
)
225 accesses
[access_idx
] = hits
[access_idx
] + misses
[access_idx
];
229 .name(name() + ".demand_accesses")
230 .desc("number of demand (read+write) accesses")
233 demandAccesses
= demandHits
+ demandMisses
;
236 .name(name() + ".overall_accesses")
237 .desc("number of overall (read+write) accesses")
240 overallAccesses
= overallHits
+ overallMisses
;
242 // miss rate formulas
243 for (int access_idx
= 0; access_idx
< NUM_MEM_CMDS
; ++access_idx
) {
244 Packet::Command cmd
= (Packet::Command
)access_idx
;
245 const string
&cstr
= temp_pkt
.cmdIdxToString(cmd
);
248 .name(name() + "." + cstr
+ "_miss_rate")
249 .desc("miss rate for " + cstr
+ " accesses")
250 .flags(total
| nozero
| nonan
)
253 missRate
[access_idx
] = misses
[access_idx
] / accesses
[access_idx
];
257 .name(name() + ".demand_miss_rate")
258 .desc("miss rate for demand accesses")
261 demandMissRate
= demandMisses
/ demandAccesses
;
264 .name(name() + ".overall_miss_rate")
265 .desc("miss rate for overall accesses")
268 overallMissRate
= overallMisses
/ overallAccesses
;
270 // miss latency formulas
271 for (int access_idx
= 0; access_idx
< NUM_MEM_CMDS
; ++access_idx
) {
272 Packet::Command cmd
= (Packet::Command
)access_idx
;
273 const string
&cstr
= temp_pkt
.cmdIdxToString(cmd
);
275 avgMissLatency
[access_idx
]
276 .name(name() + "." + cstr
+ "_avg_miss_latency")
277 .desc("average " + cstr
+ " miss latency")
278 .flags(total
| nozero
| nonan
)
281 avgMissLatency
[access_idx
] =
282 missLatency
[access_idx
] / misses
[access_idx
];
286 .name(name() + ".demand_avg_miss_latency")
287 .desc("average overall miss latency")
290 demandAvgMissLatency
= demandMissLatency
/ demandMisses
;
292 overallAvgMissLatency
293 .name(name() + ".overall_avg_miss_latency")
294 .desc("average overall miss latency")
297 overallAvgMissLatency
= overallMissLatency
/ overallMisses
;
299 blocked_cycles
.init(NUM_BLOCKED_CAUSES
);
301 .name(name() + ".blocked_cycles")
302 .desc("number of cycles access was blocked")
303 .subname(Blocked_NoMSHRs
, "no_mshrs")
304 .subname(Blocked_NoTargets
, "no_targets")
308 blocked_causes
.init(NUM_BLOCKED_CAUSES
);
310 .name(name() + ".blocked")
311 .desc("number of cycles access was blocked")
312 .subname(Blocked_NoMSHRs
, "no_mshrs")
313 .subname(Blocked_NoTargets
, "no_targets")
317 .name(name() + ".avg_blocked_cycles")
318 .desc("average number of cycles each access was blocked")
319 .subname(Blocked_NoMSHRs
, "no_mshrs")
320 .subname(Blocked_NoTargets
, "no_targets")
323 avg_blocked
= blocked_cycles
/ blocked_causes
;
326 .name(name() + ".fast_writes")
327 .desc("number of fast writes performed")
331 .name(name() + ".cache_copies")
332 .desc("number of cache copies performed")