From 6d7e2912332e6f40dda0724eff35d99ecdcc8371 Mon Sep 17 00:00:00 2001 From: Pawel Dziepak Date: Sat, 5 Oct 2013 20:45:07 +0200 Subject: [PATCH] kernel: Allow scheduler initialization to fail --- src/system/kernel/scheduler/scheduler.cpp | 10 +++++++--- src/system/kernel/scheduler/scheduler_affine.cpp | 4 +++- src/system/kernel/scheduler/scheduler_affine.h | 2 +- src/system/kernel/scheduler/scheduler_simple.cpp | 12 +++++++++++- src/system/kernel/scheduler/scheduler_simple.h | 2 +- src/system/kernel/scheduler/scheduler_simple_smp.cpp | 4 +++- src/system/kernel/scheduler/scheduler_simple_smp.h | 2 +- 7 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/system/kernel/scheduler/scheduler.cpp b/src/system/kernel/scheduler/scheduler.cpp index e4848d1d48..a8ed35a985 100644 --- a/src/system/kernel/scheduler/scheduler.cpp +++ b/src/system/kernel/scheduler/scheduler.cpp @@ -67,19 +67,23 @@ scheduler_init(void) dprintf("scheduler_init: found %" B_PRId32 " logical cpu%s\n", cpuCount, cpuCount != 1 ? "s" : ""); + status_t result; if (cpuCount > 1) { #if 0 dprintf("scheduler_init: using affine scheduler\n"); - scheduler_affine_init(); + result = scheduler_affine_init(); #else dprintf("scheduler_init: using simple SMP scheduler\n"); - scheduler_simple_smp_init(); + result = scheduler_simple_smp_init(); #endif } else { dprintf("scheduler_init: using simple scheduler\n"); - scheduler_simple_init(); + result = scheduler_simple_init(); } + if (result != B_OK) + panic("scheduler_init: failed to initialize scheduler\n"); + // Disable rescheduling until the basic kernel initialization is done and // CPUs are ready to enable interrupts. sRescheduleFunction = gScheduler->reschedule; diff --git a/src/system/kernel/scheduler/scheduler_affine.cpp b/src/system/kernel/scheduler/scheduler_affine.cpp index c2a5c0c31d..078980ebf4 100644 --- a/src/system/kernel/scheduler/scheduler_affine.cpp +++ b/src/system/kernel/scheduler/scheduler_affine.cpp @@ -556,7 +556,7 @@ static scheduler_ops kAffineOps = { // #pragma mark - -void +status_t scheduler_affine_init() { gScheduler = &kAffineOps; @@ -564,4 +564,6 @@ scheduler_affine_init() memset(sRunQueueSize, 0, sizeof(sRunQueueSize)); add_debugger_command_etc("run_queue", &dump_run_queue, "List threads in run queue", "\nLists threads in run queue", 0); + + return B_OK; } diff --git a/src/system/kernel/scheduler/scheduler_affine.h b/src/system/kernel/scheduler/scheduler_affine.h index 1762fe37a7..3c52cd06fe 100644 --- a/src/system/kernel/scheduler/scheduler_affine.h +++ b/src/system/kernel/scheduler/scheduler_affine.h @@ -7,7 +7,7 @@ #define KERNEL_SCHEDULER_AFFINE_H -void scheduler_affine_init(); +status_t scheduler_affine_init(); #endif // KERNEL_SCHEDULER_AFFINE_H diff --git a/src/system/kernel/scheduler/scheduler_simple.cpp b/src/system/kernel/scheduler/scheduler_simple.cpp index 399e65f173..606a1f936a 100644 --- a/src/system/kernel/scheduler/scheduler_simple.cpp +++ b/src/system/kernel/scheduler/scheduler_simple.cpp @@ -328,13 +328,23 @@ static scheduler_ops kSimpleOps = { // #pragma mark - -void +status_t scheduler_simple_init() { sRunQueue = new(std::nothrow) RunQueue; + if (sRunQueue == NULL) + return B_NO_MEMORY; + + status_t result = sRunQueue->GetInitStatus(); + if (result != B_OK) { + delete sRunQueue; + return result; + } gScheduler = &kSimpleOps; add_debugger_command_etc("run_queue", &dump_run_queue, "List threads in run queue", "\nLists threads in run queue", 0); + + return B_OK; } diff --git a/src/system/kernel/scheduler/scheduler_simple.h b/src/system/kernel/scheduler/scheduler_simple.h index bac69ac78c..aba7f5afbd 100644 --- a/src/system/kernel/scheduler/scheduler_simple.h +++ b/src/system/kernel/scheduler/scheduler_simple.h @@ -6,7 +6,7 @@ #define KERNEL_SCHEDULER_SIMPLE_H -void scheduler_simple_init(); +status_t scheduler_simple_init(); #endif // KERNEL_SCHEDULER_SIMPLE_H diff --git a/src/system/kernel/scheduler/scheduler_simple_smp.cpp b/src/system/kernel/scheduler/scheduler_simple_smp.cpp index c4d1e8a2df..1a4a564353 100644 --- a/src/system/kernel/scheduler/scheduler_simple_smp.cpp +++ b/src/system/kernel/scheduler/scheduler_simple_smp.cpp @@ -471,7 +471,7 @@ static scheduler_ops kSimpleSMPOps = { // #pragma mark - -void +status_t scheduler_simple_smp_init() { sCPUCount = smp_get_num_cpus(); @@ -480,4 +480,6 @@ scheduler_simple_smp_init() add_debugger_command_etc("run_queue", &dump_run_queue, "List threads in run queue", "\nLists threads in run queue", 0); + + return B_OK; } diff --git a/src/system/kernel/scheduler/scheduler_simple_smp.h b/src/system/kernel/scheduler/scheduler_simple_smp.h index 67b482494c..d59a02841f 100644 --- a/src/system/kernel/scheduler/scheduler_simple_smp.h +++ b/src/system/kernel/scheduler/scheduler_simple_smp.h @@ -6,7 +6,7 @@ #define KERNEL_SCHEDULER_SIMPLE_SMP_H -void scheduler_simple_smp_init(); +status_t scheduler_simple_smp_init(); #endif // KERNEL_SCHEDULER_SIMPLE_SMP_H