COMS W4118 Spring 2008: Homework Assignment 4

Last Updated March 28th 2008

Due Saturday, April 5th at 11:59 PM (midnight)

This homework consists of only one component: a programming assignment.  It is to be submitted via Courseworks.

The programming assignment is to be done in assigned groups.  If you do not know what team you are on contact the professor.

Programming Assignment: Adding Fair Scheduling to Linux

Programming problems are to be done in your assigned groups using one of the VMs that has been assigned to your group members. For all programming problems you will be required to submit source code, a README file documenting your files and code, and a test run of your programs. In addition, you should submit a cover sheet using either homework_work.txt or homework_nonwork.txt, depending on whether or not the programming assignment is completely working or not. For source code submissions, you only need to submit new source code files that you created and kernel source code files that you changed. You should clearly indicate your names, email addresses, and assigned group number on your submission. Each group is required to submit one writeup for the programming assignment.

You will build your own Linux kernel for this class. For each homework assignment, you will build a new Linux kernel. The image of the kernel you build for this assignment should be vmlinuz.hmwk4. Grading for this assignment will be done based on vmlinuz.hmwk4.

Description

The assignment is to add a fair share scheduler to the kernel.

Purpose

Before you start

Make sure you have your VMs available and your MRL account  It is highly recommended that you study the scheduler chapter in ULK.

Programming Assignment (75 Points): UWRR Scheduling

The Linux scheduler repeatedly switches between all the running tasks on the system, attempting to give a fair amount of CPU time to each task. Fair-share scheduling is a strategy that shares the CPU among sets of processes according to the users that own those processes. For example, suppose that Alice, Bob, and Carol belong to different users and are logged in to a machine that uses fair-share scheduling. Suppose Alice has one runnable process, Bob has three, and Carol has six. Fair-share scheduling views the ten runnable processes as belonging to the three users, and each user receives one-third of the CPU cycles to allocate to the processes that it owns. So Alice's single process would get about 33 percent of the available CPU cycles, each of Bob's three processes would get roughly 11 percent of the available CPU cycles, and each of Carol's six processes would get about 5.5 percent of the CPU cycles. 

Add a new scheduling policy to support fair-share scheduling. Call this policy UWRR, for user weighted round-robin scheduling. UWRR should use fair-share scheduling based on each process's UNIX user identification. At each invocation of the scheduler, we will use a hierachical scheme to choose which task to run: first, a user is chosen, then, a task within that user's set of tasks is chosen. If we allow each user's chosen task the same amount of time on the CPU, each user should be represented equally.

Since we are making two choices in each scheduling decision, we need two algorithms: one to choose the user, and one to choose one of that user's tasks. Let's start by assuming we will use a Round-Robin scheme to decide which user to choose. We keep a queue of users, and whichever user was chosen last time we scheduled, we choose the next user in the queue for this schedule. We then choose a task within this user's set of tasks (more on this later), and let it run for a fixed amount of time (the time quantum). Now every user gets an equal amount of CPU time.

Now let's say that some users are more equal than others. Imagine that we associate an integer, which we'll call a weight, with each user, and when a user is chosen, we let the user's chosen tasks run for W time quanta (instead of a single time quantum), where W is the user's weight. In this way we can specify that some users get more CPU time than others, and also how much more. A user with a weight of 3 will get 50% more CPU time than a user with weight 2. This is called proportional sharing. More specifically, this implementation of proportional sharing is called Weighted Round-Robin.

We still haven't specified how a task is to be chosen once we choose a user. For simplicity, use a simple round-robin (RR) scheduling algorithm to do that. The intra-user RR scheduler should use the same default timeslice as the Linux scheduler uses for a task with the default nice value. Otherwise, the RR scheduler should work the same as UWRR except that it schedules tasks, not users, and there are no different task weights.

Recall that SMP operations (CONFIG_SMP) are turned off.  Thus, you do not need to worry about modifying code for the SMP case.

  1. (60 pts) Implement a new task scheduler, which we will call User-based Weighted Round-Robin, or UWRR:

  2. (15 pts)  Create a simple test program to show that your scheduler works.  To do this write a program that goes into an infinite while(1) loop. This program would normally take up 100% of the cpu.  Now create three different users Alice, Bob, and Carol and have them each run one or more copies of the loop program. Use the program top to monitor the CPU usage, both before and after you make your scheduler modifications.  Show that your scheduler is both fair (i.e., if the weights are set equally Alice, Bob, and Carol each get 1/3 of the CPU) and can be weighted (i.e., set weights 3, 2, and 1 and show that Alice gets three time the CPU of Carol and 50% more than Bob).  Users can be added to the system using the useradd program (e.g., useradd alice).

Special Notes - Clarifications

What and How to Submit

    1. Create ~/.gitconfig
    2. Write lots of detail in the git commit messages
    3. Create test files out of the git directory
    4. Do not include binary files, patch files, configuration files in the git directory
    5. Write hostname and ip address for vm in the homework_work.txt file
    6. Shutdown VM when done, select the exact homework kernel to boot
    7. Create test directory
    8. In the README file, write how to test, and what files are included
    9. File names should follow convention given in the instructions

References