--- realfeel.c.orig 2004-10-27 15:04:46.237707040 +0200 +++ realfeel.c 2004-10-27 15:04:50.204104056 +0200 @@ -91,7 +91,7 @@ int set_realtime_priority(void) * set the process to realtime privs */ memset(&schp, 0, sizeof(schp)); - schp.sched_priority = sched_get_priority_max(SCHED_FIFO); + schp.sched_priority = sched_get_priority_max(SCHED_FIFO) - 1; if (sched_setscheduler(0, SCHED_FIFO, &schp) != 0) { perror("sched_setscheduler"); @@ -191,8 +191,19 @@ int main(int argc, char *argv[]) now = rdtsc(); delay = secondsPerTick * (now - last); if (delay > max_delay) { + int i; + max_delay = delay; printf("%.3f msec\n", 1e3 * (ideal - delay)); + /* + * To make sure that the delay due to the printf + * is not counted we skip the next period: + */ + for (i = 0; i < 10; i++) + if (read(fd, &data, sizeof(data)) == -1) + fatal("blocking read failed"); + last = rdtsc(); + continue; } ms = (-(ideal - delay) + 1.0/20000.0) * 10000; if (ms < 0)