diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h index 1bdc3aaf..017f782d 100644 --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -187,8 +187,6 @@ typedef struct { } dest; } __attribute__ ((packed)) ioapic_route_t; -#define smp_id apic_cpu_id - int apic_init(void); void apic_eoi(void); uint32_t apic_cpu_id(void); diff --git a/arch/x86/include/asm/stddef.h b/arch/x86/include/asm/stddef.h index 0d6a6f33..f3ef4468 100644 --- a/arch/x86/include/asm/stddef.h +++ b/arch/x86/include/asm/stddef.h @@ -99,6 +99,10 @@ struct state { unsigned int ss; }; +uint32_t apic_cpu_id(void); + +#define smp_id apic_cpu_id + #ifdef __cplusplus } #endif diff --git a/include/metalsvm/stddef.h b/include/metalsvm/stddef.h index 5fade774..fef0fc07 100644 --- a/include/metalsvm/stddef.h +++ b/include/metalsvm/stddef.h @@ -22,6 +22,7 @@ #include #include +#include #ifdef __cplusplus extern "C" { @@ -37,10 +38,17 @@ typedef unsigned int tid_t; #define DEFINE_PER_CORE(type, name, def_value) type name = def_value; #define CORE_ID 0 #else -#define per_core(name) name[smp_id()].var +#define per_core(name) __get_percore_##name() #define DECLARE_PER_CORE(type, name) \ typedef struct { type var __attribute__ ((aligned (CACHE_LINE))); } aligned_##name;\ - extern aligned_##name name[MAX_CORES]; + extern aligned_##name name[MAX_CORES];\ + inline static type __get_percore_##name(void) {\ + type ret; \ + uint32_t flags = irq_nested_disable(); \ + ret = name[smp_id()].var; \ + irq_nested_enable(flags);\ + return ret; \ + } #define DEFINE_PER_CORE(type, name, def_value) \ aligned_##name name[MAX_CORES] = {[0 ... MAX_CORES-1] = {def_value}}; #define CORE_ID smp_id() diff --git a/kernel/tasks.c b/kernel/tasks.c index dc0e60e4..96f47ad8 100644 --- a/kernel/tasks.c +++ b/kernel/tasks.c @@ -68,7 +68,7 @@ int multitasking_init(void) { memset(task_table[0].outbox, 0x00, sizeof(mailbox_wait_msg_t*)*MAX_TASKS); task_table[0].pgd = get_boot_pgd(); task_table[0].flags = TASK_DEFAULT_FLAGS; - per_core(current_task) = task_table+0; + current_task[0].var = task_table+0; return 0; } @@ -763,7 +763,7 @@ void scheduler(void) if (curr_task->status == TASK_RUNNING) curr_task->status = TASK_READY; task_table[new_id].status = TASK_RUNNING; - per_core(current_task) = task_table+new_id; + current_task[CORE_ID].var = task_table+new_id; goto get_task_out; } @@ -776,7 +776,7 @@ void scheduler(void) * we switch to the idle task, if the current task terminates * and no other is ready */ - per_core(current_task) = task_table+smp_id(); + current_task[CORE_ID].var = task_table+CORE_ID; get_task_out: //kprintf("schedule %d on core %d\n", per_core(current_task)->id, smp_id());