First cut at lottery scheduler assignment.
This commit is contained in:
77
scheduling-xv6-lottery/README.md
Normal file
77
scheduling-xv6-lottery/README.md
Normal file
@@ -0,0 +1,77 @@
|
||||
|
||||
# An xv6 Lottery Scheduler
|
||||
|
||||
In this project, you'll be putting a new scheduler into xv6. It is called a
|
||||
**lottery scheduler**, and the full version is described in [this
|
||||
chapter](a,href=http://www.cs.wisc.edu/~remzi/OSFEP/cpu-sched-lottery.pdf) of
|
||||
the online book; you'll be building a simpler one. The basic idea is simple:
|
||||
assign each running process a slice of the processor based in proportion to
|
||||
the number of tickets it has; the more tickets a process has, the more it
|
||||
runs. Each time slice, a randomized lottery determines the winner of the
|
||||
lottery; that winning process is the one that runs for that time slice.
|
||||
|
||||
The objectives for this project:
|
||||
* To gain further knowledge of a real kernel, xv6.
|
||||
* To familiarize yourself with a scheduler.
|
||||
* To change that scheduler to a new algorithm.
|
||||
* To make a graph to show your project behaves appropriately.
|
||||
|
||||
|
||||
## Details
|
||||
|
||||
You'll need two new system calls to implement this scheduler. The first is
|
||||
`int settickets(int number)`, which sets the number of tickets of the calling
|
||||
process. By default, each process should get one ticket; calling this routine
|
||||
makes it such that a process can raise the number of tickets it receives, and
|
||||
thus receive a higher proportion of CPU cycles. This routine should return 0
|
||||
if successful, and -1 otherwise (if, for example, the caller passes in a
|
||||
number less than one).
|
||||
|
||||
The second is `int getpinfo(struct pstat *)`. This routine returns some
|
||||
information about all running processes, including how many times each has
|
||||
been chosen to run and the process ID of each. You can use this system call to
|
||||
build a variant of the command line program `ps`, which can then be called to
|
||||
see what is going on. The structure `pstat` is defined below.
|
||||
|
||||
Most of the code for the scheduler is quite localized and can be found in
|
||||
`proc.c`; the associated header file, `proc.h` is also quite useful to
|
||||
examine. To change the scheduler, not much needs to be done; study its control
|
||||
flow and then try some small changes.
|
||||
|
||||
You'll also need to figure out how to generate random numbers in the kernel;
|
||||
some searching should lead you to a simple pseudo-random number generator,
|
||||
which you can then include in the kernel and use as appropriate.
|
||||
|
||||
Finally, you'll need to understand how to fill in the structure `pstat` in the
|
||||
kernel and pass the results to user space. The structure should look like what
|
||||
you see here, in a file you'll have to include called `pstat.h`:
|
||||
|
||||
```c
|
||||
#ifndef _PSTAT_H_
|
||||
#define _PSTAT_H_
|
||||
|
||||
#include "param.h"
|
||||
|
||||
struct pstat {
|
||||
int inuse[NPROC]; // whether this slot of the process table is in use (1 or 0)
|
||||
int tickets[NPROC]; // the number of tickets this process has
|
||||
int pid[NPROC]; // the PID of each process
|
||||
int ticks[NPROC]; // the number of ticks each process has accumulated
|
||||
};
|
||||
|
||||
#endif // _PSTAT_H_
|
||||
```
|
||||
|
||||
## Graph
|
||||
|
||||
Beyond the usual code, you'll have to make a graph for this assignment. The
|
||||
graph should show the number of time slices a set of three processes receives
|
||||
over time, where the processes have a 3:2:1 ratio of tickets (e.g., process A
|
||||
might have 30 tickets, process B 20, and process C 10). The graph is likely to
|
||||
be pretty boring, but should clearly show that your lottery scheduler works as
|
||||
desired.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user