From d13e3a4432b8656c7c3cbb8da883885baa591bcd Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 9 Nov 2015 23:54:03 +0100 Subject: [PATCH] add helper function to determine the next free core - we start with the second core, because the first is used by the LwIP thread --- hermit/arch/x86/kernel/tasks.c | 4 +++- hermit/include/hermit/tasks.h | 4 ++++ hermit/kernel/tasks.c | 34 +++++++++++++++++++++------------- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/hermit/arch/x86/kernel/tasks.c b/hermit/arch/x86/kernel/tasks.c index 0b967e21c..a013be00d 100644 --- a/hermit/arch/x86/kernel/tasks.c +++ b/hermit/arch/x86/kernel/tasks.c @@ -619,9 +619,11 @@ int create_user_task_form_socket(tid_t* id, int sd, uint8_t prio) int len, total_len, i, j; load_args_t* load_args = NULL; char *dest; - uint32_t core_id = CORE_ID; + uint32_t core_id; uint32_t counter = 0; + core_id = get_next_core_id(); + ret = read(sd, &argc, sizeof(int)); if ((ret != sizeof(int)) || (argc <= 0)) goto out; diff --git a/hermit/include/hermit/tasks.h b/hermit/include/hermit/tasks.h index 492298f7d..7e094643e 100644 --- a/hermit/include/hermit/tasks.h +++ b/hermit/include/hermit/tasks.h @@ -206,6 +206,10 @@ int wakeup_task(tid_t); */ int block_current_task(void); +/** @brief Get next core_id for a new task + */ +uint32_t get_next_core_id(void); + /** @brief Block current task until timer expires * * @param deadline Clock tick, when the timer expires diff --git a/hermit/kernel/tasks.c b/hermit/kernel/tasks.c index 03dd4efbe..795d4564c 100644 --- a/hermit/kernel/tasks.c +++ b/hermit/kernel/tasks.c @@ -261,13 +261,32 @@ void NORETURN abort(void) { do_exit(-1); } +uint32_t get_next_core_id(void) +{ + uint32_t i; + static uint32_t core_id = MAX_CORES; + + if (core_id >= MAX_CORES) + core_id = CORE_ID; + + + // we assume OpenMP applications + // => number of threads is (normaly) equal to the number of cores + // => search next available core + for(i=0, core_id=(core_id+1)%MAX_CORES; i MAX_PRIO, 0)) return -EINVAL; - if (BUILTIN_EXPECT(!readyqueues[core_id].idle, 0)) - return -EINVAL; if (BUILTIN_EXPECT((size_t)ep < KERNEL_SPACE, 0)) return -EINVAL; @@ -288,16 +305,7 @@ int clone_task(tid_t* id, entry_point_t ep, void* arg, uint8_t prio) spinlock_irqsave_lock(&table_lock); - if (core_id >= MAX_CORES) - core_id = CORE_ID; - - // we assume OpenMP applications - // => number of threads is (normaly) equal to the number of cores - // => search next available core - for(i=0, core_id=(core_id+1)%MAX_CORES; i= MAX_CORES) || !readyqueues[core_id].idle) core_id = CORE_ID;