aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ens.fr>2014-12-13 13:05:10 +0100
committerAlex Auvolat <alex.auvolat@ens.fr>2014-12-13 13:05:10 +0100
commitd24b3806edddbfff587f1cf91a64338e0fadd48f (patch)
tree268a066d80390e9bf5e1cefbae95b81dc696eaf2
parentfa495da049037c356b8bb4a3a29416aeb335887c (diff)
downloadmacroscope-d24b3806edddbfff587f1cf91a64338e0fadd48f.tar.gz
macroscope-d24b3806edddbfff587f1cf91a64338e0fadd48f.zip
Terminology change : task -> thread.
-rw-r--r--kernel/Makefile2
-rw-r--r--kernel/include/thread.h (renamed from kernel/include/task.h)14
-rw-r--r--kernel/l0/kmain.c12
-rw-r--r--kernel/l0/paging.c12
-rw-r--r--kernel/l0/thread.c (renamed from kernel/l0/task.c)100
5 files changed, 70 insertions, 70 deletions
diff --git a/kernel/Makefile b/kernel/Makefile
index 0088085..5571543 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -11,7 +11,7 @@ LDFLAGS = -T linker.ld -ffreestanding -O2 -nostdlib -lgcc -Xlinker -Map=kernel.m
OBJ = lib/string.o lib/printf.o lib/slab_alloc.o lib/mutex.o \
l0/loader.o l0/kmain.o l0/dbglog.o l0/sys.o \
- l0/gdt.o l0/idt.o l0/interrupt.o l0/context_switch.o l0/task.o \
+ l0/gdt.o l0/idt.o l0/interrupt.o l0/context_switch.o l0/thread.o \
l0/frame.o l0/paging.o l0/region.o l0/kmalloc.o
OUT = kernel.bin
diff --git a/kernel/include/task.h b/kernel/include/thread.h
index 0faa8b3..03277a2 100644
--- a/kernel/include/task.h
+++ b/kernel/include/thread.h
@@ -17,7 +17,7 @@ typedef struct saved_context {
void (*eip)();
} saved_context_t;
-typedef struct task {
+typedef struct thread {
saved_context_t ctx;
pagedir_t *current_pd_d;
@@ -29,19 +29,19 @@ typedef struct task {
void* more_data;
- struct task *next_in_queue;
-} task_t;
+ struct thread *next_in_queue;
+} thread_t;
typedef void (*entry_t)(void*);
-void tasking_setup(entry_t cont, void* data); // never returns
-task_t *new_task(entry_t entry); // task is PAUSED, and must be resume_task_with_result'ed
+void threading_setup(entry_t cont, void* data); // never returns
+thread_t *new_thread(entry_t entry); // thread is PAUSED, and must be resume_thread_with_result'ed
-extern task_t *current_task;
+extern thread_t *current_thread;
void yield();
void* wait_for_result();
-void resume_task_with_result(task_t *task, void* data, bool run_at_once);
+void resume_thread_with_result(thread_t *thread, void* data, bool run_at_once);
/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/kernel/l0/kmain.c b/kernel/l0/kmain.c
index 2ce3749..416b802 100644
--- a/kernel/l0/kmain.c
+++ b/kernel/l0/kmain.c
@@ -10,7 +10,7 @@
#include <region.h>
#include <kmalloc.h>
-#include <task.h>
+#include <thread.h>
#include <slab_alloc.h>
@@ -100,7 +100,7 @@ void kmalloc_test(void* kernel_data_end) {
dbg_print_region_info();
}
-void test_task(void* a) {
+void test_thread(void* a) {
int i = 0;
while(1) {
dbg_printf("b");
@@ -112,8 +112,8 @@ void test_task(void* a) {
}
}
void kernel_init_stage2(void* data) {
- task_t *tb = new_task(test_task);
- resume_task_with_result(tb, 0, false);
+ thread_t *tb = new_thread(test_thread);
+ resume_thread_with_result(tb, 0, false);
dbg_print_region_info();
dbg_print_frame_stats();
@@ -163,10 +163,10 @@ void kmain(struct multiboot_info_t *mbd, int32_t mb_magic) {
kmalloc_setup();
kmalloc_test(kernel_data_end);
- // enter multi-tasking mode
+ // enter multi-threading mode
// interrupts are enabled at this moment, so all
// code run from now on should be preemtible (ie thread-safe)
- tasking_setup(kernel_init_stage2, 0);
+ threading_setup(kernel_init_stage2, 0);
PANIC("Should never come here.");
}
diff --git a/kernel/l0/paging.c b/kernel/l0/paging.c
index b8fd454..683abe6 100644
--- a/kernel/l0/paging.c
+++ b/kernel/l0/paging.c
@@ -4,7 +4,7 @@
#include <dbglog.h>
#include <region.h>
#include <mutex.h>
-#include <task.h>
+#include <thread.h>
#include <kmalloc.h>
#define PAGE_OF_ADDR(x) (((size_t)x >> PAGE_SHIFT) % N_PAGES_IN_PT)
@@ -143,8 +143,8 @@ void paging_setup(void* kernel_data_end) {
}
pagedir_t *get_current_pagedir() {
- if (current_task == 0) return &kernel_pd_d;
- return current_task->current_pd_d;
+ if (current_thread == 0) return &kernel_pd_d;
+ return current_thread->current_pd_d;
}
pagedir_t *get_kernel_pagedir() {
@@ -153,7 +153,7 @@ pagedir_t *get_kernel_pagedir() {
void switch_pagedir(pagedir_t *pd) {
asm volatile("movl %0, %%cr3":: "r"(pd->phys_addr));
- if (current_task != 0) current_task->current_pd_d = pd;
+ if (current_thread != 0) current_thread->current_pd_d = pd;
}
// ============================== //
@@ -177,8 +177,8 @@ int pd_map_page(void* vaddr, uint32_t frame_id, bool rw) {
ASSERT((size_t)vaddr < PD_MIRROR_ADDR);
- pagedir_t *pdd = ((size_t)vaddr >= K_HIGHHALF_ADDR || current_task == 0
- ? &kernel_pd_d : current_task->current_pd_d);
+ pagedir_t *pdd = ((size_t)vaddr >= K_HIGHHALF_ADDR || current_thread == 0
+ ? &kernel_pd_d : current_thread->current_pd_d);
pagetable_t *pd = ((size_t)vaddr >= K_HIGHHALF_ADDR ? &kernel_pd : current_pd);
mutex_lock(&pdd->mutex);
diff --git a/kernel/l0/task.c b/kernel/l0/thread.c
index cf22f9d..b14ad9b 100644
--- a/kernel/l0/task.c
+++ b/kernel/l0/thread.c
@@ -1,4 +1,4 @@
-#include <task.h>
+#include <thread.h>
#include <kmalloc.h>
#include <dbglog.h>
#include <idt.h>
@@ -10,7 +10,7 @@ void save_context_and_enter_scheduler(saved_context_t *ctx);
void irq0_save_context_and_enter_scheduler(saved_context_t *ctx);
void resume_context(saved_context_t *ctx);
-task_t *current_task = 0;
+thread_t *current_thread = 0;
// ====================== //
// THE PROGRAMMABLE TIMER //
@@ -47,29 +47,29 @@ static inline void resume_interrupts(bool st) {
// THE TASK SCHEDULER //
// ================== //
-static task_t *queue_first_task = 0, *queue_last_task = 0;
+static thread_t *queue_first_thread = 0, *queue_last_thread = 0;
-void enqueue_task(task_t *t, bool just_ran) {
+void enqueue_thread(thread_t *t, bool just_ran) {
ASSERT(t->state == T_STATE_RUNNING);
- if (queue_first_task == 0) {
- queue_first_task = queue_last_task = t;
+ if (queue_first_thread == 0) {
+ queue_first_thread = queue_last_thread = t;
t->next_in_queue = 0;
} else if (just_ran) {
t->next_in_queue = 0;
- queue_last_task->next_in_queue = t;
- queue_last_task = t;
+ queue_last_thread->next_in_queue = t;
+ queue_last_thread = t;
} else {
- t->next_in_queue = queue_first_task;
- queue_first_task = t;
+ t->next_in_queue = queue_first_thread;
+ queue_first_thread = t;
}
}
-task_t* dequeue_task() {
- task_t *t = queue_first_task;
+thread_t* dequeue_thread() {
+ thread_t *t = queue_first_thread;
if (t == 0) return 0;
- queue_first_task = t->next_in_queue;
- if (queue_first_task == 0) queue_last_task = 0;
+ queue_first_thread = t->next_in_queue;
+ if (queue_first_thread == 0) queue_last_thread = 0;
return t;
}
@@ -82,13 +82,13 @@ void run_scheduler() {
// At this point, interrupts are disabled
// This function is expected NEVER TO RETURN
- if (current_task != 0 && current_task->state == T_STATE_RUNNING) {
- enqueue_task(current_task, true);
+ if (current_thread != 0 && current_thread->state == T_STATE_RUNNING) {
+ enqueue_thread(current_thread, true);
}
- current_task = dequeue_task();
- if (current_task != 0) {
- resume_context(&current_task->ctx);
+ current_thread = dequeue_thread();
+ if (current_thread != 0) {
+ resume_context(&current_thread->ctx);
} else {
// Wait for an IRQ
asm volatile("sti; hlt");
@@ -99,24 +99,24 @@ void run_scheduler() {
}
}
-static void run_task(void (*entry)(void*)) {
- ASSERT(current_task->state == T_STATE_RUNNING);
- ASSERT(current_task->has_result);
+static void run_thread(void (*entry)(void*)) {
+ ASSERT(current_thread->state == T_STATE_RUNNING);
+ ASSERT(current_thread->has_result);
switch_pagedir(get_kernel_pagedir());
- current_task->has_result = false;
+ current_thread->has_result = false;
asm volatile("sti");
- entry(current_task->result);
+ entry(current_thread->result);
- current_task->state = T_STATE_FINISHED;
- // TODO : add job for deleting the task, or whatever
+ current_thread->state = T_STATE_FINISHED;
+ // TODO : add job for deleting the thread, or whatever
yield(); // expected never to return!
ASSERT(false);
}
-task_t *new_task(entry_t entry) {
- task_t *t = (task_t*)kmalloc(sizeof(task_t));
+thread_t *new_thread(entry_t entry) {
+ thread_t *t = (thread_t*)kmalloc(sizeof(thread_t));
if (t == 0) return 0;
void* stack = region_alloc(KPROC_STACK_SIZE, REGION_T_KPROC_STACK, 0);
@@ -139,9 +139,9 @@ task_t *new_task(entry_t entry) {
t->ctx.esp = (uint32_t*)(t->stack_region->addr + t->stack_region->size);
*(--t->ctx.esp) = (uint32_t)entry; // push first argument : entry point
- *(--t->ctx.esp) = 0; // push invalid return address (the run_task function never returns)
+ *(--t->ctx.esp) = 0; // push invalid return address (the run_thread function never returns)
- t->ctx.eip = (void(*)())run_task;
+ t->ctx.eip = (void(*)())run_thread;
t->state = T_STATE_WAITING;
t->result = 0;
t->has_result = false;
@@ -158,17 +158,17 @@ task_t *new_task(entry_t entry) {
// ========== //
static void irq0_handler(registers_t *regs) {
- if (current_task != 0)
- irq0_save_context_and_enter_scheduler(&current_task->ctx);
+ if (current_thread != 0)
+ irq0_save_context_and_enter_scheduler(&current_thread->ctx);
}
-void tasking_setup(entry_t cont, void* arg) {
+void threading_setup(entry_t cont, void* arg) {
set_pit_frequency(TASK_SWITCH_FREQUENCY);
idt_set_irq_handler(IRQ0, irq0_handler);
- task_t *t = new_task(cont);
+ thread_t *t = new_thread(cont);
ASSERT(t != 0);
- resume_task_with_result(t, arg, false);
+ resume_thread_with_result(t, arg, false);
run_scheduler(); // never returns
ASSERT(false);
@@ -179,40 +179,40 @@ void tasking_setup(entry_t cont, void* arg) {
// ======================= //
void yield() {
- if (current_task == 0) {
- // might happen before tasking is initialized
+ if (current_thread == 0) {
+ // might happen before threading is initialized
// (but should not...)
dbg_printf("Warning: probable deadlock.");
} else {
- save_context_and_enter_scheduler(&current_task->ctx);
+ save_context_and_enter_scheduler(&current_thread->ctx);
}
}
void* wait_for_result() {
bool st = disable_interrupts();
- if (!current_task->has_result) {
- current_task->state = T_STATE_WAITING;
- save_context_and_enter_scheduler(&current_task->ctx);
+ if (!current_thread->has_result) {
+ current_thread->state = T_STATE_WAITING;
+ save_context_and_enter_scheduler(&current_thread->ctx);
}
- ASSERT(current_task->has_result);
- current_task->has_result = false;
+ ASSERT(current_thread->has_result);
+ current_thread->has_result = false;
- void *result = current_task->result;
+ void *result = current_thread->result;
resume_interrupts(st);
return result;
}
-void resume_task_with_result(task_t *task, void* data, bool run_at_once) {
+void resume_thread_with_result(thread_t *thread, void* data, bool run_at_once) {
bool st = disable_interrupts();
- task->has_result = true;
- task->result = data;
+ thread->has_result = true;
+ thread->result = data;
- if (task->state == T_STATE_WAITING) {
- task->state = T_STATE_RUNNING;
- enqueue_task(task, false);
+ if (thread->state == T_STATE_WAITING) {
+ thread->state = T_STATE_RUNNING;
+ enqueue_thread(thread, false);
}
if (run_at_once) yield();