]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
update timer calibration
authorAnthony Minessale <anthony.minessale@gmail.com>
Wed, 13 Jan 2010 21:07:39 +0000 (21:07 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Wed, 13 Jan 2010 21:07:39 +0000 (21:07 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16290 d0543943-73ff-0310-b7d9-9358b9ac24b2

configure.in
src/switch_time.c

index 0a330366b44835ffefecc2a2f4cf7c5a45082264..c0dbeb5c08696332cecaac13bb8f02ba74082047 100644 (file)
@@ -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))
 
index 0e44a8fd919b51fcca1badaf1928517a98cc580f..ab2f03e71115484bfa692a00ecfd5f3ca8a06a68 100644 (file)
@@ -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;