[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: Sun, 10 Mar 2019 22:09:59 +0200
  • Cc: Florian.Schmidt@xxxxxxxxx, simon.kuenzer@xxxxxxxxx, yuri.volchkov@xxxxxxxxx, sharan.santhanam@xxxxxxxxx
  • Delivery-date: Sun, 10 Mar 2019 20:10:18 +0000
  • Ironport-phdr: 9a23:5uW4AxTqA9oW9aIKVPnHCMA/dtpsv+yvbD5Q0YIujvd0So/mwa67ZBSFt8tkgFKBZ4jH8fUM07OQ7/m4HzRZqb+681k6OKRWUBEEjchE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i764jEdAAjwOhRoLerpBIHSk9631+ev8JHPfglEnjWwba5uIBmssQndq9QdjJd/JKo21hbHuGZDdf5MxWNvK1KTnhL86dm18ZV+7SleuO8v+tBZX6nicKs2UbJXDDI9M2Ao/8LrrgXMTRGO5nQHTGoblAdDDhXf4xH7WpfxtTb6tvZ41SKHM8D6Uaw4VDK/5KptVRTmijoINyQh/W/XlMJ+kaxVrhGmqRN9zY7Ze52ZOOZkc6/BZ94WWXZNU8BMXCJBGIO8aI4PAvIfMOZftIn9u1oOrR2jDgeqGePv0iJIjWLx0KIm1OQhCh3G3A0mH94UtHTUsc31NLoJXO+p16nE1y3Db+5N1jvn8ojIdQksrPeRVrxzacrc0VQjGgzYglmKqoHoPymZ2voTv2WZ9eZtW/qjh3Mopg1suDSixcchhpPXio8bxF3I7zh1zYkrKdC+VUV1e8SrEIFKuCGfL4Z2R8QiTHx2tysi0b0GvIK7fDANyJQ62x7Tc/yHfJaM4hLkTOuRPzJ4i2hkeLK7nRq97VOgxvfkVsmpy1lGtDBFkt7UunAM0Rzc9NSHR+Ng8kquxDqDzQPe5+FeLUwqi6bWKYQtz7AompoWq0vDHyv2mEvsjK+Rc0Up4vSn6+P8YrX6p5+cMZV4igXjMqQ2h8yyGvg3MhMUU2iD5OSzz6fv/Vf+QLlSlP05jrHZsIzGJcQcvqO5Bg5V0oAi6xa4FDeqyckXkmcZLF1bfBKKlIzpO1DVIPDkFvezmVutnyltx/zcOb3hGJrNJGDZkLj9ZbZ991JcyA0rwN5f45JUDasBIPPpVU/3rtDWEwM2Mwyxw+bmFdp9ypgTWWSRDaCFNKPdq0SH6vgxLOmRfIUVoiryK+A55/7yin80gUQdfamz0psNcn+4GO5qI16DbnrqntcBEX0FvgwkQ+zvk1CCVyBcaGq2X60m/T43EpypDZrbTIC3nLOBxDu7HoFRZm1eEVCMEHLod4KCW/sWayKSP9FukjoFVLe/UY8szheuuxHmxLpjNOXb4TcUuoz+1NJt/e3ciQky9SBoD8Say2yMT3x0nnkJRzMswqB/pkh9xUuD0ah7hPxYC8de5/VXXQgmMZ7T1fd1B8rsVQLcLZ+1TwOjQ9OnBip0Qt8vztsmZ0dmB87knh3FmS2wDOw7jbuOUbcz6b7d2TDVOt5ggyLN07I9jl9gRtZXKEWtnehn6gKVHYmfwBbRrLqjaalJhH2Fz2yE12fb5Ew=
  • Ironport-sdr: zVa1H5e3kMRoDwr7vh3fflutrI5sbuaO8PK56GkcflJGpmM1NOw/+OMcWtOga3tGggXf5AfjKg 56ZxHX60pxFA==
  • 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®.