From 435b8dd2528f597e28b4ab99f57f7f81ae52a92b Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Wed, 24 Jul 2013 09:48:54 +0200 Subject: [PATCH] foc: determine number of CPUs Issue #814 Fixes #578 --- base-foc/src/core/include/platform.h | 1 + base-foc/src/core/platform.cc | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/base-foc/src/core/include/platform.h b/base-foc/src/core/include/platform.h index 9b9eab64a..b62ecf4d7 100644 --- a/base-foc/src/core/include/platform.h +++ b/base-foc/src/core/include/platform.h @@ -159,6 +159,7 @@ namespace Genode { addr_t vm_start() const { return _vm_start; } size_t vm_size() const { return _vm_size; } Rom_fs *rom_fs() { return &_rom_fs; } + unsigned num_cpus() const; void wait_for_exit(); }; diff --git a/base-foc/src/core/platform.cc b/base-foc/src/core/platform.cc index b8120ffeb..1522f5660 100644 --- a/base-foc/src/core/platform.cc +++ b/base-foc/src/core/platform.cc @@ -35,6 +35,7 @@ namespace Fiasco { #include #include #include +#include static l4_kernel_info_t *kip; } @@ -511,4 +512,27 @@ void Platform::wait_for_exit() } +unsigned Platform::num_cpus() const { + + using namespace Genode; + using namespace Fiasco; + + l4_sched_cpu_set_t cpus = l4_sched_cpu_set(0, 0, 1); + l4_umword_t cpus_max; + l4_msgtag_t res = l4_scheduler_info(L4_BASE_SCHEDULER_CAP, &cpus_max, + &cpus); + if (l4_error(res)) { + PERR("could not detect number of CPUs - assuming 1 CPU"); + return 1; + } + + unsigned cpus_online = 0; + for (unsigned i = 0; i < sizeof(cpus.map) * 8; i++) + if ((cpus.map >> i) & 0x1) + cpus_online ++; + + return cpus_online; +} + + void Core_parent::exit(int exit_value) { }