FS-4220 --resolve i refactored this into a general cross platform function and use it everywhere else we try to set affinity

This commit is contained in:
Anthony Minessale 2012-05-15 08:31:33 -05:00
parent 0d2739bfd2
commit 5c75d4cf5b
5 changed files with 35 additions and 27 deletions

View File

@ -2328,7 +2328,7 @@ SWITCH_DECLARE(switch_status_t) switch_say_file_handle_create(switch_say_file_ha
SWITCH_DECLARE(void) switch_say_file(switch_say_file_handle_t *sh, const char *fmt, ...);
SWITCH_DECLARE(int) switch_max_file_desc(void);
SWITCH_DECLARE(void) switch_close_extra_files(int *keep, int keep_ttl);
SWITCH_DECLARE(switch_status_t) switch_core_thread_set_cpu_affinity(int cpu);
SWITCH_END_EXTERN_C
#endif
/* For Emacs:

View File

@ -1363,15 +1363,7 @@ void *SWITCH_THREAD_FUNC sofia_msg_thread_run(switch_thread_t *thread, void *obj
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "MSG Thread %d Started\n", my_id);
#ifdef HAVE_CPU_SET_MACROS
{
cpu_set_t set;
CPU_ZERO(&set);
CPU_SET(my_id, &set);
sched_setaffinity(0, sizeof(set), &set);
}
#endif
switch_core_thread_set_cpu_affinity(my_id);
while(switch_queue_pop(q, &pop) == SWITCH_STATUS_SUCCESS && pop) {
sofia_dispatch_event_t *de = (sofia_dispatch_event_t *) pop;

View File

@ -1325,6 +1325,35 @@ SWITCH_DECLARE(uint32_t) switch_core_min_dtmf_duration(uint32_t duration)
return runtime.min_dtmf_duration;
}
SWITCH_DECLARE(switch_status_t) switch_core_thread_set_cpu_affinity(int cpu)
{
switch_status_t status = SWITCH_STATUS_FALSE;
if (cpu > -1) {
#ifdef HAVE_CPU_SET_MACROS
cpu_set_t set;
CPU_ZERO(&set);
CPU_SET(cpu, &set);
if (!sched_setaffinity(0, sizeof(set), &set)) {
status = SWITCH_STATUS_SUCCESS;
}
#else
#if WIN32
if (SetThreadAffinityMask(GetCurrentThread(), (DWORD_PTR) cpu)) {
status = SWITCH_STATUS_SUCCESS;
}
#endif
#endif
}
return status;
}
static void switch_core_set_serial(void)
{
char buf[13] = "";

View File

@ -253,16 +253,8 @@ static void *SWITCH_THREAD_FUNC switch_event_dispatch_thread(switch_thread_t *th
EVENT_DISPATCH_QUEUE_RUNNING[my_id] = 1;
switch_mutex_unlock(EVENT_QUEUE_MUTEX);
#ifdef HAVE_CPU_SET_MACROS
{
cpu_set_t set;
CPU_ZERO(&set);
CPU_SET(my_id, &set);
sched_setaffinity(0, sizeof(set), &set);
}
#endif
switch_core_thread_set_cpu_affinity(my_id);
for (;;) {
void *pop = NULL;

View File

@ -795,14 +795,9 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime)
runtime.profile_timer = switch_new_profile_timer();
switch_get_system_idle_time(runtime.profile_timer, &runtime.profile_time);
#ifdef HAVE_CPU_SET_MACROS
if (runtime.timer_affinity > -1) {
cpu_set_t set;
CPU_ZERO(&set);
CPU_SET(runtime.timer_affinity, &set);
sched_setaffinity(0, sizeof(set), &set);
if (runtime.timer_affinity > -1) {
switch_core_thread_set_cpu_affinity(runtime.timer_affinity);
}
#endif
switch_time_sync();
time_sync = runtime.time_sync;