From a0b0997b5cd674c4d5e77bafb9f6499c8c9bf04e Mon Sep 17 00:00:00 2001
From: derMihai <mihairenea@gmail.com>
Date: Mon, 25 Mar 2019 18:22:31 +0100
Subject: [PATCH] determine_next_mode(): check if process is runnable

---
 kernel/sched/sched.h | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index eec6da7a2bf5..1e2a79da89d8 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -904,8 +904,30 @@ static inline int determine_next_mode_pb(struct rq *rq)
 				 * Is the tick interrupt active in this moment?
 				 */
 				if(pb->count_admin_cycles > pb->n_admin_cycles){
-					mode = PB_EXEC_MODE;
-					pb->count_admin_cycles = 0;
+					/*
+					 * If the current plan_entry's process is blocked, we cannot
+					 * go in PB_EXEC_MODE. The reason could be, that administrative
+					 * tasks were pushed forward by the default scheduler and the IO
+					 * starved. We have to wait until the process is runnable.
+					 */
+					if (pb->plan[pb->c_entry].task_struct->state >= 0) {
+						/*
+						 * 0 	== Runnable (IO succeeded)
+						 * >0 	== stopped (Process finished)
+						 */
+						mode = PB_EXEC_MODE;
+						pb->count_admin_cycles = 0;
+
+					} else {
+						/*
+						 * -1	== unrunnable
+						 */
+						mode = PB_ADMIN_MODE;
+						printk(KERN_WARNING "PB TASK %llu BLOCKED BY IO FOR %llu TOO MANY TICKS\n",
+								pb->plan[pb->c_entry].task_id,
+								pb->count_admin_cycles - pb->n_admin_cycles);
+					}
+
 				}else{
 					mode = PB_ADMIN_MODE;
 				}
-- 
GitLab