Commit 90b06817c375bdb49bf9729029b96a982fbd6792
1 parent
5c68199029
Exists in
master
Memory access time
Showing 3 changed files with 66 additions and 14 deletions Side-by-side Diff
memory/memory_access_time.c
View file @
90b0681
... | ... | @@ -4,11 +4,11 @@ |
4 | 4 | |
5 | 5 | #define KB 1024 |
6 | 6 | #define MB 1024 * KB |
7 | -#define MAX_ARRAY_SIZE 32*MB | |
7 | +#define MAX_ITERATIONS 1000000 | |
8 | 8 | #define STRIDE_SIZE 16 |
9 | 9 | #define CPU_FREQ 900 |
10 | 10 | |
11 | -unsigned long long access_time_1(int size, int stride_size){ | |
11 | +unsigned long long func(int size, int stride_size){ | |
12 | 12 | struct timeval start, end; |
13 | 13 | struct timezone tz; |
14 | 14 | unsigned long long time1, time2; |
15 | 15 | |
16 | 16 | |
17 | 17 | |
18 | 18 | |
19 | 19 | |
20 | 20 | |
... | ... | @@ -16,35 +16,35 @@ |
16 | 16 | int *array = (int *)malloc(size); |
17 | 17 | int len = (size)/sizeof(int); |
18 | 18 | unsigned int i; |
19 | - for(i=0; i < MAX_ARRAY_SIZE; i++) { | |
19 | + for(i=0; i < MAX_ITERATIONS; i++) { | |
20 | 20 | array[( i * stride_size) % len] = array[( i * stride_size) % len]+i; |
21 | 21 | } |
22 | 22 | |
23 | - gettimeofday(&start, NULL); | |
24 | - //asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (time1)); | |
25 | - for(i=0; i < MAX_ARRAY_SIZE; i++) { | |
23 | + //gettimeofday(&start, NULL); | |
24 | + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (time1)); | |
25 | + for(i=0; i < MAX_ITERATIONS; i++) { | |
26 | 26 | j = array[( i * stride_size) % len]; |
27 | 27 | } |
28 | - gettimeofday(&end, NULL); | |
29 | - //asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (time2)); | |
28 | + //gettimeofday(&end, NULL); | |
29 | + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (time2)); | |
30 | 30 | |
31 | 31 | free(array); |
32 | - //return time2-time1; | |
33 | - return (-start.tv_sec*1e6-start.tv_usec+end.tv_sec*1e6+end.tv_usec); | |
32 | + return time2 - time1; | |
33 | + //return (-start.tv_sec*1e6-start.tv_usec+end.tv_sec*1e6+end.tv_usec); | |
34 | 34 | } |
35 | 35 | |
36 | 36 | int main() |
37 | 37 | { |
38 | 38 | int i, j; |
39 | 39 | |
40 | - for (j = 128; j <= 1024; j*=2) { | |
40 | + for (j = 16; j <= 1024; j*=2) { | |
41 | 41 | printf("Stride size: %u\n", j); |
42 | 42 | for (i = 1024; i <= 32 * MB; i*=2) { |
43 | - unsigned long long access_time = access_time_1(i, j); | |
43 | + unsigned long long access_time = func(i, j); | |
44 | 44 | //unsigned overhead = 10; |
45 | 45 | //multiply access time by 1000 to convert to ns |
46 | - //double avg = (access_time * 1.111)/(MAX_ARRAY_SIZE); | |
47 | - double avg = (access_time * 1000.0)/(MAX_ARRAY_SIZE); | |
46 | + //double avg = (access_time * 1.111)/(MAX_ITERATIONS); | |
47 | + double avg = (access_time * 1000.0)/(MAX_ITERATIONS); | |
48 | 48 | printf("Size: %uKB access: %lluus, avg: %gns\n", i >> 10, access_time, avg); |
49 | 49 | } |
50 | 50 | } |
memory/memory_access_time_overhead.c
View file @
90b0681
1 | +#include<stdio.h> | |
2 | +#include <sys/time.h> | |
3 | +#include <stdlib.h> | |
4 | + | |
5 | +#define KB 1024 | |
6 | +#define MB 1024 * KB | |
7 | +#define MAX_ITERATIONS 1000000 | |
8 | +#define STRIDE_SIZE 16 | |
9 | +#define CPU_FREQ 900 | |
10 | + | |
11 | +unsigned long long func(int size, int stride_size){ | |
12 | + struct timeval start, end; | |
13 | + struct timezone tz; | |
14 | + unsigned long long time1, time2; | |
15 | + int j; | |
16 | + int *array = (int *)malloc(size); | |
17 | + int len = (size)/sizeof(int); | |
18 | + unsigned int i; | |
19 | + for(i=0; i < MAX_ITERATIONS; i++) { | |
20 | + array[( i * stride_size) % len] = array[( i * stride_size) % len]+i; | |
21 | + } | |
22 | + | |
23 | + //gettimeofday(&start, NULL); | |
24 | + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (time1)); | |
25 | + for(i=0; i < MAX_ITERATIONS; i++) { | |
26 | + j = ( i * stride_size) % len; | |
27 | + } | |
28 | + //gettimeofday(&end, NULL); | |
29 | + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (time2)); | |
30 | + | |
31 | + free(array); | |
32 | + return time2 - time1; | |
33 | + //return (-start.tv_sec*1e6-start.tv_usec+end.tv_sec*1e6+end.tv_usec); | |
34 | +} | |
35 | + | |
36 | +int main() | |
37 | +{ | |
38 | + int i, j; | |
39 | + | |
40 | + for (j = 16; j <= 1024; j*=2) { | |
41 | + printf("Stride size: %u\n", j); | |
42 | + for (i = 1024; i <= 32 * MB; i*=2) { | |
43 | + unsigned long long access_time = func(i, j); | |
44 | + //unsigned overhead = 10; | |
45 | + //multiply access time by 1000 to convert to ns | |
46 | + //double avg = (access_time * 1.111)/(MAX_ITERATIONS); | |
47 | + double avg = (access_time * 1000.0)/(MAX_ITERATIONS); | |
48 | + printf("Size: %uKB access: %lluus, avg: %gns\n", i >> 10, access_time, avg); | |
49 | + } | |
50 | + } | |
51 | + return 0; | |
52 | +} |
memory/memory_access_time_overhead_new.o
View file @
90b0681