cosmetic changes and add some scheduling statistics

This commit is contained in:
Stefan Lankes 2011-08-03 19:37:05 +02:00
parent 22dab59699
commit 452aa3b1d1
7 changed files with 44 additions and 11 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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; i<MAX_CORES; i++) {
if (task_table[i].status == TASK_IDLE) {
kprintf("core %d :\t%u idle slices\n", id, task_table[i].time_slices);
id++;
}
}
return 0;
}
int multitasking_init(void) {
if (BUILTIN_EXPECT(task_table[0].status == TASK_RUNNING, 1)) {
mailbox_wait_msg_init(&task_table[0].inbox);
@ -82,6 +100,7 @@ size_t get_idle_task(uint32_t id)
return -EINVAL;
task_table[id].id = id;
task_table[id].time_slices = 0;
task_table[id].status = TASK_IDLE;
atomic_int32_set(&task_table[id].user_usage, 0);
mailbox_wait_msg_init(&task_table[id].inbox);
@ -217,6 +236,7 @@ static int create_task(tid_t* id, internal_entry_point_t ep, void* arg)
}
task_table[i].id = i;
task_table[i].time_slices = 0;
spinlock_init(&task_table[i].vma_lock);
task_table[i].vma_list = NULL;
mailbox_wait_msg_init(&task_table[i].inbox);
@ -816,6 +836,9 @@ void scheduler(void)
orig_task = curr_task = per_core(current_task);
/* increase the number of used time slices */
curr_task->time_slices++;
/* signalizes that this task could be reused */
if (curr_task->status == TASK_FINISHED)
curr_task->status = TASK_INVALID;

View file

@ -121,6 +121,8 @@ static int join_test(void* arg)
kprintf("Child %u finished: result = %d\n", id, result);
dump_scheduling_statistics();
return 0;
}