diff --git a/configure.in b/configure.in index 0a330366b4..c0dbeb5c08 100644 --- a/configure.in +++ b/configure.in @@ -437,6 +437,7 @@ AC_CHECK_FUNCS([wcsncmp setgroups asprintf setenv pselect gettimeofday localtime AX_HAVE_CPU_SET AC_CHECK_LIB(rt, clock_gettime, [AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [Define if you have clock_gettime()])]) +AC_CHECK_LIB(rt, clock_getres, [AC_DEFINE(HAVE_CLOCK_GETRES, 1, [Define if you have clock_getres()])]) AC_CHECK_LIB(rt, clock_nanosleep, [AC_DEFINE(HAVE_CLOCK_NANOSLEEP, 1, [Define if you have clock_nanosleep()])]) AC_CHECK_FUNC(socket, , AC_CHECK_LIB(socket, socket)) diff --git a/src/switch_time.c b/src/switch_time.c index 0e44a8fd91..ab2f03e711 100644 --- a/src/switch_time.c +++ b/src/switch_time.c @@ -181,13 +181,31 @@ static void calibrate_clock(void) { int x; switch_interval_time_t avg, val = 1000, want = 1000; - int over = 0, under = 0, good = 0, step = 50; + int over = 0, under = 0, good = 0, step = 50, diff = 0; + +#ifdef HAVE_CLOCK_GETRES + struct timespec ts; + clock_getres(CLOCK_MONOTONIC, &ts); + if (ts.tv_nsec / 1000 > 1500) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, + "Timer resolution of %ld microseconds detected do you have your kernel timer set to higher than 1khz?\n", ts.tv_nsec / 1000); + return; + } +#endif for (x = 0; x < 500; x++) { avg = average_time(val, 100); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Test: %ld Average: %ld Step: %d\n", val, avg, step); - if (abs((int)(want - avg)) <= 2) { + diff = abs((int)(want - avg)); + if (diff > 1500) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, + "Abnormally large timer gap detected, do you have your kernel timer set to higher than 1khz?\n"); + return; + } + + + if (diff <= 2) { under = over = 0; if (++good > 10) { break;