Skip to content
Snippets Groups Projects
Commit a43ee518 authored by Armin Luntzer's avatar Armin Luntzer
Browse files

saving working state of EDF + core scheduler in actual OS

parent 88c53c0a
Branches
No related tags found
No related merge requests found
......@@ -251,7 +251,7 @@ int kernel_main(void)
attr.wcet = us_to_ktime(200);
sched_set_attr(t, &attr);
kthread_wake_up(t);
#if 1
t = kthread_create(task3, NULL, KTHREAD_CPU_AFFINITY_NONE, "print2");
sched_get_attr(t, &attr);
attr.policy = SCHED_EDF;
......@@ -260,7 +260,8 @@ int kernel_main(void)
attr.wcet = us_to_ktime(100);
sched_set_attr(t, &attr);
kthread_wake_up(t);
#endif
#if 1
t = kthread_create(task1, NULL, KTHREAD_CPU_AFFINITY_NONE, "print3");
sched_get_attr(t, &attr);
attr.policy = SCHED_EDF;
......@@ -269,7 +270,8 @@ int kernel_main(void)
attr.wcet = us_to_ktime(100);
sched_set_attr(t, &attr);
kthread_wake_up(t);
#endif
#if 1
t = kthread_create(task0, NULL, KTHREAD_CPU_AFFINITY_NONE, "res");
sched_get_attr(t, &attr);
attr.policy = SCHED_EDF;
......@@ -278,7 +280,7 @@ int kernel_main(void)
attr.wcet = ms_to_ktime(100);
sched_set_attr(t, &attr);
kthread_wake_up(t);
#endif
#endif
......
......@@ -36,7 +36,9 @@ void schedule(void)
struct task_struct *current;
int64_t slot_ns;
int64_t wake_ns = 0;
int64_t wake_ns = 1000000000;
ktime rt;
static int once;
......@@ -55,12 +57,20 @@ void schedule(void)
/* get the current task for this CPU */
current = current_set[0]->task;
rt = ktime_sub(ktime_get(), current->exec_start);
/** XXX need timeslice_update callback for schedulers */
/* update remaining runtime of current thread */
current->runtime = ktime_sub(current->exec_start, ktime_get());
current->runtime = ktime_sub(current->runtime, rt);
current->total = ktime_add(current->total, rt);
retry:
next = NULL;
wake_ns = 1000000000;
/* XXX: for now, try to wake up any threads not running
* this is a waste of cycles and instruction space; should be
* done in the scheduler's code (somewhere) */
......@@ -82,13 +92,15 @@ retry:
* next is non-NULL
*/
next = sched->pick_next_task(&sched->tq);
#if 0
if (next)
printk("next %s %llu %llu\n", next->name, next->first_wake, ktime_get());
else
printk("NULL\n");
printk("NULL %llu\n", ktime_get());
#endif
/* check if we need to limit the next tasks timeslice;
* since our scheduler list is sorted by scheduler priority,
* only update the value if wake_next is not set;
......@@ -109,22 +121,17 @@ retry:
* the corresponding scheduler
*/
if (!wake_ns)
wake_ns = sched->task_ready_ns(&sched->tq);
if (next) {
slot_ns = next->sched->timeslice_ns(next);
/* we found something to execute, off we go */
if (next)
break;
}
}
if (!next) {
/* there is absolutely nothing nothing to do, check again later */
if (wake_ns)
tick_set_next_ns(wake_ns);
else
tick_set_next_ns(1e9); /* XXX pause for a second, there are no threads in any scheduler */
goto exit;
}
......@@ -134,7 +141,7 @@ retry:
* schedulers, e.g. EDF
*/
slot_ns = next->sched->timeslice_ns(next);
wake_ns = sched->task_ready_ns(&sched->tq);
if (wake_ns < slot_ns)
slot_ns = wake_ns;
......@@ -152,9 +159,9 @@ retry:
/* subtract readout overhead */
tick_set_next_ns(ktime_sub(slot_ns, 2000LL));
#if 1
if (slot_ns < 20000UL) {
if (slot_ns < 19000UL) {
// printk("wake %llu slot %llu %s\n", wake_ns, slot_ns, next->name);
goto retry;
printk("wake %llu slot %llu %s\n", wake_ns, slot_ns, next->name);
BUG();
}
#endif
......
......@@ -107,6 +107,7 @@ static inline bool schedule_edf_can_execute(struct task_struct *tsk, ktime now)
if (tsk->runtime <= 0)
return false;
if (ktime_before(tsk->deadline, now)) {
sched_print_edf_list_internal(&tsk->sched->tq, ktime_get());
printk("%s violated, %lld %lld, dead %lld wake %lld now %lld start %lld\n", tsk->name,
tsk->runtime, ktime_us_delta(tsk->deadline, now),
tsk->deadline, tsk->wakeup, now, tsk->exec_start);
......@@ -153,6 +154,8 @@ static inline void schedule_edf_reinit_task(struct task_struct *tsk, ktime now)
tsk->deadline = ktime_add(tsk->wakeup, tsk->attr.deadline_rel);
tsk->runtime = tsk->attr.wcet;
tsk->slices++;
}
......@@ -242,7 +245,6 @@ static int edf_schedulable(struct task_queue *tq, const struct task_struct *task
return 0;
}
u = (double) (int32_t) task->attr.wcet / (double) (int32_t) task->attr.period;
return 0;
}
......@@ -346,7 +348,7 @@ static struct task_struct *edf_pick_next(struct task_queue *tq)
slot = first->runtime;
}
#if 0 /* XXX should not be needed, but needs verification! */
#if 1 /* XXX should not be needed, but needs verification! */
if (!go) {
list_for_each_entry_safe(tsk, tmp, &tq->run, node) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment