Lab 04
NCTU OSDI Lab 4: Multitasking
Documentation: Lab 4
Lab 4 Demo Release
Required
- Required 1
- Design your own task struct with at least one field called task id. Task ids should be unique.
- Implement
privilege_task_create
. - Implement
context_switch
. - In the end of
privilege_task_create
, put the task into the runqueue. - Replace
context_switch
withschedule
in the privilege tasks, you should be able to create more than 2 tasks and switch between them.
- Requried 2
- Reimplement the core timer handler, it updates the current task’s reschedule flag.
- Create more than 2 privilege tasks. Each of them keeps checking the reschedule flag. If the flag is set, it prints some message, clears reschedule flag and issue
schedule
.
- Required 3
- Implement
do_exec
. - Implement user tasks preemption.
- Implement
- Required 4
- Implement
uart_read
anduart_write
. - Implement
exec
. - Implement
fork
. - Implement
exit
and zombie reaper by one of the above methods.
- Implement
Elective
In the elective part, you should enable interrupt except some critical regions in EL1. Otherwise, you won’t get any score.
- Implement
kill
and signal handler for SIGKILL. - Implement a priority based scheduler.
- Implement a wait queue for uart reading.interrupt after top half of ISR.
- Implement
mutex_lock
,mutex_unlock
. If task fail to acquire the lock, it would go to sleep and context switch to other tasks. - Let kernel could be preempted without explicit calling schedule.
Questions
- Consider the following POSIX signal example code. Can you elaborate how to design the kernel to support it?
#include <stdio.h> #include <signal.h> #include <unistd.h> void handler(int sig) { printf("Hello\n"); } int main() { signal(SIGINT, handler); char buf[256]; int n = read(0, buf, 256); buf[n] = '\0'; printf("Bye %s\n", buf); }
- Can you prevent all possible context switch by disabling interrupt?
- Do you think microkernel need to be preemptive kernel or not? Why or why not?