update timer calibration
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16290 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
dbcf55a001
commit
d314f25424
|
@ -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))
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue