]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add timerfd support to the core for now you must enable it in switch.conf.xml with...
authorAnthony Minessale <anthm@freeswitch.org>
Tue, 22 Mar 2011 01:49:39 +0000 (20:49 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Tue, 22 Mar 2011 01:49:39 +0000 (20:49 -0500)
configure.in
src/include/switch_core.h
src/switch_core.c
src/switch_time.c

index 7978d0475451cf6e5cf3a5c4a9f346e03e0dd10f..cb5319c1523e72d7d25034968f7237743e2730f3 100644 (file)
@@ -461,7 +461,7 @@ AC_PROG_GCC_TRADITIONAL
 AC_FUNC_MALLOC
 AC_TYPE_SIGNAL
 AC_FUNC_STRFTIME
-AC_CHECK_FUNCS([gethostname vasprintf mmap mlock mlockall usleep getifaddrs])
+AC_CHECK_FUNCS([gethostname vasprintf mmap mlock mlockall usleep getifaddrs timerfd_create])
 AC_CHECK_FUNCS([sched_setscheduler setpriority setrlimit setgroups initgroups])
 AC_CHECK_FUNCS([wcsncmp setgroups asprintf setenv pselect gettimeofday localtime_r gmtime_r strcasecmp stricmp _stricmp])
 
index 590e01ace27f8d40ea623257a6099d29226a1000..37c672334f6a199c9b196f0e81b4c6b76fc62cc6 100644 (file)
@@ -2050,6 +2050,7 @@ SWITCH_DECLARE(void) switch_load_network_lists(switch_bool_t reload);
 SWITCH_DECLARE(switch_bool_t) switch_check_network_list_ip_token(const char *ip_str, const char *list_name, const char **token);
 #define switch_check_network_list_ip(_ip_str, _list_name) switch_check_network_list_ip_token(_ip_str, _list_name, NULL)
 SWITCH_DECLARE(void) switch_time_set_monotonic(switch_bool_t enable);
+SWITCH_DECLARE(void) switch_time_set_timerfd(switch_bool_t enable);
 SWITCH_DECLARE(void) switch_time_set_nanosleep(switch_bool_t enable);
 SWITCH_DECLARE(void) switch_time_set_matrix(switch_bool_t enable);
 SWITCH_DECLARE(void) switch_time_set_cond_yield(switch_bool_t enable);
index 96e4b4ae276b1d8b21bc275b28d18be3e3ee4092..73516cf168b82e45dd10d0ef305eb4fd134e659a 100644 (file)
@@ -1635,6 +1635,8 @@ static void switch_load_core_config(const char *file)
                                        }
                                } else if (!strcasecmp(var, "enable-monotonic-timing")) {
                                        switch_time_set_monotonic(switch_true(var));
+                               } else if (!strcasecmp(var, "enable-softtimer-timerfd")) {
+                                       switch_time_set_timerfd(switch_true(var));
                                } else if (!strcasecmp(var, "enable-clock-nanosleep")) {
                                        switch_time_set_nanosleep(switch_true(var));
                                } else if (!strcasecmp(var, "enable-cond-yield")) {
index 2a3ee2b515b0348824629e2b98aea9adbc6ce9b5..375682e0055baa99891fa06d62d8750b48985d9a 100644 (file)
@@ -34,6 +34,9 @@
 #include <switch.h>
 #include <stdio.h>
 #include "private/switch_core_pvt.h"
+#ifdef HAVE_TIMERFD_CREATE
+#include <sys/timerfd.h>
+#endif
 
 //#if defined(DARWIN)
 #define DISABLE_1MS_COND
@@ -58,6 +61,13 @@ static int MONO = 1;
 static int MONO = 0;
 #endif
 
+#if defined(HAVE_TIMERFD_CREATE)
+// We'll default this to 1 after we have had some positive feedback that it works well
+static int TFD = 0;
+#else
+static int TFD = 0;
+#endif
+
 static int NANO = 0;
 
 static int OFFSET = 0;
@@ -72,18 +82,10 @@ static DWORD win32_last_get_time_tick = 0;
 CRITICAL_SECTION  timer_section;
 #endif
 
-#define ONEMS
-#ifdef ONEMS
 static int STEP_MS = 1;
 static int STEP_MIC = 1000;
 static uint32_t TICK_PER_SEC = 1000;
 static int MS_PER_TICK = 10;
-#else
-static int STEP_MS = 10;
-static int STEP_MIC = 10000;
-static uint32_t TICK_PER_SEC = 1000;
-static int MS_PER_TICK = 10;
-#endif
 
 static switch_memory_pool_t *module_pool = NULL;
 
@@ -310,8 +312,23 @@ SWITCH_DECLARE(time_t) switch_epoch_time_now(time_t *t)
 
 SWITCH_DECLARE(void) switch_time_set_monotonic(switch_bool_t enable)
 {
+#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
        MONO = enable ? 1 : 0;
        switch_time_sync();
+#else
+       MONO = 0;
+#endif
+}
+
+
+SWITCH_DECLARE(void) switch_time_set_timerfd(switch_bool_t enable)
+{
+#if defined(HAVE_TIMERFD_CREATE)
+       TFD = enable ? 1 : 0;
+       switch_time_sync();
+#else
+       TFD = 0;
+#endif
 }
 
 
@@ -487,9 +504,6 @@ static switch_status_t timer_init(switch_timer_t *timer)
 
                if (timer->interval > 0 && timer->interval < MS_PER_TICK) {
                        MS_PER_TICK = timer->interval;
-                       STEP_MS = 1;
-                       STEP_MIC = 1000;
-                       TICK_PER_SEC = 10000;
                        switch_time_sync();
                }
 
@@ -662,6 +676,29 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime)
        switch_time_t ts = 0, last = 0;
        int fwd_errs = 0, rev_errs = 0;
        int profile_tick = 0;
+       int tfd = -1;
+
+#ifdef HAVE_TIMERFD_CREATE
+       struct itimerspec spec = { { 0 } };
+
+       if (MONO && TFD) {
+               tfd = timerfd_create(CLOCK_MONOTONIC, 0);
+
+               if (tfd > -1) {
+                       spec.it_interval.tv_sec = 0;
+                       spec.it_interval.tv_nsec = 1000000;
+                       spec.it_value.tv_sec = spec.it_interval.tv_sec;
+                       spec.it_value.tv_nsec = spec.it_interval.tv_nsec;
+               
+                       if (timerfd_settime(tfd, TFD_TIMER_ABSTIME, &spec, NULL)) {
+                               close(tfd);
+                               tfd = -1;
+                       }
+               }
+       }
+#else
+       tfd = -1;
+#endif
 
        runtime.profile_timer = switch_new_profile_timer();
        switch_get_system_idle_time(runtime.profile_timer, &runtime.profile_time);
@@ -740,7 +777,13 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime)
                        if (globals.timer_count >= runtime.tipping_point) {
                                os_yield();
                        } else {
-                               do_sleep(1000);
+                               if (tfd > -1 && globals.RUNNING == 1) {
+                                       uint64_t exp;
+                                       int r;
+                                       r = read(tfd, &exp, sizeof(exp));
+                               } else {
+                                       do_sleep(1000);
+                               }
                        }
 
                        last = ts;
@@ -838,6 +881,11 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime)
                }
        }
 
+       if (tfd > -1) {
+               close(tfd);
+               tfd = -1;
+       }
+
 
        switch_mutex_lock(globals.mutex);
        globals.RUNNING = 0;