[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH 21/23] lib/ukschedpreempt: Add idle thread
Just like the cooperative scheduler, the preemptive scheduler also has an idle thread. The difference is that in this case, the idle thread is more involved in the scheduling process. Whenever it is scheduled, the idle thread cleans up the resources of detached threads. Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx> --- lib/ukschedpreempt/schedpreempt.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/ukschedpreempt/schedpreempt.c b/lib/ukschedpreempt/schedpreempt.c index 0a01c3df..ef0cbabe 100644 --- a/lib/ukschedpreempt/schedpreempt.c +++ b/lib/ukschedpreempt/schedpreempt.c @@ -159,6 +159,7 @@ void schedpreempt_thread_remove(struct uk_sched *s, struct uk_thread *t) uk_thread_exit(t); UK_TAILQ_INSERT_HEAD(&s->exited_threads, t, thread_list); + /* Idle thread will free the resources */ if (t == uk_thread_current()) { /* thread exiting */ schedpreempt_schedule(s, t); @@ -251,6 +252,33 @@ int schedpreempt_thread_get_tslice(struct uk_sched *s __unused, return 0; } +static void idle_thread_fn(void *unused __unused) +{ + struct uk_thread *current, *t, *tmp; + struct uk_sched *s; + + current = uk_thread_current(); + + s = current->sched; + UK_ASSERT(current == uk_sched_get_idle(s)); + + /* start scheduling */ + uk_sched_yield(); + + while (1) { + UK_TAILQ_FOREACH_SAFE(t, &s->exited_threads, thread_list, tmp) { + if (!t->detached) + /* someone will eventually wait for it */ + continue; + + uk_sched_thread_destroy(s, t); + } + + ukplat_lcpu_halt_irq(); + uk_sched_yield(); + } +} + static void schedpreempt_yield(struct uk_sched *s) { unsigned long flags; @@ -277,6 +305,8 @@ struct uk_sched *uk_schedpreempt_init(struct uk_alloc *a) prioq_init(&prv->ready_queue); UK_TAILQ_INIT(&prv->sleeping_threads); + uk_sched_idle_init(sched, NULL, idle_thread_fn); + uk_sched_init(sched, schedpreempt_yield, schedpreempt_thread_add, -- 2.20.1 _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |