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

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


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Tue, 18 Sep 2018 18:27:23 +0300
  • Cc: felipe.huici@xxxxxxxxx, florian.schmidt@xxxxxxxxx, simon.kuenzer@xxxxxxxxx, yuri.volchkov@xxxxxxxxx
  • Delivery-date: Tue, 18 Sep 2018 15:27:41 +0000
  • Ironport-phdr: 9a23:MDOHhBYjo9++6D9bCZZS5LX/LSx+4OfEezUN459isYplN5qZrsW+bnLW6fgltlLVR4KTs6sC17KJ9fi4EUU7or+5+EgYd5JNUxJXwe43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6arXK99yMdFQviPgRpOOv1BpTSj8Oq3Oyu5pHfeQpFiCa/bL9oMBm6sRjau9ULj4dlNqs/0AbCrGFSe+RRy2NoJFaTkAj568yt4pNt8Dletuw4+cJYXqr0Y6o3TbpDDDQ7KG81/9HktQPCTQSU+HQRVHgdnwdSDAjE6BH6WYrxsjf/u+Fg1iSWIdH6QLYpUjmk8qxlSgLniD0fOjA57m/Zl8J+gqFcrh2jqRxy2JLYbJ2POfZiZK7RYc8WSGxcVchRTSxBBYa8YpMRAuoGJuZYs4j9p10TphW4GAmsHP7vwSJPi3Dq2q06yPghEQDA3AA6G9IOrWzUrMjuOagOSuC51rHIzSjYYP9Mwzf975HFfxY8qv+PRbJ9adfdxEYyGw/fjVidqZbpMy2L2ukPqWSW4fJsWf+ghmI6sQ18oTiiyt0yhoTHiI8Z0E3I+CpnzIszONa2UlR0YcS+H5tVryyaMox2Td48TGxwoyY6z6EGuYa8fCgX1JQr3x7fZOKDc4iP+h/jSuORLi15hHJhYr6wmw2y/VK4yu3hTca4ykxKri1dntnNsHACyQDT59CaRvZy40utwzWC2gDJ5u1aP0w5l7DXJpA5zr41jJUTsEDDHiHsmEXxia+bblkr+u+z6+T7Y7XmoIWQN4tpigHmL6QjgdCwAf8iPggWQmiU4v6w1Kfk/UHhWrVFkuU2krXFsJDdPckbo6+5AwlU0oYk8BazFiqp38oGnXYZKFJIYxaHj4nyO1HSO/D0F/i+jEqqkDtxwPDGJLLhCI3XLnffiLfhYap960lExQo9099f45NUCqkfL/7pWk/xqd3YAQM4MwGvxeboFsly1ocEVm2UGKOWLr7Su0eS5u0zO+mMeJMVuDHlJvgr4/7uimU5mV4Hcqmvx5cXc2y3HvRjI0WYfHXsnswMEWEUsQUiSOzlkkaNXSRNaHavR6g8/C00CJq6DYffQYCgmKeB3Ca+Hp1RYGBKEFOMEWr2eIWCWvYDdjiSL9RnkjMaSbehT5Uu2gq0uADk1rptNvDU9TEAtZL/yNh14PXelBEv9TxuDsSRyX+NT2ZwnmwURz8236d/oVJmx1eFz6d3n/hYGsZI6P9TTAg6KM2U8+svDtH0WwXaO9uEVluiatGnGi0qCMI8xZkJeUkuNc+li0Xo2DG2Arlds6GTGdRg+aXHw3n3YcJg02vu37Jnl0QsBNFIYz71zpVj/hTeUtaa236SkLynIPwR
  • 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>
---
 lib/uksched/exportsyms.uk      |  1 +
 lib/uksched/include/uk/sched.h |  2 ++
 lib/uksched/sched.c            | 18 ++++++++++++++++++
 lib/ukschedcoop/schedcoop.c    | 27 ++++-----------------------
 4 files changed, 25 insertions(+), 23 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 07e7aef..8276e15 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_printd(DLVL_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 dd22209..d78ca54 100644
--- a/lib/ukschedcoop/schedcoop.c
+++ b/lib/ukschedcoop/schedcoop.c
@@ -194,27 +194,16 @@ struct uk_sched *uk_schedcoop_init(struct uk_alloc *a)
 
        uk_printd(DLVL_INFO, "Initializing cooperative scheduler\n");
 
-       sched = uk_malloc(a, sizeof(struct uk_sched));
-       if (sched == NULL) {
-               uk_printd(DLVL_WARN, "Could not allocate memory for 
scheduler.");
-               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_printd(DLVL_WARN,
-                               "Could not allocate memory for scheduler 
private data.");
-               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);
 
@@ -224,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®.