Closed iainworkman closed 7 years ago
proc.c::proc struct will need an
int contextSwitches; // A count of the number of context switches this process has undergone
// Per-process state
struct proc {
uint sz; // Size of process memory (bytes)
pde_t* pgdir; // Page table
char *kstack; // Bottom of kernel stack for this process
enum procstate state; // Process state
int pid; // Process ID
struct proc *parent; // Parent process
struct trapframe *tf; // Trap frame for current syscall
struct context *context; // swtch() here to run process
void *chan; // If non-zero, sleeping on chan
int killed; // If non-zero, have been killed
struct file *ofile[NOFILE]; // Open files
struct inode *cwd; // Current directory
char name[16]; // Process name (debugging)
};
swtch.S contains the assembly routing swtch which handles context switches.
There are two calls to swtch proc.c:LL286 and proc.c:LL314
I imagine one of these will be where we increment the added counter in the switching process.
Hints from the tutorial said we should look in:
sysproc.c
syscall.c
syscall.h ~ #defines of system call -> code mapping
user.h ~ Userland interface for system calls (ie what you include in your user C code)
usys.S ~ Macro which creates the assembly automatically for the system codes.
For this part of the assignment, you will download, configure and compile a simple operating system kernel (xv6). You will need to read parts of the kernel to understand its structure, and finally, you will make a small modification to the kernel.
Your task is to add a system call csinfo() that returns an integer value giving the number of context switches that took place in the process from the time it started.
You will also need to write a userspace program to test your new system call. Your userspace program should do some simple tasks (make some function calls, maybe even use the task from Part A, forking off children processes, or sleep) and invoke your new system call periodically and then print the result. Recall that xv6 does not natively support multi-threaded processes.
You will need a counter in the proc structure to keep track of this value, and to determine where to increment it.
Some tips: