Homework 4

W4118 Fall 2012

UPDATED: Thursday 11/01/2012 at 3:00pm EST

DUE: Friday, 11/9/2012 at 11:59pm EST

All non-programming, written problems in this assignment are to be done by yourself. Group collaboration is permitted only on the kernel programming problems. All homework submissions (both individual and group) are to be made via Git. Git repository access will use the same public/private key-pair you used for previous homeworks (see these Git instructions).

Individual Written Problems:

Solutions are available here.

The Git repository you will use for the individual, written portion of this assignment can cloned using: git clone gitosis@os1.cs.columbia.edu:UNI/hmwk4.git (replace UNI with your own UNI). This repository will be accessible only by you.

Exercise numbers refer to the course textbook, Operating System Concepts Essentials. Each problem is worth 5 points.

  1. Exercise 5.12 but assuming a 2-CPU system scheduled from a single runqueue.

  2. Exercise 5.16

  3. Exercise 5.17

  4. Exercise 5.21

  5. When a process forks a child, both parent and child processes are runnable. Assuming there are no other processes in the system and a single CPU system, explain how the Linux 3.1 default scheduler will schedule the parent and child processes, including which process will run after the execution of fork.

  6. Explain how load balancing is done in the realtime scheduler in Linux 3.1.

Group Programming Problems:

Solutions are available here.

Group programming problems are to be done in your assigned groups. The Git repository your entire group will use to submit the group programming problems can be cloned using: git clone gitosis@os1.cs.columbia.edu:TEAM/hmwk4.git (Replace TEAM with the name of your team, e.g. team1). This repository will be accessible to all members of your team, and all team members are expected to commit (local) and push (update the server) changes / contributions to the repository equally. You should become familiar with team-based shared repository Git commands such as git-pull, git-merge, git-fetch. One important thing to remember is to pull any changes into your local repository before trying to push any commits to the class server.

All team members should make at least five commits to the team's Git repository. The point is to make incremental changes and use an iterative development cycle. Please follow the Linux kernel coding style.
Hint(1): use the checkpatch.pl script to ensure your code conforms to this standard. Points will be deducted for non-compliance!

It's a good idea to clone your repository after your final push (but before the deadline) and test the cloned code to be sure it behaves as expected.

All kernel programming assignments in this year's class are done on the Android operating and targeting the ARM architecture. For more information on how to get your development environment configured, please see this page: Development Guide.

The kernel programming for this assignment will be done using a Nexus 7 tablet. The Android platform can run on many different architectures, but the specific platform we will be targeting is the ARM CPU family. The Nexus 7 tablets use an ARMv7 quad-core CPU which is embedded in the Nvidia Tegra 3 SoC.

Because the target CPU is different from the CPU running in your personal computer, you will have to cross-compile any software, including the linux kernel, to run on the different platform. You should use the same virtual machine you used for homeworks 2 and 3.

  1.   (60 pts.) A Symmetric Multiprocessor Weighted Round-Robin Scheduler

    Setting / Getting Weights:
    For setting and getting the weights, you are to implement the following system calls:
    /* Set the SCHED_WRR weight of process, as identified by 'pid'.
     * If 'pid' is 0, set the weight for the calling process.
     * System call number 376.
     */
    int sched_setweight(pid_t pid, int weight);
    
    /* Obtain the SCHED_WRR weight of a process as identified by 'pid'.
     * If 'pid' is 0, return the weight of the calling process.
     * System call number 377.
    int sched_getweight(pid_t pid);
    
    Only the administrator (root user) or the user who owns the process may adjust a process' weight using sched_setweight(). Furthermore, only the administrator may increase a process' weight. Any user should be able to call sched_getweight(). It is an error to try and set the weight on a process not using the SCHED_WRR policy. The system calls should handle all errors appropriately. The system calls should be implemented in kernel/sched.c.

    Clarification: The system calls refer to the process whose ID is specified by pid, i.e. only one task's weight should be changed in the kernel. (In _overly simplistic_ terms, the weight of the task_struct whose pid is specified by pid is changed). If you've already implemented it such that the process represented by pid and all of its threads weights are changed, you can leave it, but this implementation is more complicated so there is more potential for it to be implemented incorrectly.
  2.   (10 pts.) Investigate
    Demonstrate that your scheduler works with a test program that calculates the prime factorization of a number using the naive Trail Division method. Track how long this program takes to execute with different weightings set and plot the result. You should choose a number to factor that will take sufficiently long to calculate the prime factorization of, such that it demonstrates the effect weighting has on its execution time. Timing of the execution can be done either internally in the program's code or externally so long as it is sufficiently accurate to show the effect of weighting.

    You should provide a complete set of results that show all your tests. If there are any results that do not yield execution time proportional to weights, explain why. Your results and any explanations should be put in the written file in the root of your team's hmwk4 repository. Your plot should be named plot.pdf and should be put in the root of your team's hmwk4 repository (next to the written file).

Additional Hints/Tips

Kernel / Scheduler Hacking:

Linux users: If you are a Linux user and cannot connect your device to your VM to flash the system (or you would just like a more efficient set up), you may want to develop on your Linux host machine. While we do not have the resources to support your desktop installations, you may find this more convenient. To make it work, you should follow these steps:
  1. Obtain the Android SDK from your VM. It's located at /home/w4118/utils/android-sdk_r20.0.3-linux-jellybean.tgz
  2. Extract it to ~/ (once extracted, there will be a ~/android-sdk-linux directory)
  3. Add ~/android-sdk-linux/tools and ~/android-sdk-linux/platform-tools to your path (e.g. in ~/.bashrc)
  4. Download the code-sourcery cross-compiler from here
  5. Extract this tar somewhere (e.g. ~/tools)
  6. Add the extracted arm-2010.09/bin directory to your path (e.g. in ~/.bashrc)
  7. Set the CROSS_COMPILE variable to arm-none-linux-gnueabi-
Hint: You can use your VM as a guide by looking at its ~/utils directory and ~/.bashrc file.