]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/uksched/*: Use per-lcpu variable for current thread
authorAndra Paraschiv <andra@unikraft.io>
Thu, 2 Mar 2023 14:19:06 +0000 (14:19 +0000)
committerUnikraft <monkey@unikraft.io>
Fri, 28 Apr 2023 11:58:17 +0000 (11:58 +0000)
Currently there is a global variable that keeps track of the current
thread that is used by the scheduler logic.

Use a per-lcpu variable instead, to also match the case when multiple
cores are used for the unikernel setup.

Signed-off-by: Andra Paraschiv <andra@unikraft.io>
Reviewed-by: Razvan Virtan <virtanrazvan@gmail.com>
Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #784

lib/uksched/include/uk/sched_impl.h
lib/uksched/include/uk/thread.h
lib/uksched/sched.c

index d01b600ec9f30fddaa3fe6d8f6c32d8d255f381f..bf09b90a3fa91c270a61d5ab644d158ee9762c1d 100644 (file)
@@ -84,11 +84,14 @@ unsigned int uk_sched_thread_gc(struct uk_sched *sched);
 static inline
 void uk_sched_thread_switch(struct uk_thread *next)
 {
-       struct uk_thread *prev = __uk_sched_thread_current;
+       struct uk_thread *prev;
+
+       prev = ukplat_per_lcpu_current(__uk_sched_thread_current);
 
        UK_ASSERT(prev);
 
-       __uk_sched_thread_current = next;
+       ukplat_per_lcpu_current(__uk_sched_thread_current) = next;
+
        prev->tlsp = ukplat_tlsp_get();
        if (prev->ectx)
                ukarch_ectx_store(prev->ectx);
index 52ff52fd8bee098d81b6b1812250b1a38310c8a8..6579a4a4c5b1242790c2a1fad44599666e562162 100644 (file)
@@ -34,6 +34,7 @@
 #include <uk/arch/lcpu.h>
 #include <uk/arch/time.h>
 #include <uk/arch/ctx.h>
+#include <uk/plat/lcpu.h>
 #include <uk/plat/tls.h>
 #include <uk/wait_types.h>
 #include <uk/list.h>
@@ -89,12 +90,12 @@ UK_TAILQ_HEAD(uk_thread_list, struct uk_thread);
        uk_sched_thread_exit()
 
 /* managed by sched.c */
-extern struct uk_thread *__uk_sched_thread_current;
+extern UKPLAT_PER_LCPU_DEFINE(struct uk_thread *, __uk_sched_thread_current);
 
 static inline
 struct uk_thread *uk_thread_current(void)
 {
-       return __uk_sched_thread_current;
+       return ukplat_per_lcpu_current(__uk_sched_thread_current);
 }
 
 /*
index 7ac275997d687f08732df2845008b21bbdd52a57..4edb22f1c1331ebcb5cf13175191d69799d7bb01 100644 (file)
@@ -43,8 +43,7 @@
 
 struct uk_sched *uk_sched_head;
 
-/* FIXME: Define per CPU (CPU-local variable declaration needed) */
-struct uk_thread *__uk_sched_thread_current;
+UKPLAT_PER_LCPU_DEFINE(struct uk_thread *, __uk_sched_thread_current);
 
 int uk_sched_register(struct uk_sched *s)
 {
@@ -220,7 +219,7 @@ int uk_sched_start(struct uk_sched *s)
        uk_thread_set_runnable(main_thread);
 
        /* Set main_thread as current scheduled thread */
-       __uk_sched_thread_current = main_thread;
+       ukplat_per_lcpu_current(__uk_sched_thread_current) = main_thread;
 
        /* Add main to the scheduler's thread list */
        UK_TAILQ_INSERT_TAIL(&s->thread_list, main_thread, thread_list);
@@ -235,7 +234,7 @@ int uk_sched_start(struct uk_sched *s)
        return 0;
 
 err_unset_thread_current:
-       __uk_sched_thread_current = NULL;
+       ukplat_per_lcpu_current(__uk_sched_thread_current) = NULL;
        uk_thread_release(main_thread);
 err_out:
        return ret;