]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
time sync stuff for vps
authorAnthony Minessale <anthony.minessale@gmail.com>
Wed, 16 Apr 2008 22:02:06 +0000 (22:02 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Wed, 16 Apr 2008 22:02:06 +0000 (22:02 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8122 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_core.h
src/switch_core.c
src/switch_time.c

index ed444a2430a12bc8e61b79cc5c751a1414e01e2d..1d38acaad4b8e10b8675d71e193d2cc27a17c576 100644 (file)
@@ -1597,6 +1597,7 @@ SWITCH_DECLARE(void) switch_time_sync(void);
 SWITCH_DECLARE(time_t) switch_timestamp(time_t *t);
 SWITCH_DECLARE(void) switch_load_network_lists(switch_bool_t reload);
 SWITCH_DECLARE(switch_bool_t) switch_check_network_list_ip(const char *ip_str, const char *list_name);
+SWITCH_DECLARE(void) switch_time_set_monotonic(switch_bool_t enable);
 
 ///\}
 
index 167085a0a1c3f694da58cd39250f2ffd68b536ae..4f2fe0ab26d057059d10753b0bf7b4573714fc57 100644 (file)
@@ -898,6 +898,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
                                        runtime.mailer_app_args = switch_core_strdup(runtime.memory_pool, val);
                                } else if (!strcasecmp(var, "sessions-per-second")) {
                                        switch_core_sessions_per_second(atoi(val));
+                               } else if (!strcasecmp(var, "disable-monotonic-timing")) {
+                                       switch_time_set_monotonic(SWITCH_FALSE);
                                } else if (!strcasecmp(var, "max-sessions")) {
                                        switch_core_session_limit(atoi(val));
                                }
index f9bc7f22d48739af8744d19b2499b2e27eb98dde..c4018a3dbc1d396e71aa024f4ee20a9713a8737d 100644 (file)
@@ -101,6 +101,13 @@ static int MONO = 1;
 static int MONO = 0;
 #endif
 
+
+SWITCH_DECLARE(void) switch_time_set_monotonic(switch_bool_t enable) 
+{
+       MONO = enable ? 1 : 0;
+       switch_time_sync();
+}
+
 static switch_time_t time_now(int64_t offset)
 {
        switch_time_t now;
@@ -112,7 +119,7 @@ static switch_time_t time_now(int64_t offset)
                now = ts.tv_sec * APR_USEC_PER_SEC + (ts.tv_nsec/1000) + offset;
        } else {
 #endif
-       now = switch_time_now();
+               now = switch_time_now();
 
 #if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
        }
@@ -179,12 +186,12 @@ static switch_status_t timer_init(switch_timer_t *timer)
        return SWITCH_STATUS_MEMERR;
 }
 
-#define check_roll() if (private_info->roll < TIMER_MATRIX[timer->interval].roll) {\
-               private_info->roll++;\
-               private_info->reference = private_info->start = TIMER_MATRIX[timer->interval].tick;\
-       }\
-
-
+#define check_roll() if (private_info->roll < TIMER_MATRIX[timer->interval].roll) {    \
+               private_info->roll++;                                                                                   \
+               private_info->reference = private_info->start = TIMER_MATRIX[timer->interval].tick;     \
+       }                                                                                                                                       \
+       
+       
 static switch_status_t timer_step(switch_timer_t *timer)
 {
        timer_private_t *private_info = timer->private_info;
@@ -193,7 +200,7 @@ static switch_status_t timer_step(switch_timer_t *timer)
        if (globals.RUNNING != 1 || private_info->ready == 0) {
                return SWITCH_STATUS_FALSE;
        }
-
+       
        check_roll();
        samples = timer->samples * (private_info->reference - private_info->start);
 
@@ -326,18 +333,23 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime)
        ts = 0;
        last = 0;
        fwd_errs = rev_errs = 0;
-
+       
        while (globals.RUNNING == 1) {
                runtime.reference += STEP_MIC;
                while ((ts = time_now(runtime.offset)) < runtime.reference) {
                        if (ts < last) {
-                               int64_t diff = (int64_t)(ts - last);
-                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Reverse Clock Skew Detected!\n");
-                               runtime.reference = switch_time_now();
-                               current_ms = 0;
-                               tick = 0;
-                               runtime.initiated += diff;
-                               rev_errs++;
+                               if (MONO) {
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Virtual Migration Detected! Syncing Clock\n");
+                                       switch_time_sync();
+                               } else {
+                                       int64_t diff = (int64_t)(ts - last);
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Reverse Clock Skew Detected!\n");
+                                       runtime.reference = switch_time_now();
+                                       current_ms = 0;
+                                       tick = 0;
+                                       runtime.initiated += diff;
+                                       rev_errs++;
+                               }
                        } else {
                                rev_errs = 0;
                        }
@@ -347,13 +359,18 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime)
                
 
                if (ts > (runtime.reference + too_late)) {
-                       switch_time_t diff = ts - runtime.reference - STEP_MIC;
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Forward Clock Skew Detected!\n");
-                       fwd_errs++;
-                       runtime.reference = switch_time_now();
-                       current_ms = 0;
-                       tick = 0;
-                       runtime.initiated += diff;
+                       if (MONO) {
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Virtual Migration Detected! Syncing Clock\n");
+                               switch_time_sync();
+                       } else {
+                               switch_time_t diff = ts - runtime.reference - STEP_MIC;
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Forward Clock Skew Detected!\n");
+                               fwd_errs++;
+                               runtime.reference = switch_time_now();
+                               current_ms = 0;
+                               tick = 0;
+                               runtime.initiated += diff;
+                       }
                } else {
                        fwd_errs = 0;
                }