From 8733a2c8950f552de5d239974ca6d6d09d529228 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 1 Oct 2012 11:47:26 -0500 Subject: [PATCH] some priority queuing tweaks for performance --- src/mod/applications/mod_conference/mod_conference.c | 1 + src/mod/endpoints/mod_sofia/sofia.c | 7 +++++-- src/switch_core.c | 2 +- src/switch_core_io.c | 2 ++ src/switch_core_sqldb.c | 3 ++- src/switch_event.c | 1 + src/switch_time.c | 5 ++++- 7 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/mod/applications/mod_conference/mod_conference.c b/src/mod/applications/mod_conference/mod_conference.c index 0bdf28822b..d84f3b6f7d 100644 --- a/src/mod/applications/mod_conference/mod_conference.c +++ b/src/mod/applications/mod_conference/mod_conference.c @@ -7748,6 +7748,7 @@ static void launch_conference_thread(conference_obj_t *conference) switch_set_flag_locked(conference, CFLAG_RUNNING); switch_threadattr_create(&thd_attr, conference->pool); switch_threadattr_detach_set(thd_attr, 1); + switch_threadattr_priority_increase(thd_attr); switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); switch_mutex_lock(globals.hash_mutex); switch_mutex_unlock(globals.hash_mutex); diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index f7f7bddead..2793cd7354 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -1599,7 +1599,7 @@ void *SWITCH_THREAD_FUNC sofia_msg_thread_run(switch_thread_t *thread, void *obj msg_queue_threads++; switch_mutex_unlock(mod_sofia_globals.mutex); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "MSG Thread %d Started\n", my_id); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "MSG Thread %d Started\n", my_id); for(;;) { @@ -1612,12 +1612,13 @@ void *SWITCH_THREAD_FUNC sofia_msg_thread_run(switch_thread_t *thread, void *obj if (pop) { sofia_dispatch_event_t *de = (sofia_dispatch_event_t *) pop; sofia_process_dispatch_event(&de); + switch_os_yield(); } else { break; } } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "MSG Thread Ended\n"); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "MSG Thread Ended\n"); switch_mutex_lock(mod_sofia_globals.mutex); msg_queue_threads--; @@ -1934,6 +1935,8 @@ void sofia_event_callback(nua_event_t event, if (profile->pres_type) { switch_cond_next(); + } else { + switch_os_yield(); } diff --git a/src/switch_core.c b/src/switch_core.c index 6cce356061..488b755232 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -736,7 +736,7 @@ SWITCH_DECLARE(int32_t) set_realtime_priority(void) char data[] = "-1\n"; struct sched_param sched = { 0 }; sched.sched_priority = 1; - if (sched_setscheduler(0, SCHED_FIFO, &sched)) { + if (sched_setscheduler(0, SCHED_RR, &sched)) { sched.sched_priority = 0; if (sched_setscheduler(0, SCHED_OTHER, &sched)) { return -1; diff --git a/src/switch_core_io.c b/src/switch_core_io.c index 8978306adb..7b9580c0bb 100644 --- a/src/switch_core_io.c +++ b/src/switch_core_io.c @@ -112,6 +112,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi switch_assert(session != NULL); + switch_os_yield(); + if (switch_mutex_trylock(session->codec_read_mutex) == SWITCH_STATUS_SUCCESS) { switch_mutex_unlock(session->codec_read_mutex); } else { diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c index d77b432c90..2e3e71f204 100644 --- a/src/switch_core_sqldb.c +++ b/src/switch_core_sqldb.c @@ -2539,7 +2539,7 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_ switch_threadattr_create(&thd_attr, sql_manager.memory_pool); switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); - + switch_threadattr_priority_increase(thd_attr); switch_core_sqldb_start_thread(); switch_thread_create(&sql_manager.db_thread, thd_attr, switch_core_sql_db_thread, NULL, sql_manager.memory_pool); @@ -2641,6 +2641,7 @@ SWITCH_DECLARE(void) switch_core_sqldb_start_thread(void) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Starting SQL thread.\n"); switch_threadattr_create(&thd_attr, sql_manager.memory_pool); switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); + switch_threadattr_priority_increase(thd_attr); switch_thread_create(&sql_manager.thread, thd_attr, switch_core_sql_thread, NULL, sql_manager.memory_pool); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL thread is already running\n"); diff --git a/src/switch_event.c b/src/switch_event.c index 3a02e3a449..175dadf5cf 100644 --- a/src/switch_event.c +++ b/src/switch_event.c @@ -276,6 +276,7 @@ static void *SWITCH_THREAD_FUNC switch_event_dispatch_thread(switch_thread_t *th event = (switch_event_t *) pop; switch_event_deliver(&event); + switch_os_yield(); } diff --git a/src/switch_time.c b/src/switch_time.c index fb9fea1de0..54bf9338ef 100644 --- a/src/switch_time.c +++ b/src/switch_time.c @@ -150,6 +150,7 @@ SWITCH_DECLARE(void) switch_os_yield(void) #if defined(WIN32) SwitchToThread(); #else + usleep(1); sched_yield(); #endif } @@ -672,8 +673,10 @@ 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(); + switch_os_yield(); + + if (runtime.tipping_point && globals.timer_count >= runtime.tipping_point) { - switch_os_yield(); globals.use_cond_yield = 0; } else { if (globals.use_cond_yield == 1) {