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

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



Hi Costin,

thanks for the patience. Now it's looking good, thanks!

On 3/22/19 4:15 PM, Costin Lupu wrote:
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>

Reviewed-by: Florian Schmidt <florian.schmidt@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)


--
Dr. Florian Schmidt
フローリアン・シュミット
Research Scientist,
Systems and Machine Learning Group
NEC Laboratories Europe
Kurfürsten-Anlage 36, D-69115 Heidelberg
Tel.     +49 (0)6221 4342-265
Fax:     +49 (0)6221 4342-155
e-mail:  florian.schmidt@xxxxxxxxx
============================================================
Registered at Amtsgericht Mannheim, Germany, HRB728558

_______________________________________________
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®.