From da29b0119510c57ec54aba18879dc1c9c3ff3b43 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 15 Jan 2010 21:09:51 +0000 Subject: [PATCH] few new command line opts -vm for conditonal timer, -nocal to skip timer calibration and -nort to turn off clock_realtime fam of functions git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16324 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_types.h | 5 ++++- src/switch.c | 22 ++++++++++++++++++++-- src/switch_time.c | 26 +++++++++++++++++++++----- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/src/include/switch_types.h b/src/include/switch_types.h index d664aa8030..309c00eade 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -242,7 +242,10 @@ typedef enum { SCF_RESTART = (1 << 4), SCF_SHUTDOWN_REQUESTED = (1 << 5), SCF_USE_AUTO_NAT = (1 << 6), - SCF_EARLY_HANGUP = (1 << 7) + SCF_EARLY_HANGUP = (1 << 7), + SCF_CALIBRATE_CLOCK = (1 << 8), + SCF_USE_COND_TIMING = (1 << 9), + SCF_USE_CLOCK_RT = (1 << 10) } switch_core_flag_enum_t; typedef uint32_t switch_core_flag_t; diff --git a/src/switch.c b/src/switch.c index 00a884b316..a07101e41b 100644 --- a/src/switch.c +++ b/src/switch.c @@ -171,7 +171,7 @@ void WINAPI ServiceCtrlHandler(DWORD control) /* the main service entry point */ void WINAPI service_main(DWORD numArgs, char **args) { - switch_core_flag_t flags = SCF_USE_SQL | SCF_USE_AUTO_NAT; + switch_core_flag_t flags = SCF_USE_SQL | SCF_USE_AUTO_NAT | SCF_CALIBRATE_CLOCK | SCF_USE_CLOCK_RT; const char *err = NULL; /* error value for return from freeswitch initialization */ /* we have to initialize the service-specific stuff */ memset(&status, 0, sizeof(SERVICE_STATUS)); @@ -282,7 +282,7 @@ int main(int argc, char *argv[]) #ifdef __sun switch_core_flag_t flags = SCF_USE_SQL; #else - switch_core_flag_t flags = SCF_USE_SQL | SCF_USE_AUTO_NAT; + switch_core_flag_t flags = SCF_USE_SQL | SCF_USE_AUTO_NAT | SCF_CALIBRATE_CLOCK | SCF_USE_CLOCK_RT; #endif int ret = 0; switch_status_t destroy_status; @@ -328,7 +328,10 @@ 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-nonat -- disable auto nat detection\n" + "\t-nocal -- disable clock calibration\n" + "\t-nort -- disable clock clock_realtime\n" "\t-stop -- stop freeswitch\n" "\t-nc -- do not output to a console and background\n" "\t-c -- output to a console and stay in the foreground\n" @@ -492,6 +495,21 @@ int main(int argc, char *argv[]) known_opt++; } + if (local_argv[x] && !strcmp(local_argv[x], "-vm")) { + flags |= SCF_USE_COND_TIMING; + known_opt++; + } + + if (local_argv[x] && !strcmp(local_argv[x], "-nort")) { + flags &= ~SCF_USE_CLOCK_RT; + known_opt++; + } + + if (local_argv[x] && !strcmp(local_argv[x], "-nocal")) { + flags &= ~SCF_CALIBRATE_CLOCK; + known_opt++; + } + if (local_argv[x] && !strcmp(local_argv[x], "-vg")) { flags |= SCF_VG; known_opt++; diff --git a/src/switch_time.c b/src/switch_time.c index cfc052e1ae..c3e0dd3c12 100644 --- a/src/switch_time.c +++ b/src/switch_time.c @@ -198,7 +198,7 @@ SWITCH_DECLARE(void) switch_time_calibrate_clock(void) OFFSET = 0; - for (x = 0; x < 500; x++) { + for (x = 0; x < 100; x++) { avg = average_time(val, 50); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Test: %ld Average: %ld Step: %d\n", (long)val, (long)avg, step); @@ -231,8 +231,12 @@ SWITCH_DECLARE(void) switch_time_calibrate_clock(void) } } - OFFSET = (int)(want - val); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Timer offset of %d calculated\n", OFFSET); + if (good >= 10) { + OFFSET = (int)(want - val); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Timer offset of %d calculated\n", OFFSET); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Timer offset of NOT calculated\n"); + } } @@ -943,8 +947,20 @@ SWITCH_MODULE_LOAD_FUNCTION(softtimer_load) timer_interface->timer_check = timer_check; timer_interface->timer_destroy = timer_destroy; - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Calibrating timer, please wait...\n"); - switch_time_calibrate_clock(); + if (!switch_test_flag((&runtime), SCF_USE_CLOCK_RT)) { + 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_CALIBRATE_CLOCK)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Calibrating timer, please wait...\n"); + switch_time_calibrate_clock(); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Clock calibration disabled.\n"); + } /* indicate that the module should continue to be loaded */ return SWITCH_STATUS_SUCCESS;