[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH 18/23] lib/ukschedpreempt: Block threads


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Mon, 8 Jul 2019 11:33:47 +0300
  • Cc: felipe.huici@xxxxxxxxx, simon.kuenzer@xxxxxxxxx
  • Delivery-date: Mon, 08 Jul 2019 08:50:22 +0000
  • Ironport-phdr: 9a23:cv8GXR2KUFWdgR1PsmDT+DRfVm0co7zxezQtwd8ZseIRL/ad9pjvdHbS+e9qxAeQG9mCsbQY06GO7+jJYi8p2d65qncMcZhBBVcuqP49uEgeOvODElDxN/XwbiY3T4xoXV5h+GynYwAOQJ6tL1LdrWev4jEMBx7xKRR6JvjvGo7Vks+7y/2+94fcbglVmjaxe7x/IAm5oQnNucQdnJdvJLs2xhbVuHVDZv5YxXlvJVKdnhb84tm/8Zt++ClOuPwv6tBNX7zic6s3UbJXAjImM3so5MLwrhnMURGP5noHXWoIlBdDHhXI4wv7Xpf1tSv6q/Z91SyHNsD4Ubw4RTKv5LptRRT1iikIKiQ5/XnXhMJukaxVrhGvqRt9zI7ae4yZKOZyc7nBcd4AWWZNQsBcXDFBDIOmaIsPCvIMMPhfr4nmu1sOrB2+DhSqCuPy0j9Im2L90Kom3OQmCgHGwA0gH9QUvHTQsdX1LLoSXPupw6nT1znDd+5W1izn5IjSdRAsuPeBVq9zf8rJ0UQjCgzIgkiKpYHmPz6ZzPoBv3aZ4uZ6W++jk3Mrpg5srjS1xcohipPFipwbx13K7yl13Yk4KcO+RUVme9CrCoFQuDufN4ZuR8MiRHxntzgix70dvJ67YDAKyJM6xx7Dc/CHc5aH4hbkVOuJPzd4gWhqeLO7hxqo7Ueg0ffwVtGp0FlRtCZFiN7MumgM1xzV9MeHVuNw8lqu1DqSzQze6eFJLVoqmabFKZMt2LA9moIWsUvZHy/2nEv2jLWRdkUh4uWn9+PnYq76pp+dMY94kAX+Mrk2msyiGuk3LhMOU3KD+eShz7Lv51f5QLJSgv0sjqbZqIzaJdgcpqOhBg9V04Aj6xe4Dze9ydgXgGcILExbdxKDlIXpP1DOIOvkDfekmVitnylkx/bcMr3mGJXNIWDJkK39crZl905c1A0zwMhR551KDrEBIerzVVHruNzYEx85MhC7w+f8BdV7yIwRRWaPDbWCP6/Ir1CI+/olI/OQa48NpDb9N/8l6ub1jX84nF8deq+p0YEUaHClAPtmJUSYbmT2gtoaF2cFoBYxTOjwh1KZSzJceWuyDOoA4WQ+CYSnCpyGSo2zjbip2CagAoYQdm1ATFeWHiTGbYKBDtwLcz6TJIdFjyQZHeyqTJQ91BfosBLi1pJsNazM5yder5W1h4s93PHaiRxnrW88NM+ayWzYF2w=
  • Ironport-sdr: IocDUlxw/+qV1EwckEbT84zhiiffqdzx++8hBfWF7F2sVO2V0lACGZ6jrLrfaWey9et2Adzt4q h9Q76qRaOV2g==
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

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

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.