base: Idle wait fix

Avoid unexpected idle wait

The current scheduler has possibility to missing 'ready' workload and
to deadlock, since the static variable 'queue_header' is overwritten
in the 'update_header_bits_counter' function. This patch fixes the
problem by retrying the search in case that no 'ready' workload is
found in a 'ready' workload block.

Signed-off-by: Kazunori Asayama <asayama@sm.sony.co.jp>
Signed-off-by: Yuji Mano <yuji.mano@am.sony.com>
diff --git a/base/src/common/kernel_internal_types.h b/base/src/common/kernel_internal_types.h
index 4df701e..eec536e 100644
--- a/base/src/common/kernel_internal_types.h
+++ b/base/src/common/kernel_internal_types.h
@@ -46,9 +46,10 @@
 
 #define MARS_KERNEL_ID_NONE			0xffff
 
-#define MARS_KERNEL_STATUS_BUSY			0x0
+#define MARS_KERNEL_STATUS_EXIT			0x0
 #define MARS_KERNEL_STATUS_IDLE			0x1
-#define MARS_KERNEL_STATUS_EXIT			0x2
+#define MARS_KERNEL_STATUS_BUSY			0x2
+#define MARS_KERNEL_STATUS_RETRY		0x3
 
 #define MARS_KERNEL_TICKS_FLAG_SYNC_BEGIN	0x1
 #define MARS_KERNEL_TICKS_FLAG_SYNC_END		0x2
diff --git a/base/src/mpu/kernel/kernel.c b/base/src/mpu/kernel/kernel.c
index 8ed045d..c3506c3 100644
--- a/base/src/mpu/kernel/kernel.c
+++ b/base/src/mpu/kernel/kernel.c
@@ -730,7 +730,7 @@
 	/* search block for workload index to run */
 	index = search_block(block, 1);
 	if (index < 0)
-		return MARS_KERNEL_STATUS_IDLE;
+		return MARS_KERNEL_STATUS_RETRY;
 
 	/* set global workload info based on workload block and index */
 	workload_id = MARS_WORKLOAD_PER_BLOCK * block + index;
@@ -938,13 +938,14 @@
 		int status = scheduler();
 
 		switch (status) {
-		case MARS_KERNEL_STATUS_BUSY:
+		case MARS_KERNEL_STATUS_EXIT:
+			exit_flag = 1;
 			break;
 		case MARS_KERNEL_STATUS_IDLE:
 			scheduler_idle_wait();
 			break;
-		case MARS_KERNEL_STATUS_EXIT:
-			exit_flag = 1;
+		case MARS_KERNEL_STATUS_BUSY:
+		case MARS_KERNEL_STATUS_RETRY:
 			break;
 		}
 	}