[01/60] xen/sched: only allow schedulers with all mandatory functions available
diff mbox series

Message ID 20190528103313.1343-2-jgross@suse.com
State New, archived
Headers show
Series
  • xen: add core scheduling support
Related show

Commit Message

Juergen Gross May 28, 2019, 10:32 a.m. UTC
Some functions of struct scheduler are mandatory. Test those in the
scheduler initialization loop to be present and drop schedulers not
complying.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
V1: new patch
---
 xen/common/schedule.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

Comments

Dario Faggioli June 11, 2019, 4:03 p.m. UTC | #1
On Tue, 2019-05-28 at 12:32 +0200, Juergen Gross wrote:
> Some functions of struct scheduler are mandatory. Test those in the
> scheduler initialization loop to be present and drop schedulers not
> complying.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>
>
As discussed in the other thread already, I personally do like this
(and things like to this) quite a bit... Thanks for doing it!

Reviewed-by: Dario Faggioli <dfaggioli@suse.com>

Regards

Patch
diff mbox series

diff --git a/xen/common/schedule.c b/xen/common/schedule.c
index 66f1e2611b..72d8be3906 100644
--- a/xen/common/schedule.c
+++ b/xen/common/schedule.c
@@ -1726,9 +1726,33 @@  void __init scheduler_init(void)
 
     for ( i = 0; i < NUM_SCHEDULERS; i++)
     {
+#define sched_test_func(f)                               \
+        if ( !schedulers[i]->f )                         \
+        {                                                \
+            printk("scheduler %s misses .%s, dropped\n", \
+                   schedulers[i]->opt_name, #f);         \
+            schedulers[i] = NULL;                        \
+        }
+
+        sched_test_func(init);
+        sched_test_func(deinit);
+        sched_test_func(pick_cpu);
+        sched_test_func(alloc_vdata);
+        sched_test_func(free_vdata);
+        sched_test_func(switch_sched);
+        sched_test_func(do_schedule);
+
+#undef sched_test_func
+
         if ( schedulers[i]->global_init && schedulers[i]->global_init() < 0 )
+        {
+            printk("scheduler %s failed initialization, dropped\n",
+                   schedulers[i]->opt_name);
             schedulers[i] = NULL;
-        else if ( !ops.name && !strcmp(schedulers[i]->opt_name, opt_sched) )
+        }
+
+        if ( schedulers[i] && !ops.name &&
+             !strcmp(schedulers[i]->opt_name, opt_sched) )
             ops = *schedulers[i];
     }