Hello -
I noticed some negative roundtrip times when running traceroute, which
uses the monotonic clock to calculate the RTT.
If I run the following code, it eventually bombs. It bombs quick if I
launch Firefox.
timespeccmp failed
tp1 s:103780 n:63101042
tp2 s:103779 n:761117849
----
#include <sys/time.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
int
main(void)
{
int r;
struct timespec tp1, tp2, tout;
tout.tv_sec = 0;
tout.tv_nsec = 100000;
for (;;) {
r = clock_gettime(CLOCK_MONOTONIC, &tp1);
if (r == -1) {
perror("clock_gettime");
exit(-1);
}
nanosleep(&tout, NULL);
r = clock_gettime(CLOCK_MONOTONIC, &tp2);
if (r == -1) {
perror("clock_gettime");
exit(-1);
}
// tp1 should never be larger than tp2
r = timespeccmp(&tp1, &tp2, >);
if (r == 1) {
printf("timespeccmp failed\n");
printf("tp1 s:%lld n:%ld\n", tp1.tv_sec,
tp1.tv_nsec);
printf("tp2 s:%lld n:%ld\n", tp2.tv_sec,
tp2.tv_nsec);
exit(-1);
}
}
return 0;
}