Commit b20e8571eeebb9546bf966a988355f09ee715b20

Authored by Aravind Kumar
1 parent 88a6d902f9
Exists in master

imemory access time

Showing 2 changed files with 14 additions and 10 deletions Side-by-side Diff

memory/memory_access_time.c View file @ b20e857
... ... @@ -8,38 +8,42 @@
8 8 #define STRIDE_SIZE 16
9 9 #define CPU_FREQ 900
10 10  
11   -unsigned access_time_1(int size, int stride_size){
  11 +unsigned long long access_time_1(int size, int stride_size){
12 12 struct timeval start, end;
13 13 struct timezone tz;
14   - unsigned time1, time2;
  14 + unsigned long long time1, time2;
15 15 int j;
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++) {
  20 + array[( i * stride_size) % len] = array[( i * stride_size) % len]+i;
  21 + }
19 22  
20   - //gettimeofday(&start, &tz);
21   - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (time1));
  23 + gettimeofday(&start, NULL);
  24 + //asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (time1));
22 25 for(i=0; i < MAX_ARRAY_SIZE; i++) {
23 26 j = array[( i * stride_size) % len];
24   - j++;
25 27 }
26   - //gettimeofday(&end, &tz);
27   - 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));
28 30  
29 31 free(array);
30   - return time2-time1;
  32 + //return time2-time1;
  33 + return (-start.tv_sec*1e6-start.tv_usec+end.tv_sec*1e6+end.tv_usec);
31 34 }
32 35  
33 36 int main()
34 37 {
35 38 int i, j;
36 39  
37   - for (j = 4; j <= 1024; j*=2) {
  40 + for (j = 128; j <= 1024; j*=2) {
38 41 printf("Stride size: %u\n", j);
39 42 for (i = 1024; i <= 32 * MB; i*=2) {
40   - unsigned access_time = access_time_1(i, j);
  43 + unsigned long long access_time = access_time_1(i, j);
41 44 //unsigned overhead = 10;
42 45 //multiply access time by 1000 to convert to ns
  46 + //double avg = (access_time * 1.111)/(MAX_ARRAY_SIZE);
43 47 double avg = (access_time * 1000.0)/(MAX_ARRAY_SIZE);
44 48 printf("Size: %uKB access: %lluus, avg: %gns\n", i >> 10, access_time, avg);
45 49 }
memory/memory_access_time.o View file @ b20e857

No preview for this file type