Homework 4

W4118 Fall 2011

UPDATED: Saturday, 11/05/2011 at 7:35pm EST

DUE: Wednesday, 11/9/2011 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:

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.9

  2. Exercise 5.11

  3. Exercise 5.12

  4. Exercise 5.19

  5. Exercise 5.20

  6. Exercise 5.21

Group Programming Problems:

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. Some useful screen casts / tutorials can be found on gitcasts.com.

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 located in the linux-msm-2.6.32/scripts directory within your repository. Points will be deducted for non-compliance!

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 Google Android Developer Phone 1, ADP1, (CVN students may complete this assignments using the emulator). The Android platform can run on many different architectures, but the specific platform we will be targetting is the ARM CPU family. The Google ADP1 phones use an ARMv6 CPU (specifically, ARM1136) which is embedded in a Qualcomm System-On-a-Chip processor called the MSM 7201a (which actually incorporates the cellular baseband processor, and the application processor).

Because the target CPU is (most likely) 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.   (70 pts.) The Display-Boosted Multilevel Container Scheduler
    Write a new Linux kernel scheduling class, and demonstrate correct behavior by modifying all Android Java programs to use the new schduling class.

    The Linux scheduler repeatedly switches between all running tasks in the system attempting to give a fair amount of CPU time to each task. On an embedded device in which only one or two applications at a time (e.g. the top-most application in Android's display stack, and the phone's status bar) are visible to the user, it can be beneficial to give those applications visible on the display more CPU time. Scheduling these "interactive" applications more often than background tasks should make the system appear more responsive to the user, and increase their productivity. Let's call this type of scheduling, display-boosted.

    We can use this display-boosting concept together with a multilevel feedback scheduler. A multilevel feedback scheduler provides an approximation to shortest job first scheduling for improving interactive performance. Applications that are using the display receive higher priority and shorter time slices. As an application consumes more CPU and does not use the display, its priority is reduced and its time slice is increased. If an application uses the display again, its priority is boosted back to the top again with a shorter time slice. The result is that applications that frequently use the display will run with higher priority, and gradually lose that priority the longer they run without accessing the display.

    As we learned in previous homeworks, each Android Java application uses several threads for performing various functions. Because we want the application as a whole to be more responsive, we will need some notion of a container which represents a group of processes/threads. This is straight-forward on the Android system because each application runs under a unique user ID (which is set/created when the application is installed). If any one of the process in a container draws on the display then the entire container should get an increased amount of CPU time.

    In the scheduling algorithm you write, each process/thread in a container will receive the same CPU time slice, and should be scheduled in a first-come-first-serve manner until either all processes in a container use up their time slices, or there are no more runnable tasks in the container. When either of these conditions occur, the container should be moved to the end of the next-lowest priority queue, and the time quanta for each contained process/thread should be refreshed to the value which corresponds to the queue in which the container was placed (see scheduling algorithm below for details).

    Objectives:

    Display notification:

    You may have been wondering how you will know that a given process is drawing or using the display. Fortunately this part has been done for you. The display_mod directory in your homework repository contains a modified version of the libsurfaceflinger.so library, and a Makefile which will install the new library onto your phone/emulator. Simply run make install_emu or make install_dev and follow the instructions. This modified library makes a special (custom) system call every time a rectangle is rendered on the screen. This system call is named set_display_owner and is implemented in the kernel/sys.c file in the Linux kernel directory in your homework repository. Take a look at the implementation, and customize as necessary!

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, you may want to develop on your Linux host machine. While we do now have the resources to support your desktop installations, you may find this more convenient. To make it work, you should follow these steps:
  1. Download the Android SDK from here
  2. Extract it to ~/android-sdk-os.f2011
  3. Inside the platforms subdirectory, extract the file android-os.f2011.tar.bz2
  4. Download the code-sourcery cross-compiler from here
  5. Extract this tar somewhere (e.g. ~/tools)
  6. Add the arm-2011.03/bin directory to your path in for example ~/.bashrc
  7. Set the CROSS_COMPILE variable to arm-none-linux-gnueabi-