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

[Minios-devel] [UNIKRAFT PATCH v4 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 16:16:35 +0200
  • Cc: Florian.Schmidt@xxxxxxxxx
  • Delivery-date: Fri, 22 Mar 2019 14:16:52 +0000
  • Ironport-phdr: 9a23:kZbtexQW+pca8bHVpHW5Mq7kCdpsv+yvbD5Q0YIujvd0So/mwa6yZR2N2/xhgRfzUJnB7Loc0qyK6vimBjVLvMnJmUtBWaQEbwUCh8QSkl5oK+++Imq/EsTXaTcnFt9JTl5v8iLzG0FUHMHjew+a+SXqvnYdFRrlKAV6OPn+FJLMgMSrzeCy/IDYbxlViDanbr5+MQm6oR/Tu8ULjodvKqQ8wQbVr3VVfOhb2XlmLk+JkRbm4cew8p9j8yBOtP8k6sVNT6b0cbkmQLJBFDgpPHw768PttRnYUAuA/WAcXXkMkhpJGAfK8hf3VYrsvyTgt+p93C6aPdDqTb0xRD+v4btnRAPuhSwaMTMy7WPZhdFqjK9DoByvuQFxzYDXbo+SNvV+cLjQcc8GSWdbQspcTTBNDp+6YoASD+QBJ+FYr4zlqlYQqhu+HhWsBOLpyjRVgHH2wLU60/k8GgzBwAMgGMkOsGjVrNXzLqsSVf21zLHVzTjYc/xWwi3x6JDVch86u/2MR7VwfNPXxEIyFA3Flk2dpZHqMj+IzOgAsGiW4/B+We6xiWMrsQ98riCyysojl4XFnIEYx1De+Slnzos4K8e0RFN0bNK6FpZbqjuUOJFsQsw4RmFloCM6yrobtpGlZCUK05EnxwLHa/yAboiI/grvVOaPLjd8g3JoYKy/hxOo/kihzu3wTNW70E1Qoipdj9nDrWoB1wbU6sSfS/t9+Fmu2SqX2gzO5exIPFo4mKnbJpI73LI8iJgevV7NEyPunUX5lq6WdkEq+uiy7OTnZ63rqYObN49vlgH+M6Iulta7AeQlKggOQnOW9vin1LH55U35Xa5FgucskqneqJzaP9gUpralAw9J1YYu8xO/Dzag0NQZmnkHN0tJdw+ZgIj3JV7OJOv1DfO+g1S3jDdr3OrKP7L/DZXLNHTDl63hfbll4U5G1AUz1cxf545TCrwZIPzzXkjxtMbZDhAjNQy42fvpB8l91oMbWGKAH7OZPbjUsVCW+u0vJ/ODa5QPtDnjNvh2r8Lp2Ho4n14aZuyl0IUabFi8H+96OAOJbHyqhc0OQkkQuQ9rZ+vxlFyEGRpOf2v6C6k7/S06DsSiEJ/ebou2xqSc1mGhGcsFNSh9FlmQHCKwJM2/UPAWZXfKLw==
  • Ironport-sdr: yIt5SLkPTdrSTA/ll+95BmZg4rndWlXiuC4hvN+RKbRvS7RfUb45HbYw0wmvqF2Gbx/ETMLpb7 NUNkWgg6JcPw==
  • 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 | 17 ++++++++++++-----
 lib/uksched/thread.c           |  1 +
 lib/ukschedcoop/schedcoop.c    |  4 +++-
 3 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/lib/uksched/include/uk/sched.h b/lib/uksched/include/uk/sched.h
index 9e218688..3eb1f4ec 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,31 @@ 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);
+       if (t->sched != s)
+               return -EINVAL;
        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/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®.