]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
compromising on timing code, remove -vm and make it default, make new -heavy-timing...
authorAnthony Minessale <anthony.minessale@gmail.com>
Mon, 1 Mar 2010 19:25:27 +0000 (19:25 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Mon, 1 Mar 2010 19:25:27 +0000 (19:25 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16853 d0543943-73ff-0310-b7d9-9358b9ac24b2

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

index a32879166b10bc9570510370b4cf115ca61dc490..8ae0db483968cedd865b2ce23c7717d30e63561c 100644 (file)
@@ -246,7 +246,7 @@ typedef enum {
        SCF_USE_AUTO_NAT = (1 << 6),
        SCF_EARLY_HANGUP = (1 << 7),
        SCF_CALIBRATE_CLOCK = (1 << 8),
-       SCF_USE_COND_TIMING = (1 << 9),
+       SCF_USE_HEAVY_TIMING = (1 << 9),
        SCF_USE_CLOCK_RT = (1 << 10)
 } switch_core_flag_enum_t;
 typedef uint32_t switch_core_flag_t;
index 10bf4b3fae79994b70e4c916bbd704ba790a0378..5c761e372c179d3ee79dc44bc890c2d6f919cc0c 100644 (file)
@@ -330,7 +330,7 @@ int main(int argc, char *argv[])
                "\t-hp                    -- enable high priority settings\n"
                "\t-vg                    -- run under valgrind\n"
                "\t-nosql                 -- disable internal sql scoreboard\n"
-               "\t-vm                    -- use possibly more vm-friendly timing code.\n"
+               "\t-heavy-timer           -- Heavy Timer, possibly more accurate but at a cost\n"
                "\t-nonat                 -- disable auto nat detection\n"
                "\t-nocal                 -- disable clock calibration\n"
                "\t-nort                  -- disable clock clock_realtime\n"
@@ -485,8 +485,8 @@ int main(int argc, char *argv[])
                        known_opt++;
                }
 
-               if (local_argv[x] && !strcmp(local_argv[x], "-vm")) {
-                       flags |= SCF_USE_COND_TIMING;
+               if (local_argv[x] && !strcmp(local_argv[x], "-heavy-timer")) {
+                       flags |= SCF_USE_HEAVY_TIMING;
                        known_opt++;
                }
 
index dfec0d1996780c41832956a894af71717c36551c..1b53ed13ef137d4e7bbe12751cfb1fb9234d91b3 100644 (file)
@@ -1286,6 +1286,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
 
        switch_log_init(runtime.memory_pool, runtime.colorize_console);
 
+       runtime.tipping_point = 1500;
+       runtime.timer_affinity = -1;
        switch_load_core_config("switch.conf");
 
 
@@ -1300,8 +1302,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
        switch_rtp_init(runtime.memory_pool);
 
        runtime.running = 1;
-       runtime.tipping_point = 1000000;
-       runtime.timer_affinity = -1;
        runtime.initiated = switch_time_now();
        
        switch_scheduler_add_task(switch_epoch_time_now(NULL), heartbeat_callback, "heartbeat", "core", 0, NULL, SSHF_NONE | SSHF_NO_DEL);
index 3af5efadcbdf163b8d41800d066e2553023beadd..6af48dd219621a255bbbdf0590be4fee3a76901d 100644 (file)
@@ -63,15 +63,22 @@ static int NANO = 0;
 
 static int OFFSET = 0;
 
-static int COND = 0;
+static int COND = 1;
 
 static int MATRIX = 1;
 
+#define ONEMS
+#ifdef ONEMS
+static int STEP_MS = 1;
+static int STEP_MIC = 1000;
+static uint32_t TICK_PER_SEC = 10000;
+static int MS_PER_TICK = 1;
+#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;
 
@@ -80,6 +87,7 @@ static struct {
        int32_t STARTED;
        int32_t use_cond_yield;
        switch_mutex_t *mutex;
+       uint32_t timer_count;
 } globals;
 
 #ifdef WIN32
@@ -375,7 +383,7 @@ SWITCH_DECLARE(void) switch_sleep(switch_interval_time_t t)
 
 SWITCH_DECLARE(void) switch_cond_next(void)
 {
-       if (session_manager.session_count > runtime.tipping_point) {
+       if (globals.timer_count >= runtime.tipping_point) {
                os_yield();
                return;
        }
@@ -451,6 +459,13 @@ static switch_status_t timer_init(switch_timer_t *timer)
                        switch_time_sync();
                }
 
+               switch_mutex_lock(globals.mutex);
+               globals.timer_count++;
+               if (globals.timer_count == (runtime.tipping_point + 1)) {
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Crossed tipping point of %u, shifting into high-gear.\n", runtime.tipping_point);
+               }
+               switch_mutex_unlock(globals.mutex);
+
                return SWITCH_STATUS_SUCCESS;
        }
 
@@ -532,8 +547,9 @@ static switch_status_t timer_next(switch_timer_t *timer)
        while (globals.RUNNING == 1 && private_info->ready && TIMER_MATRIX[timer->interval].tick < private_info->reference) {
                check_roll();
 
-               if (session_manager.session_count > runtime.tipping_point) {
+               if (globals.timer_count >= runtime.tipping_point) {
                        os_yield();
+                       globals.use_cond_yield = 0;
                } else {
                        if (globals.use_cond_yield == 1) {
                                switch_mutex_lock(TIMER_MATRIX[cond_index].mutex);
@@ -594,6 +610,16 @@ static switch_status_t timer_destroy(switch_timer_t *timer)
        if (private_info) {
                private_info->ready = 0;
        }
+
+       switch_mutex_lock(globals.mutex);
+       if (globals.timer_count) {
+               globals.timer_count--;
+               if (globals.timer_count == (runtime.tipping_point - 1)) {
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Fell Below tipping point of %u, shifting into low-gear.\n", runtime.tipping_point);
+               }
+       }
+       switch_mutex_unlock(globals.mutex);
+
        return SWITCH_STATUS_SUCCESS;
 }
 
@@ -676,7 +702,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime)
                                rev_errs = 0;
                        }
 
-                       if (session_manager.session_count > runtime.tipping_point) {
+                       if (globals.timer_count >= runtime.tipping_point) {
                                os_yield();
                        } else {
                                do_sleep(1000);
@@ -987,8 +1013,8 @@ SWITCH_MODULE_LOAD_FUNCTION(softtimer_load)
                switch_time_set_nanosleep(SWITCH_FALSE);
        }
 
-       if (switch_test_flag((&runtime), SCF_USE_COND_TIMING)) {
-               switch_time_set_cond_yield(SWITCH_TRUE);
+       if (switch_test_flag((&runtime), SCF_USE_HEAVY_TIMING)) {
+               switch_time_set_cond_yield(SWITCH_FALSE);
        }
 
        if (switch_test_flag((&runtime), SCF_CALIBRATE_CLOCK)) {