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

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


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Tue, 18 Sep 2018 18:27:26 +0300
  • Cc: felipe.huici@xxxxxxxxx, florian.schmidt@xxxxxxxxx, simon.kuenzer@xxxxxxxxx, yuri.volchkov@xxxxxxxxx
  • Delivery-date: Tue, 18 Sep 2018 15:27:41 +0000
  • Ironport-phdr: 9a23:vSTYeBKH9GUpdNIWj9mcpTZWNBhigK39O0sv0rFitYgfI/jxwZ3uMQTl6Ol3ixeRBMOHs60C07KempujcFRI2YyGvnEGfc4EfD4+ouJSoTYdBtWYA1bwNv/gYn9yNs1DUFh44yPzahANS47xaFLIv3K98yMZFAnhOgppPOT1HZPZg9iq2+yo9JDffwdFiCChbb9uMR67sRjfus4KjIV4N60/0AHJonxGe+RXwWNnO1eelAvi68mz4ZBu7T1et+ou+MBcX6r6eb84TaFDAzQ9L281/szrugLdQgaJ+3ART38ZkhtMAwjC8RH6QpL8uTb0u+ZhxCWXO9D9QLYpUjqg8qhrUgflhicZOTAk/m/Zict+g6BVoB+6uxBz35TZbJ2POfZiYq/Qe84RS2pbXsZWUixMGp2xb4wUD+odPOZYqZT2qV0TrRumGAmnGeTixSNPhn/twa060uIhHRvC3Aw9B9IOrW/Zo8nuNKsISeC10bLHwS/Zb/NRwDrw7pXDfBM5ofyUQL59ftfdxVMsGg7FlFmct5LpMjGP2ukDq2SX8uVtWf+1h2Mkqwx9uCajy8kih4XTm44YxU7I+CNky4gvP9K4UlR0Ydu8HZtVsCGVKpV5T9s5Q2FtpCY60roGuYOnfCQSyJQo2Rrfa/uffoiW5xLsTueRITNiiH15Y7KznQ6y8VW7xeHmTMm0105GritDktbSqnAAzwHf58eaRvdn/Uqs2SyD2x7N5uxGO0w5m7LXK5s7zb4xkpoTv17DHijzmEjukKCWcV4k+vSp6+TheLnmooKcN5dpigzlLqsugdazAfwlMgcVRWSb4+O82KX5/ULlWLVKkuE2kq7BvZDfJMQboK+5AwhO0oo69hmwESmm38ocnXQcKFJFeQmHj5TyO13UL/H3E/G/j06rkDdxyPDMJqfhDYnVLnjfjLfheq5w60BCxwo3zNBf/4xbBqsBIPLuW0/+qN3YAwQ/MwOq3+nnDM9y2ZgEVW2RH6+TKLnSvkOQ5uIzP+mMY5cYuDj5K/gi/f7ujGU2mVkHcamywZQXaHW4HvV7LEWFenfshMkOHnsOvgUkV+PmkkONUSNLbXaoQ608/i07CJ6hDYrbXYCtgbmB3CC9HpFMZWBGF06DEXHpdoqaQfcBcySSLdF9nTwAT7euUJUt2g+ztAXi0bpoMvLU+jEEtZLkzNV05/DTlQsz9TBuEcSd1GWNQH10nmMLQD82wrtyoUpjxVif1ah3medXGcZN6PNUAU8GMsvZzup7DMu3Vg/fc9OhTFe9Xs7gETw3CNUrzIwgeUF4Tv6llQzC2WKOHqcI3+iAA4co86Sa22XpOu520DDeyaNnlV5wEZgHDnGvmqMqr1ubPIXOiUjMz6s=
  • 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 will be called for
them.

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
---
 lib/uksched/include/uk/sched.h  |  1 +
 lib/uksched/include/uk/thread.h |  4 ++++
 lib/uksched/sched.c             |  7 ++++---
 lib/ukschedcoop/schedcoop.c     | 11 +++--------
 4 files changed, 12 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/include/uk/thread.h b/lib/uksched/include/uk/thread.h
index d28c458..7a1b630 100644
--- a/lib/uksched/include/uk/thread.h
+++ b/lib/uksched/include/uk/thread.h
@@ -87,11 +87,15 @@ struct uk_thread *uk_thread_current(void)
 }
 
 #define RUNNABLE_FLAG   0x00000001
+#define EXITED_FLAG     0x00000002
 
 #define is_runnable(_thread)    ((_thread)->flags &   RUNNABLE_FLAG)
 #define set_runnable(_thread)   ((_thread)->flags |=  RUNNABLE_FLAG)
 #define clear_runnable(_thread) ((_thread)->flags &= ~RUNNABLE_FLAG)
 
+#define is_exited(_thread)      ((_thread)->flags &   EXITED_FLAG)
+#define set_exited(_thread)     ((_thread)->flags |=  EXITED_FLAG)
+
 int uk_thread_init(struct uk_thread *thread,
                struct ukplat_ctx_callbacks *cbs, struct uk_alloc *allocator,
                const char *name, void *stack,
diff --git a/lib/uksched/sched.c b/lib/uksched/sched.c
index 968723c..c5b7c9f 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_printd(DLVL_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 f616330..a2bf2ad 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,12 +123,9 @@ 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) {
-               if (thread != prev) {
-                       UK_TAILQ_REMOVE(&prv->exited_threads,
-                                       thread, thread_list);
+       UK_TAILQ_FOREACH_SAFE(thread, &s->exited_threads, thread_list, tmp) {
+               if (thread != prev)
                        uk_thread_destroy(thread);
-               }
        }
 }
 
@@ -166,7 +162,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);
 
        ukplat_lcpu_restore_irqf(flags);
 
@@ -211,7 +207,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®.