#include #include #include #include #include #include #include #define NR_ALPHAS ('z' - 'a' + 1) int main(int argc, char **argv) { struct timespec intv_ts = { }, ts; unsigned long long time0, time1; long long msecs = 10; const size_t map_size = 4096 * 4; if (argc > 1) { msecs = atoll(argv[1]); if (msecs <= 0) { fprintf(stderr, "test-latency [interval-in-msecs]\n"); return 1; } } intv_ts.tv_sec = msecs / 1000; intv_ts.tv_nsec = (msecs % 1000) * 1000000; clock_gettime(CLOCK_MONOTONIC, &ts); time1 = ts.tv_sec * 1000000000LLU + ts.tv_nsec; while (1) { void *map, *p; int idx; char c; nanosleep(&intv_ts, NULL); map = mmap(NULL, map_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (map == MAP_FAILED) { perror("mmap"); return 1; } for (p = map; p < map + map_size; p += 4096) *(volatile unsigned long *)p = 0xdeadbeef; munmap(map, map_size); time0 = time1; clock_gettime(CLOCK_MONOTONIC, &ts); time1 = ts.tv_sec * 1000000000LLU + ts.tv_nsec; idx = (time1 - time0) / msecs / 1000000; idx = log2(idx); if (idx <= 1) { c = '.'; } else { if (idx > 9) idx = 9; c = '0' + idx; } write(1, &c, 1); } }