This report explains briefly the changes and improvements made to the existing xv6 riscv operating system.
cd
to the directory containingMakefile
and runmake qemu SCHEDULER=[OPTIONS] CPUS=[1-8]
. TheSCHEDULER
andCPUS
flags are optional. If not specified, SCHEDULER=RR and CPUS=8.
-
The
trace
system call, when called upon by a process, tracks down the system calls being issued by that process during its execution. The children of the calling processes are also tracked, but any other process executing parallely is not tracked, unless the process itself calls trace. -
The trace system call takes one argument, a bitmask of the system call functions that are to be traced. The call is implemented by making modifications to the proc structure. A new integer variable
mask
is added. -
mask
keeps track of which system calls to trace by setting the corresponding bit "high", in accordance with the numbering in the filekernel/syscall.h
. -
In the
allocproc
structure, the mask is initialized to 0, indicating that by default no system calls need to be tracked. Whentrace
is called, it sets the mask of the current process equal to the argument taken as input. -
In the file
kernel/syscall.c
, whenever a system call is performed, an additional piece of code checks, based off the value ofmask
, whether the current system call needs to be tracked or not. In the former case, it prints the required information about the system call after it has executed. -
The
strace
function is a command line function and is implemented by simply executing trace at the start of the process and thereafter calling the exec function for the arguments after the first two ones, which denote the name of the call, strace and the second argument contains the bitmask.
-
The sigalarm system call informs a process as it takes CPU time. It takes two arguments,
<interval>
and<handler>
, and calls the functionhandler
after everyinterval
ticks of the CPU. -
This system call is implemented by further modifying the proc structure and adding new variables,
alarm
,alarmTime
,interruptFunction
,tickCount
. -
alarm
stores whether the sigalarm function is called or not. -
alarmTime
stores the duration after which the handler needs to be called. -
interruptFunction
, as the name suggests, stores the function pointer handler, and is initialized to 0 inallocproc
. -
tickCount
stores the number of ticks that the process has currently used up. WhentickCount
equalsalarmTime
, it is set back to 0, and the program counter of the calling process is set tointerruptFunction
. -
The modified code is largely present in
kernel/trap.c
inside the functionusertrap
.
- We modify the
Makefile
so that we can take the scheduler argument and use desired scheduler.
OPTION | Scheduler | rtime | wtime |
---|---|---|---|
RR | Round Robin | 20 | 182 |
FCFS | First Come First Serve | 41 | 185 |
LBS | Lottery Based Scheduler | 21 | 186 |
PBS | Priority Based Scheduler | 20 | 143 |
MLFQ | Multi-Level Feedback Queue |
- Round Robin is the default scheduling protocol already implemented in xv6.