Merge zizzer:/z/m5/Bitkeeper/newmem
[gem5.git] / src / mem / cache / cache_impl.hh
1 /*
2 * Copyright (c) 2002-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 * Dave Greene
30 * Nathan Binkert
31 */
32
33 /**
34 * @file
35 * Cache definitions.
36 */
37
38 #include <assert.h>
39 #include <math.h>
40
41 #include <cassert>
42 #include <iostream>
43 #include <string>
44
45 #include "sim/host.hh"
46 #include "base/misc.hh"
47 #include "cpu/smt.hh"
48
49 #include "mem/cache/cache.hh"
50 #include "mem/cache/cache_blk.hh"
51 #include "mem/cache/miss/mshr.hh"
52 #include "mem/cache/prefetch/prefetcher.hh"
53
54 #include "sim/sim_exit.hh" // for SimExitEvent
55
56 template<class TagStore, class Buffering, class Coherence>
57 bool
58 Cache<TagStore,Buffering,Coherence>::
59 doTimingAccess(Packet *pkt, CachePort *cachePort, bool isCpuSide)
60 {
61 if (isCpuSide)
62 {
63 if (pkt->isWrite() && (pkt->req->isLocked())) {
64 pkt->req->setScResult(1);
65 }
66 if (!(pkt->flags & SATISFIED)) {
67 access(pkt);
68 }
69 }
70 else
71 {
72 if (pkt->isResponse())
73 handleResponse(pkt);
74 else {
75 //Check if we should do the snoop
76 if (pkt->flags && SNOOP_COMMIT)
77 snoop(pkt);
78 }
79 }
80 return true;
81 }
82
83 template<class TagStore, class Buffering, class Coherence>
84 Tick
85 Cache<TagStore,Buffering,Coherence>::
86 doAtomicAccess(Packet *pkt, bool isCpuSide)
87 {
88 if (isCpuSide)
89 {
90 //Temporary solution to LL/SC
91 if (pkt->isWrite() && (pkt->req->isLocked())) {
92 pkt->req->setScResult(1);
93 }
94
95 probe(pkt, true, NULL);
96 //TEMP ALWAYS SUCCES FOR NOW
97 pkt->result = Packet::Success;
98 }
99 else
100 {
101 if (pkt->isResponse())
102 handleResponse(pkt);
103 else
104 snoopProbe(pkt);
105 }
106 //Fix this timing info
107 return hitLatency;
108 }
109
110 template<class TagStore, class Buffering, class Coherence>
111 void
112 Cache<TagStore,Buffering,Coherence>::
113 doFunctionalAccess(Packet *pkt, bool isCpuSide)
114 {
115 if (isCpuSide)
116 {
117 //TEMP USE CPU?THREAD 0 0
118 pkt->req->setThreadContext(0,0);
119
120 //Temporary solution to LL/SC
121 if (pkt->isWrite() && (pkt->req->isLocked())) {
122 assert("Can't handle LL/SC on functional path\n");
123 }
124
125 probe(pkt, false, memSidePort);
126 //TEMP ALWAYS SUCCESFUL FOR NOW
127 pkt->result = Packet::Success;
128 }
129 else
130 {
131 probe(pkt, false, cpuSidePort);
132 }
133 }
134
135 template<class TagStore, class Buffering, class Coherence>
136 void
137 Cache<TagStore,Buffering,Coherence>::
138 recvStatusChange(Port::Status status, bool isCpuSide)
139 {
140
141 }
142
143
144 template<class TagStore, class Buffering, class Coherence>
145 Cache<TagStore,Buffering,Coherence>::
146 Cache(const std::string &_name,
147 Cache<TagStore,Buffering,Coherence>::Params &params)
148 : BaseCache(_name, params.baseParams),
149 prefetchAccess(params.prefetchAccess),
150 tags(params.tags), missQueue(params.missQueue),
151 coherence(params.coherence), prefetcher(params.prefetcher),
152 doCopy(params.doCopy), blockOnCopy(params.blockOnCopy)
153 {
154 //FIX BUS POINTERS
155 // if (params.in == NULL) {
156 topLevelCache = true;
157 // }
158 //PLEASE FIX THIS, BUS SIZES NOT BEING USED
159 tags->setCache(this, blkSize, 1/*params.out->width, params.out->clockRate*/);
160 tags->setPrefetcher(prefetcher);
161 missQueue->setCache(this);
162 missQueue->setPrefetcher(prefetcher);
163 coherence->setCache(this);
164 prefetcher->setCache(this);
165 prefetcher->setTags(tags);
166 prefetcher->setBuffer(missQueue);
167 #if 0
168 invalidatePkt = new Packet;
169 invalidatePkt->cmd = Packet::InvalidateReq;
170 #endif
171 }
172
173 template<class TagStore, class Buffering, class Coherence>
174 void
175 Cache<TagStore,Buffering,Coherence>::regStats()
176 {
177 BaseCache::regStats();
178 tags->regStats(name());
179 missQueue->regStats(name());
180 coherence->regStats(name());
181 prefetcher->regStats(name());
182 }
183
184 template<class TagStore, class Buffering, class Coherence>
185 bool
186 Cache<TagStore,Buffering,Coherence>::access(PacketPtr &pkt)
187 {
188 //@todo Add back in MemDebug Calls
189 // MemDebug::cacheAccess(pkt);
190 BlkType *blk = NULL;
191 PacketList writebacks;
192 int size = blkSize;
193 int lat = hitLatency;
194 if (prefetchAccess) {
195 //We are determining prefetches on access stream, call prefetcher
196 prefetcher->handleMiss(pkt, curTick);
197 }
198 if (!pkt->req->isUncacheable()) {
199 if (pkt->isInvalidate() && !pkt->isRead()
200 && !pkt->isWrite()) {
201 //Upgrade or Invalidate
202 //Look into what happens if two slave caches on bus
203 DPRINTF(Cache, "%s %x ? blk_addr: %x\n", pkt->cmdString(),
204 pkt->getAddr() & (((ULL(1))<<48)-1),
205 pkt->getAddr() & ~((Addr)blkSize - 1));
206
207 //@todo Should this return latency have the hit latency in it?
208 // respond(pkt,curTick+lat);
209 pkt->flags |= SATISFIED;
210 // return MA_HIT; //@todo, return values
211 return true;
212 }
213 blk = tags->handleAccess(pkt, lat, writebacks);
214 } else {
215 size = pkt->getSize();
216 }
217 // If this is a block size write/hint (WH64) allocate the block here
218 // if the coherence protocol allows it.
219 /** @todo make the fast write alloc (wh64) work with coherence. */
220 /** @todo Do we want to do fast writes for writebacks as well? */
221 if (!blk && pkt->getSize() >= blkSize && coherence->allowFastWrites() &&
222 (pkt->cmd == Packet::WriteReq || pkt->cmd == Packet::WriteInvalidateReq) ) {
223 // not outstanding misses, can do this
224 MSHR* outstanding_miss = missQueue->findMSHR(pkt->getAddr());
225 if (pkt->cmd == Packet::WriteInvalidateReq || !outstanding_miss) {
226 if (outstanding_miss) {
227 warn("WriteInv doing a fastallocate"
228 "with an outstanding miss to the same address\n");
229 }
230 blk = tags->handleFill(NULL, pkt, BlkValid | BlkWritable,
231 writebacks);
232 ++fastWrites;
233 }
234 }
235 while (!writebacks.empty()) {
236 missQueue->doWriteback(writebacks.front());
237 writebacks.pop_front();
238 }
239 DPRINTF(Cache, "%s %x %s blk_addr: %x pc %x\n", pkt->cmdString(),
240 pkt->getAddr() & (((ULL(1))<<48)-1), (blk) ? "hit" : "miss",
241 pkt->getAddr() & ~((Addr)blkSize - 1), pkt->req->getPC());
242 if (blk) {
243 // Hit
244 hits[pkt->cmdToIndex()][0/*pkt->req->getThreadNum()*/]++;
245 // clear dirty bit if write through
246 if (pkt->needsResponse())
247 respond(pkt, curTick+lat);
248 // return MA_HIT;
249 return true;
250 }
251
252 // Miss
253 if (!pkt->req->isUncacheable()) {
254 misses[pkt->cmdToIndex()][0/*pkt->req->getThreadNum()*/]++;
255 /** @todo Move miss count code into BaseCache */
256 if (missCount) {
257 --missCount;
258 if (missCount == 0)
259 exitSimLoop("A cache reached the maximum miss count");
260 }
261 }
262 missQueue->handleMiss(pkt, size, curTick + hitLatency);
263 // return MA_CACHE_MISS;
264 return true;
265 }
266
267
268 template<class TagStore, class Buffering, class Coherence>
269 Packet *
270 Cache<TagStore,Buffering,Coherence>::getPacket()
271 {
272 Packet * pkt = missQueue->getPacket();
273 if (pkt) {
274 if (!pkt->req->isUncacheable()) {
275 if (pkt->cmd == Packet::HardPFReq) misses[Packet::HardPFReq][0/*pkt->req->getThreadNum()*/]++;
276 BlkType *blk = tags->findBlock(pkt);
277 Packet::Command cmd = coherence->getBusCmd(pkt->cmd,
278 (blk)? blk->status : 0);
279 missQueue->setBusCmd(pkt, cmd);
280 }
281 }
282
283 assert(!doMasterRequest() || missQueue->havePending());
284 assert(!pkt || pkt->time <= curTick);
285 return pkt;
286 }
287
288 template<class TagStore, class Buffering, class Coherence>
289 void
290 Cache<TagStore,Buffering,Coherence>::sendResult(PacketPtr &pkt, bool success)
291 {
292 if (success) {
293 missQueue->markInService(pkt);
294 //Temp Hack for UPGRADES
295 if (pkt->cmd == Packet::UpgradeReq) {
296 handleResponse(pkt);
297 }
298 } else if (pkt && !pkt->req->isUncacheable()) {
299 missQueue->restoreOrigCmd(pkt);
300 }
301 }
302
303 template<class TagStore, class Buffering, class Coherence>
304 void
305 Cache<TagStore,Buffering,Coherence>::handleResponse(Packet * &pkt)
306 {
307 BlkType *blk = NULL;
308 if (pkt->senderState) {
309 // MemDebug::cacheResponse(pkt);
310 DPRINTF(Cache, "Handling reponse to %x, blk addr: %x\n",pkt->getAddr(),
311 pkt->getAddr() & (((ULL(1))<<48)-1));
312
313 if (pkt->isCacheFill() && !pkt->isNoAllocate()) {
314 blk = tags->findBlock(pkt);
315 CacheBlk::State old_state = (blk) ? blk->status : 0;
316 PacketList writebacks;
317 blk = tags->handleFill(blk, (MSHR*)pkt->senderState,
318 coherence->getNewState(pkt,old_state),
319 writebacks, pkt);
320 while (!writebacks.empty()) {
321 missQueue->doWriteback(writebacks.front());
322 writebacks.pop_front();
323 }
324 }
325 missQueue->handleResponse(pkt, curTick + hitLatency);
326 }
327 }
328
329 template<class TagStore, class Buffering, class Coherence>
330 void
331 Cache<TagStore,Buffering,Coherence>::pseudoFill(Addr addr)
332 {
333 // Need to temporarily move this blk into MSHRs
334 MSHR *mshr = missQueue->allocateTargetList(addr);
335 int lat;
336 PacketList dummy;
337 // Read the data into the mshr
338 BlkType *blk = tags->handleAccess(mshr->pkt, lat, dummy, false);
339 assert(dummy.empty());
340 assert(mshr->pkt->flags & SATISFIED);
341 // can overload order since it isn't used on non pending blocks
342 mshr->order = blk->status;
343 // temporarily remove the block from the cache.
344 tags->invalidateBlk(addr);
345 }
346
347 template<class TagStore, class Buffering, class Coherence>
348 void
349 Cache<TagStore,Buffering,Coherence>::pseudoFill(MSHR *mshr)
350 {
351 // Need to temporarily move this blk into MSHRs
352 assert(mshr->pkt->cmd == Packet::ReadReq);
353 int lat;
354 PacketList dummy;
355 // Read the data into the mshr
356 BlkType *blk = tags->handleAccess(mshr->pkt, lat, dummy, false);
357 assert(dummy.empty());
358 assert(mshr->pkt->flags & SATISFIED);
359 // can overload order since it isn't used on non pending blocks
360 mshr->order = blk->status;
361 // temporarily remove the block from the cache.
362 tags->invalidateBlk(mshr->pkt->getAddr());
363 }
364
365
366 template<class TagStore, class Buffering, class Coherence>
367 Packet *
368 Cache<TagStore,Buffering,Coherence>::getCoherencePacket()
369 {
370 return coherence->getPacket();
371 }
372
373
374 template<class TagStore, class Buffering, class Coherence>
375 void
376 Cache<TagStore,Buffering,Coherence>::snoop(Packet * &pkt)
377 {
378 Addr blk_addr = pkt->getAddr() & ~(Addr(blkSize-1));
379 BlkType *blk = tags->findBlock(pkt);
380 MSHR *mshr = missQueue->findMSHR(blk_addr);
381 if (isTopLevel() && coherence->hasProtocol()) { //@todo Move this into handle bus req
382 //If we find an mshr, and it is in service, we need to NACK or invalidate
383 if (mshr) {
384 if (mshr->inService) {
385 if ((mshr->pkt->isInvalidate() || !mshr->pkt->isCacheFill())
386 && (pkt->cmd != Packet::InvalidateReq && pkt->cmd != Packet::WriteInvalidateReq)) {
387 //If the outstanding request was an invalidate (upgrade,readex,..)
388 //Then we need to ACK the request until we get the data
389 //Also NACK if the outstanding request is not a cachefill (writeback)
390 pkt->flags |= SATISFIED;
391 pkt->flags |= NACKED_LINE;
392 assert("Don't detect these on the other side yet\n");
393 respondToSnoop(pkt, curTick + hitLatency);
394 return;
395 }
396 else {
397 //The supplier will be someone else, because we are waiting for
398 //the data. This should cause this cache to be forced to go to
399 //the shared state, not the exclusive even though the shared line
400 //won't be asserted. But for now we will just invlidate ourselves
401 //and allow the other cache to go into the exclusive state.
402 //@todo Make it so a read to a pending read doesn't invalidate.
403 //@todo Make it so that a read to a pending read can't be exclusive now.
404
405 //Set the address so find match works
406 assert("Don't have invalidates yet\n");
407 invalidatePkt->addrOverride(pkt->getAddr());
408
409 //Append the invalidate on
410 missQueue->addTarget(mshr,invalidatePkt);
411 DPRINTF(Cache, "Appending Invalidate to blk_addr: %x\n", pkt->getAddr() & (((ULL(1))<<48)-1));
412 return;
413 }
414 }
415 }
416 //We also need to check the writeback buffers and handle those
417 std::vector<MSHR *> writebacks;
418 if (missQueue->findWrites(blk_addr, writebacks)) {
419 DPRINTF(Cache, "Snoop hit in writeback to blk_addr: %x\n", pkt->getAddr() & (((ULL(1))<<48)-1));
420
421 //Look through writebacks for any non-uncachable writes, use that
422 for (int i=0; i<writebacks.size(); i++) {
423 mshr = writebacks[i];
424
425 if (!mshr->pkt->req->isUncacheable()) {
426 if (pkt->isRead()) {
427 //Only Upgrades don't get here
428 //Supply the data
429 pkt->flags |= SATISFIED;
430
431 //If we are in an exclusive protocol, make it ask again
432 //to get write permissions (upgrade), signal shared
433 pkt->flags |= SHARED_LINE;
434
435 assert(pkt->isRead());
436 Addr offset = pkt->getAddr() & ~(blkSize - 1);
437 assert(offset < blkSize);
438 assert(pkt->getSize() <= blkSize);
439 assert(offset + pkt->getSize() <=blkSize);
440 memcpy(pkt->getPtr<uint8_t>(), mshr->pkt->getPtr<uint8_t>() + offset, pkt->getSize());
441
442 respondToSnoop(pkt, curTick + hitLatency);
443 }
444
445 if (pkt->isInvalidate()) {
446 //This must be an upgrade or other cache will take ownership
447 missQueue->markInService(mshr->pkt);
448 }
449 return;
450 }
451 }
452 }
453 }
454 CacheBlk::State new_state;
455 bool satisfy = coherence->handleBusRequest(pkt,blk,mshr, new_state);
456 if (satisfy) {
457 tags->handleSnoop(blk, new_state, pkt);
458 respondToSnoop(pkt, curTick + hitLatency);
459 return;
460 }
461 tags->handleSnoop(blk, new_state);
462 }
463
464 template<class TagStore, class Buffering, class Coherence>
465 void
466 Cache<TagStore,Buffering,Coherence>::snoopResponse(Packet * &pkt)
467 {
468 //Need to handle the response, if NACKED
469 if (pkt->flags & NACKED_LINE) {
470 //Need to mark it as not in service, and retry for bus
471 assert(0); //Yeah, we saw a NACK come through
472
473 //For now this should never get called, we return false when we see a NACK
474 //instead, by doing this we allow the bus_blocked mechanism to handle the retry
475 //For now it retrys in just 2 cycles, need to figure out how to change that
476 //Eventually we will want to also have success come in as a parameter
477 //Need to make sure that we handle the functionality that happens on successufl
478 //return of the sendAddr function
479 }
480 }
481
482 template<class TagStore, class Buffering, class Coherence>
483 void
484 Cache<TagStore,Buffering,Coherence>::invalidateBlk(Addr addr)
485 {
486 tags->invalidateBlk(addr);
487 }
488
489
490 /**
491 * @todo Fix to not assume write allocate
492 */
493 template<class TagStore, class Buffering, class Coherence>
494 Tick
495 Cache<TagStore,Buffering,Coherence>::probe(Packet * &pkt, bool update, CachePort* otherSidePort)
496 {
497 // MemDebug::cacheProbe(pkt);
498 if (!pkt->req->isUncacheable()) {
499 if (pkt->isInvalidate() && !pkt->isRead()
500 && !pkt->isWrite()) {
501 //Upgrade or Invalidate, satisfy it, don't forward
502 DPRINTF(Cache, "%s %x ? blk_addr: %x\n", pkt->cmdString(),
503 pkt->getAddr() & (((ULL(1))<<48)-1),
504 pkt->getAddr() & ~((Addr)blkSize - 1));
505 pkt->flags |= SATISFIED;
506 return 0;
507 }
508 }
509
510 PacketList writebacks;
511 int lat;
512 BlkType *blk = tags->handleAccess(pkt, lat, writebacks, update);
513
514 if (!blk) {
515 // Need to check for outstanding misses and writes
516 Addr blk_addr = pkt->getAddr() & ~(blkSize - 1);
517
518 // There can only be one matching outstanding miss.
519 MSHR* mshr = missQueue->findMSHR(blk_addr);
520
521 // There can be many matching outstanding writes.
522 std::vector<MSHR*> writes;
523 missQueue->findWrites(blk_addr, writes);
524
525 if (!update) {
526 otherSidePort->sendFunctional(pkt);
527
528 // Check for data in MSHR and writebuffer.
529 if (mshr) {
530 warn("Found outstanding miss on an non-update probe");
531 MSHR::TargetList *targets = mshr->getTargetList();
532 MSHR::TargetList::iterator i = targets->begin();
533 MSHR::TargetList::iterator end = targets->end();
534 for (; i != end; ++i) {
535 Packet * target = *i;
536 // If the target contains data, and it overlaps the
537 // probed request, need to update data
538 if (target->isWrite() && target->intersect(pkt)) {
539 uint8_t* pkt_data;
540 uint8_t* write_data;
541 int data_size;
542 if (target->getAddr() < pkt->getAddr()) {
543 int offset = pkt->getAddr() - target->getAddr();
544 pkt_data = pkt->getPtr<uint8_t>();
545 write_data = target->getPtr<uint8_t>() + offset;
546 data_size = target->getSize() - offset;
547 assert(data_size > 0);
548 if (data_size > pkt->getSize())
549 data_size = pkt->getSize();
550 } else {
551 int offset = target->getAddr() - pkt->getAddr();
552 pkt_data = pkt->getPtr<uint8_t>() + offset;
553 write_data = target->getPtr<uint8_t>();
554 data_size = pkt->getSize() - offset;
555 assert(data_size > pkt->getSize());
556 if (data_size > target->getSize())
557 data_size = target->getSize();
558 }
559
560 if (pkt->isWrite()) {
561 memcpy(pkt_data, write_data, data_size);
562 } else {
563 memcpy(write_data, pkt_data, data_size);
564 }
565 }
566 }
567 }
568 for (int i = 0; i < writes.size(); ++i) {
569 Packet * write = writes[i]->pkt;
570 if (write->intersect(pkt)) {
571 warn("Found outstanding write on an non-update probe");
572 uint8_t* pkt_data;
573 uint8_t* write_data;
574 int data_size;
575 if (write->getAddr() < pkt->getAddr()) {
576 int offset = pkt->getAddr() - write->getAddr();
577 pkt_data = pkt->getPtr<uint8_t>();
578 write_data = write->getPtr<uint8_t>() + offset;
579 data_size = write->getSize() - offset;
580 assert(data_size > 0);
581 if (data_size > pkt->getSize())
582 data_size = pkt->getSize();
583 } else {
584 int offset = write->getAddr() - pkt->getAddr();
585 pkt_data = pkt->getPtr<uint8_t>() + offset;
586 write_data = write->getPtr<uint8_t>();
587 data_size = pkt->getSize() - offset;
588 assert(data_size > pkt->getSize());
589 if (data_size > write->getSize())
590 data_size = write->getSize();
591 }
592
593 if (pkt->isWrite()) {
594 memcpy(pkt_data, write_data, data_size);
595 } else {
596 memcpy(write_data, pkt_data, data_size);
597 }
598
599 }
600 }
601 return 0;
602 } else {
603 // update the cache state and statistics
604 if (mshr || !writes.empty()){
605 // Can't handle it, return pktuest unsatisfied.
606 return 0;
607 }
608 if (!pkt->req->isUncacheable()) {
609 // Fetch the cache block to fill
610 BlkType *blk = tags->findBlock(pkt);
611 Packet::Command temp_cmd = coherence->getBusCmd(pkt->cmd,
612 (blk)? blk->status : 0);
613
614 Packet * busPkt = new Packet(pkt->req,temp_cmd, -1, blkSize);
615
616 busPkt->allocate();
617
618 busPkt->time = curTick;
619
620 lat = memSidePort->sendAtomic(busPkt);
621
622 //Be sure to flip the response to a request for coherence
623 busPkt->makeAtomicResponse();
624
625 /* if (!(busPkt->flags & SATISFIED)) {
626 // blocked at a higher level, just return
627 return 0;
628 }
629
630 */ misses[pkt->cmdToIndex()][0/*pkt->req->getThreadNum()*/]++;
631
632 CacheBlk::State old_state = (blk) ? blk->status : 0;
633 tags->handleFill(blk, busPkt,
634 coherence->getNewState(busPkt, old_state),
635 writebacks, pkt);
636 // Handle writebacks if needed
637 while (!writebacks.empty()){
638 memSidePort->sendAtomic(writebacks.front());
639 writebacks.pop_front();
640 }
641 return lat + hitLatency;
642 } else {
643 return memSidePort->sendAtomic(pkt);
644 }
645 }
646 } else {
647 // There was a cache hit.
648 // Handle writebacks if needed
649 while (!writebacks.empty()){
650 memSidePort->sendAtomic(writebacks.front());
651 writebacks.pop_front();
652 }
653
654 if (update) {
655 hits[pkt->cmdToIndex()][0/*pkt->req->getThreadNum()*/]++;
656 } else if (pkt->isWrite()) {
657 // Still need to change data in all locations.
658 return otherSidePort->sendAtomic(pkt);
659 }
660 return curTick + lat;
661 }
662 fatal("Probe not handled.\n");
663 return 0;
664 }
665
666 template<class TagStore, class Buffering, class Coherence>
667 Tick
668 Cache<TagStore,Buffering,Coherence>::snoopProbe(PacketPtr &pkt)
669 {
670 Addr blk_addr = pkt->getAddr() & ~(Addr(blkSize-1));
671 BlkType *blk = tags->findBlock(pkt);
672 MSHR *mshr = missQueue->findMSHR(blk_addr);
673 CacheBlk::State new_state = 0;
674 bool satisfy = coherence->handleBusRequest(pkt,blk,mshr, new_state);
675 if (satisfy) {
676 tags->handleSnoop(blk, new_state, pkt);
677 return hitLatency;
678 }
679 tags->handleSnoop(blk, new_state);
680 return 0;
681 }
682