Handle NACK's that occur from devices on the same bus.
[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 && !(pkt->flags & NACKED_LINE)) {
291 missQueue->markInService(pkt, mshr);
292 //Temp Hack for UPGRADES
293 if (pkt->cmd == Packet::UpgradeReq) {
294 pkt->flags &= ~CACHE_LINE_FILL;
295 handleResponse(pkt);
296 }
297 } else if (pkt && !pkt->req->isUncacheable()) {
298 pkt->flags &= ~NACKED_LINE;
299 pkt->flags &= ~SATISFIED;
300 pkt->flags &= ~SNOOP_COMMIT;
301 missQueue->restoreOrigCmd(pkt);
302 }
303 }
304
305 template<class TagStore, class Buffering, class Coherence>
306 void
307 Cache<TagStore,Buffering,Coherence>::handleResponse(Packet * &pkt)
308 {
309 BlkType *blk = NULL;
310 if (pkt->senderState) {
311 if (pkt->result == Packet::Nacked) {
312 //pkt->reinitFromRequest();
313 warn("NACKs from devices not connected to the same bus not implemented\n");
314 return;
315 }
316 if (pkt->result == Packet::BadAddress) {
317 //Make the response a Bad address and send it
318 }
319 // MemDebug::cacheResponse(pkt);
320 DPRINTF(Cache, "Handling reponse to %x, blk addr: %x\n",pkt->getAddr(),
321 pkt->getAddr() & (((ULL(1))<<48)-1));
322
323 if (pkt->isCacheFill() && !pkt->isNoAllocate()) {
324 blk = tags->findBlock(pkt);
325 CacheBlk::State old_state = (blk) ? blk->status : 0;
326 PacketList writebacks;
327 CacheBlk::State new_state = coherence->getNewState(pkt,old_state);
328 DPRINTF(Cache, "Block for blk addr %x moving from state %i to %i\n",
329 pkt->getAddr() & (((ULL(1))<<48)-1), old_state, new_state);
330 blk = tags->handleFill(blk, (MSHR*)pkt->senderState,
331 new_state, writebacks, pkt);
332 while (!writebacks.empty()) {
333 missQueue->doWriteback(writebacks.front());
334 writebacks.pop_front();
335 }
336 }
337 missQueue->handleResponse(pkt, curTick + hitLatency);
338 }
339 }
340
341 template<class TagStore, class Buffering, class Coherence>
342 void
343 Cache<TagStore,Buffering,Coherence>::pseudoFill(Addr addr)
344 {
345 // Need to temporarily move this blk into MSHRs
346 MSHR *mshr = missQueue->allocateTargetList(addr);
347 int lat;
348 PacketList dummy;
349 // Read the data into the mshr
350 BlkType *blk = tags->handleAccess(mshr->pkt, lat, dummy, false);
351 assert(dummy.empty());
352 assert(mshr->pkt->flags & SATISFIED);
353 // can overload order since it isn't used on non pending blocks
354 mshr->order = blk->status;
355 // temporarily remove the block from the cache.
356 tags->invalidateBlk(addr);
357 }
358
359 template<class TagStore, class Buffering, class Coherence>
360 void
361 Cache<TagStore,Buffering,Coherence>::pseudoFill(MSHR *mshr)
362 {
363 // Need to temporarily move this blk into MSHRs
364 assert(mshr->pkt->cmd == Packet::ReadReq);
365 int lat;
366 PacketList dummy;
367 // Read the data into the mshr
368 BlkType *blk = tags->handleAccess(mshr->pkt, lat, dummy, false);
369 assert(dummy.empty());
370 assert(mshr->pkt->flags & SATISFIED);
371 // can overload order since it isn't used on non pending blocks
372 mshr->order = blk->status;
373 // temporarily remove the block from the cache.
374 tags->invalidateBlk(mshr->pkt->getAddr());
375 }
376
377
378 template<class TagStore, class Buffering, class Coherence>
379 Packet *
380 Cache<TagStore,Buffering,Coherence>::getCoherencePacket()
381 {
382 return coherence->getPacket();
383 }
384
385
386 template<class TagStore, class Buffering, class Coherence>
387 void
388 Cache<TagStore,Buffering,Coherence>::snoop(Packet * &pkt)
389 {
390 Addr blk_addr = pkt->getAddr() & ~(Addr(blkSize-1));
391 BlkType *blk = tags->findBlock(pkt);
392 MSHR *mshr = missQueue->findMSHR(blk_addr);
393 if (isTopLevel() && coherence->hasProtocol()) { //@todo Move this into handle bus req
394 //If we find an mshr, and it is in service, we need to NACK or invalidate
395 if (mshr) {
396 if (mshr->inService) {
397 if ((mshr->pkt->isInvalidate() || !mshr->pkt->isCacheFill())
398 && (pkt->cmd != Packet::InvalidateReq && pkt->cmd != Packet::WriteInvalidateReq)) {
399 //If the outstanding request was an invalidate (upgrade,readex,..)
400 //Then we need to ACK the request until we get the data
401 //Also NACK if the outstanding request is not a cachefill (writeback)
402 assert(!(pkt->flags & SATISFIED));
403 pkt->flags |= SATISFIED;
404 pkt->flags |= NACKED_LINE;
405 warn("NACKs from devices not connected to the same bus not implemented\n");
406 //respondToSnoop(pkt, curTick + hitLatency);
407 return;
408 }
409 else {
410 //The supplier will be someone else, because we are waiting for
411 //the data. This should cause this cache to be forced to go to
412 //the shared state, not the exclusive even though the shared line
413 //won't be asserted. But for now we will just invlidate ourselves
414 //and allow the other cache to go into the exclusive state.
415 //@todo Make it so a read to a pending read doesn't invalidate.
416 //@todo Make it so that a read to a pending read can't be exclusive now.
417
418 //Set the address so find match works
419 panic("Don't have invalidates yet\n");
420 invalidatePkt->addrOverride(pkt->getAddr());
421
422 //Append the invalidate on
423 missQueue->addTarget(mshr,invalidatePkt);
424 DPRINTF(Cache, "Appending Invalidate to blk_addr: %x\n", pkt->getAddr() & (((ULL(1))<<48)-1));
425 return;
426 }
427 }
428 }
429 //We also need to check the writeback buffers and handle those
430 std::vector<MSHR *> writebacks;
431 if (missQueue->findWrites(blk_addr, writebacks)) {
432 DPRINTF(Cache, "Snoop hit in writeback to blk_addr: %x\n", pkt->getAddr() & (((ULL(1))<<48)-1));
433
434 //Look through writebacks for any non-uncachable writes, use that
435 for (int i=0; i<writebacks.size(); i++) {
436 mshr = writebacks[i];
437
438 if (!mshr->pkt->req->isUncacheable()) {
439 if (pkt->isRead()) {
440 //Only Upgrades don't get here
441 //Supply the data
442 assert(!(pkt->flags & SATISFIED));
443 pkt->flags |= SATISFIED;
444
445 //If we are in an exclusive protocol, make it ask again
446 //to get write permissions (upgrade), signal shared
447 pkt->flags |= SHARED_LINE;
448
449 assert(pkt->isRead());
450 Addr offset = pkt->getAddr() & ~(blkSize - 1);
451 assert(offset < blkSize);
452 assert(pkt->getSize() <= blkSize);
453 assert(offset + pkt->getSize() <=blkSize);
454 memcpy(pkt->getPtr<uint8_t>(), mshr->pkt->getPtr<uint8_t>() + offset, pkt->getSize());
455
456 respondToSnoop(pkt, curTick + hitLatency);
457 }
458
459 if (pkt->isInvalidate()) {
460 //This must be an upgrade or other cache will take ownership
461 missQueue->markInService(mshr->pkt, mshr);
462 }
463 return;
464 }
465 }
466 }
467 }
468 CacheBlk::State new_state;
469 bool satisfy = coherence->handleBusRequest(pkt,blk,mshr, new_state);
470 if (satisfy) {
471 DPRINTF(Cache, "Cache snooped a %s request and now supplying data,"
472 "new state is %i\n",
473 pkt->cmdString(), new_state);
474
475 tags->handleSnoop(blk, new_state, pkt);
476 respondToSnoop(pkt, curTick + hitLatency);
477 return;
478 }
479 if (blk) DPRINTF(Cache, "Cache snooped a %s request, new state is %i\n",
480 pkt->cmdString(), new_state);
481 tags->handleSnoop(blk, new_state);
482 }
483
484 template<class TagStore, class Buffering, class Coherence>
485 void
486 Cache<TagStore,Buffering,Coherence>::snoopResponse(Packet * &pkt)
487 {
488 //Need to handle the response, if NACKED
489 if (pkt->flags & NACKED_LINE) {
490 //Need to mark it as not in service, and retry for bus
491 assert(0); //Yeah, we saw a NACK come through
492
493 //For now this should never get called, we return false when we see a NACK
494 //instead, by doing this we allow the bus_blocked mechanism to handle the retry
495 //For now it retrys in just 2 cycles, need to figure out how to change that
496 //Eventually we will want to also have success come in as a parameter
497 //Need to make sure that we handle the functionality that happens on successufl
498 //return of the sendAddr function
499 }
500 }
501
502 template<class TagStore, class Buffering, class Coherence>
503 void
504 Cache<TagStore,Buffering,Coherence>::invalidateBlk(Addr addr)
505 {
506 tags->invalidateBlk(addr);
507 }
508
509
510 /**
511 * @todo Fix to not assume write allocate
512 */
513 template<class TagStore, class Buffering, class Coherence>
514 Tick
515 Cache<TagStore,Buffering,Coherence>::probe(Packet * &pkt, bool update, CachePort* otherSidePort)
516 {
517 // MemDebug::cacheProbe(pkt);
518 if (!pkt->req->isUncacheable()) {
519 if (pkt->isInvalidate() && !pkt->isRead()
520 && !pkt->isWrite()) {
521 //Upgrade or Invalidate, satisfy it, don't forward
522 DPRINTF(Cache, "%s %x ? blk_addr: %x\n", pkt->cmdString(),
523 pkt->getAddr() & (((ULL(1))<<48)-1),
524 pkt->getAddr() & ~((Addr)blkSize - 1));
525 pkt->flags |= SATISFIED;
526 return 0;
527 }
528 }
529
530 PacketList writebacks;
531 int lat;
532 BlkType *blk = tags->handleAccess(pkt, lat, writebacks, update);
533
534 if (!blk) {
535 // Need to check for outstanding misses and writes
536 Addr blk_addr = pkt->getAddr() & ~(blkSize - 1);
537
538 // There can only be one matching outstanding miss.
539 MSHR* mshr = missQueue->findMSHR(blk_addr);
540
541 // There can be many matching outstanding writes.
542 std::vector<MSHR*> writes;
543 missQueue->findWrites(blk_addr, writes);
544
545 if (!update) {
546 otherSidePort->sendFunctional(pkt);
547
548 // Check for data in MSHR and writebuffer.
549 if (mshr) {
550 warn("Found outstanding miss on an non-update probe");
551 MSHR::TargetList *targets = mshr->getTargetList();
552 MSHR::TargetList::iterator i = targets->begin();
553 MSHR::TargetList::iterator end = targets->end();
554 for (; i != end; ++i) {
555 Packet * target = *i;
556 // If the target contains data, and it overlaps the
557 // probed request, need to update data
558 if (target->isWrite() && target->intersect(pkt)) {
559 uint8_t* pkt_data;
560 uint8_t* write_data;
561 int data_size;
562 if (target->getAddr() < pkt->getAddr()) {
563 int offset = pkt->getAddr() - target->getAddr();
564 pkt_data = pkt->getPtr<uint8_t>();
565 write_data = target->getPtr<uint8_t>() + offset;
566 data_size = target->getSize() - offset;
567 assert(data_size > 0);
568 if (data_size > pkt->getSize())
569 data_size = pkt->getSize();
570 } else {
571 int offset = target->getAddr() - pkt->getAddr();
572 pkt_data = pkt->getPtr<uint8_t>() + offset;
573 write_data = target->getPtr<uint8_t>();
574 data_size = pkt->getSize() - offset;
575 assert(data_size > pkt->getSize());
576 if (data_size > target->getSize())
577 data_size = target->getSize();
578 }
579
580 if (pkt->isWrite()) {
581 memcpy(pkt_data, write_data, data_size);
582 } else {
583 memcpy(write_data, pkt_data, data_size);
584 }
585 }
586 }
587 }
588 for (int i = 0; i < writes.size(); ++i) {
589 Packet * write = writes[i]->pkt;
590 if (write->intersect(pkt)) {
591 warn("Found outstanding write on an non-update probe");
592 uint8_t* pkt_data;
593 uint8_t* write_data;
594 int data_size;
595 if (write->getAddr() < pkt->getAddr()) {
596 int offset = pkt->getAddr() - write->getAddr();
597 pkt_data = pkt->getPtr<uint8_t>();
598 write_data = write->getPtr<uint8_t>() + offset;
599 data_size = write->getSize() - offset;
600 assert(data_size > 0);
601 if (data_size > pkt->getSize())
602 data_size = pkt->getSize();
603 } else {
604 int offset = write->getAddr() - pkt->getAddr();
605 pkt_data = pkt->getPtr<uint8_t>() + offset;
606 write_data = write->getPtr<uint8_t>();
607 data_size = pkt->getSize() - offset;
608 assert(data_size > pkt->getSize());
609 if (data_size > write->getSize())
610 data_size = write->getSize();
611 }
612
613 if (pkt->isWrite()) {
614 memcpy(pkt_data, write_data, data_size);
615 } else {
616 memcpy(write_data, pkt_data, data_size);
617 }
618
619 }
620 }
621 return 0;
622 } else {
623 // update the cache state and statistics
624 if (mshr || !writes.empty()){
625 // Can't handle it, return pktuest unsatisfied.
626 panic("Atomic access ran into outstanding MSHR's or WB's!");
627 }
628 if (!pkt->req->isUncacheable()) {
629 // Fetch the cache block to fill
630 BlkType *blk = tags->findBlock(pkt);
631 Packet::Command temp_cmd = coherence->getBusCmd(pkt->cmd,
632 (blk)? blk->status : 0);
633
634 Packet * busPkt = new Packet(pkt->req,temp_cmd, -1, blkSize);
635
636 busPkt->allocate();
637
638 busPkt->time = curTick;
639
640 lat = memSidePort->sendAtomic(busPkt);
641
642 //Be sure to flip the response to a request for coherence
643 if (busPkt->needsResponse()) {
644 busPkt->makeAtomicResponse();
645 }
646
647 /* if (!(busPkt->flags & SATISFIED)) {
648 // blocked at a higher level, just return
649 return 0;
650 }
651
652 */ misses[pkt->cmdToIndex()][0/*pkt->req->getThreadNum()*/]++;
653
654 CacheBlk::State old_state = (blk) ? blk->status : 0;
655 tags->handleFill(blk, busPkt,
656 coherence->getNewState(busPkt, old_state),
657 writebacks, pkt);
658 // Handle writebacks if needed
659 while (!writebacks.empty()){
660 memSidePort->sendAtomic(writebacks.front());
661 writebacks.pop_front();
662 }
663 return lat + hitLatency;
664 } else {
665 return memSidePort->sendAtomic(pkt);
666 }
667 }
668 } else {
669 // There was a cache hit.
670 // Handle writebacks if needed
671 while (!writebacks.empty()){
672 memSidePort->sendAtomic(writebacks.front());
673 writebacks.pop_front();
674 }
675
676 if (update) {
677 hits[pkt->cmdToIndex()][0/*pkt->req->getThreadNum()*/]++;
678 } else if (pkt->isWrite()) {
679 // Still need to change data in all locations.
680 otherSidePort->sendFunctional(pkt);
681 }
682 return curTick + lat;
683 }
684 fatal("Probe not handled.\n");
685 return 0;
686 }
687
688 template<class TagStore, class Buffering, class Coherence>
689 Tick
690 Cache<TagStore,Buffering,Coherence>::snoopProbe(PacketPtr &pkt)
691 {
692 Addr blk_addr = pkt->getAddr() & ~(Addr(blkSize-1));
693 BlkType *blk = tags->findBlock(pkt);
694 MSHR *mshr = missQueue->findMSHR(blk_addr);
695 CacheBlk::State new_state = 0;
696 bool satisfy = coherence->handleBusRequest(pkt,blk,mshr, new_state);
697 if (satisfy) {
698 DPRINTF(Cache, "Cache snooped a %s request and now supplying data,"
699 "new state is %i\n",
700 pkt->cmdString(), new_state);
701
702 tags->handleSnoop(blk, new_state, pkt);
703 return hitLatency;
704 }
705 if (blk) DPRINTF(Cache, "Cache snooped a %s request, new state is %i\n",
706 pkt->cmdString(), new_state);
707 tags->handleSnoop(blk, new_state);
708 return 0;
709 }
710