#define _GNU_SOURCE #define _XOPEN_SOURCE 500 #include #include #include #include #include #include #include #include #define BUFLEN 4096 static char wistmpfile[] = "/mnt/willitscale.XXXXXX"; char *testcase_description = "Same file pwrite"; char *buf; #define FILE_SIZE (4096*1024) void testcase_prepare(void) { int fd = mkstemp(wistmpfile); assert(fd >= 0); assert(pwrite(fd, "X", 1, FILE_SIZE-1) == 1); buf = mmap(NULL, FILE_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); assert(buf != (void *)-1); close(fd); } void testcase(unsigned long long *iterations) { int cpu = sched_getcpu(); int fd = open(wistmpfile, O_RDWR); off_t offset = sched_getcpu() * BUFLEN; long counter = 0; long counterread = 0; long *counterbuf = (void *)&buf[offset]; printf("offset: %ld\n", offset); printf(" buf: %p\n", buf); printf("counterbuf: %p\n", counterbuf); assert(fd >= 0); while (1) { int ret; if (cpu == 1) { ret = madvise(buf, FILE_SIZE, MADV_DONTNEED); continue; } *counterbuf = counter; posix_fadvise(fd, offset, BUFLEN, POSIX_FADV_DONTNEED); ret = pread(fd, &counterread, sizeof(counterread), offset); assert(ret == sizeof(counterread)); if (counterread != counter) { printf("cpu: %d\n", cpu); printf(" counter %ld\n", counter); printf("counterread %ld\n", counterread); printf("*counterbuf %ld\n", *counterbuf); while(1); } counter++; (*iterations)++; } } void testcase_cleanup(void) { unlink(wistmpfile); }