CS 450 Homework 1

Links: [Course Home] [Schedule] [Learning Objectives] [Resources] [Moodle]


Due Wednesday, February 22 at 10:00 AM. No late submissions accepted.

Instructions

Complete the following problems. I will test your code on the CS department server (blue.cs.sonoma.edu). You may work in groups of up to three students. Please have just one group member submit the assignment; see submission instructions below.

Problem 1: Virtual memory exploration [25 points]

Write a C program (p1.c) based on Figure 2.7 (p. 54) in your textbook, with the following changes:

Take a screenshot of multiple copies of this program running at the same time, and explain what the outputs in the screenshot tell you about the memory addresses used by different processes.

Problem 2: Asynchronous notifications [25 points]

In this program, you will practice setting up a Unix signal handler to receive asynchronous notifications from the kernel to your program. Specifically, you will define a function to catch the SIGALRM signal, and then you will set an alarm to go off in a few seconds. Stub code:

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

/* The signal handler isn't allowed to do anything except
 * access this variable and re-invoke signal().
 */
volatile sig_atomic_t alarm_flag = 0;

/* Prototype for signal handler */
void alarm_handler (int sig);

int main (void) {
  // Call signal() to set up a handler for SIGALRM


  // Call alarm() to have the alarm go off in a few seconds


  while (!alarm_flag) {
    puts("Waiting for an alarm");
  }

  return 0;
}

You need to:

Helpful references:

In your research, you may see that signal is now deprecated and sigaction is what all the kids are doing these days. That's true! But sigaction is more complicated, so signal is a good place to start.

In an initial comment, explain what happens when you run your program, and why.

Problem 3: Syscalls and syscall timing [25 points]

Do Exercise 2-12 (p. 91) in your book, with the following changes:

Your output should be something like:

elapsed time for my function: 1.03e-07s
elapsed time for syscall: 9.6e-08s

Generate an assembly version of your program (using the -S flag) to see if you can get a sense of what your function is really doing and what the syscall is really doing. Why don't you see a syscall or int 0x80 instruction directly in your assembly file?

In an initial comment to your code, explain the work that each call (your function and the syscall) must do, and try to explain the relative performance.

Problem 4: Interrupts and virtualization [25 points]

Cite any online sources you use to help answer this question. Your answer should either be a text file (p4.txt) or a PDF (p4.pdf).

Part A: Define interrupt coalescing. What are the pros and cons, and under what circumstances does it work best?

Part B: Read through Section 2, including Figure 1, of the following paper:

Irfan Ahmad, Ajay Gulati, and Ali Mashtizadeh, "vIC: Interrupt Coalescing for Virtual Machine Storage Device IO." In Proceedings of the USENIX Annual Technical Conference, 2011. [paper][video]

Describe why interrupt handling can be so expensive in a virtualized environment.

Submission

One person in your group should turn in a tar or zipfile on Moodle containing the following: