1
0
Fork 0
mirror of https://github.com/hermitcore/libhermit.git synced 2025-03-09 00:00:03 +01:00

add helper function to determine the next free core

- we start with the second core, because the first is used by the LwIP thread
This commit is contained in:
Stefan Lankes 2015-11-09 23:54:03 +01:00
parent 373dd9f9d4
commit d13e3a4432
3 changed files with 28 additions and 14 deletions

View file

@ -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;

View file

@ -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

View file

@ -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_CORES; i++, core_id=(core_id+1)%MAX_CORES)
if (readyqueues[core_id].idle)
break;
return core_id;
}
int clone_task(tid_t* id, entry_point_t ep, void* arg, uint8_t prio)
{
int ret = -EINVAL;
uint32_t i;
void* stack = NULL;
task_t* curr_task;
static uint32_t core_id = MAX_CORES;
uint32_t core_id;
if (BUILTIN_EXPECT(!ep, 0))
return -EINVAL;
@ -275,8 +294,6 @@ int clone_task(tid_t* id, entry_point_t ep, void* arg, uint8_t prio)
return -EINVAL;
if (BUILTIN_EXPECT(prio > 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; i++, core_id=(core_id+1)%MAX_CORES)
if (readyqueues[core_id].idle)
break;
core_id = get_next_core_id();
if ((core_id >= MAX_CORES) || !readyqueues[core_id].idle)
core_id = CORE_ID;