Answered step by step
Verified Expert Solution
Question
1 Approved Answer
An xv 6 Lottery SchedulerDetails You'll need two new system calls to implement this scheduler. The first is int settickets ( int number ) ,
An xv Lottery SchedulerDetails
You'll need two new system calls to implement this scheduler. The first is int setticketsint 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 if successful, and otherwise if for example, the caller passes in a number less than one
The second is int getpinfostruct 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; note, you cannot change this structure, and must use it exactly as is This routine should return if successful, and otherwise if for example, a bad or NULL pointer is passed into the kernel
Most of the code for the scheduler is quite localized and can be found in proc.c; the associated header file, proc.h will also need some modification. To change the scheduler, not much needs to be done; study its control flow and then try some small changes.
You'll need to assign tickets to a process when it is created. Specifically, you'll need to make sure a child process inherits the same number of tickets as its parents. Thus, if the parent has tickets, and calls fork to create a child process, the child should also get tickets.
You'll also need to figure out how to generate random numbers in the kernel; some searching eg grep rand should lead you to a simple pseudorandom 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:
#ifndef PSTATH
#define PSTATH
#include "param.h
struct pstat
int inuseNPROC; whether this slot of the process table is in use or
int ticketsNPROC; the number of tickets this process has
int pidNPROC; the PID of each process
int ticksNPROC; the number of ticks each process has accumulated
;
#endif PSTATH
Good examples of how to pass arguments into the kernel are found in existing system calls. In particular, follow the path of read which will lead you to sysread which will show you how to use argptrand related calls to obtain a pointer that has been passed into the kernel. Note how careful the kernel is with pointers passed from user space they are a security threat and thus must be checked very carefully before usage.
The attached program below uses the system calls described above and generates a test. It takes approximately seconds to run and prints something approximately once per second.
The last line should look something like:
Reading from left to right, process has ticket and won the lottery times. The interesting processes are which have and tickets each and won the scheduling lottery and times. Your numbers may differ, but the proporitions between the processes should be pretty close.
totalticks
propA ~
propB ~
propC ~
Below is schedtest.c It should be added to your repository and added to the list of programs built for running inside of xvlook at stressfs for an example in the Makefile
pl
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started