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

[Minios-devel] [UNIKRAFT PATCH 21/23] lib/ukschedpreempt: Add idle thread


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Mon, 8 Jul 2019 11:33:50 +0300
  • Cc: felipe.huici@xxxxxxxxx, simon.kuenzer@xxxxxxxxx
  • Delivery-date: Mon, 08 Jul 2019 08:50:24 +0000
  • Ironport-phdr: 9a23:6RhqwhS7z/b7PSu8Ap6M0mgw1tpsv+yvbD5Q0YIujvd0So/mwa6yYxGN2/xhgRfzUJnB7Loc0qyK6vqmBTRLucrJmUtBWaQEbwUCh8QSkl5oK+++Imq/EsTXaTcnFt9JTl5v8iLzG0FUHMHjew+a+SXqvnYdFRrlKAV6OPn+FJLMgMSrzeCy/IDYbxlViDanbr5+MQu6oR/eu8UKjoduNqk8wQbVr3VVfOhb2XlmLk+JkRbm4cew8p9j8yBOtP8k6sVNT6b0cbkmQLJBFDgpPHw768PttRnYUAuA/WAcXXkMkhpJGAfK8hf3VYrsvyTgt+p93C6aPdDqTb0xRD+v4btnRAPuhSwaMTMy7WPZhdFqjK9DoByvuQFxzYDXbo+SNvV+cLjQcc8GSWdbQspcTTBNDp+6YoASD+QBJ+FYr4zlqlYQqhu+HhWsBOLpyjRVgHH2wLU60/k8GgzBwAMgGMkOsGjVrNXzLqsSVf21zLHVzTjYc/xWwi3x6JDVch86u/2MR7VwfNPXxEIyFA3Flk2dpZHqMj+IzOgAsGiW4/B+We6xiWMrsQ98riCyysojl4XFnIEYx1De+Slnzos4K8e0RFN0bNK6FpZbqjuUOJFsQsw4RmFloCM6yrobtpGlZCUK05EnxwLHa/yAboiI/grvVOaPLjd8g3JoYKy/hxOo/kihzu3wTNW70E1Qoipdj9nDrWoB1wbU6sSfS/t9+Fmu2SqX2gzO5exIPFo4mKnbJpI73LI8iJgevV7NEyPunUX5lq6WdkEq+uiy7OTnZ63rqYObN49vlgH+M6Iulta7AeQlKggOQnOW9vin1LH55U35Xa5FgucskqneqJzaP9gUpralAw9J1YYu8xO/Dzag0NQZmnkHN0tJdw+ZgIj3JV7OJOv1DfO+g1S3jDdr3OrKP7L/DZXLNHTDl63hfbll4U5G1AUz1cxf545TCrwZLvL8REvxtN3ADhAnKQC0w/vnCNRh2YMfQm+PBLGWP7/WsVCS/e0jOfeDZJINsjbnN/cl/+LujWM+mVIFZqmp3J4XaHe+Hvh8IEWZfGTjgtEAEGgUpAozV+rqh0OeXj5XfXm9RLgw6S8mCNHuMYCWQ4GrgbuamSu2AJBSTmRHEUyXV2flccODQfhfRjiVJ5pKlScYVL7pb5I5yFn6vwjh17thaO7J4jAwvomlzMV/offUw0JhvQdoBtiQhjneB1p/mXkFEmc7
  • Ironport-sdr: qazS/lTJ5eX6WNtjOsWGzvTzbuo7u4KNOq44Glb3N2+5kJDH2a4NIfWZHCp6yu9lRyj7kRpRhS wZXYM/Hlljgw==
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

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

 


Rackspace

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