DF-5707 / watch.c
/* watch.c - poll randseed via /dev/mem without forking; timestamp changes */ #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <unistd.h> #include <time.h> #include <inttypes.h> #define KERNBASE 0xFFFFFFFF80000000ULL int main(int argc, char **argv) { int secs = argc > 1 ? atoi(argv[1]) : 15; int fd = open("/dev/mem", O_RDONLY); if (fd < 0) { perror("open"); return 1; } off_t phys = 0x81124c00; /* randseed */ uint64_t prev = 0, cur; struct timespec ts; struct timespec t0; clock_gettime(CLOCK_MONOTONIC, &t0); if (pread(fd, &prev, 8, phys) != 8) { perror("pread"); return 1; } for (;;) { clock_gettime(CLOCK_MONOTONIC, &ts); double el = (ts.tv_sec - t0.tv_sec) + 1e-9*(ts.tv_nsec - t0.tv_nsec); if (el > secs) break; if (pread(fd, &cur, 8, phys) != 8) { perror("pread"); return 1; } if (cur != prev) { printf("%9.6f 0x%llx\n", el, (unsigned long long)cur); fflush(stdout); prev = cur; } } return 0; } |