CS405 HW 1
30XP
hand in hard copy at start of class.
task 1: System Calls vs. Procedure Calls
How much more expensive is a system call than a procedure call? Write a simple test program to compare the cost of a simple procedure call to a simple system call (“getpid()” is a good candidate on UNIX; see the man page.) (Note: be careful to prevent the optimizing compiler from “optimizing out” your procedure calls. Do not compile with optimization on.)
- Run your experiment on two different hardware architectures and report the results.
- Explain the difference (if any) between the time required by your simple procedure call and simple system call by discussing what work each call must do (be specific). [Note: Do not provide the source code for your program, just the results].
Hint: You should use system calls such as gethrtime() or gettimeofday() for time measurements. Design your code such that the measurement overhead is negligible. Also, be aware that timer values in some systems have limited resolution (e.g., millisecond resolution).
task 2 (this one is tough)
When an operating system receives a system call from a program, a switch to the operating system code occurs with the help of the hardware. In such a switch, the hardware sets the mode of operation to supervisor mode, calls the operating system trap handler at a location specified by the operating system, and allows the operating system to return back to user mode after it finishes its trap handling. Now, consider the stack on which the operating system must run when it receives the system call. Should this be a different stack from the one that the application uses, or could it use the same stack as the application program? Assume that the application program is blocked while the system call runs.
Assignment and wording from Mike Dahlin.