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

[Minios-devel] [UNIKRAFT PATCH v2 6/8] lib/uksched: Revisit thread exiting logic


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Thu, 10 Jan 2019 17:22:10 +0200
  • Cc: felipe.huici@xxxxxxxxx, Florian.Schmidt@xxxxxxxxx, simon.kuenzer@xxxxxxxxx, yuri.volchkov@xxxxxxxxx
  • Delivery-date: Thu, 10 Jan 2019 15:22:26 +0000
  • Ironport-phdr: 9a23:op9TlR3i00G3Cge5smDT+DRfVm0co7zxezQtwd8ZseMfLvad9pjvdHbS+e9qxAeQG9mDu7Qc06L/iOPJYSQ4+5GPsXQPItRndiQuroEopTEmG9OPEkbhLfTnPGQQFcVGU0J5rTngaRAGUMnxaEfPrXKs8DUcBgvwNRZvJuTyB4Xek9m72/q99pHPYAhEniaxba9vJxiqsAvdsdUbj5F/Iagr0BvJpXVIe+VSxWx2IF+Yggjx6MSt8pN96ipco/0u+dJOXqX8ZKQ4UKdXDC86PGAv5c3krgfMQA2S7XYBSGoWkx5IAw/Y7BHmW5r6ryX3uvZh1CScIMb7S60/Vza/4KdxUBLmiDkJOSM3/m/UjcJ/jqxbrQm9qxBj2YPYfJuYOOZicq7bYNgURXBBXsFUVyFZHI68aJAPD/YAPeZesoLzoUYOrQOjBQKxA+7g1jhIhmTq3a071eQtCwXG3BE4H9ITq3nbsM71OL0KUeCo16bE1y/Db/RP1Dr79YPGcQghrOmRUb9/bMbd00oiGgPfglmOt4DoPSmZ2+oVv2SG4OdsSPijhm0npg1rvDSiyMkhhpPUio8a1FzJ8zhyzpwvKt2iUkF7ZMapEJ5Xty6HKYR7WtgiQ2R0uCYizb0GpIK7cDAKyJs5wx7fbOSKc5aN4h35VeaRJS10i25+eL6lnxay7FOvxvfmVsmzyFpKryxFncfQtn0VyhDe5dWLRuF+80qhwzqDyR7f5+NeLU06jabbLoQuwr80lpodq0TDGSr2lV3qg6+RbUUk5umo6+L9brXiu5+cL5J0hxriPaQ1gMC/Gfk4PRMUU2iB/uSwzKfj8lHhQLVWkv02lbHUsJXbJcQdp665BBRV3p8+5BmhETepztAYkGIDLFJEYxKHk5PpN0vBIf/mC/ezmVOskC1kx/reJL3uHo3NLmTfkLfmZbtz60pcyA0pzdBe/Z1UDKsNLu/vVU/xsdzYDwI2MxCvzubhFtpyyoceVniUDaODLqzSrEeC5vgzLOmUeI8VpDH9JuAr5/HwiX85mEcdcrez0ZsXdXC4H+hpI0SCbHrqnNgODWMKsRAlQ+DwllKCTCZZZ2yuUKIk+jE7FIWmAJ/YRoCshbyB2yG7EodVZmBbFF+MF3bpeJueW/oXbiKdPNNukjgeWre6UYMuywyuvhfgy7V7NurU5jEYtZX72dl1+u3TjxAy+SZqD8Sa12GCU2F0nmAPRz8ox61/p1JyxUuH0adimPNUD8Jc5+4aGjs9YJvdye19EJX+VxzMev+NSU26WZO2DDd3Scg+kPEUZEMoMNK5khHFlw63G6Jdw7eMH4A19OTYwmDsD81mjW7b3u87iA91EYN0KWS6i/snpEDoDInTnhDBmg==
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

We use a list for terminated threads on all schedulers because it
keeps references to those threads until wait is called for them.

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
---
 lib/uksched/include/uk/sched.h |  1 +
 lib/uksched/sched.c            |  7 ++++---
 lib/ukschedcoop/schedcoop.c    | 11 +++--------
 3 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/lib/uksched/include/uk/sched.h b/lib/uksched/include/uk/sched.h
