scheduler: refine schedule_edf function to handle multiple task

There will be new task added in schedule_edf function, refine the
function to handle multiple task.

Signed-off-by: Pan Xiuli <xiuli.pan@linux.intel.com>
This commit is contained in:
Pan Xiuli 2018-09-18 11:44:10 +08:00
parent cc4e8c8205
commit 5b39370e1e
1 changed files with 29 additions and 29 deletions

View File

@ -102,13 +102,9 @@ static inline struct task *edf_get_next(uint64_t current,
uint64_t delta;
uint64_t deadline;
int reschedule = 0;
uint32_t flags;
spin_lock_irq(&sch->lock, flags);
/* any tasks in the scheduler ? */
if (list_is_empty(&sch->list)) {
spin_unlock_irq(&sch->lock, flags);
return NULL;
}
@ -159,7 +155,6 @@ static inline struct task *edf_get_next(uint64_t current,
}
}
spin_unlock_irq(&sch->lock, flags);
return next_task;
}
@ -187,35 +182,40 @@ static struct task *schedule_edf(void)
tracev_pipe("edf");
/* get the current time */
current = platform_timer_get(platform_timer);
/* get next task to be scheduled */
task = edf_get_next(current, NULL);
interrupt_clear(PLATFORM_SCHEDULE_IRQ);
/* any tasks ? */
if (task == NULL)
return NULL;
/* can task be started now ? */
if (task->start > current) {
/* no, then schedule wake up */
future_task = task;
} else {
/* yes, run current task */
task->start = current;
/* init task for running */
wait_init(&task->complete);
while (!list_is_empty(&sch->list)) {
spin_lock_irq(&sch->lock, flags);
task->state = TASK_STATE_RUNNING;
list_item_del(&task->list);
/* get the current time */
current = platform_timer_get(platform_timer);
/* get next task to be scheduled */
task = edf_get_next(current, NULL);
spin_unlock_irq(&sch->lock, flags);
/* now run task at correct run level */
run_task(task);
/* any tasks ? */
if (!task)
return NULL;
/* can task be started now ? */
if (task->start <= current) {
/* yes, run current task */
task->start = current;
/* init task for running */
spin_lock_irq(&sch->lock, flags);
task->state = TASK_STATE_RUNNING;
list_item_del(&task->list);
spin_unlock_irq(&sch->lock, flags);
/* now run task at correct run level */
run_task(task);
} else {
/* no, then schedule wake up */
future_task = task;
break;
}
}
/* tell caller about future task */