optimizations and disable the conditional thing till we see why it dies at 100cps X 800 calls

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@2708 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2006-09-15 21:43:18 +00:00
parent 9efc687d7a
commit aa2a793e28
6 changed files with 117 additions and 152 deletions

View File

@ -739,7 +739,6 @@ static switch_status_t activate_rtp(private_object_t *tech_pvt)
tech_pvt->read_codec.implementation->ianacode, tech_pvt->read_codec.implementation->ianacode,
tech_pvt->read_codec.implementation->microseconds_per_frame / 1000); tech_pvt->read_codec.implementation->microseconds_per_frame / 1000);
tech_pvt->rtp_session = switch_rtp_new(tech_pvt->local_sdp_audio_ip, tech_pvt->rtp_session = switch_rtp_new(tech_pvt->local_sdp_audio_ip,
tech_pvt->local_sdp_audio_port, tech_pvt->local_sdp_audio_port,
tech_pvt->remote_sdp_audio_ip, tech_pvt->remote_sdp_audio_ip,
@ -1360,7 +1359,8 @@ static void sip_i_state(int status,
case nua_callstate_calling: case nua_callstate_calling:
break; break;
case nua_callstate_proceeding: case nua_callstate_proceeding:
if (session && r_sdp) { if (channel) {
if (r_sdp) {
sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int)strlen(r_sdp), 0); sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int)strlen(r_sdp), 0);
sdp_session_t *sdp; sdp_session_t *sdp;
uint8_t match = 0; uint8_t match = 0;
@ -1383,19 +1383,20 @@ static void sip_i_state(int status,
switch_channel_pre_answer(channel); switch_channel_pre_answer(channel);
return; return;
} }
}
if (channel) {
switch_channel_set_variable(channel, "endpoint_disposition", "NO CODECS"); switch_channel_set_variable(channel, "endpoint_disposition", "NO CODECS");
}
nua_respond(nh, SIP_488_NOT_ACCEPTABLE, nua_respond(nh, SIP_488_NOT_ACCEPTABLE,
//SIPTAG_CONTACT(tech_pvt->contact), //SIPTAG_CONTACT(tech_pvt->contact),
TAG_END()); TAG_END());
}
}
break; break;
case nua_callstate_completing: case nua_callstate_completing:
nua_ack(nh, TAG_END()); nua_ack(nh, TAG_END());
break; break;
case nua_callstate_received: case nua_callstate_received:
if (session && r_sdp) { if (channel) {
if (r_sdp) {
sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int)strlen(r_sdp), 0); sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int)strlen(r_sdp), 0);
sdp_session_t *sdp; sdp_session_t *sdp;
uint8_t match = 0; uint8_t match = 0;
@ -1420,20 +1421,20 @@ static void sip_i_state(int status,
switch_core_session_thread_launch(session); switch_core_session_thread_launch(session);
return; return;
} }
}
if (channel) {
switch_channel_set_variable(channel, "endpoint_disposition", "NO CODECS"); switch_channel_set_variable(channel, "endpoint_disposition", "NO CODECS");
}
nua_respond(nh, SIP_488_NOT_ACCEPTABLE, nua_respond(nh, SIP_488_NOT_ACCEPTABLE,
//SIPTAG_CONTACT(tech_pvt->contact), //SIPTAG_CONTACT(tech_pvt->contact),
TAG_END()); TAG_END());
}
}
break; break;
case nua_callstate_early: case nua_callstate_early:
break; break;
case nua_callstate_completed: case nua_callstate_completed:
break; break;
case nua_callstate_ready: case nua_callstate_ready:
if (session) { if (channel) {
if (r_sdp) { if (r_sdp) {
sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int)strlen(r_sdp), 0); sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int)strlen(r_sdp), 0);
sdp_session_t *sdp; sdp_session_t *sdp;
@ -1458,18 +1459,19 @@ static void sip_i_state(int status,
switch_channel_answer(channel); switch_channel_answer(channel);
return; return;
} }
switch_channel_set_variable(channel, "endpoint_disposition", "NO CODECS");
nua_respond(nh, SIP_488_NOT_ACCEPTABLE,
//SIPTAG_CONTACT(tech_pvt->contact),
TAG_END());
} else if (switch_test_flag(tech_pvt, TFLAG_EARLY_MEDIA)) { } else if (switch_test_flag(tech_pvt, TFLAG_EARLY_MEDIA)) {
switch_channel_set_variable(channel, "endpoint_disposition", "ANSWER"); switch_channel_set_variable(channel, "endpoint_disposition", "ANSWER");
switch_channel_answer(channel); switch_channel_answer(channel);
return; return;
} //else probably an ack
} }
}
if (channel) {
switch_channel_set_variable(channel, "endpoint_disposition", "NO CODECS");
}
nua_respond(nh, SIP_488_NOT_ACCEPTABLE,
//SIPTAG_CONTACT(tech_pvt->contact),
TAG_END());
break; break;
case nua_callstate_terminating: case nua_callstate_terminating:
break; break;

