brillcodec: Apply W/A for worker threads starvation. 29/11729/1
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Mon, 14 Oct 2013 10:20:04 +0000 (19:20 +0900)
committerKitae Kim <kt920.kim@samsung.com>
Mon, 4 Nov 2013 05:38:41 +0000 (14:38 +0900)
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 <syeon.hwang@samsung.com>
tizen/src/hw/maru_brill_codec.c

index 7c2e9a6..c4da658 100644 (file)
@@ -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);