1 /* Copyright (c) 2014 The Regents of the University of California
2 * Barret Rhoden <brho@cs.berkeley.edu>
3 * See LICENSE for details.
5 * mmap_test: dumping ground for various tests, such as PFs on files. */
15 #include <parlib/parlib.h>
16 #include <parlib/timing.h>
18 #include <sys/types.h>
26 static void mmap_test(void)
29 for (int *i = addr; (void*)i < addr + nr_pgs * PGSIZE; i += STRIDE) {
34 void *worker_thread(void* arg)
43 int main(int argc, char** argv)
51 printf("Usage: %s FILENAME [NR_PGS]\n", argv[0]);
54 /* if you're going to create, you'll need to seek too */
55 //fd = open(argv[1], O_RDWR | O_CREAT, 0666);
56 fd = open(argv[1], O_RDWR, 0666);
58 perror("Unable to open file");
64 nr_pgs = atoi(argv[2]);
65 if (fstat(fd, &statbuf)) {
66 perror("Stat failed");
69 nr_pgs = MIN(nr_pgs, (ROUNDUP(statbuf.st_size, PGSIZE) >> PGSHIFT));
70 addr = mmap(0, nr_pgs * PGSIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
71 if (addr == MAP_FAILED) {
72 perror("mmap failed");
75 printf("Running as an SCP\n");
77 printf("Spawning worker thread, etc...\n");
78 pthread_create(&child, NULL, &worker_thread, NULL);
79 pthread_join(child, &child_ret);