View File

@ -69,7 +69,7 @@ all: depends $(MODNAME).$(DYNAMIC_LIB_EXTEN)
depends: depends:
MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) mozilla.tar.gz --prefix=$(PREFIX) MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) mozilla.tar.gz --prefix=$(PREFIX)
MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install curl-7.15.2.tar.gz --prefix=$(PREFIX) MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install curl-7.15.2.tar.gz --prefix=$(PREFIX) --without-libidn
MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install libetpan-0.45.tar.gz --prefix=$(PREFIX) MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install libetpan-0.45.tar.gz --prefix=$(PREFIX)
$(MODNAME).$(DYNAMIC_LIB_EXTEN): $(MODNAME).c $(MODNAME).$(DYNAMIC_LIB_EXTEN): $(MODNAME).c

View File

@ -45,31 +45,27 @@ static const char modname[] = "mod_threadtimer";
#define MAX_ELEMENTS 1000 #define MAX_ELEMENTS 1000
struct timer_private { struct timer_private {
uint64_t tick; uint32_t reference;
uint64_t reference;
uint32_t interval;
//switch_mutex_t *mutex;
struct timer_private *next;
}; };
typedef struct timer_private timer_private_t; typedef struct timer_private timer_private_t;
struct timer_head { struct timer_matrix {
timer_private_t *private_info; uint64_t tick;
switch_mutex_t *mutex; uint32_t count;
}; };
typedef struct timer_head timer_head_t; typedef struct timer_matrix timer_matrix_t;
static timer_head_t *TIMER_MATRIX[MAX_ELEMENTS+1]; static timer_matrix_t TIMER_MATRIX[MAX_ELEMENTS+1];
#define IDLE_SPEED 100 #define IDLE_SPEED 100
static inline void set_timer(void) static inline void set_timer(void)
{ {
uint32_t index = 0, min = IDLE_SPEED; uint32_t index = 0, min = IDLE_SPEED;
for(index = 0; index < MAX_ELEMENTS; index++) { for(index = 0; index < MAX_ELEMENTS; index++) {
if (TIMER_MATRIX[index] && TIMER_MATRIX[index]->private_info) { if (TIMER_MATRIX[index].count) {
if (min > index) { if (min > index) {
min = index; min = index;
} }
@ -83,27 +79,13 @@ static inline void set_timer(void)
static inline switch_status_t timer_init(switch_timer_t *timer) static inline switch_status_t timer_init(switch_timer_t *timer)
{ {
timer_private_t *private_info; timer_private_t *private_info;
timer_head_t *head;
if ((private_info = switch_core_alloc(timer->memory_pool, sizeof(*private_info)))) { if ((private_info = switch_core_alloc(timer->memory_pool, sizeof(*private_info)))) {
switch_mutex_lock(globals.mutex);
TIMER_MATRIX[timer->interval].count++;
switch_mutex_unlock(globals.mutex);
timer->private_info = private_info; timer->private_info = private_info;
if (!TIMER_MATRIX[timer->interval]) { private_info->reference = TIMER_MATRIX[timer->interval].tick;
if (!(TIMER_MATRIX[timer->interval] = switch_core_alloc(module_pool, sizeof(timer_head_t)))) {
return SWITCH_STATUS_MEMERR;
}
switch_mutex_init(&TIMER_MATRIX[timer->interval]->mutex, SWITCH_MUTEX_NESTED, module_pool);
}
head = TIMER_MATRIX[timer->interval];
//switch_mutex_init(&private_info->mutex, SWITCH_MUTEX_NESTED, timer->memory_pool);
private_info->interval = timer->interval;
switch_mutex_lock(head->mutex);
private_info->next = head->private_info;
head->private_info = private_info;
switch_mutex_unlock(head->mutex);
set_timer(); set_timer();
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
@ -116,9 +98,7 @@ static inline switch_status_t timer_step(switch_timer_t *timer)
{ {
timer_private_t *private_info = timer->private_info; timer_private_t *private_info = timer->private_info;
//switch_mutex_lock(private_info->mutex); private_info->reference += timer->interval;
private_info->reference += private_info->interval;
//switch_mutex_unlock(private_info->mutex);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -128,9 +108,8 @@ static inline switch_status_t timer_next(switch_timer_t *timer)
{ {
timer_private_t *private_info = timer->private_info; timer_private_t *private_info = timer->private_info;
timer_step(timer); timer_step(timer);
while (private_info->tick < private_info->reference) { while (TIMER_MATRIX[timer->interval].tick < private_info->reference) {
switch_yield(1000); switch_yield(1000);
} }
timer->samplecount += timer->samples; timer->samplecount += timer->samples;
@ -144,14 +123,12 @@ static inline switch_status_t timer_check(switch_timer_t *timer)
timer_private_t *private_info = timer->private_info; timer_private_t *private_info = timer->private_info;
switch_status_t status; switch_status_t status;
//switch_mutex_lock(private_info->mutex); if (TIMER_MATRIX[timer->interval].tick < private_info->reference) {
if (private_info->tick < private_info->reference) {
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
} else { } else {
private_info->reference += private_info->interval; private_info->reference += timer->interval;
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
} }
//switch_mutex_unlock(private_info->mutex);
return status; return status;
} }
@ -159,26 +136,9 @@ static inline switch_status_t timer_check(switch_timer_t *timer)
static inline switch_status_t timer_destroy(switch_timer_t *timer) static inline switch_status_t timer_destroy(switch_timer_t *timer)
{ {
timer_private_t *private_info = timer->private_info; switch_mutex_lock(globals.mutex);
timer_head_t *head; TIMER_MATRIX[timer->interval].count--;
timer_private_t *ptr, *last = NULL; switch_mutex_unlock(globals.mutex);
head = TIMER_MATRIX[timer->interval];
assert(head != NULL);
assert(private_info != NULL);
switch_mutex_lock(head->mutex);
for(ptr = head->private_info; ptr; ptr = ptr->next) {
if (ptr == private_info) {
if (last) {
last->next = private_info->next;
} else {
head->private_info = private_info->next;
}
}
last = ptr;
}
switch_mutex_unlock(head->mutex);
set_timer(); set_timer();
timer->private_info = NULL; timer->private_info = NULL;
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
@ -223,7 +183,6 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
{ {
switch_time_t reference = switch_time_now(); switch_time_t reference = switch_time_now();
uint32_t current_ms = 0; uint32_t current_ms = 0;
timer_private_t *ptr;
uint32_t x; uint32_t x;
memset(&globals, 0, sizeof(globals)); memset(&globals, 0, sizeof(globals));
@ -235,7 +194,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
while(globals.RUNNING == 1) { while(globals.RUNNING == 1) {
reference += globals.timer_microseconds; reference += globals.timer_microseconds;
//printf("TEST %d\n", globals.timer_microseconds);
while (switch_time_now() < reference) { while (switch_time_now() < reference) {
//switch_yield((reference - now) - 1000); //switch_yield((reference - now) - 1000);
switch_yield(globals.timer_microseconds >> 1); switch_yield(globals.timer_microseconds >> 1);
@ -251,14 +210,8 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
index = (current_ms % i == 0) ? i : 0; index = (current_ms % i == 0) ? i : 0;
if (TIMER_MATRIX[index] && TIMER_MATRIX[index]->private_info) { if (TIMER_MATRIX[index].count) {
switch_mutex_lock(TIMER_MATRIX[index]->mutex); TIMER_MATRIX[index].tick += index;
for (ptr = TIMER_MATRIX[index]->private_info; ptr; ptr = ptr->next) {
//switch_mutex_lock(ptr->mutex);
ptr->tick += ptr->interval;
//switch_mutex_unlock(ptr->mutex);
}
switch_mutex_unlock(TIMER_MATRIX[index]->mutex);
} }
} }

View File

@ -589,10 +589,11 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_state(switch_c
switch_event_fire(&event); switch_event_fire(&event);
} }
} }
/*
if (state < CS_DONE) { if (state < CS_DONE) {
switch_core_session_signal_state_change(channel->session); switch_core_session_signal_state_change(channel->session);
} }
*/
} else { } else {
switch_log_printf(SWITCH_CHANNEL_ID_LOG, (char *) file, func, line, SWITCH_LOG_WARNING, "%s Invalid State Change %s -> %s\n", switch_log_printf(SWITCH_CHANNEL_ID_LOG, (char *) file, func, line, SWITCH_LOG_WARNING, "%s Invalid State Change %s -> %s\n",
channel->name, channel->name,
@ -875,7 +876,7 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_hangup(switch_chan
} }
switch_core_session_kill_channel(channel->session, SWITCH_SIG_KILL); switch_core_session_kill_channel(channel->session, SWITCH_SIG_KILL);
switch_core_session_signal_state_change(channel->session); //switch_core_session_signal_state_change(channel->session);
} }
return channel->state; return channel->state;
} }

View File

@ -90,8 +90,8 @@ struct switch_core_session {
switch_audio_resampler_t *read_resampler; switch_audio_resampler_t *read_resampler;
switch_audio_resampler_t *write_resampler; switch_audio_resampler_t *write_resampler;
switch_mutex_t *mutex; //switch_mutex_t *mutex;
switch_thread_cond_t *cond; //switch_thread_cond_t *cond;
switch_thread_rwlock_t *rwlock; switch_thread_rwlock_t *rwlock;
@ -2489,11 +2489,13 @@ static void switch_core_standard_on_hold(switch_core_session_t *session)
SWITCH_DECLARE(void) switch_core_session_signal_state_change(switch_core_session_t *session) SWITCH_DECLARE(void) switch_core_session_signal_state_change(switch_core_session_t *session)
{ {
/* If trylock fails the signal is already awake so we need'nt bother */ return;
/* If trylock fails the signal is already awake so we needn't bother
if (switch_mutex_trylock(session->mutex) == SWITCH_STATUS_SUCCESS) { if (switch_mutex_trylock(session->mutex) == SWITCH_STATUS_SUCCESS) {
switch_thread_cond_signal(session->cond); switch_thread_cond_signal(session->cond);
switch_mutex_unlock(session->mutex); switch_mutex_unlock(session->mutex);
} }
*/
} }
SWITCH_DECLARE(unsigned int) switch_core_session_runing(switch_core_session_t *session) SWITCH_DECLARE(unsigned int) switch_core_session_runing(switch_core_session_t *session)
@ -2605,7 +2607,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
driver_state_handler = endpoint_interface->state_handler; driver_state_handler = endpoint_interface->state_handler;
assert(driver_state_handler != NULL); assert(driver_state_handler != NULL);
switch_mutex_lock(session->mutex); //switch_mutex_lock(session->mutex);
while ((state = switch_channel_get_state(session->channel)) != CS_DONE) { while ((state = switch_channel_get_state(session->channel)) != CS_DONE) {
if (state != laststate) { if (state != laststate) {
@ -2884,17 +2886,26 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
laststate = midstate; laststate = midstate;
} }
if (state < CS_DONE && midstate == switch_channel_get_state(session->channel)) { if (state >= CS_HANGUP) {
switch_thread_cond_wait(session->cond, session->mutex); goto done;
} }
if (midstate == switch_channel_get_state(session->channel)) {
//switch_thread_cond_wait(session->cond, session->mutex);
switch_yield(10000);
} else {
switch_yield(1000);
}
} }
done: done:
//switch_mutex_unlock(session->mutex);
#ifdef CRASH_PROT #ifdef CRASH_PROT
apr_hash_set(runtime.stack_table, &thread_id, sizeof(thread_id), NULL); apr_hash_set(runtime.stack_table, &thread_id, sizeof(thread_id), NULL);
#endif #endif
session->thread_running = 0; session->thread_running = 0;
switch_mutex_unlock(session->mutex);
} }
SWITCH_DECLARE(void) switch_core_session_destroy(switch_core_session_t **session) SWITCH_DECLARE(void) switch_core_session_destroy(switch_core_session_t **session)
@ -3140,9 +3151,9 @@ SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request(const switch
session->enc_read_frame.data = session->enc_read_buf; session->enc_read_frame.data = session->enc_read_buf;
session->enc_read_frame.buflen = sizeof(session->enc_read_buf); session->enc_read_frame.buflen = sizeof(session->enc_read_buf);
switch_mutex_init(&session->mutex, SWITCH_MUTEX_NESTED, session->pool); //switch_mutex_init(&session->mutex, SWITCH_MUTEX_NESTED, session->pool);
switch_thread_rwlock_create(&session->bug_rwlock, session->pool); switch_thread_rwlock_create(&session->bug_rwlock, session->pool);
switch_thread_cond_create(&session->cond, session->pool); //switch_thread_cond_create(&session->cond, session->pool);
switch_thread_rwlock_create(&session->rwlock, session->pool); switch_thread_rwlock_create(&session->rwlock, session->pool);
switch_mutex_lock(runtime.session_table_mutex); switch_mutex_lock(runtime.session_table_mutex);

View File

@ -204,9 +204,7 @@ SWITCH_DECLARE(int) switch_socket_waitfor(switch_pollfd_t *poll, int ms)
{ {
int nsds = 0; int nsds = 0;
if (switch_poll(poll, 1, &nsds, ms) != SWITCH_STATUS_SUCCESS) { switch_poll(poll, 1, &nsds, ms);
return -1;
}
return nsds; return nsds;
} }