forked from CMU-SAFARI/Cache-Memory-Hog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache_miss_sequential.c
More file actions
97 lines (78 loc) · 2.21 KB
/
Copy pathcache_miss_sequential.c
File metadata and controls
97 lines (78 loc) · 2.21 KB
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
//Author: Arnab Ghosh
#include <stdio.h>
#include <string.h>
#include <unistd.h>
//#include "timer.h"
////////////////////////////////////////////////////////////////////////
// Xeon L5630 Processor
// L1 I-Cache: 4-way 128-set 32 KiB
// L1 D-Cache: 8-way 64-set 32 KiB
// L2 Cache: 8-way 512-set 256 KiB
// L3 Cache: 16-way 12288-set 12 MiB
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
// My processor
// L1 I-Cache :4-way 128-set 32 KiB
// L1 D-Cache :8-way 64-set 32 KiB
// L2 Cache :8-way 512-set 256 KiB
// L3 Cache :12-way 8192-set 6 MiB
////////////////////////////////////////////////////////////////////////
#define SAMPLES 5
#define TIMES (1<<20)
#define BYTES_PER_KB (1024LL)
#define BYTES_PER_MB (1024*1024LL)
#define BYTES_PER_GB (1024*1024*1024LL)
#define PAGE_SIZE (1<<12)
#define CACHE_LINE_STRIDE (1<<6)
#define L2_SET_STRIDE (1<<15)
#define L3_SET_STRIDE (9*64*1024LL)
#define GIGABYTES_RAM 6
typedef unsigned int u32;
////////////////////////////////////////////////////////////////////////////
// This fragment of code tries to miss in the cache to reduce the available
// bandwidth to the other application vying for the memory bandwidth
//
// It tries to generate a streaming pattern of requests going across pages
// to prevent the effect of prefetching .
////////////////////////////////////////////////////////////////////////////
static char array[GIGABYTES_RAM*BYTES_PER_GB];
void bypass_access(u32 sets, u32 ways)
{
u32 i, j, k;
volatile u32 s;
i=0;
while(i*PAGE_SIZE*CACHE_LINE_STRIDE*2<GIGABYTES_RAM*BYTES_PER_GB){
s=array[i*PAGE_SIZE*CACHE_LINE_STRIDE*2];
i++;
}
}
int main()
{
#ifndef SETS
# define SETS 1024
#endif
#ifdef SETS
#if SETS<1
# define SETS 1
#endif
#if SETS>8192
# define SETS 8192
#endif
#endif
#ifndef WAYS
# define WAYS 12
#endif
#ifdef WAYS
#if WAYS<1
# define WAYS 1
#endif
#if WAYS>12
# define WAYS 12
#endif
#endif
while (1) {
unsigned long long i;
bypass_access(SETS, WAYS);
}
return 0;
}