This project extends the basic XV6 operating system with additional system calls, thread support, scheduler enhancements, and memory management features. It is intended for learning OS development and exploring low-level system programming concepts.
pipeimplementationfindprograme(all file and directory at the cwd)
SYSCALL(halt)SYSCALL(time)SYSCALL(stime)SYSCALL(trace)SYSCALL(procinfo)
scheduler latencyRound-Robin schedulerLottery schedulerHybrid scheduler: delay = -1 first, then tickets based
Relocateuser space processes, not start at 0x00Page faulthander implmentation in the trap.mprotectandmunprotect: set write permission for the certain page.mmapandmunmap: map the memory and directly operate memory to write/read files/devices.
clone(): syscall to create process-based thread (share page table and address space)join(): wait for the thread exit, ignore the process exit.thread_create(): thread library to call clone() to create thread. Malloc stack in the function.thread_join(): thread library to call joind() to release the tread and also free the allocated stack.
syscallhandling (0x40 trap) Implemented system call dispatching via trap vector 0x40.procinfosyscall Query process information including PID, state, parent, and memory usage.timesyscall Return system time for processes.
clonesyscall- Create threads by sharing the process page directory (
pgdir). - Arguments (
arg1,arg2) and return value are placed on the thread stack. - Allocates stack and updates shared memory size (
sz) safely with locks.
- Create threads by sharing the process page directory (
joinsyscall- Wait for a thread to exit.
- Cleans up thread resources without freeing VM (unless it is a process).
- Thread exit handling
- Closes files on thread exit.
- Process exit (
exit) also cleans up child threads.
- Thread vs. Process wait logic
waitskips threads but waits for processes to exit and frees VM.joinskips processes but waits for threads to exit.
- Round Robin
- Standard time-slice scheduling with latency tracking and next runnable selection.
- Lottery Scheduler (Tickets)
- Random selection of runnable process based on ticket count.
- Hybrid Scheduler
- Initially uses delay-1 scheduling, then switches to ticket-based lottery.
- Page fault handling
- Added custom trap handler for page faults.
- Permission management
protect/unprotectsyscall to change memory page permissions.
mmapsupport- Allows dynamic mapping of memory regions.
- Move entry address (
sz)- Adjusts user process entry addresses from
userBasefor threads and memory management.
- Adjusts user process entry addresses from
- Supports basic inter-process communication using pipes.
- GDB support
- Debug kernel and user processes with breakpoints.
- Poweroff syscall
- Gracefully shuts down the system.
- Tracing syscall implementation
- Track system call execution for debugging.
- Build and run XV6 with your modified kernel:
make qemu