2 * Copyright (c) 2002-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 * Definitions of the Indirect Index Cache tagstore.
42 #include "mem/cache/base_cache.hh"
43 #include "mem/cache/tags/iic.hh"
44 #include "base/intmath.hh"
45 #include "sim/root.hh" // for curTick
47 #include "base/trace.hh" // for DPRINTF
52 /** Track the number of accesses to each cache set. */
55 IIC::IIC(IIC::Params
¶ms
) :
56 hashSets(params
.numSets
), blkSize(params
.blkSize
), assoc(params
.assoc
),
57 hitLatency(params
.hitLatency
), subSize(params
.subblockSize
),
58 numSub(blkSize
/subSize
),
59 trivialSize((floorLog2(params
.size
/subSize
)*numSub
)/8),
60 tagShift(floorLog2(blkSize
)), blkMask(blkSize
- 1),
61 subShift(floorLog2(subSize
)), subMask(numSub
- 1),
62 hashDelay(params
.hashDelay
),
63 numBlocks(params
.size
/subSize
),
64 numTags(hashSets
* assoc
+ params
.size
/blkSize
-1),
65 numSecondary(params
.size
/blkSize
),
67 primaryBound(hashSets
* assoc
)
72 if (blkSize
< 4 || !isPowerOf2(blkSize
)) {
73 fatal("Block size must be at least 4 and a power of 2");
75 if (hashSets
<= 0 || !isPowerOf2(hashSets
)) {
76 fatal("# of hashsets must be non-zero and a power of 2");
79 fatal("associativity must be greater than zero");
81 if (hitLatency
<= 0) {
82 fatal("access latency must be greater than zero");
84 if (numSub
*subSize
!= blkSize
) {
85 fatal("blocksize must be evenly divisible by subblock size");
89 freeSecond
= numSecondary
;
92 warmupBound
= params
.size
/blkSize
;
94 // Replacement Policy Initialization
100 // allocate data reference counters
101 dataReferenceCount
= new int[numBlocks
];
102 memset(dataReferenceCount
, 0, numBlocks
*sizeof(int));
104 // Allocate storage for both internal data and block fast access data.
105 // We allocate it as one large chunk to reduce overhead and to make
108 dataStore
= new uint8_t[(numBlocks
+ numTags
) * blkSize
];
109 dataBlks
= new uint8_t*[numBlocks
];
110 for (i
= 0; i
< numBlocks
; ++i
) {
111 dataBlks
[i
] = &dataStore
[data_index
];
113 data_index
+= subSize
;
116 assert(data_index
== numBlocks
* subSize
);
118 // allocate and init tag store
119 tagStore
= new IICTag
[numTags
];
122 // allocate and init sets
123 sets
= new IICSet
[hashSets
];
124 for (i
= 0; i
< hashSets
; ++i
) {
125 sets
[i
].assoc
= assoc
;
126 sets
[i
].tags
= new IICTag
*[assoc
];
127 sets
[i
].chain_ptr
= tagNull
;
129 for (int j
= 0; j
< assoc
; ++j
) {
130 IICTag
*tag
= &tagStore
[blkIndex
++];
131 tag
->chain_ptr
= tagNull
;
132 tag
->data_ptr
.resize(numSub
);
134 tag
->trivialData
= new uint8_t[trivialSize
];
136 sets
[i
].tags
[j
] = tag
;
138 tag
->data
= &dataStore
[data_index
];
139 data_index
+= blkSize
;
143 assert(blkIndex
== primaryBound
);
145 for (i
= primaryBound
; i
< tagNull
; i
++) {
146 tagStore
[i
].chain_ptr
= i
+1;
147 //setup data ptrs to subblocks
148 tagStore
[i
].data_ptr
.resize(numSub
);
149 tagStore
[i
].size
= blkSize
;
150 tagStore
[i
].trivialData
= new uint8_t[trivialSize
];
151 tagStore
[i
].numData
= 0;
153 tagStore
[i
].data
= &dataStore
[data_index
];
154 data_index
+= blkSize
;
156 freelist
= primaryBound
;
161 delete [] dataReferenceCount
;
167 /* register cache stats */
169 IIC::regStats(const string
&name
)
171 using namespace Stats
;
173 BaseTags::regStats(name
);
175 hitHashDepth
.init(0, 20, 1);
176 missHashDepth
.init(0, 20, 1);
177 setAccess
.init(0, hashSets
, 1);
179 /** IIC Statistics */
181 .name(name
+ ".hit_hash_depth_dist")
182 .desc("Dist. of Hash lookup depths")
187 .name(name
+ ".miss_hash_depth_dist")
188 .desc("Dist. of Hash lookup depths")
192 repl
->regStats(name
);
196 .name(name
+ ".set_access_dist")
197 .desc("Dist. of Accesses across sets")
202 .name(name
+ ".miss_depth_total")
203 .desc("Total of miss depths")
207 .name(name
+ ".hash_miss")
208 .desc("Total of misses in hash table")
212 .name(name
+ ".hit_depth_total")
213 .desc("Total of hit depths")
217 .name(name
+ ".hash_hit")
218 .desc("Total of hites in hash table")
222 // probe cache for presence of given block.
224 IIC::probe(int asid
, Addr addr
) const
226 return (findBlock(addr
,asid
) != NULL
);
230 IIC::findBlock(Addr addr
, int asid
, int &lat
)
232 Addr tag
= extractTag(addr
);
233 unsigned set
= hash(addr
);
236 unsigned long chain_ptr
;
239 setAccess
.sample(set
);
241 IICTag
*tag_ptr
= sets
[set
].findTag(asid
, tag
, chain_ptr
);
243 if (tag_ptr
== NULL
&& chain_ptr
!= tagNull
) {
245 tag_ptr
= secondaryChain(asid
, tag
, chain_ptr
, &secondary_depth
);
246 set_lat
+= secondary_depth
;
247 // set depth for statistics fix this later!!! egh
248 sets
[set
].depth
= set_lat
;
250 if (tag_ptr
!= NULL
) {
251 /* need to move tag into primary table */
252 // need to preserve chain: fix this egh
253 sets
[set
].tags
[assoc
-1]->chain_ptr
= tag_ptr
->chain_ptr
;
254 tagSwap(tag_ptr
- tagStore
, sets
[set
].tags
[assoc
-1] - tagStore
);
255 tag_ptr
= sets
[set
].findTag(asid
, tag
, chain_ptr
);
256 assert(tag_ptr
!=NULL
);
260 set_lat
= set_lat
* hashDelay
+ hitLatency
;
261 if (tag_ptr
!= NULL
) {
262 // IIC replacement: if this is not the first element of
264 sets
[set
].moveToHead(tag_ptr
);
266 hitHashDepth
.sample(sets
[set
].depth
);
268 hitDepthTotal
+= sets
[set
].depth
;
269 tag_ptr
->status
|= BlkReferenced
;
271 if (tag_ptr
->whenReady
> curTick
&& tag_ptr
->whenReady
- curTick
> set_lat
) {
272 lat
= tag_ptr
->whenReady
- curTick
;
275 tag_ptr
->refCount
+= 1;
278 // fall through: cache block not found, not a hit...
279 missHashDepth
.sample(sets
[set
].depth
);
281 missDepthTotal
+= sets
[set
].depth
;
288 IIC::findBlock(Packet
* &pkt
, int &lat
)
290 Addr addr
= pkt
->paddr
;
291 int asid
= pkt
->req
->asid
;
293 Addr tag
= extractTag(addr
);
294 unsigned set
= hash(addr
);
297 unsigned long chain_ptr
;
300 setAccess
.sample(set
);
302 IICTag
*tag_ptr
= sets
[set
].findTag(asid
, tag
, chain_ptr
);
304 if (tag_ptr
== NULL
&& chain_ptr
!= tagNull
) {
306 tag_ptr
= secondaryChain(asid
, tag
, chain_ptr
, &secondary_depth
);
307 set_lat
+= secondary_depth
;
308 // set depth for statistics fix this later!!! egh
309 sets
[set
].depth
= set_lat
;
311 if (tag_ptr
!= NULL
) {
312 /* need to move tag into primary table */
313 // need to preserve chain: fix this egh
314 sets
[set
].tags
[assoc
-1]->chain_ptr
= tag_ptr
->chain_ptr
;
315 tagSwap(tag_ptr
- tagStore
, sets
[set
].tags
[assoc
-1] - tagStore
);
316 tag_ptr
= sets
[set
].findTag(asid
, tag
, chain_ptr
);
317 assert(tag_ptr
!=NULL
);
321 set_lat
= set_lat
* hashDelay
+ hitLatency
;
322 if (tag_ptr
!= NULL
) {
323 // IIC replacement: if this is not the first element of
325 sets
[set
].moveToHead(tag_ptr
);
327 hitHashDepth
.sample(sets
[set
].depth
);
329 hitDepthTotal
+= sets
[set
].depth
;
330 tag_ptr
->status
|= BlkReferenced
;
332 if (tag_ptr
->whenReady
> curTick
&& tag_ptr
->whenReady
- curTick
> set_lat
) {
333 lat
= tag_ptr
->whenReady
- curTick
;
336 tag_ptr
->refCount
+= 1;
339 // fall through: cache block not found, not a hit...
340 missHashDepth
.sample(sets
[set
].depth
);
342 missDepthTotal
+= sets
[set
].depth
;
349 IIC::findBlock(Addr addr
, int asid
) const
351 Addr tag
= extractTag(addr
);
352 unsigned set
= hash(addr
);
354 unsigned long chain_ptr
;
356 IICTag
*tag_ptr
= sets
[set
].findTag(asid
, tag
, chain_ptr
);
357 if (tag_ptr
== NULL
&& chain_ptr
!= tagNull
) {
359 tag_ptr
= secondaryChain(asid
, tag
, chain_ptr
, &secondary_depth
);
366 IIC::findReplacement(Packet
* &pkt
, PacketList
* &writebacks
,
367 BlkList
&compress_blocks
)
369 DPRINTF(IIC
, "Finding Replacement for %x\n", pkt
->paddr
);
370 unsigned set
= hash(pkt
->paddr
);
372 unsigned long *tmp_data
= new unsigned long[numSub
];
374 // Get a enough subblocks for a full cache line
375 for (int i
= 0; i
< numSub
; ++i
){
376 tmp_data
[i
] = getFreeDataBlock(writebacks
);
377 assert(dataReferenceCount
[tmp_data
[i
]]==0);
380 tag_ptr
= getFreeTag(set
, writebacks
);
383 for (int i
=0; i
< numSub
; ++i
) {
384 tag_ptr
->data_ptr
[i
] = tmp_data
[i
];
385 dataReferenceCount
[tag_ptr
->data_ptr
[i
]]++;
387 tag_ptr
->numData
= numSub
;
388 assert(tag_ptr
- tagStore
< primaryBound
); // make sure it is in primary
389 tag_ptr
->chain_ptr
= tagNull
;
390 sets
[set
].moveToHead(tag_ptr
);
393 list
<unsigned long> tag_indexes
;
394 repl
->doAdvance(tag_indexes
);
395 while (!tag_indexes
.empty()) {
396 if (!tagStore
[tag_indexes
.front()].isCompressed()) {
397 compress_blocks
.push_back(&tagStore
[tag_indexes
.front()]);
399 tag_indexes
.pop_front();
402 tag_ptr
->re
= (void*)repl
->add(tag_ptr
-tagStore
);
408 IIC::freeReplacementBlock(PacketList
* & writebacks
)
411 unsigned long data_ptr
;
412 /* consult replacement policy */
413 tag_ptr
= &tagStore
[repl
->getRepl()];
414 assert(tag_ptr
->isValid());
416 DPRINTF(Cache
, "Replacing %x in IIC: %s\n",
417 regenerateBlkAddr(tag_ptr
->tag
,0),
418 tag_ptr
->isModified() ? "writeback" : "clean");
419 /* write back replaced block data */
420 if (tag_ptr
&& (tag_ptr
->isValid())) {
421 int thread_num
= (tag_ptr
->xc
) ? tag_ptr
->xc
->getThreadNum() : 0;
422 replacements
[thread_num
]++;
423 totalRefs
+= tag_ptr
->refCount
;
425 tag_ptr
->refCount
= 0;
427 if (tag_ptr
->isModified()) {
429 buildWritebackReq(regenerateBlkAddr(tag_ptr
->tag
, 0),
430 tag_ptr
->req
->asid
, tag_ptr
->xc
, blkSize
,
431 (cache
->doData())?tag_ptr
->data
:0,
433 writebacks
.push_back(writeback
);
437 // free the data blocks
438 for (int i
= 0; i
< tag_ptr
->numData
; ++i
) {
439 data_ptr
= tag_ptr
->data_ptr
[i
];
440 assert(dataReferenceCount
[data_ptr
]>0);
441 if (--dataReferenceCount
[data_ptr
] == 0) {
442 freeDataBlock(data_ptr
);
449 IIC::getFreeDataBlock(PacketList
* & writebacks
)
451 struct IICTag
*tag_ptr
;
452 unsigned long data_ptr
;
455 /* find data block */
456 while (blkFreelist
.empty()) {
457 freeReplacementBlock(writebacks
);
460 data_ptr
= blkFreelist
.front();
461 blkFreelist
.pop_front();
462 DPRINTF(IICMore
,"Found free data at %d\n",data_ptr
);
469 IIC::getFreeTag(int set
, PacketList
* & writebacks
)
471 unsigned long tag_index
;
474 tag_ptr
= sets
[set
].findFree();
475 // if no free in primary, and secondary exists
476 if (!tag_ptr
&& numSecondary
) {
477 // need to spill a tag into secondary storage
478 while (freelist
== tagNull
) {
479 // get replacements until one is in secondary
480 freeReplacementBlock(writebacks
);
483 tag_index
= freelist
;
484 freelist
= tagStore
[freelist
].chain_ptr
;
487 assert(tag_index
!= tagNull
);
488 tagSwap(tag_index
, sets
[set
].tags
[assoc
-1] - tagStore
);
489 tagStore
[tag_index
].chain_ptr
= sets
[set
].chain_ptr
;
490 sets
[set
].chain_ptr
= tag_index
;
492 tag_ptr
= sets
[set
].tags
[assoc
-1];
494 DPRINTF(IICMore
,"Found free tag at %d\n",tag_ptr
- tagStore
);
496 if (!warmedUp
&& tagsInUse
.value() >= warmupBound
) {
498 warmupCycle
= curTick
;
505 IIC::freeTag(IICTag
*tag_ptr
)
507 unsigned long tag_index
, tmp_index
;
510 // we have a tag to clear
511 DPRINTF(IICMore
,"Freeing Tag for %x\n",
512 regenerateBlkAddr(tag_ptr
->tag
,0));
515 tag_ptr
->numData
= 0;
517 tag_index
= tag_ptr
- tagStore
;
518 if (tag_index
>= primaryBound
) {
519 // tag_ptr points to secondary store
520 assert(tag_index
< tagNull
); // remove this?? egh
521 if (tag_ptr
->chain_ptr
== tagNull
) {
522 // need to fix chain list
523 unsigned tmp_set
= hash(tag_ptr
->tag
<< tagShift
);
524 if (sets
[tmp_set
].chain_ptr
== tag_index
) {
525 sets
[tmp_set
].chain_ptr
= tagNull
;
527 tmp_index
= sets
[tmp_set
].chain_ptr
;
528 while (tmp_index
!= tagNull
529 && tagStore
[tmp_index
].chain_ptr
!= tag_index
) {
530 tmp_index
= tagStore
[tmp_index
].chain_ptr
;
532 assert(tmp_index
!= tagNull
);
533 tagStore
[tmp_index
].chain_ptr
= tagNull
;
535 tag_ptr
->chain_ptr
= freelist
;
536 freelist
= tag_index
;
539 // copy next chained entry to this tag location
540 tmp_index
= tag_ptr
->chain_ptr
;
541 tagSwap(tmp_index
, tag_index
);
542 tagStore
[tmp_index
].chain_ptr
= freelist
;
543 freelist
= tmp_index
;
547 // tag_ptr in primary hash table
548 assert(tag_index
< primaryBound
);
550 unsigned tmp_set
= hash(tag_ptr
->tag
<< tagShift
);
551 if (sets
[tmp_set
].chain_ptr
!= tagNull
) { // collapse chain
552 tmp_index
= sets
[tmp_set
].chain_ptr
;
553 tagSwap(tag_index
, tmp_index
);
554 tagStore
[tmp_index
].chain_ptr
= freelist
;
555 freelist
= tmp_index
;
557 sets
[tmp_set
].chain_ptr
= tag_ptr
->chain_ptr
;
558 sets
[tmp_set
].moveToTail(tag_ptr
);
565 IIC::freeDataBlock(unsigned long data_ptr
)
567 assert(dataReferenceCount
[data_ptr
] == 0);
568 DPRINTF(IICMore
, "Freeing data at %d\n", data_ptr
);
569 blkFreelist
.push_front(data_ptr
);
572 /** Use a simple modulo hash. */
573 #define SIMPLE_HASH 0
576 IIC::hash(Addr addr
) const {
578 return extractTag(addr
) % iic_hash_size
;
580 Addr tag
, mask
, x
, y
;
581 tag
= extractTag(addr
);
582 mask
= hashSets
-1; /* assumes iic_hash_size is a power of 2 */
584 y
= (tag
>> (int)(::log(hashSets
)/::log(2))) & mask
;
585 assert (x
< hashSets
&& y
< hashSets
);
592 IICSet::moveToHead(IICTag
*tag
)
597 // write 'next' block into blks[i], moving up from MRU toward LRU
598 // until we overwrite the block we moved to head.
600 // start by setting up to write 'blk' into blks[0]
606 // swap blks[i] and next
607 IICTag
*tmp
= tags
[i
];
611 } while (next
!= tag
);
615 IICSet::moveToTail(IICTag
*tag
)
617 if (tags
[assoc
-1] == tag
)
620 // write 'next' block into blks[i], moving up from MRU toward LRU
621 // until we overwrite the block we moved to head.
623 // start by setting up to write 'blk' into blks[0]
629 // swap blks[i] and next
630 IICTag
*tmp
= tags
[i
];
634 } while (next
!= tag
);
638 IIC::tagSwap(unsigned long index1
, unsigned long index2
)
640 DPRINTF(IIC
,"Swapping tag[%d]=%x for tag[%d]=%x\n",index1
,
641 tagStore
[index1
].tag
<<tagShift
, index2
,
642 tagStore
[index2
].tag
<<tagShift
);
644 tmp_tag
= tagStore
[index1
];
645 tagStore
[index1
] = tagStore
[index2
];
646 tagStore
[index2
] = tmp_tag
;
647 if (tagStore
[index1
].isValid())
648 repl
->fixTag(tagStore
[index1
].re
, index2
, index1
);
649 if (tagStore
[index2
].isValid())
650 repl
->fixTag(tagStore
[index2
].re
, index1
, index2
);
655 IIC::secondaryChain(int asid
, Addr tag
, unsigned long chain_ptr
,
659 while (chain_ptr
!= tagNull
) {
660 DPRINTF(IIC
,"Searching secondary at %d for %x\n", chain_ptr
,
662 if (tagStore
[chain_ptr
].tag
== tag
&&
663 tagStore
[chain_ptr
].asid
== asid
&&
664 (tagStore
[chain_ptr
].isValid())) {
666 return &tagStore
[chain_ptr
];
669 chain_ptr
= tagStore
[chain_ptr
].chain_ptr
;
676 IIC::decompressBlock(unsigned long index
)
678 IICTag
*tag_ptr
= &tagStore
[index
];
679 if (tag_ptr
->isCompressed()) {
680 // decompress the data here.
685 IIC::compressBlock(unsigned long index
)
687 IICTag
*tag_ptr
= &tagStore
[index
];
688 if (!tag_ptr
->isCompressed()) {
689 // Compress the data here.
694 IIC::invalidateBlk(int asid
, Addr addr
)
696 IICTag
* tag_ptr
= findBlock(addr
, asid
);
698 for (int i
= 0; i
< tag_ptr
->numData
; ++i
) {
699 dataReferenceCount
[tag_ptr
->data_ptr
[i
]]--;
700 if (dataReferenceCount
[tag_ptr
->data_ptr
[i
]] == 0) {
701 freeDataBlock(tag_ptr
->data_ptr
[i
]);
704 repl
->removeEntry(tag_ptr
->re
);
710 IIC::readData(IICTag
*blk
, uint8_t *data
){
711 assert(cache
->doData());
712 assert(blk
->size
<= trivialSize
|| blk
->numData
> 0);
713 int data_size
= blk
->size
;
714 if (data_size
> trivialSize
) {
715 for (int i
= 0; i
< blk
->numData
; ++i
){
716 memcpy(data
+i
*subSize
,
717 &(dataBlks
[blk
->data_ptr
[i
]][0]),
718 (data_size
>subSize
)?subSize
:data_size
);
719 data_size
-= subSize
;
722 memcpy(data
,blk
->trivialData
,data_size
);
727 IIC::writeData(IICTag
*blk
, uint8_t *write_data
, int size
,
728 PacketList
* & writebacks
){
729 assert(cache
->doData());
730 assert(size
< blkSize
|| !blk
->isCompressed());
731 DPRINTF(IIC
, "Writing %d bytes to %x\n", size
,
733 // Find the number of subblocks needed, (round up)
734 int num_subs
= (size
+ (subSize
-1))/subSize
;
735 if (size
<= trivialSize
) {
738 assert(num_subs
<= numSub
);
739 if (num_subs
> blk
->numData
) {
740 // need to allocate more data blocks
741 for (int i
= blk
->numData
; i
< num_subs
; ++i
){
742 blk
->data_ptr
[i
] = getFreeDataBlock(writebacks
);
743 dataReferenceCount
[blk
->data_ptr
[i
]] += 1;
745 } else if (num_subs
< blk
->numData
){
746 // can free data blocks
747 for (int i
=num_subs
; i
< blk
->numData
; ++i
){
748 // decrement reference count and compare to zero
751 * Make this work with copying.
753 if (--dataReferenceCount
[blk
->data_ptr
[i
]] == 0) {
754 freeDataBlock(blk
->data_ptr
[i
]);
759 blk
->numData
= num_subs
;
761 assert(size
<= trivialSize
|| blk
->numData
> 0);
762 if (size
> trivialSize
){
763 for (int i
= 0; i
< blk
->numData
; ++i
){
764 memcpy(&dataBlks
[blk
->data_ptr
[i
]][0], write_data
+ i
*subSize
,
765 (size
>subSize
)?subSize
:size
);
769 memcpy(blk
->trivialData
,write_data
,size
);
775 * @todo This code can break if the src is evicted to get a tag for the dest.
778 IIC::doCopy(Addr source
, Addr dest
, int asid
, PacketList
* &writebacks
)
780 IICTag
*dest_tag
= findBlock(dest
, asid
);
783 for (int i
= 0; i
< dest_tag
->numData
; ++i
) {
784 if (--dataReferenceCount
[dest_tag
->data_ptr
[i
]] == 0) {
785 freeDataBlock(dest_tag
->data_ptr
[i
]);
788 // Reset replacement entry
790 dest_tag
= getFreeTag(hash(dest
), writebacks
);
791 dest_tag
->re
= (void*) repl
->add(dest_tag
- tagStore
);
792 dest_tag
->set
= hash(dest
);
793 dest_tag
->tag
= extractTag(dest
);
794 dest_tag
->req
->asid
= asid
;
795 dest_tag
->status
= BlkValid
| BlkWritable
;
797 // Find the source tag here since it might move if we need to find a
798 // tag for the destination.
799 IICTag
*src_tag
= findBlock(source
, asid
);
801 assert(!cache
->doData() || src_tag
->size
<= trivialSize
802 || src_tag
->numData
> 0);
803 // point dest to source data and inc counter
804 for (int i
= 0; i
< src_tag
->numData
; ++i
) {
805 dest_tag
->data_ptr
[i
] = src_tag
->data_ptr
[i
];
806 ++dataReferenceCount
[dest_tag
->data_ptr
[i
]];
809 // Maintain fast access data.
810 memcpy(dest_tag
->data
, src_tag
->data
, blkSize
);
812 dest_tag
->xc
= src_tag
->xc
;
813 dest_tag
->size
= src_tag
->size
;
814 dest_tag
->numData
= src_tag
->numData
;
815 if (src_tag
->numData
== 0) {
816 // Data is stored in the trivial data, just copy it.
817 memcpy(dest_tag
->trivialData
, src_tag
->trivialData
, src_tag
->size
);
820 dest_tag
->status
|= BlkDirty
;
821 if (dest_tag
->size
< blkSize
) {
822 dest_tag
->status
|= BlkCompressed
;
824 dest_tag
->status
&= ~BlkCompressed
;
829 IIC::fixCopy(Packet
* &pkt
, PacketList
* &writebacks
)
831 // if reference counter is greater than 1, do copy
833 Addr blk_addr
= blkAlign(pkt
->paddr
);
834 IICTag
* blk
= findBlock(blk_addr
, pkt
->req
->asid
);
836 if (blk
->numData
> 0 && dataReferenceCount
[blk
->data_ptr
[0]] != 1) {
838 // Mark the block as referenced so it doesn't get replaced.
839 blk
->status
|= BlkReferenced
;
840 for (int i
= 0; i
< blk
->numData
; ++i
){
841 unsigned long new_data
= getFreeDataBlock(writebacks
);
842 // Need to refresh pointer
844 * @todo Remove this refetch once we change IIC to pointer based
846 blk
= findBlock(blk_addr
, pkt
->req
->asid
);
848 if (cache
->doData()) {
849 memcpy(&(dataBlks
[new_data
][0]),
850 &(dataBlks
[blk
->data_ptr
[i
]][0]),
853 dataReferenceCount
[blk
->data_ptr
[i
]]--;
854 dataReferenceCount
[new_data
]++;
855 blk
->data_ptr
[i
] = new_data
;
863 for (int i
= 0; i
< numTags
; ++i
) {
864 if (tagStore
[i
].isValid()) {
865 totalRefs
+= tagStore
[i
].refCount
;