diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h index 91f30387..da3b3556 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -42,9 +42,9 @@ extern "C" { // feature list 1 #define CPU_FEATURE_FPU (1 << 0) #define CPU_FEATURE_MMX (1 << 23) -#define CPU_FEATURE_FXSR (1 << 24) +#define CPU_FEATURE_FXSR (1 << 24) #define CPU_FEATURE_SSE (1 << 25) -#define CPU_FEATURE_SSE2 (1 << 26) +#define CPU_FEATURE_SSE2 (1 << 26) // feature list 2 #define CPU_FEATURE_AVX (1 << 28) diff --git a/arch/x86/include/asm/tasks.h b/arch/x86/include/asm/tasks.h index c12f946a..d2cf6731 100644 --- a/arch/x86/include/asm/tasks.h +++ b/arch/x86/include/asm/tasks.h @@ -36,6 +36,11 @@ extern "C" { #endif +/** + * @brief Dump some scheduling statistics + */ +int dump_scheduling_statistics(void); + /** @brief Fork a task from current task * * @param task Pointer to the task structure to fork to diff --git a/arch/x86/kernel/apic.c b/arch/x86/kernel/apic.c index 29033d0e..0651750e 100644 --- a/arch/x86/kernel/apic.c +++ b/arch/x86/kernel/apic.c @@ -301,9 +301,6 @@ void smp_start(uint32_t id) // install IDT idt_install(); - // enable additional cpu features - cpu_detection(); - /* enable paging */ write_cr3((uint32_t)get_boot_pgd()); i = read_cr0(); @@ -320,6 +317,9 @@ void smp_start(uint32_t id) */ register_task(per_core(current_task)); + // enable additional cpu features + cpu_detection(); + smp_main(); // idle loop diff --git a/include/metalsvm/tasks_types.h b/include/metalsvm/tasks_types.h index 9725454b..f63ae533 100644 --- a/include/metalsvm/tasks_types.h +++ b/include/metalsvm/tasks_types.h @@ -41,11 +41,11 @@ extern "C" { #endif #define TASK_INVALID 0 -#define TASK_READY 1 +#define TASK_READY 1 #define TASK_RUNNING 2 #define TASK_BLOCKED 3 #define TASK_FINISHED 4 -#define TASK_IDLE 5 +#define TASK_IDLE 5 #define TASK_DEFAULT_FLAGS 0 #define TASK_FPU_INIT (1 << 0) @@ -61,8 +61,10 @@ typedef struct task { tid_t id; /// Task status (INVALID, READY, RUNNING, ...) uint32_t status; + /// Number of used time slices + uint32_t time_slices; /// Usage in number of pages - atomic_int32_t user_usage; + atomic_int32_t user_usage; /// Avoids concurrent access to the page directory spinlock_t pgd_lock; /// pointer to the page directory @@ -85,7 +87,7 @@ typedef struct task { mailbox_wait_msg_t* outbox[MAX_TASKS]; /// FPU state union fpu_state fpu; -} __attribute__((packed)) task_t; +} task_t; #ifdef __cplusplus } diff --git a/kernel/main.c b/kernel/main.c index 86646610..8b54795f 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -128,6 +128,7 @@ int main(void) list_root(); test_init(); per_core(current_task)->status = TASK_IDLE; + per_core(current_task)->time_slices = 0; // reset the number of time slices reschedule(); while(1) { diff --git a/kernel/tasks.c b/kernel/tasks.c index 00e23098..95c4c1ed 100644 --- a/kernel/tasks.c +++ b/kernel/tasks.c @@ -47,8 +47,8 @@ * A task's id will be its position in this array. */ static task_t task_table[MAX_TASKS] = { \ - [0] = {0, TASK_RUNNING, ATOMIC_INIT(0), SPINLOCK_INIT, NULL, SPINLOCK_INIT, NULL, 0, 0, 0, 0}, \ - [1 ... MAX_TASKS-1] = {0, TASK_INVALID, ATOMIC_INIT(0), SPINLOCK_INIT, NULL, SPINLOCK_INIT, NULL, 0, 0, 0, 0}}; + [0] = {0, TASK_RUNNING, 0, ATOMIC_INIT(0), SPINLOCK_INIT, NULL, SPINLOCK_INIT, NULL, 0, 0, 0, 0}, \ + [1 ... MAX_TASKS-1] = {0, TASK_INVALID, 0, ATOMIC_INIT(0), SPINLOCK_INIT, NULL, SPINLOCK_INIT, NULL, 0, 0, 0, 0}}; static spinlock_irqsave_t table_lock = SPINLOCK_IRQSAVE_INIT; DEFINE_PER_CORE(task_t*, current_task, task_table+0); @@ -63,6 +63,24 @@ task_t* get_current_task(void) { return per_core(current_task); } +int dump_scheduling_statistics(void) +{ + uint32_t i; + uint32_t id = 0; + + kprintf("Scheduling statistics:\n"); + kprintf("======================\n"); + kprintf("total ticks:\t%llu\n", get_clock_tick()); + for(i=0; itime_slices++; + /* signalizes that this task could be reused */ if (curr_task->status == TASK_FINISHED) curr_task->status = TASK_INVALID; diff --git a/kernel/tests.c b/kernel/tests.c index ecef70c2..bced389b 100644 --- a/kernel/tests.c +++ b/kernel/tests.c @@ -121,6 +121,8 @@ static int join_test(void* arg) kprintf("Child %u finished: result = %d\n", id, result); + dump_scheduling_statistics(); + return 0; }