index 443dbf3..c3e2866 100644
--- a/lib/uksched/include/uk/sched.h
+++ b/lib/uksched/include/uk/sched.h
@@ -87,6 +87,7 @@ struct uk_sched {
 
        /* internal */
        struct uk_thread idle;
+       struct uk_thread_list exited_threads;
        struct ukplat_ctx_callbacks plat_ctx_cbs;
        struct uk_alloc *allocator;
        struct uk_sched *next;
diff --git a/lib/uksched/sched.c b/lib/uksched/sched.c
index 6e1d8ee..ed55a64 100644
--- a/lib/uksched/sched.c
+++ b/lib/uksched/sched.c
@@ -122,6 +122,7 @@ struct uk_sched *uk_sched_create(struct uk_alloc *a, size_t 
prv_size)
        }
 
        sched->allocator = a;
+       UK_TAILQ_INIT(&sched->exited_threads);
        sched->prv = (void *) sched + sizeof(struct uk_sched);
 
        return sched;
@@ -217,6 +218,9 @@ void uk_sched_thread_destroy(struct uk_sched *sched, struct 
uk_thread *thread)
 {
        UK_ASSERT(sched != NULL);
        UK_ASSERT(thread != NULL);
+       UK_ASSERT(is_exited(thread));
+
+       UK_TAILQ_REMOVE(&sched->exited_threads, thread, thread_list);
 
        uk_free(sched->allocator, thread->sched_info);
        uk_thread_fini(thread, sched->allocator);
@@ -238,9 +242,6 @@ void uk_sched_thread_exit(void)
        struct uk_thread *thread;
 
        thread = uk_thread_current();
-
-       uk_pr_info("Thread \"%s\" exited.\n", thread->name);
-
        UK_ASSERT(thread->sched);
        uk_sched_thread_remove(thread->sched, thread);
        UK_CRASH("Error stopping thread.");
diff --git a/lib/ukschedcoop/schedcoop.c b/lib/ukschedcoop/schedcoop.c
index f7ab92d..5616ee1 100644
--- a/lib/ukschedcoop/schedcoop.c
+++ b/lib/ukschedcoop/schedcoop.c
@@ -37,7 +37,6 @@
 
 struct schedcoop_private {
        struct uk_thread_list thread_list;
-       struct uk_thread_list exited_threads;
        int threads_started;
 };
 
@@ -124,18 +123,15 @@ static void schedcoop_schedule(struct uk_sched *s)
        if (prev != next)
                uk_sched_thread_switch(s, prev, next);
 
-       UK_TAILQ_FOREACH_SAFE(thread, &prv->exited_threads, thread_list, tmp) {
+       UK_TAILQ_FOREACH_SAFE(thread, &s->exited_threads, thread_list, tmp) {
                struct thread_info_base *tib = thread->sched_info;
 
                if (!tib->is_detached)
                        /* someone will eventually wait for it */
                        continue;
 
-               if (thread != prev) {
-                       UK_TAILQ_REMOVE(&prv->exited_threads,
-                                       thread, thread_list);
+               if (thread != prev)
                        uk_thread_destroy(thread);
-               }
        }
 }
 
@@ -172,7 +168,7 @@ static void schedcoop_thread_remove(struct uk_sched *s, 
struct uk_thread *t)
        clear_runnable(t);
 
        /* Put onto exited list */
-       UK_TAILQ_INSERT_HEAD(&prv->exited_threads, t, thread_list);
+       UK_TAILQ_INSERT_HEAD(&s->exited_threads, t, thread_list);
        uk_thread_exit(t);
 
        ukplat_lcpu_restore_irqf(flags);
@@ -218,7 +214,6 @@ struct uk_sched *uk_schedcoop_init(struct uk_alloc *a)
        ukplat_ctx_callbacks_init(&sched->plat_ctx_cbs, ukplat_ctx_sw);
 
        prv = sched->prv;
-       UK_TAILQ_INIT(&prv->exited_threads);
        UK_TAILQ_INIT(&prv->thread_list);
        prv->threads_started = 0;
 
-- 
2.11.0


_______________________________________________
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®.