Homework 4
W4118 Fall 2008
UPDATED: 11/2/2008 at 11:27pm EST
DUE: 11/9/2008 at 11:59pm

W4118 Fall 2008 - Homework 4


Individual written problems are to be done individually. Group programming problems are to be done in your assigned programming groups. All homework submissions are to be made via Courseworks. Refer to the homework policy section on the class web site for further details.

Individual Written Problems:

Exercise numbers refer to the course textbook, Modern Operating Systems. Each problem is worth 5 points.

  1. Ch 2 Exercise 20

  2. Ch 2 Exercise 32

  3. Ch 2 Exercise 36

  4. Ch 2 Exercise 37

  5. Ch 2 Exercise 42

  6. Ch 10 Exercise 16

  7. Suppose a new process with the default scheduler and default nice value is created and run using the Linux 2.6.11 kernel. What is the default time quantum assigned to the process to run when using an x86 CPU?

  8. Describe what happens in the Linux 2.6.11 kernel when a SCHED_NORMAL process runs out its time quantum and is preempted when a timer interrupt occurs. Be sure to list the procedures that are called and explain the function of each.

Group Programming Problems:

Programming problems are to be done in your assigned groups using the VM that has been assigned to your group. For all programming problems you will be required to submit source code, a kernel patch, 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.

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. You should base your changes on the 2.6.11 kernel that you installed for Homework 2, but without the modifications you made for the new systems calls you wrote for Homework 2. In particular, submitted kernel patches should be patched against your modified KDB-enabled kernel from Homework 2, i.e. do not include KDB code in your patch.

CWRR 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. Unfortunately, this means that multi-threaded applications will get more CPU time just because they contain more threads. Similarly, users who run more processes will also get more CPU time. An alternative is to introduce a notion called a container, which contains a group of processes. Fair-share scheduling with containers is a strategy that shares the CPU among sets of processes according to the container that is associated with those processes. For example, suppose Mary, Jane, and Sam are each assigned a separate container and using a machine that uses fair-share scheduling. Suppose Mary has one runnable process, Jane has three, and Sam has six. Fair-share scheduling views the ten runnable processes in three containers, and each container receives one-third of the CPU cycles to allocate to the processes that it owns. So Mary's single process would get about 33 percent of the available CPU cycles, each of Jane's three processes would get roughly 11 percent of the available CPU cycles, and each of Sam's six processes would get about 5.5 percent of the CPU cycles. Suppose Jane created two more processes. Jane would still in total get one-third of the CPU, so that each of her processes would now get about 6.7% of the CPU.

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

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

Now let's say that some containers are more equal than others. Imagine that we associate an integer, which we'll call a weight, with each container, and when a user is chosen, we let the container's chosen tasks run for W time quanta (instead of a single time quantum), where W is the container's weight. In this way we can specify that some containers get more CPU time than others, and also how much more. A container with a weight of 3 will get 50% more CPU time than a container 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 container. For simplicity, use a simple round-robin (RR) scheduling algorithm to do that. The intracontainer 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 CWRR except that it schedules tasks, not containers, and there are no different task weights.

  1. (50 pts) Implement a new task scheduler, which we will call Container-based Weighted Round-Robin, or CWRR:

  2. (10 pts) Create a test program that creates some number of processes and assigns different numbers of them to containers with different weights, then measures CPU usage as the processes run to show that your CWRR scheduler behaves properly. Submit your test program source file and a writeup of your results.