Compare View
Commits (2)
Diff
Showing 5 changed files Side-by-side Diff
filesystem/file_cache.c
View file @
bfd14a3
... | ... | @@ -6,9 +6,7 @@ |
6 | 6 | #define BLOCK_SIZE 1024 |
7 | 7 | void main() |
8 | 8 | { |
9 | - char fname[10]="file"; | |
10 | - char *fno[] = {"1", "2", "3", "4", "5", "6", "7"}; | |
11 | - char *file; | |
9 | + char *fnames[] = {"file_1", "file_2", "file_3", "file_4", "file_5", "file_6", "file_7"}; | |
12 | 10 | char buffer[BLOCK_SIZE]; |
13 | 11 | struct timeval start, end; |
14 | 12 | int fd=0; |
... | ... | @@ -16,10 +14,9 @@ void main() |
16 | 14 | unsigned long long time; |
17 | 15 | int status; |
18 | 16 | for (i = 0; i < 7; i++) { |
19 | - file = strcat(fname, fno[i]); | |
20 | - printf("File %d: %s\n", i, file); | |
17 | + fd = open(fnames[i], O_RDONLY); | |
18 | + printf("File %d: %s\n", i, fnames[i]); | |
21 | 19 | fflush(NULL); |
22 | - fd = open(file, O_RDONLY); | |
23 | 20 | if (!fd) { |
24 | 21 | printf("unable to open\n"); |
25 | 22 | exit(0); |
... | ... | @@ -33,13 +30,10 @@ void main() |
33 | 30 | } |
34 | 31 | gettimeofday(&end, NULL); |
35 | 32 | time = (end.tv_sec*1e6+end.tv_usec) - (start.tv_sec*1e6+start.tv_usec); |
36 | - printf("timestamp %llu - %llu\n", end.tv_sec*1e6+end.tv_usec, start.tv_sec*1e6+start.tv_usec); | |
33 | + //printf("timestamp %llu - %llu\n", end.tv_sec*1e6+end.tv_usec, start.tv_sec*1e6+start.tv_usec); | |
37 | 34 | printf("time taken to read file # %d - %llu\n", i, time); |
38 | 35 | sync(); |
39 | 36 | status = system("sudo /sbin/sysctl vm.drop_caches=3"); |
40 | 37 | sync(); |
41 | - strcpy(fname, "file"); | |
42 | 38 | } |
43 | - | |
44 | - | |
45 | 39 | } |
filesystem/file_cache.o
View file @
bfd14a3
memory/memory_access_time.c
View file @
bfd14a3
... | ... | @@ -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; |
... | ... | @@ -16,35 +16,35 @@ unsigned long long access_time_1(int size, int stride_size){ |
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 @
bfd14a3
... | ... | @@ -0,0 +1,52 @@ |
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 @
bfd14a3