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

[Minios-devel] [UNIKRAFT PATCH v3 06/12] lib/uksched: Revisit thread exiting logic


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Fri, 22 Mar 2019 17:15:55 +0200
  • Cc: Florian.Schmidt@xxxxxxxxx
  • Delivery-date: Fri, 22 Mar 2019 15:16:53 +0000
  • Ironport-phdr: 9a23:3KCPfB+0a+7MLP9uRHKM819IXTAuvvDOBiVQ1KB30uMcTK2v8tzYMVDF4r011RmVBN2dtKsP1LGempujcFRI2YyGvnEGfc4EfD4+ouJSoTYdBtWYA1bwNv/gYn9yNs1DUFh44yPzahANS47xaFLIv3K98yMZFAnhOgppPOT1HZPZg9iq2+yo9JDffhlEiCC/bL9vIxm7rwvcvdQKjIV/Lao81gHHqWZSdeRMwmNoK1OTnxLi6cq14ZVu7Sdete8/+sBZSan1cLg2QrJeDDQ9LmA6/9brugXZTQuO/XQTTGMbmQdVDgff7RH6WpDxsjbmtud4xSKXM9H6QawyVD+/6apgVR3mhzodNzMh8G/ZlNF+gqxYrhympRN/zZXZbJ2JOPdkYq/QZ88WSXZHU81MVyJBGIS8b44XAucfOuZYtJX9p1oIrRCjAwesGfvvyiJVjXLxwaI61P8hER3H3AwmBd4OtGnUrM3oNKoJTe+117PEzS3eb/xNwzv98o/IfwknrPqRXrxwadLcxVQgGg/YlFmdqozoMymL2ugTsWWX9eRtWfqyh2Motg19uDuiy8c2hoXXiI8YxErI+Th2zYorI9CzVVR1bsS+EJRKsiGXL452QsQ/TG52oCs60bgGuYKjfCgN1ZQn2wbTa/yZfIiM5RLuTPiRITJii3JkfLKznQq98VO6xu3kS8m7y0xGrjBCktXUt3AN0QLc6tSfR/dg8UqtxCyD2gPT5+1eP0w4i6jWJ4Qvz7Iok5ocq0XDHiv4mEXsi6+Wc10p9fSv6+T8frXmp5mcO5VwigHjKqQuh9eyDvgjMgQUR2ib5P+z2Kf5/U3+WLlKlOE5krHFsJDGIsQWvqu5Aw5T0oYi7Ba/FC6q38kGknkZMl1FfAmKj4zoO1HVPPD4Fu2zgluynzdt3fzGOafhAprVJHjZjLjhZap961JbyAcrzd5f45VUCqsAIP3pXE/9rsHWAQM5MwyxwuboFcl925gYWW2RHqCZNLndvkSS6u0xPunfLLMS7TP8Lfki/LvigGE0nXcZfLK1xt0HZXb+Ge5pcGuDZn+5qdAaDWYM9i4jVPGi3FaFSiJSYTC2QrohzjogTpq7B8HZQdb+0/S6wC6nE8gONSh9AVeWHCKweg==
  • Ironport-sdr: v+br0W6kTG4mTnugM5dHDuhK/2M1Cz1CRTuVdmycPUKynIR0kazm6rxp7wjpcFYp8kPls1gCMk qY17M28CzthQ==
  • 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>
Reviewed-by: Florian Schmidt <florian.schmidt@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 9554c6e1..e5630ed6 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 d7ca7f35..a0d706f5 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;
@@ -213,6 +214,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_thread_fini(thread, sched->allocator);
        uk_pfree(sched->allocator, thread->stack, STACK_SIZE_PAGE_ORDER);
        uk_free(sched->allocator, thread);
@@ -232,9 +236,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 5091c913..2a646760 100644
--- a/lib/ukschedcoop/schedcoop.c
+++ b/lib/ukschedcoop/schedcoop.c
@@ -36,7 +36,6 @@
 
 struct schedcoop_private {
        struct uk_thread_list thread_list;
-       struct uk_thread_list exited_threads;
        int threads_started;
 };
 
@@ -123,16 +122,13 @@ 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) {
                if (!thread->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);
-               }
        }
 }
 
@@ -163,7 +159,7 @@ static void schedcoop_thread_remove(struct uk_sched *s, 
struct uk_thread *t)
        uk_thread_exit(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);
 
@@ -208,7 +204,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®.