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

[Minios-devel] [UNIKRAFT PATCH v2 2/8] lib/uksched: Add function for allocating scheduler common info


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Thu, 10 Jan 2019 17:22:06 +0200
  • Cc: felipe.huici@xxxxxxxxx, Florian.Schmidt@xxxxxxxxx, simon.kuenzer@xxxxxxxxx, yuri.volchkov@xxxxxxxxx
  • Delivery-date: Thu, 10 Jan 2019 15:22:24 +0000
  • Ironport-phdr: 9a23:pPPfkxVJSjIJXLcgWY2TEXQ92+jV8LGtZVwlr6E/grcLSJyIuqrYbR2Dt8tkgFKBZ4jH8fUM07OQ7/iwHzRYqb+681k6OKRWUBEEjchE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i764jEdAAjwOhRoLerpBIHSk9631+ev8JHPfglEnjWwba9xIRmssQndqtQdjJd/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/7yin80gVEdcret3ZsWcHC3AO5qI0WEYXrtntgBEHwHvgwgQ+P2jF2NSyVca2ysUKIh/js7Ep6pDZ/fRoCxh7yMxDy7HpxTZmBBDFCAC3Tod5iaVPcKaSOdPNVhnycCVbe/V4Ah0QuhuxTgx7V5M+re4jcYuo771Nhp++3Tkgk/9DxpD8SH0mGBVX90nmQMRzAq3KB/okt9ykmY3Kh+nfNXCdhT6OlSXQsgK5Hc0r8yN9enXwPHf9CSDVqrXNiiKTUwVc4qhc8DZQB6AdrxoArE2n+BBKQJlrrDIIEs7+qI1H/qO8d7jXLbzLQJhEJgWtZFc3eh0P0svzPPDpLExh3K352hcr4RiXbA
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

We introduce uk_sched_create function which allocates the memory
needed for schedulers data. It also initializes data that is
common to all schedulers.

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
Reviewed-by: Florian Schmidt <florian.schmidt@xxxxxxxxx>
---
 lib/uksched/exportsyms.uk      |  1 +
 lib/uksched/include/uk/sched.h |  2 ++
 lib/uksched/sched.c            | 18 ++++++++++++++++++
 lib/ukschedcoop/schedcoop.c    | 26 ++++----------------------
 4 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/lib/uksched/exportsyms.uk b/lib/uksched/exportsyms.uk
index 9dc133c..45a9694 100644
--- a/lib/uksched/exportsyms.uk
+++ b/lib/uksched/exportsyms.uk
@@ -2,6 +2,7 @@ uk_sched_default_init
 uk_sched_register
 uk_sched_get_default
 uk_sched_set_default
+uk_sched_create
 uk_sched_start
 uk_sched_idle_init
 uk_sched_thread_create
diff --git a/lib/uksched/include/uk/sched.h b/lib/uksched/include/uk/sched.h
index bbfe442..d2fc8df 100644
--- a/lib/uksched/include/uk/sched.h
+++ b/lib/uksched/include/uk/sched.h
@@ -114,6 +114,8 @@ static inline void uk_sched_thread_remove(struct uk_sched 
*s,
  * Internal scheduler functions
  */
 
+struct uk_sched *uk_sched_create(struct uk_alloc *a, size_t prv_size);
+
 void uk_sched_idle_init(struct uk_sched *sched,
                void *stack, void (*function)(void *));
 
diff --git a/lib/uksched/sched.c b/lib/uksched/sched.c
index 12780ec..c3be206 100644
--- a/lib/uksched/sched.c
+++ b/lib/uksched/sched.c
@@ -109,6 +109,24 @@ int uk_sched_set_default(struct uk_sched *s)
        return 0;
 }
 
+struct uk_sched *uk_sched_create(struct uk_alloc *a, size_t prv_size)
+{
+       struct uk_sched *sched = NULL;
+
+       UK_ASSERT(a != NULL);
+
+       sched = uk_malloc(a, sizeof(struct uk_sched) + prv_size);
+       if (sched == NULL) {
+               uk_pr_warn("Could not allocate scheduler.");
+               return NULL;
+       }
+
+       sched->allocator = a;
+       sched->prv = (void *) sched + sizeof(struct uk_sched);
+
+       return sched;
+}
+
 void uk_sched_start(struct uk_sched *sched)
 {
        UK_ASSERT(sched != NULL);
diff --git a/lib/ukschedcoop/schedcoop.c b/lib/ukschedcoop/schedcoop.c
index 6f51ece..3e3a92f 100644
--- a/lib/ukschedcoop/schedcoop.c
+++ b/lib/ukschedcoop/schedcoop.c
@@ -194,26 +194,16 @@ struct uk_sched *uk_schedcoop_init(struct uk_alloc *a)
 
        uk_pr_info("Initializing cooperative scheduler\n");
 
-       sched = uk_malloc(a, sizeof(struct uk_sched));
-       if (sched == NULL) {
-               uk_pr_warn("Could not allocate memory for scheduler.\n");
-               goto out_err;
-       }
-
-       sched->allocator = a;
+       sched = uk_sched_create(a, sizeof(struct schedcoop_private));
+       if (sched == NULL)
+               return NULL;
 
        ukplat_ctx_callbacks_init(&sched->plat_ctx_cbs, ukplat_ctx_sw);
 
-       prv = uk_malloc(a, sizeof(struct schedcoop_private));
-       if (prv == NULL) {
-               uk_pr_warn("Could not allocate memory for scheduler private 
data.\n");
-               goto out_err;
-       }
-
+       prv = sched->prv;
        UK_TAILQ_INIT(&prv->exited_threads);
        UK_TAILQ_INIT(&prv->thread_list);
        prv->threads_started = 0;
-       sched->prv = prv;
 
        uk_sched_idle_init(sched, NULL, idle_thread_fn);
 
@@ -223,12 +213,4 @@ struct uk_sched *uk_schedcoop_init(struct uk_alloc *a)
                        schedcoop_thread_remove);
 
        return sched;
-
-out_err:
-       if (prv)
-               uk_free(a, prv);
-       if (sched)
-               uk_free(a, sched);
-
-       return NULL;
 }
-- 
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®.