]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/uksched: Interface for returning idle thread
authorSimon Kuenzer <simon@unikraft.io>
Mon, 22 May 2023 16:02:50 +0000 (18:02 +0200)
committerUnikraft <monkey@unikraft.io>
Wed, 9 Aug 2023 12:06:28 +0000 (12:06 +0000)
With the intention for accessing metrics (like thread execution time), this
commit introduces an interface to return a reference to the idle thread.

Signed-off-by: Simon Kuenzer <simon@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #965

lib/uksched/include/uk/sched.h
lib/uksched/include/uk/sched_impl.h
lib/ukschedcoop/schedcoop.c

index d2aaa542aa81b5d0dcd5b490bd7bde1ecef190d1..7d1a05c69b5c34b0492e696e9baf653e1c33a6db 100644 (file)
@@ -72,6 +72,9 @@ typedef void  (*uk_sched_thread_blocked_func_t)
 typedef void  (*uk_sched_thread_woken_func_t)
                (struct uk_sched *s, struct uk_thread *t);
 
+typedef const struct uk_thread * (*uk_sched_idle_thread_func_t)
+               (struct uk_sched *s, unsigned int proc_id);
+
 typedef int   (*uk_sched_start_t)(struct uk_sched *s, struct uk_thread *main);
 
 struct uk_sched {
@@ -81,6 +84,7 @@ struct uk_sched {
        uk_sched_thread_remove_func_t   thread_remove;
        uk_sched_thread_blocked_func_t  thread_blocked;
        uk_sched_thread_woken_func_t    thread_woken;
+       uk_sched_idle_thread_func_t     idle_thread;
 
        uk_sched_start_t sched_start;
 
@@ -136,6 +140,25 @@ static inline void uk_sched_thread_woken(struct uk_thread *t)
        s->thread_woken(s, t);
 }
 
+/**
+ * Returns the reference to the idle thread that is responsible for
+ * the processing unit `proc_id`. Please note that `proc_id` is not
+ * a logical core ID; it is a linear increasing number over the managed
+ * logical cores by the scheduler instance `s`.
+ * It is possible that a scheduler implementation does not operate with idle
+ * threads and returns `NULL`.
+ */
+static inline const struct uk_thread *uk_sched_idle_thread(struct uk_sched *s,
+                                                          unsigned int proc_id)
+{
+       UK_ASSERT(s);
+
+       if (unlikely(!s->idle_thread))
+               return NULL;
+
+       return s->idle_thread(s, proc_id);
+}
+
 /**
  * Create a main thread from current context and call thread starter function
  */
index bf09b90a3fa91c270a61d5ab644d158ee9762c1d..613f585f12935027cd0421ca2fb4aa9220983b42 100644 (file)
@@ -55,7 +55,7 @@ int uk_sched_register(struct uk_sched *s);
 #define uk_sched_init(s, start_func, yield_func, \
                thread_add_func, thread_remove_func, \
                thread_blocked_func, thread_woken_func, \
-               def_allocator) \
+               idle_thread_func, def_allocator) \
        do { \
                (s)->sched_start     = start_func; \
                (s)->yield           = yield_func; \
@@ -63,6 +63,7 @@ int uk_sched_register(struct uk_sched *s);
                (s)->thread_remove   = thread_remove_func; \
                (s)->thread_blocked  = thread_blocked_func; \
                (s)->thread_woken    = thread_woken_func; \
+               (s)->idle_thread     = idle_thread_func; \
                uk_sched_register((s)); \
                \
                (s)->a = (def_allocator); \
index 56d94881ee82e36e63d192da3f90ba08f7702da4..afa37c3d561148c00bbb8174e6373ed4b090e88a 100644 (file)
@@ -307,6 +307,7 @@ struct uk_sched *uk_schedcoop_create(struct uk_alloc *a)
                        schedcoop_thread_remove,
                        schedcoop_thread_blocked,
                        schedcoop_thread_woken,
+                       NULL,
                        a);
 
        /* Add idle thread to the scheduler's thread list */