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;
/* 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));
#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;
"\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"
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++;
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);
}
}
- 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");
+ }
}
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;