Revision
16324
Author
anthm
Date
2010-01-15 15:09:51 -0600 (Fri, 15 Jan 2010)

Log Message

few new command line opts -vm for conditonal timer, -nocal to skip timer calibration and -nort to turn off clock_realtime fam of functions

Modified Paths

Diff

Modified: freeswitch/trunk/src/include/switch_types.h (16323 => 16324)


--- freeswitch/trunk/src/include/switch_types.h	2010-01-15 18:06:17 UTC (rev 16323)
+++ freeswitch/trunk/src/include/switch_types.h	2010-01-15 21:09:51 UTC (rev 16324)
@@ -242,7 +242,10 @@
 	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;
 

Modified: freeswitch/trunk/src/switch.c (16323 => 16324)


--- freeswitch/trunk/src/switch.c	2010-01-15 18:06:17 UTC (rev 16323)
+++ freeswitch/trunk/src/switch.c	2010-01-15 21:09:51 UTC (rev 16324)
@@ -171,7 +171,7 @@
 /* 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 @@
 #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 @@
 		"\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 @@
 			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++;

Modified: freeswitch/trunk/src/switch_time.c (16323 => 16324)


--- freeswitch/trunk/src/switch_time.c	2010-01-15 18:06:17 UTC (rev 16323)
+++ freeswitch/trunk/src/switch_time.c	2010-01-15 21:09:51 UTC (rev 16324)
@@ -198,7 +198,7 @@
 
 	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 @@
 		}
 	}
 
-	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,9 +947,21 @@
 	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;
 }