-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathID_Cache.h
727 lines (592 loc) · 20.7 KB
/
ID_Cache.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
typedef uint32_t CACHE_STATS;
#ifndef I_D_CACHE_H
#define I_D_CACHE_H
#include <string>
#include<assert.h>
/*!
* @brief Checks if n is a power of 2.
* @returns true if n is power of 2
*/
// static inline bool IsPower2(uint32_t n)
// {
// return ((n & (n - 1)) == 0);
// }
/*!
* @brief Computes floor(log2(n))
* Works by finding position of MSB set.
* @returns -1 if n == 0.
*/
// static inline int32_t FloorLog2(uint32_t n)
// {
// int32_t p = 0;
// if (n == 0) return -1;
// if (n & 0xffff0000) { p += 16; n >>= 16; }
// if (n & 0x0000ff00) { p += 8; n >>= 8; }
// if (n & 0x000000f0) { p += 4; n >>= 4; }
// if (n & 0x0000000c) { p += 2; n >>= 2; }
// if (n & 0x00000002) { p += 1; }
// return p;
// }
/*!
* @brief Computes floor(log2(n))
* Works by finding position of MSB set.
* @returns -1 if n == 0.
*/
// static inline int32_t CeilLog2(uint32_t n)
// {
// return FloorLog2(n - 1) + 1;
// }
/*!
* @brief Cache tag - self clearing on creation
*/
class CACHE_TAG
{
private:
uint64_t _tag;
public:
CACHE_TAG(uint64_t tag = 0) { _tag = tag; }
bool operator==(const CACHE_TAG &right) const { return _tag == right._tag; }
operator uint64_t() const { return _tag; }
};
/*!
* Everything related to cache sets
*/
namespace CACHE_SET
{
/*!
* @brief Cache set direct mapped
*/
class DIRECT_MAPPED
{
private:
CACHE_TAG _tag;
int32_t _ASID;
int32_t _valid;
public:
DIRECT_MAPPED(uint32_t associativity = 1) { assert(associativity == 1); _tag=-1; _ASID=-1; _valid=0;}
void SetAssociativity(uint32_t associativity) { assert(associativity == 1); }
uint32_t GetAssociativity(uint32_t associativity) { return 1; }
uint32_t Find_And_Access(CACHE_TAG tag, int32_t ASID)
{
if(_valid==1 && _tag == tag && _ASID==ASID)
return true;
else
return false;
}
void Replace(CACHE_TAG tag, int32_t ASID) { _tag = tag; _ASID=ASID; _valid=1;}
void Invalidate(CACHE_TAG tag, int32_t ASID)
{
if(_valid==1 && _tag == tag && _ASID==ASID)
_valid=0;
}
void Flush() { _tag = 0; _ASID=0; _valid=0;}
};
/*!
* @brief Cache set with round robin replacement
*/
template <uint32_t MAX_ASSOCIATIVITY = 4>
class ROUND_ROBIN
{
private:
CACHE_TAG _tags[MAX_ASSOCIATIVITY];
uint32_t _tagsLastIndex;
uint32_t _nextReplaceIndex;
int32_t _ASID[MAX_ASSOCIATIVITY];
int32_t _valid[MAX_ASSOCIATIVITY];
bool _modify[MAX_ASSOCIATIVITY];
public:
ROUND_ROBIN(uint32_t associativity = MAX_ASSOCIATIVITY)
: _tagsLastIndex(associativity - 1)
{
assert(associativity <= MAX_ASSOCIATIVITY);
_nextReplaceIndex = _tagsLastIndex;
for (int32_t index = _tagsLastIndex; index >= 0; index--)
{
_tags[index] = CACHE_TAG(0);
_ASID[index] = 0;
_valid[index] = 0;
_modify[index] = 0;
}
}
void SetAssociativity(uint32_t associativity)
{
assert(associativity <= MAX_ASSOCIATIVITY);
_tagsLastIndex = associativity - 1;
_nextReplaceIndex = _tagsLastIndex;
}
uint32_t GetAssociativity(uint32_t associativity) { return _tagsLastIndex + 1; }
uint32_t Find_And_Access(CACHE_TAG tag, int32_t ASID, bool is_write)
{
bool result = true;
for (int32_t index = _tagsLastIndex; index >= 0; index--)
{
// this is an ugly micro-optimization, but it does cause a
// tighter assembly loop for ARM that way ...
if(_tags[index] == tag && _ASID[index] == ASID && _valid[index]==1)
{
if(is_write==true)
_modify[index]=1;
goto end;
}
}
result = false;
end: return result;
}
bool Replace(CACHE_TAG tag, int32_t ASID, uint64_t &victim_tag)
{
bool victim_cache_modfiy_bit=0;
// g++ -O3 too dumb to do CSE on following lines?!
const uint32_t index = _nextReplaceIndex;
victim_cache_modfiy_bit=_modify[index];
victim_tag= _tags[index];
_tags[index] = tag;
_ASID[index] = ASID;
_valid[index] = 1;
_modify[index] = 0;
// condition typically faster than modulo
_nextReplaceIndex = (index == 0 ? _tagsLastIndex : index - 1);
return victim_cache_modfiy_bit;
}
void Invalidate(CACHE_TAG tag, int32_t ASID)
{
bool result = true;
for (int32_t index = _tagsLastIndex; index >= 0; index--)
{
// this is an ugly micro-optimization, but it does cause a
// tighter assembly loop for ARM that way ...
uint64_t tag_bits= _tags[index] >> 6;
if(_tags[index] == tag && _ASID[index] == ASID && _valid[index]==1)
{
_valid[index] = 0;
}
}
}
void Flush()
{
for (int32_t index = _tagsLastIndex; index >= 0; index--)
{
_tags[index] = 0;
_ASID[index] = 0;
_valid[index] = 0;
}
_nextReplaceIndex=_tagsLastIndex;
}
};
} // namespace CACHE_SET
namespace CACHE_ALLOC
{
typedef enum
{
STORE_ALLOCATE,
STORE_NO_ALLOCATE
} STORE_ALLOCATION;
}
/*!
* @brief Generic cache base class; no allocate specialization, no cache set specialization
*/
class CACHE_BASE
{
public:
// types, constants
typedef enum
{
ACCESS_TYPE_LOAD,
ACCESS_TYPE_STORE,
ACCESS_TYPE_NUM
} ACCESS_TYPE;
protected:
static const uint32_t HIT_MISS_NUM = 2;
CACHE_STATS _access[ACCESS_TYPE_NUM][HIT_MISS_NUM];
private:
// input params
const std::string _name;
const uint32_t _cacheSize;
const uint32_t _lineSize;
const uint32_t _associativity;
uint32_t _numberOfFlushes;
uint32_t _numberOfResets;
// computed params
const uint32_t _lineShift;
const uint32_t _setIndexMask;
CACHE_STATS SumAccess(bool hit) const
{
CACHE_STATS sum = 0;
for (uint32_t accessType = 0; accessType < ACCESS_TYPE_NUM; accessType++)
{
sum += _access[accessType][hit];
}
return sum;
}
protected:
uint32_t NumSets() const { return _setIndexMask + 1; }
public:
// constructors/destructors
CACHE_BASE(std::string name, uint32_t cacheSize, uint32_t lineSize, uint32_t associativity);
// accessors
uint32_t CacheSize() const { return _cacheSize; }
uint32_t LineSize() const { return _lineSize; }
uint32_t Associativity() const { return _associativity; }
//
CACHE_STATS Hits(ACCESS_TYPE accessType) const { return _access[accessType][true];}
CACHE_STATS Misses(ACCESS_TYPE accessType) const { return _access[accessType][false];}
CACHE_STATS Accesses(ACCESS_TYPE accessType) const { return Hits(accessType) + Misses(accessType);}
CACHE_STATS Hits() const { return SumAccess(true);}
CACHE_STATS Misses() const { return SumAccess(false);}
CACHE_STATS Accesses() const { return Hits() + Misses();}
CACHE_STATS Flushes() const { return _numberOfFlushes;}
CACHE_STATS Resets() const { return _numberOfResets;}
void SplitAddress(const uint64_t addr, CACHE_TAG & tag, uint32_t & setIndex) const
{
tag = addr >> _lineShift;
setIndex = tag & _setIndexMask;
}
void SplitAddress(const uint64_t addr, CACHE_TAG & tag, uint32_t & setIndex, uint32_t & lineIndex) const
{
const uint32_t lineMask = _lineSize - 1;
lineIndex = addr & lineMask;
SplitAddress(addr, tag, setIndex);
}
void IncFlushCounter()
{
_numberOfFlushes += 1;
}
void IncResetCounter()
{
_numberOfResets += 1;
}
std::string GetName()
{
return _name;
}
std::ostream & StatsLong(std::ostream & out) const;
};
CACHE_BASE::CACHE_BASE(std::string name, uint32_t cacheSize, uint32_t lineSize, uint32_t associativity)
: _name(name),
_cacheSize(cacheSize),
_lineSize(lineSize),
_associativity(associativity),
_lineShift(FloorLog2(lineSize)),
_setIndexMask((cacheSize / (associativity * lineSize)) - 1)
{
assert(IsPower2(_lineSize));
assert(IsPower2(_setIndexMask + 1));
for (uint32_t accessType = 0; accessType < ACCESS_TYPE_NUM; accessType++)
{
_access[accessType][false] = 0;
_access[accessType][true] = 0;
}
}
/*!
* @brief Stats output method
*/
std::ostream & CACHE_BASE::StatsLong(std::ostream & out) const
{
const uint32_t headerWidth = 19;
const uint32_t numberWidth = 10;
out << _name << ":" << std::endl;
for (uint32_t i = 0; i < ACCESS_TYPE_NUM; i++)
{
const ACCESS_TYPE accessType = ACCESS_TYPE(i);
std::string type(accessType == ACCESS_TYPE_LOAD ? "Load" : "Store");
out << StringString(type + " Hits: ", headerWidth)
<< StringInt(Hits(accessType), numberWidth) << std::endl;
out << StringString(type + " Misses: ", headerWidth)
<< StringInt(Misses(accessType), numberWidth) << std::endl;
out << StringString(type + " Accesses: ", headerWidth)
<< StringInt(Accesses(accessType), numberWidth) << std::endl;
out << StringString(type + " Miss Rate: ", headerWidth)
<< StringFlt(100.0 * Misses(accessType) / Accesses(accessType), 2, numberWidth-1) << "%" << std::endl;
out << std::endl;
}
out << StringString("Total Hits: ", headerWidth, ' ')
<< StringInt(Hits(), numberWidth) << std::endl;
out << StringString("Total Misses: ", headerWidth, ' ')
<< StringInt(Misses(), numberWidth) << std::endl;
out << StringString("Total Accesses: ", headerWidth, ' ')
<< StringInt(Accesses(), numberWidth) << std::endl;
out << StringString("Total Miss Rate: ", headerWidth, ' ')
<< StringFlt(100.0 * Misses() / Accesses(), 2, numberWidth-1) << "%" << std::endl;
out << StringString("Flushes: ", headerWidth, ' ')
<< StringInt(Flushes(), numberWidth) << std::endl;
out << StringString("Stat Resets: ", headerWidth, ' ')
<< StringInt(Resets(), numberWidth) << std::endl;
out << std::endl;
return out;
}
/// ostream operator for CACHE_BASE
std::ostream & operator<< (std::ostream & out, const CACHE_BASE & cacheBase)
{
return cacheBase.StatsLong(out);
}
/*!
* @brief Templated cache class with specific cache set allocation policies
*
* All that remains to be done here is allocate and deallocate the right
* type of cache sets.
*/
template <class SET, uint32_t MAX_SETS, uint32_t STORE_ALLOCATION>
class CACHE : public CACHE_BASE
{
private:
SET _sets[MAX_SETS];
public:
// constructors/destructors
CACHE(std::string name, uint32_t cacheSize, uint32_t lineSize, uint32_t associativity)
: CACHE_BASE(name, cacheSize, lineSize, associativity)
{
assert(NumSets() <= MAX_SETS);
for (uint32_t i = 0; i < NumSets(); i++)
{
_sets[i].SetAssociativity(associativity);
}
}
// modifiers
/// Cache access from addr to addr+size-1
bool AccessMultiCacheLine(uint64_t addr, uint32_t size, ACCESS_TYPE accessType, int32_t ASID, int &line_read, bool *linehit);
bool AccessCacheMulti(uint64_t addr, uint32_t size, ACCESS_TYPE accessType, int32_t ASID);
/// Cache access at addr that does not span cache lines
bool AccessSingleCacheLine(uint64_t addr, ACCESS_TYPE accessType, int32_t ASID);
bool ReplaceCACHE(uint64_t addr, ACCESS_TYPE accessType, int32_t ASID, uint64_t &victim_addr);
bool ReplaceCACHE(uint64_t addr, ACCESS_TYPE accessType, int32_t ASID);
void InvalidateCACHE(uint64_t addr, int32_t ASID);
void Flush();
void ResetStats();
};
/*!
* @return true if all accessed cache lines hit
*/
template <class SET, uint32_t MAX_SETS, uint32_t STORE_ALLOCATION>
bool CACHE<SET,MAX_SETS,STORE_ALLOCATION>::AccessMultiCacheLine(uint64_t addr, uint32_t size, ACCESS_TYPE accessType, int32_t ASID, int &line_read, bool *linehit)
{
const uint64_t highAddr = addr + size;
bool allHit = true;
const uint64_t lineSize = LineSize();
const uint64_t notLineMask = ~(lineSize - 1);
do
{
line_read++;
CACHE_TAG tag;
uint32_t setIndex;
SplitAddress(addr, tag, setIndex);
SET & set = _sets[setIndex];
bool is_write=false;
if(accessType == ACCESS_TYPE_STORE)
is_write=true;
bool localHit = set.Find_And_Access(tag,ASID,is_write);
allHit &= localHit;
linehit[line_read-1]=localHit;
// on miss, loads always allocate, stores optionally
//if ( (! localHit) && (accessType == ACCESS_TYPE_LOAD || STORE_ALLOCATION == CACHE_ALLOC::STORE_ALLOCATE))
//{
// set.Replace(tag, ASID);
//}
addr = (addr & notLineMask) + lineSize; // start of next cache line
}
while (addr < highAddr);
_access[accessType][allHit]++;
return allHit;
}
template <class SET, uint32_t MAX_SETS, uint32_t STORE_ALLOCATION>
bool CACHE<SET,MAX_SETS,STORE_ALLOCATION>::AccessCacheMulti(uint64_t addr, uint32_t size, ACCESS_TYPE accessType, int32_t ASID)
{
const uint64_t highAddr = addr + size;
bool allHit = true;
const uint64_t lineSize = LineSize();
const uint64_t notLineMask = ~(lineSize - 1);
do
{
CACHE_TAG tag;
uint32_t setIndex;
SplitAddress(addr, tag, setIndex);
SET & set = _sets[setIndex];
bool localHit = set.Find_And_Access(tag,ASID,0);
allHit &= localHit;
// on miss, loads always allocate, stores optionally
//if ( (! localHit) && (accessType == ACCESS_TYPE_LOAD || STORE_ALLOCATION == CACHE_ALLOC::STORE_ALLOCATE))
//{
// set.Replace(tag, ASID);
//}
addr = (addr & notLineMask) + lineSize; // start of next cache line
}
while (addr < highAddr);
_access[accessType][allHit]++;
return allHit;
}
/*!
* @return true if accessed cache line hits
*/
template <class SET, uint32_t MAX_SETS, uint32_t STORE_ALLOCATION>
bool CACHE<SET,MAX_SETS,STORE_ALLOCATION>::AccessSingleCacheLine(uint64_t addr, ACCESS_TYPE accessType, int32_t ASID)
{
CACHE_TAG tag;
uint32_t setIndex;
SplitAddress(addr, tag, setIndex);
SET & set = _sets[setIndex];
bool is_write=false;
if(accessType == ACCESS_TYPE_STORE)
is_write=true;
bool hit = set.Find_And_Access(tag,ASID,is_write);
// on miss, loads always allocate, stores optionally
//if ( (! hit) && (accessType == ACCESS_TYPE_LOAD || STORE_ALLOCATION == CACHE_ALLOC::STORE_ALLOCATE))
//{
// set.Replace(tag,ASID);
//}
_access[accessType][hit]++;
return hit;
}
/*!
* @return true if accessed cache line hits
*/
template <class SET, uint32_t MAX_SETS, uint32_t STORE_ALLOCATION>
bool CACHE<SET,MAX_SETS,STORE_ALLOCATION>::ReplaceCACHE(uint64_t addr, ACCESS_TYPE accessType, int32_t ASID, uint64_t &victim_addr)
{
bool victim_cache_modify_bit=0;
uint64_t victim_tag;
CACHE_TAG tag;
uint32_t setIndex;
SplitAddress(addr, tag, setIndex);
SET & set = _sets[setIndex];
//bool hit = set.Find(tag,ASID,paddr);
// on miss, loads always allocate, stores optionally
if ((accessType == ACCESS_TYPE_LOAD || STORE_ALLOCATION == CACHE_ALLOC::STORE_ALLOCATE))
{
victim_cache_modify_bit=set.Replace(tag,ASID,victim_tag);
}
victim_addr=victim_tag<<6;
return victim_cache_modify_bit;
}
template <class SET, uint32_t MAX_SETS, uint32_t STORE_ALLOCATION>
bool CACHE<SET,MAX_SETS,STORE_ALLOCATION>::ReplaceCACHE(uint64_t addr, ACCESS_TYPE accessType, int32_t ASID)
{
bool victim_cache_modify_bit=0;
uint64_t victim_tag;
CACHE_TAG tag;
uint32_t setIndex;
SplitAddress(addr, tag, setIndex);
SET & set = _sets[setIndex];
//bool hit = set.Find(tag,ASID,paddr);
// on miss, loads always allocate, stores optionally
if ((accessType == ACCESS_TYPE_LOAD || STORE_ALLOCATION == CACHE_ALLOC::STORE_ALLOCATE))
{
victim_cache_modify_bit=set.Replace(tag,ASID,victim_tag);
}
return victim_cache_modify_bit;
}
template <class SET, uint32_t MAX_SETS, uint32_t STORE_ALLOCATION>
void CACHE<SET,MAX_SETS,STORE_ALLOCATION>::InvalidateCACHE(uint64_t addr, int32_t ASID)
{
CACHE_TAG tag;
uint32_t setIndex;
SplitAddress(addr, tag, setIndex);
SET & set = _sets[setIndex];
//bool hit = set.Find(tag,ASID,paddr);
// on miss, loads always allocate, stores optionally
set.Invalidate(tag,ASID);
// if ((accessType == ACCESS_TYPE_LOAD || STORE_ALLOCATION == CACHE_ALLOC::STORE_ALLOCATE))
// {
// set.Replace(tag,ASID,paddr);
// }
//_access[accessType][hit]++;
//return hit;
}
template <class SET, uint32_t MAX_SETS, uint32_t STORE_ALLOCATION>
void CACHE<SET,MAX_SETS,STORE_ALLOCATION>::Flush()
{
for (int32_t index = NumSets(); index >= 0; index--) {
SET & set = _sets[index];
set.Flush();
}
IncFlushCounter();
}
template <class SET, uint32_t MAX_SETS, uint32_t STORE_ALLOCATION>
void CACHE<SET,MAX_SETS,STORE_ALLOCATION>::ResetStats()
{
for (uint32_t accessType = 0; accessType < ACCESS_TYPE_NUM; accessType++)
{
_access[accessType][false] = 0;
_access[accessType][true] = 0;
}
IncResetCounter();
}
void GetNextBlockAddress(uint64_t &paddr, int32_t ASID)
{
const uint64_t lineSize = 64;
const uint64_t notLineMask = ~(lineSize - 1);
paddr = (paddr & notLineMask) + lineSize;
}
// define shortcuts
#define CACHE_DIRECT_MAPPED(MAX_SETS, ALLOCATION) CACHE<CACHE_SET::DIRECT_MAPPED, MAX_SETS, ALLOCATION>
#define CACHE_ROUND_ROBIN(MAX_SETS, MAX_ASSOCIATIVITY, ALLOCATION) CACHE<CACHE_SET::ROUND_ROBIN<MAX_ASSOCIATIVITY>, MAX_SETS, ALLOCATION>
namespace IL1
{
// 1st level instruction cache: 32 kB, 64 B lines, 8-way associative
// const uint32_t cacheSize = 32*KILO;
const uint32_t cacheSize = 32*KILO;
const uint32_t lineSize = 64;
const uint32_t associativity = 8;
const CACHE_ALLOC::STORE_ALLOCATION allocation = CACHE_ALLOC::STORE_NO_ALLOCATE;
const uint32_t max_sets = cacheSize / (lineSize * associativity);
const uint32_t max_associativity = associativity;
typedef CACHE_ROUND_ROBIN(max_sets, max_associativity, allocation) CACHE;
}extern IL1::CACHE il1s[core_count*num_nodes];
#define BOOST_PP_LOCAL_LIMITS (0, ((core_count*num_nodes)-1))
#define BOOST_PP_LOCAL_MACRO(n) IL1::CACHE("L1_I"#n, IL1::cacheSize, IL1::lineSize, IL1::associativity),
IL1::CACHE il1s[]=
{
#include "boost/preprocessor/iteration/detail/local.hpp"
};
namespace DL1
{
// 1st level data cache: 32 kB, 64 B lines, 8-way associative
// const uint32_t cacheSize = 32*KILO;
const uint32_t cacheSize = 32*KILO;
const uint32_t lineSize = 64;
const uint32_t associativity = 8;
const CACHE_ALLOC::STORE_ALLOCATION allocation = CACHE_ALLOC::STORE_NO_ALLOCATE;
const uint32_t max_sets = cacheSize / (lineSize * associativity);
const uint32_t max_associativity = associativity;
typedef CACHE_ROUND_ROBIN(max_sets, max_associativity, allocation) CACHE;
}extern DL1::CACHE dl1s[core_count*num_nodes];
#define BOOST_PP_LOCAL_LIMITS (0, ((core_count*num_nodes)-1))
#define BOOST_PP_LOCAL_MACRO(n) DL1::CACHE("L1_D"#n, DL1::cacheSize, DL1::lineSize, DL1::associativity),
DL1::CACHE dl1s[]=
{
#include "boost/preprocessor/iteration/detail/local.hpp"
};
namespace L2
{
// 2nd level cache: 256 KB, 64 B lines, 4-way associative
// const uint32_t cacheSize = 256*KILO;
const uint32_t cacheSize = 256*KILO;
const uint32_t lineSize = 64;
const uint32_t associativity = 4;
const CACHE_ALLOC::STORE_ALLOCATION allocation = CACHE_ALLOC::STORE_NO_ALLOCATE;
const uint32_t max_sets = cacheSize / (lineSize * associativity);
const uint32_t max_associativity = associativity;
typedef CACHE_ROUND_ROBIN(max_sets, max_associativity, allocation) CACHE;
}extern L2::CACHE l2s[core_count*num_nodes];
#define BOOST_PP_LOCAL_LIMITS (0, ((core_count*num_nodes)-1))
#define BOOST_PP_LOCAL_MACRO(n) L2::CACHE("L2_"#n, L2::cacheSize, L2::lineSize, L2::associativity),
L2::CACHE l2s[]=
{
#include "boost/preprocessor/iteration/detail/local.hpp"
};
namespace UL3
{
// 3rd level unified cache: 16 MB, 64 B lines, 16-way associative
const uint32_t cacheSize = (core_count*2*MEGA);
//const uint32_t cacheSize = (8*KILO);
const uint32_t lineSize = 64;
const uint32_t associativity = 16;
const CACHE_ALLOC::STORE_ALLOCATION allocation = CACHE_ALLOC::STORE_ALLOCATE;
const uint32_t max_sets = cacheSize / (lineSize * associativity);
const uint32_t max_associativity = associativity;
typedef CACHE_ROUND_ROBIN(max_sets, max_associativity, allocation) CACHE;
}extern UL3::CACHE ul3[num_nodes];
#define BOOST_PP_LOCAL_LIMITS (0, (num_nodes-1))
#define BOOST_PP_LOCAL_MACRO(n) UL3::CACHE("L3_"#n, UL3::cacheSize, UL3::lineSize, UL3::associativity),
UL3::CACHE ul3[]=
{
#include "boost/preprocessor/iteration/detail/local.hpp"
};
#endif // PIN_CACHE_H