#include #include #include #include #define DIFFTS(a, b) ((a.tv_sec - b.tv_sec) + 1e-9 * (a.tv_nsec - b.tv_nsec)) int main() { struct timespec ts1, ts2, ts3, ts4 = {0}; struct timex t; t.modes = ADJ_TICK; t.tick = 9000; if (adjtimex(&t) < 0) return 1; while (1) { clock_gettime(CLOCK_REALTIME, &ts1); clock_gettime(CLOCK_MONOTONIC_RAW, &ts2); if (ts4.tv_sec) printf("freq offset = %.0f ppm\n", (DIFFTS(ts1, ts3) / DIFFTS(ts2, ts4) - 1.0) * 1e6); ts3 = ts1; ts4 = ts2; usleep(1000000); } return 0; }