Commit 8314bd572f9abd9faef2574cd00bc17c1d5c401c
1 parent
e17bc6f3be
Exists in
master
pfpault
Showing 2 changed files with 3 additions and 3 deletions Inline Diff
memory/pagefault.c
View file @
8314bd5
#include <stdio.h> | 1 | 1 | #include <stdio.h> | |
#include <stdlib.h> | 2 | 2 | #include <stdlib.h> | |
#include <errno.h> | 3 | 3 | #include <errno.h> | |
#include <unistd.h> | 4 | 4 | #include <unistd.h> | |
#include <stdlib.h> | 5 | 5 | #include <stdlib.h> | |
#include <sys/mman.h> | 6 | 6 | #include <sys/mman.h> | |
#include <sys/stat.h> | 7 | 7 | #include <sys/stat.h> | |
#include <fcntl.h> | 8 | 8 | #include <fcntl.h> | |
9 | 9 | |||
#define KB 1024 | 10 | 10 | #define KB 1024 | |
#define MB 1024 * KB | 11 | 11 | #define MB 1024 * KB | |
#define GB 1024 * MB | 12 | 12 | #define GB 1024 * MB | |
#define SIZE_OF_MEMORY 839*MB // Main memory size | 13 | 13 | #define SIZE_OF_MEMORY 839*MB // Main memory size | |
#define CPU_FREQ 900000.0 | 14 | 14 | #define CPU_FREQ 900000.0 | |
#define ITERATIONS 1024.0*1024.0 | 15 | 15 | #define ITERATIONS 1024.0*1024.0 | |
#define handle_error(msg) do { perror(msg); exit(EXIT_FAILURE); } while (0) | 16 | 16 | #define handle_error(msg) do { perror(msg); exit(EXIT_FAILURE); } while (0) | |
17 | 17 | |||
18 | 18 | |||
int main(int argc, char *argv[]){ | 19 | 19 | int main(int argc, char *argv[]){ | |
20 | 20 | |||
int fd1, fd2; | 21 | 21 | int fd1, fd2; | |
char *addr1, *addr2; | 22 | 22 | char *addr1, *addr2; | |
register volatile int c=0; | 23 | 23 | register volatile int c=0; | |
int i, j; | 24 | 24 | int i, j; | |
unsigned s_t, e_t, t=0; | 25 | 25 | unsigned s_t, e_t, t=0; | |
26 | 26 | |||
if (argc != 3){ | 27 | 27 | if (argc != 3){ | |
printf("usage: a.out <file1> <file2> \n"); | 28 | 28 | printf("usage: a.out <file1> <file2> \n"); | |
exit(EXIT_FAILURE); | 29 | 29 | exit(EXIT_FAILURE); | |
} | 30 | 30 | } | |
31 | 31 | |||
if ((fd1 = open(argv[1], O_RDONLY)) == -1){ | 32 | 32 | if ((fd1 = open(argv[1], O_RDONLY)) == -1){ | |
//handle_error("open"); | 33 | 33 | //handle_error("open"); | |
printf("exit fd1\n"); | 34 | 34 | printf("exit fd1\n"); | |
exit(0); | 35 | 35 | exit(0); | |
} | 36 | 36 | } | |
37 | 37 | |||
if ((fd2 = open(argv[2], O_RDONLY)) == -1){ | 38 | 38 | if ((fd2 = open(argv[2], O_RDONLY)) == -1){ | |
//handle_error("open"); | 39 | 39 | //handle_error("open"); | |
printf("exit fd2\n"); | 40 | 40 | printf("exit fd2\n"); | |
exit(0); | 41 | 41 | exit(0); | |
} | 42 | 42 | } | |
43 | 43 | |||
posix_fadvise(fd1, 0, 0, POSIX_FADV_RANDOM); | 44 | 44 | posix_fadvise(fd1, 0, 0, POSIX_FADV_RANDOM); | |
posix_fadvise(fd2, 0, 0, POSIX_FADV_RANDOM); | 45 | 45 | posix_fadvise(fd2, 0, 0, POSIX_FADV_RANDOM); | |
46 | 46 | |||
addr1 = (char *) mmap(0, SIZE_OF_MEMORY, PROT_READ, MAP_PRIVATE | MAP_POPULATE, fd1, 0); | 47 | 47 | addr1 = (char *) mmap(0, SIZE_OF_MEMORY, PROT_READ, MAP_PRIVATE | MAP_POPULATE, fd1, 0); | |
if (addr1 == MAP_FAILED){ | 48 | 48 | if (addr1 == MAP_FAILED){ | |
printf("mmap1 %d %s", errno, strerror(errno)); | 49 | 49 | printf("mmap1 %d %s", errno, strerror(errno)); | |
exit(0); | 50 | 50 | exit(0); | |
} | 51 | 51 | } | |
addr2 = (char *) mmap(0, SIZE_OF_MEMORY, PROT_READ, MAP_PRIVATE | MAP_POPULATE, fd2, 0); | 52 | 52 | addr2 = (char *) mmap(0, SIZE_OF_MEMORY, PROT_READ, MAP_PRIVATE | MAP_POPULATE, fd2, 0); | |
if (addr2 == MAP_FAILED){ | 53 | 53 | if (addr2 == MAP_FAILED){ | |
printf("mmap2 %d %s", errno, strerror(errno)); | 54 | 54 | printf("mmap2 %d %s", errno, strerror(errno)); | |
exit(0); | 55 | 55 | exit(0); | |
} | 56 | 56 | } | |
57 | 57 | |||
madvise(addr1, 0, MADV_RANDOM); | 58 | 58 | madvise(addr1, 0, MADV_RANDOM); | |
madvise(addr2, 0, MADV_RANDOM); | 59 | 59 | madvise(addr2, 0, MADV_RANDOM); | |
asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (i)); | 60 | 60 | asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (i)); | |
printf("User enable regr: %x\n", i); | 61 | 61 | printf("User enable regr: %x\n", i); | |
62 | 62 | |||
j = 32; | 63 | 63 | j = 32; | |
for(i = 0; i < 100; i=i++){ | 64 | 64 | for(i = 0; i < 60000; i=i+10){ | |
asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (s_t)); | 65 | 65 | asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (s_t)); | |
c+= (addr1[i + j*4*KB]); // read at multiple of page size, so every read causes a page fault | 66 | 66 | c+= (addr1[i*4*KB]); // read at multiple of page size, so every read causes a page fault | |
j = j*2; | 67 | 67 | // j = j*2; | |
//c = c+1; | 68 | 68 | //c = c+1; | |
asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (e_t)); | 69 | 69 | asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (e_t)); | |
t += (e_t - s_t); | 70 | 70 | t += (e_t - s_t); |
memory/pagefault.o
View file @
8314bd5
-
mentioned in commit ca5a96