<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[Freeswitch-trunk][16081] </title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<div id="header">FreeSWITCH Subversion</div>
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://fisheye.freeswitch.org/changelog/FreeSWITCH?cs=16081">16081</a></dd>
<dt>Author</dt> <dd>anthm</dd>
<dt>Date</dt> <dd>2009-12-29 17:21:20 -0600 (Tue, 29 Dec 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>trade some max call count for more accurate timing in full media situations, hint: use 30ms ptime for drastic reduction in resources</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunkconfigurein">freeswitch/trunk/configure.in</a></li>
<li><a href="#freeswitchtrunksrcincludeswitch_coreh">freeswitch/trunk/src/include/switch_core.h</a></li>
<li><a href="#freeswitchtrunksrcswitch_corec">freeswitch/trunk/src/switch_core.c</a></li>
<li><a href="#freeswitchtrunksrcswitch_core_sessionc">freeswitch/trunk/src/switch_core_session.c</a></li>
<li><a href="#freeswitchtrunksrcswitch_timec">freeswitch/trunk/src/switch_time.c</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunkconfigurein"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/configure.in (16080 => 16081)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/configure.in        2009-12-29 22:44:31 UTC (rev 16080)
+++ freeswitch/trunk/configure.in        2009-12-29 23:21:20 UTC (rev 16081)
</span><span class="lines">@@ -399,7 +399,7 @@
</span><span class="cx"> AC_TYPE_SIGNAL
</span><span class="cx"> AC_FUNC_STRFTIME
</span><span class="cx"> AC_CHECK_FUNCS([gethostname vasprintf mmap mlock mlockall usleep getifaddrs])
</span><del>-AC_CHECK_FUNCS([sched_setscheduler setpriority setrlimit setgroups initgroups])
</del><ins>+AC_CHECK_FUNCS([sched_setscheduler sched_setaffinity setpriority setrlimit setgroups initgroups])
</ins><span class="cx"> AC_CHECK_FUNCS([wcsncmp setgroups asprintf setenv pselect gettimeofday localtime_r gmtime_r strcasecmp stricmp _stricmp])
</span><span class="cx">
</span><span class="cx"> AC_CHECK_LIB(rt, clock_gettime, [AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [Define if you have clock_gettime()])])
</span></span></pre></div>
<a id="freeswitchtrunksrcincludeswitch_coreh"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/include/switch_core.h (16080 => 16081)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/include/switch_core.h        2009-12-29 22:44:31 UTC (rev 16080)
+++ freeswitch/trunk/src/include/switch_core.h        2009-12-29 23:21:20 UTC (rev 16081)
</span><span class="lines">@@ -1941,6 +1941,7 @@
</span><span class="cx"> SWITCH_DECLARE(switch_bool_t) switch_check_network_list_ip_token(const char *ip_str, const char *list_name, const char **token);
</span><span class="cx"> #define switch_check_network_list_ip(_ip_str, _list_name) switch_check_network_list_ip_token(_ip_str, _list_name, NULL)
</span><span class="cx"> SWITCH_DECLARE(void) switch_time_set_monotonic(switch_bool_t enable);
</span><ins>+SWITCH_DECLARE(void) switch_time_set_nanosleep(switch_bool_t enable);
</ins><span class="cx"> SWITCH_DECLARE(uint32_t) switch_core_min_dtmf_duration(uint32_t duration);
</span><span class="cx"> SWITCH_DECLARE(uint32_t) switch_core_max_dtmf_duration(uint32_t duration);
</span><span class="cx"> SWITCH_DECLARE(uint32_t) switch_core_default_dtmf_duration(uint32_t duration);
</span></span></pre></div>
<a id="freeswitchtrunksrcswitch_corec"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_core.c (16080 => 16081)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_core.c        2009-12-29 22:44:31 UTC (rev 16080)
+++ freeswitch/trunk/src/switch_core.c        2009-12-29 23:21:20 UTC (rev 16081)
</span><span class="lines">@@ -1409,8 +1409,10 @@
</span><span class="cx">                                         if (tmp > 0) {
</span><span class="cx">                                                 switch_core_default_dtmf_duration((uint32_t) tmp);
</span><span class="cx">                                         }
</span><del>-                                } else if (!strcasecmp(var, "disable-monotonic-timing")) {
-                                        switch_time_set_monotonic(SWITCH_FALSE);
</del><ins>+                                } else if (!strcasecmp(var, "enable-monotonic-timing")) {
+                                        switch_time_set_monotonic(switch_true(var));
+                                } else if (!strcasecmp(var, "enable-clock-nanosleep")) {
+                                        switch_time_set_nanosleep(switch_true(var));
</ins><span class="cx">                                 } else if (!strcasecmp(var, "max-sessions") && !zstr(val)) {
</span><span class="cx">                                         switch_core_session_limit(atoi(val));
</span><span class="cx">                                 } else if (!strcasecmp(var, "rtp-start-port") && !zstr(val)) {
</span></span></pre></div>
<a id="freeswitchtrunksrcswitch_core_sessionc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_core_session.c (16080 => 16081)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_core_session.c        2009-12-29 22:44:31 UTC (rev 16080)
+++ freeswitch/trunk/src/switch_core_session.c        2009-12-29 23:21:20 UTC (rev 16081)
</span><span class="lines">@@ -1281,13 +1281,13 @@
</span><span class="cx">         switch_mutex_unlock(runtime.throttle_mutex);
</span><span class="cx">
</span><span class="cx">         if (sps <= 0) {
</span><del>-                //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Throttle Error!\n");
</del><ins>+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Throttle Error! %d\n", session_manager.session_count);
</ins><span class="cx">                 UNPROTECT_INTERFACE(endpoint_interface);
</span><span class="cx">                 return NULL;
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         if ((count + 1) > session_manager.session_limit) {
</span><del>-                //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Over Session Limit!\n");
</del><ins>+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Over Session Limit! %d\n", session_manager.session_limit);
</ins><span class="cx">                 UNPROTECT_INTERFACE(endpoint_interface);
</span><span class="cx">                 return NULL;
</span><span class="cx">         }
</span></span></pre></div>
<a id="freeswitchtrunksrcswitch_timec"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_time.c (16080 => 16081)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_time.c        2009-12-29 22:44:31 UTC (rev 16080)
+++ freeswitch/trunk/src/switch_time.c        2009-12-29 23:21:20 UTC (rev 16081)
</span><span class="lines">@@ -70,6 +70,7 @@
</span><span class="cx"> #define IDLE_SPEED 100
</span><span class="cx"> #define STEP_MS 1
</span><span class="cx"> #define STEP_MIC 1000
</span><ins>+#define TICK_PER_SEC 1000
</ins><span class="cx">
</span><span class="cx"> struct timer_private {
</span><span class="cx">         switch_size_t reference;
</span><span class="lines">@@ -85,6 +86,7 @@
</span><span class="cx">         uint32_t roll;
</span><span class="cx">         switch_mutex_t *mutex;
</span><span class="cx">         switch_thread_cond_t *cond;
</span><ins>+        switch_thread_rwlock_t *rwlock;
</ins><span class="cx"> };
</span><span class="cx"> typedef struct timer_matrix timer_matrix_t;
</span><span class="cx">
</span><span class="lines">@@ -92,23 +94,39 @@
</span><span class="cx">
</span><span class="cx"> static void do_sleep(switch_interval_time_t t)
</span><span class="cx"> {
</span><ins>+#if defined(HAVE_CLOCK_NANOSLEEP) || defined(DARWIN)
+        struct timespec ts;
+#endif
+
</ins><span class="cx"> #if defined(WIN32)
</span><span class="cx">         if (t < 1000) {
</span><span class="cx">                 t = 1000;
</span><span class="cx">         }
</span><span class="cx"> #endif
</span><span class="cx">
</span><del>-#if defined(DARWIN)
-        struct timespec ts;
</del><ins>+#if !defined(DARWIN)
+        if (t > 100000) {
+                apr_sleep(t);
+        }
+#endif
+        
+
+#if defined(HAVE_CLOCK_NANOSLEEP)
</ins><span class="cx">         ts.tv_sec = t / APR_USEC_PER_SEC;
</span><ins>+        ts.tv_nsec = ((t % APR_USEC_PER_SEC) * 1000) - 1000000;
+        clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL);
+#elif defined(DARWIN)
+        ts.tv_sec = t / APR_USEC_PER_SEC;
</ins><span class="cx">         ts.tv_nsec = (t % APR_USEC_PER_SEC) * 1000;
</span><del>-        
</del><span class="cx">         nanosleep(&ts, NULL);
</span><del>-        sched_yield();
</del><span class="cx"> #else
</span><span class="cx">         apr_sleep(t);
</span><span class="cx"> #endif
</span><span class="cx">
</span><ins>+#if defined(DARWIN)
+sched_yield();
+#endif
+
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> SWITCH_DECLARE(switch_time_t) switch_micro_time_now(void)
</span><span class="lines">@@ -132,13 +150,24 @@
</span><span class="cx"> static int MONO = 0;
</span><span class="cx"> #endif
</span><span class="cx">
</span><ins>+#if defined(HAVE_CLOCK_NANOSLEEP)
+static int NANO = 1;
+#else
+static int NANO = 0;
+#endif
</ins><span class="cx">
</span><ins>+
</ins><span class="cx"> SWITCH_DECLARE(void) switch_time_set_monotonic(switch_bool_t enable)
</span><span class="cx"> {
</span><span class="cx">         MONO = enable ? 1 : 0;
</span><span class="cx">         switch_time_sync();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+SWITCH_DECLARE(void) switch_time_set_nanosleep(switch_bool_t enable)
+{
+        NANO = enable ? 1 : 0;
+}
+
</ins><span class="cx"> static switch_time_t time_now(int64_t offset)
</span><span class="cx"> {
</span><span class="cx">         switch_time_t now;
</span><span class="lines">@@ -334,17 +363,26 @@
</span><span class="cx">
</span><span class="cx">         while (globals.RUNNING == 1 && private_info->ready && TIMER_MATRIX[timer->interval].tick < private_info->reference) {
</span><span class="cx">                 check_roll();
</span><ins>+                        
+                if (NANO) {
+                        do_sleep(1000 * timer->interval);
+                        continue;
+                }
+
</ins><span class="cx">                 if (globals.use_cond_yield == 1) {
</span><del>-                        switch_mutex_lock(TIMER_MATRIX[cond_index].mutex);                
-                        if (TIMER_MATRIX[timer->interval].tick < private_info->reference) {
-                                switch_thread_cond_wait(TIMER_MATRIX[cond_index].cond, TIMER_MATRIX[cond_index].mutex);        
</del><ins>+                        if (switch_mutex_lock(TIMER_MATRIX[cond_index].mutex) == SWITCH_STATUS_SUCCESS) {
+                                if (TIMER_MATRIX[timer->interval].tick < private_info->reference) {
+                                        switch_thread_cond_wait(TIMER_MATRIX[cond_index].cond, TIMER_MATRIX[cond_index].mutex);        
+                                }
+                                switch_mutex_unlock(TIMER_MATRIX[cond_index].mutex);
+                        } else {
+                                do_sleep(1000);
</ins><span class="cx">                         }
</span><del>-                        switch_mutex_unlock(TIMER_MATRIX[cond_index].mutex);
</del><span class="cx">                 } else {
</span><span class="cx">                         do_sleep(1000);
</span><span class="cx">                 }
</span><span class="cx">         }
</span><del>-        
</del><ins>+
</ins><span class="cx">         if (globals.RUNNING == 1) {
</span><span class="cx">                 return SWITCH_STATUS_SUCCESS;
</span><span class="cx">         }
</span><span class="lines">@@ -406,6 +444,13 @@
</span><span class="cx">         switch_time_t ts = 0, last = 0;
</span><span class="cx">         int fwd_errs = 0, rev_errs = 0;
</span><span class="cx">
</span><ins>+#ifdef HAVE_SCHED_SETAFFINITY
+        cpu_set_t set;
+        CPU_ZERO(&set);
+        CPU_SET(0, &set);
+        sched_setaffinity(0, sizeof(set), &set);
+#endif
+
</ins><span class="cx">         switch_time_sync();
</span><span class="cx">
</span><span class="cx">         globals.STARTED = globals.RUNNING = 1;
</span><span class="lines">@@ -421,6 +466,7 @@
</span><span class="cx">                         if (ts == last) {
</span><span class="cx">                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Broken MONOTONIC Clock Detected!, Support Disabled.\n");
</span><span class="cx">                                 MONO = 0;
</span><ins>+                                NANO = 0;
</ins><span class="cx">                                 runtime.reference = switch_time_now();
</span><span class="cx">                                 runtime.initiated = runtime.reference;
</span><span class="cx">                                 break;
</span><span class="lines">@@ -435,15 +481,16 @@
</span><span class="cx">         fwd_errs = rev_errs = 0;
</span><span class="cx">
</span><span class="cx"> #ifndef DISABLE_1MS_COND
</span><del>-        switch_mutex_init(&TIMER_MATRIX[1].mutex, SWITCH_MUTEX_NESTED, module_pool);
-        switch_thread_cond_create(&TIMER_MATRIX[1].cond, module_pool);
</del><ins>+        if (!NANO) {
+                switch_mutex_init(&TIMER_MATRIX[1].mutex, SWITCH_MUTEX_NESTED, module_pool);
+                switch_thread_cond_create(&TIMER_MATRIX[1].cond, module_pool);
+        }
</ins><span class="cx"> #endif
</span><span class="cx">
</span><del>-        globals.use_cond_yield = globals.RUNNING == 1;
-
</del><ins>+        globals.use_cond_yield = globals.RUNNING = 1;
+        
</ins><span class="cx">         while (globals.RUNNING == 1) {
</span><span class="cx">                 runtime.reference += STEP_MIC;
</span><del>-
</del><span class="cx">                 while ((ts = time_now(runtime.offset)) < runtime.reference) {
</span><span class="cx">                         if (ts < last) {
</span><span class="cx">                                 if (MONO) {
</span><span class="lines">@@ -461,11 +508,10 @@
</span><span class="cx">                         } else {
</span><span class="cx">                                 rev_errs = 0;
</span><span class="cx">                         }
</span><del>-                        do_sleep(STEP_MIC);
</del><ins>+                        do_sleep(STEP_MIC);                
</ins><span class="cx">                         last = ts;
</span><span class="cx">                 }
</span><span class="cx">
</span><del>-
</del><span class="cx">                 if (ts > (runtime.reference + too_late)) {
</span><span class="cx">                         if (MONO) {
</span><span class="cx">                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Virtual Migration Detected! Syncing Clock\n");
</span><span class="lines">@@ -495,7 +541,7 @@
</span><span class="cx">                 current_ms += STEP_MS;
</span><span class="cx">                 tick += STEP_MS;
</span><span class="cx">
</span><del>-                if (tick >= 1000) {
</del><ins>+                if (tick >= TICK_PER_SEC) {
</ins><span class="cx">                         if (runtime.sps <= 0) {
</span><span class="cx">                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Over Session Rate of %d!\n", runtime.sps_total);
</span><span class="cx">                         }
</span><span class="lines">@@ -525,9 +571,11 @@
</span><span class="cx">                                         if (TIMER_MATRIX[x].count) {
</span><span class="cx">                                                 TIMER_MATRIX[x].tick++;
</span><span class="cx"> #ifdef DISABLE_1MS_COND
</span><del>-                                                if (TIMER_MATRIX[x].mutex && switch_mutex_trylock(TIMER_MATRIX[x].mutex) == SWITCH_STATUS_SUCCESS) {
-                                                        switch_thread_cond_broadcast(TIMER_MATRIX[x].cond);
-                                                        switch_mutex_unlock(TIMER_MATRIX[x].mutex);
</del><ins>+                                                if (!NANO) {
+                                                        if (TIMER_MATRIX[x].mutex && switch_mutex_trylock(TIMER_MATRIX[x].mutex) == SWITCH_STATUS_SUCCESS) {
+                                                                switch_thread_cond_broadcast(TIMER_MATRIX[x].cond);
+                                                                switch_mutex_unlock(TIMER_MATRIX[x].mutex);
+                                                        }
</ins><span class="cx">                                                 }
</span><span class="cx"> #endif
</span><span class="cx">                                                 if (TIMER_MATRIX[x].tick == MAX_TICK) {
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>
</body>
</html>