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