From 6db29a98366c906c0ceccb580b1000fb7b3d7866 Mon Sep 17 00:00:00 2001 From: SeokYeon Hwang Date: Mon, 14 Oct 2013 19:20:04 +0900 Subject: [PATCH] brillcodec: Apply W/A for worker threads starvation. 1. Increase default thread pool size to 8. 2. Check idle threads and add sleep against threads starvation. Change-Id: I20695a07ed601ed44b2a639c1c62aaf2ebea3575 Signed-off-by: SeokYeon Hwang --- tizen/src/hw/maru_brill_codec.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tizen/src/hw/maru_brill_codec.c b/tizen/src/hw/maru_brill_codec.c index 7c2e9a6..c4da658 100644 --- a/tizen/src/hw/maru_brill_codec.c +++ b/tizen/src/hw/maru_brill_codec.c @@ -90,7 +90,8 @@ static PixFmtInfo pix_fmt_info[PIX_FMT_NB]; // thread static int worker_thread_cnt = 0; -#define DEFAULT_WORKER_THREAD_CNT 4 +static int idle_thread_cnt = 0; +#define DEFAULT_WORKER_THREAD_CNT 8 static void *maru_brill_codec_threads(void *opaque); @@ -136,7 +137,7 @@ static void maru_brill_codec_add_ioparam_queue(MaruBrillCodecState *s, void *iop static void maru_brill_codec_get_cpu_cores(void) { worker_thread_cnt = get_number_of_processors(); - if (worker_thread_cnt == 1) { + if (worker_thread_cnt < DEFAULT_WORKER_THREAD_CNT) { worker_thread_cnt = DEFAULT_WORKER_THREAD_CNT; } @@ -221,7 +222,15 @@ static void maru_brill_codec_wakeup_threads(MaruBrillCodecState *s, int api_inde } maru_brill_codec_add_ioparam_queue(s, (void *)ioparam); + qemu_mutex_lock(&s->context_mutex); + // W/A for threads starvation. + while (idle_thread_cnt == 0) { + qemu_mutex_unlock(&s->context_mutex); + TRACE("Worker threads are exhausted\n"); + usleep(2000); // wait 2ms. + qemu_mutex_lock(&s->context_mutex); + } qemu_cond_signal(&s->threadpool.cond); qemu_mutex_unlock(&s->context_mutex); } @@ -237,7 +246,9 @@ static void *maru_brill_codec_threads(void *opaque) CodecParamStg *elem = NULL; qemu_mutex_lock(&s->context_mutex); + ++idle_thread_cnt; // protected under mutex. qemu_cond_wait(&s->threadpool.cond, &s->context_mutex); + --idle_thread_cnt; // protected under mutex. qemu_mutex_unlock(&s->context_mutex); qemu_mutex_lock(&s->ioparam_queue_mutex); -- 2.7.4