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

[Minios-devel] [UNIKRAFT PATCH v3 08/12] lib/uksched: Set scheduler reference only if adding the thread was successful


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Fri, 22 Mar 2019 17:15:57 +0200
  • Cc: Florian.Schmidt@xxxxxxxxx
  • Delivery-date: Fri, 22 Mar 2019 15:16:54 +0000
  • Ironport-phdr: 9a23:PWbNuhAaNyJifLNQ6D7gUyQJP3N1i/DPJgcQr6AfoPdwSPT6rsbcNUDSrc9gkEXOFd2Cra4d06yJ6uu/AiQp2tWoiDg6aptCVhsI2409vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6nK94iQPFRrhKAF7Ovr6GpLIj8Swyuu+54Dfbx9HiTagfb9+Nhe7oRjeusQUj4ZpN7o8xAbOrnZUYepd2HlmJUiUnxby58ew+IBs/iFNsP8/9MBOTLv3cb0gQbNXEDopPWY15Nb2tRbYVguA+mEcUmQNnRVWBQXO8Qz3UY3wsiv+sep9xTWaMMjrRr06RTiu86FmQwLuhSwaNTA27XvXh9RwgqxFvRyvqR9xzYnWb4GbL/dyYr/RcMkGSWdbQspdSypMCZ68YYsVCOoBOP5Vopf6p1sVsRu+BA+sD/7pxD9Vnn/2wLAx3uM9HgHBxwwgA9MOsHLOoNXxKacSSf21wbLUwjXYdf9WwSr955PSfhA7pvGBRLR9etfSx0k3Dw7Jk1qdpZH/Mz6W1ukBqXaX4/RiWO61hWMrsxx9rzeyyss2iYTEhpgZxk7K+Ch32oo5ONK1RFB9bNW5CpVfrTuaOJFzQs46RmFovzs1xaMetJ6geSgK1IwnxxnCa/yba4SI4gzsVOKWITpgmnJlfaiwhxe28US61uL8TdO40E5XriVeiNXMrHcN2wTS6siBVPR94l+s1SuA2gzO8O1JIkA5mbDFJ5I/wLM8jJQevVzGHiDsmUX2iKGWdl8j+uit8+nofrLmpoSAN491jAHyKKAumtGnAeQlKQUBQ3Ob9f6k1L3+5kL1Wq9KjvounqnDrJ/aPdgbprK+AwJN14Yj6hC/Dzah0NQDhHUIMUxKeAyZgIjtIFzOJPH4Deyjg1S3ijtqyO7JPrv7DpXKNHjDn6/rfaxh5E5E1Aoz0ddf6opUBLEFJ/LzQE7xu8beDhMjLgK73+bnCNB81owDRWKCGamZP73Ovl+M/O0gOPOAa5EIuGW1F/9w4v/ojHgi3FMQY6St9Z8Wc2yjWORrJQOee3W/rM0GFDIhuREiTeqirECaTHYHbHGpQ6M6oDUmEJ+OBpyFXp2nxqaGinToVqZKb3xLXwjfWUzjcJ+JDq8B
  • Ironport-sdr: MkTXjjNmcvDwIFlpQBeX4a6/foUJw0hCSgRhsgS5yk3wlGlw8JbD9H0RIpBsGP9rE8HAb9ElJz 162FDElS6MSA==
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

Scheduler may reject adding threads if certain conditions are not met.
Therefore we set the scheduler reference only if adding the thread was
successful.

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

diff --git a/lib/uksched/include/uk/sched.h b/lib/uksched/include/uk/sched.h
index 9e218688..80fc2f78 100644
--- a/lib/uksched/include/uk/sched.h
+++ b/lib/uksched/include/uk/sched.h
@@ -59,7 +59,7 @@ int uk_sched_set_default(struct uk_sched *s);
 typedef void  (*uk_sched_yield_func_t)
                (struct uk_sched *s);
 
-typedef void  (*uk_sched_thread_add_func_t)
+typedef int   (*uk_sched_thread_add_func_t)
                (struct uk_sched *s, struct uk_thread *t,
                        const uk_thread_attr_t *attr);
 typedef void  (*uk_sched_thread_remove_func_t)
@@ -107,24 +107,30 @@ static inline void uk_sched_yield(void)
        s->yield(s);
 }
 
-static inline void uk_sched_thread_add(struct uk_sched *s,
+static inline int uk_sched_thread_add(struct uk_sched *s,
                struct uk_thread *t, const uk_thread_attr_t *attr)
 {
+       int rc;
+
        UK_ASSERT(s);
        UK_ASSERT(t);
        if (attr)
                t->detached = attr->detached;
-       t->sched = s;
-       s->thread_add(s, t, attr);
+       rc = s->thread_add(s, t, attr);
+       if (rc == 0)
+               t->sched = s;
+       return rc;
 }
 
-static inline void uk_sched_thread_remove(struct uk_sched *s,
+static inline int uk_sched_thread_remove(struct uk_sched *s,
                struct uk_thread *t)
 {
        UK_ASSERT(s);
        UK_ASSERT(t);
+       UK_ASSERT(t->sched == s);
        s->thread_remove(s, t);
        t->sched = NULL;
+       return 0;
 }
 
 static inline int uk_sched_thread_set_prio(struct uk_sched *s,
diff --git a/lib/uksched/sched.c b/lib/uksched/sched.c
index 5f6bc685..104c5280 100644
--- a/lib/uksched/sched.c
+++ b/lib/uksched/sched.c
@@ -197,10 +197,14 @@ struct uk_thread *uk_sched_thread_create(struct uk_sched 
*sched,
        if (rc)
                goto err;
 
-       uk_sched_thread_add(sched, thread, attr);
+       rc = uk_sched_thread_add(sched, thread, attr);
+       if (rc)
+               goto err_add;
 
        return thread;
 
+err_add:
+       uk_thread_fini(thread, sched->allocator);
 err:
        if (stack)
                uk_free(sched->allocator, stack);
diff --git a/lib/uksched/thread.c b/lib/uksched/thread.c
index ff0fb39f..4d931a74 100644
--- a/lib/uksched/thread.c
+++ b/lib/uksched/thread.c
@@ -89,6 +89,7 @@ int uk_thread_init(struct uk_thread *thread,
        thread->wakeup_time = 0LL;
        thread->detached = false;
        uk_waitq_init(&thread->waiting_threads);
+       thread->sched = NULL;
 
 #ifdef CONFIG_HAVE_LIBC
        //TODO _REENT_INIT_PTR(&thread->reent);
diff --git a/lib/ukschedcoop/schedcoop.c b/lib/ukschedcoop/schedcoop.c
index a3f265c6..559df006 100644
--- a/lib/ukschedcoop/schedcoop.c
+++ b/lib/ukschedcoop/schedcoop.c
@@ -132,7 +132,7 @@ static void schedcoop_schedule(struct uk_sched *s)
        }
 }
 
-static void schedcoop_thread_add(struct uk_sched *s, struct uk_thread *t,
+static int schedcoop_thread_add(struct uk_sched *s, struct uk_thread *t,
        const uk_thread_attr_t *attr __unused)
 {
        unsigned long flags;
@@ -143,6 +143,8 @@ static void schedcoop_thread_add(struct uk_sched *s, struct 
uk_thread *t,
        flags = ukplat_lcpu_save_irqf();
        UK_TAILQ_INSERT_TAIL(&prv->thread_list, t, thread_list);
        ukplat_lcpu_restore_irqf(flags);
+
+       return 0;
 }
 
 static void schedcoop_thread_remove(struct uk_sched *s, struct uk_thread *t)
-- 
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®.