COSC 360

Operating Systems


Project 4


Due October 12th (Thursday)

Overview

This project will have you explore concepts related to processes, scheduling, and context switching.

To Do

Type up answers to the following questions:

  1. Investigate one different hardware architecture (such as SPARC or MIPS), and determine what information needs to be saved during a context switch.

  2. Devise your own scheduling policy for a dual-core processor (i.e., a processor that contains two separate processing cores that can execute in parallel). Explain your reasoning.

  3. Consider a modification to the code that stores processor state in the process table instead of on the process's stack (i.e., assume the process table entry contains an array that holds the contents of registers). What are the advantages of each approach?

  4. Change the code (but make a backup first!) in resched.c to implement round-robin scheduling. The scheduler will, every time resched() is called, simply move to the next process in the ready list (whatever process comes after the currently running process). If it reaches the tail, it jumps back to the head of the list.

    In order to see what is getting put on the processor each time, call kprintf() to print the new PID that was selected (do this before the context switch happens). Your message might say "PID 4 is now on the processor.".

  5. Change the code (but make a backup first!) in resched.c to implement a new scheduling policy called random scheduling. This scheduler will choose at random a process from the ready list. The probability of choosing a specific process will be proportional to its priority. For example, assume that there are three processes eligible for execution P1, P2, and P3 (each of them is either in the ready list or is the current process) with priorities 30, 20, and 10. The totalSum of those priorities is 60. The goal of the random scheduler is to allocate the CPU with a probability of 30/60 to P1, 20/60 to P2, and 10/60 to P3.

    To accomplish this, each time a rescheduling happens, the scheduler will generate a random number between 0 and totalSum minus 1 (0 to 59 in this case). If the random number is less than the priority of the first process in the list of processes eligible for execution, then the scheduler schedules this process for execution. Otherwise, the random number is decreased by priority units and it goes to the next process in the list and so on. For example, assume that the random number generated was 38, and the first process in the list is P1. As 38 is not less than 30, we decrease the number 38 by 30 and we go to the next process in the list. As 8 is less than 20, then the scheduler will choose P2 for execution.

    In order to see what is getting put on the processor each time, call kprintf() to print the new PID that was selected (do this before the context switch happens). Your message might say "PID 4 is now on the processor.".

Submit

To submit, type up your answers in any text editor, convert the file to a PDF, zip the file along with all your code as "project4.zip", and submit it to Moodle by the due date.