|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH 18/23] lib/ukschedpreempt: Block threads
Similarly to cooperative scheduling, preemptive scheduling supports thread
blocking and waking. And just like cooperative scheduling, the sleeping threads
are put on a separate list. The sleeping threads will be woken up on timer
interrupts, but this will be added in the following patches.
Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
---
lib/ukschedpreempt/schedpreempt.c | 32 +++++++++++++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)
diff --git a/lib/ukschedpreempt/schedpreempt.c
b/lib/ukschedpreempt/schedpreempt.c
index ec8d50e4..fdd9681c 100644
--- a/lib/ukschedpreempt/schedpreempt.c
+++ b/lib/ukschedpreempt/schedpreempt.c
@@ -39,6 +39,7 @@
struct schedpreempt_private {
struct prioq ready_queue;
+ struct uk_thread_list sleeping_threads;
};
static
@@ -76,6 +77,32 @@ void schedpreempt_thread_remove(struct uk_sched *s, struct
uk_thread *t)
ukplat_lcpu_restore_irqf(flags);
}
+static
+void schedpreempt_thread_blocked(struct uk_sched *s, struct uk_thread *t)
+{
+ struct schedpreempt_private *prv = s->prv;
+
+ UK_ASSERT(ukplat_lcpu_irqs_disabled());
+
+ if (t != uk_thread_current())
+ prioq_dequeue(&prv->ready_queue, t);
+ if (t->wakeup_time > 0)
+ UK_TAILQ_INSERT_TAIL(&prv->sleeping_threads, t, thread_list);
+}
+
+static
+void schedpreempt_thread_woken(struct uk_sched *s, struct uk_thread *t)
+{
+ struct schedpreempt_private *prv = s->prv;
+
+ UK_ASSERT(ukplat_lcpu_irqs_disabled());
+
+ if (t->wakeup_time > 0)
+ UK_TAILQ_REMOVE(&prv->sleeping_threads, t, thread_list);
+ if (t != uk_thread_current())
+ prioq_enqueue(&prv->ready_queue, t);
+}
+
struct uk_sched *uk_schedpreempt_init(struct uk_alloc *a)
{
struct uk_sched *sched = NULL;
@@ -91,13 +118,14 @@ struct uk_sched *uk_schedpreempt_init(struct uk_alloc *a)
prv = sched->prv;
prioq_init(&prv->ready_queue);
+ UK_TAILQ_INIT(&prv->sleeping_threads);
uk_sched_init(sched,
NULL,
schedpreempt_thread_add,
schedpreempt_thread_remove,
- NULL,
- NULL,
+ schedpreempt_thread_blocked,
+ schedpreempt_thread_woken,
NULL,
NULL,
NULL,
--
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 |