/* adjtimex() tick adjustment test * by: John Stultz <john.stultz@linaro.org> * (C) Copyright Linaro Limited 2015 * Licensed under the GPLv2 * * To build: * $ gcc adjtick.c -o adjtick -lrt * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details.
*/ #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <sys/time.h> #include <sys/timex.h> #include <time.h> #include <include/vdso/time64.h>
#include"../kselftest.h"
#define MILLION 1000000
long systick;
longlong llabs(longlong val)
{ if (val < 0)
val = -val; return val;
}
if (tx1.offset || tx1.freq || tx1.tick != tickval) {
printf(" [ERROR]\n");
printf("\tUnexpected adjtimex return values, make sure ntpd is not running.\n"); return -1;
}
/* * Here we use 100ppm difference as an error bound. * We likely should see better, but some coarse clocksources * cannot match the HZ tick size accurately, so we have a * internal correction factor that doesn't scale exactly * with the adjustment, resulting in > 10ppm error during * a 10% adjustment. 100ppm also gives us more breathing * room for interruptions during the measurement.
*/ if (llabs(eppm - ppm) > 100) {
printf(" [FAILED]\n"); return -1;
}
printf(" [OK]\n");
return 0;
}
int main(int argc, char **argv)
{ struct timespec raw; long tick, max, interval, err; struct timex tx1;
err = 0;
setbuf(stdout, NULL);
if (clock_gettime(CLOCK_MONOTONIC_RAW, &raw)) {
printf("ERR: NO CLOCK_MONOTONIC_RAW\n"); return -1;
}
printf("Each iteration takes about 15 seconds\n");
systick = sysconf(_SC_CLK_TCK);
systick = USEC_PER_SEC/sysconf(_SC_CLK_TCK);
max = systick/10; /* +/- 10% */
interval = max/4; /* in 4 steps each side */
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.