Question
c program. Problem 2 measuring cost of system call Purpose: to understand mode switch penalty and the cost difference among system calls. Your task is
c program.
Problem 2 measuring cost of system call
Purpose: to understand mode switch penalty and the cost difference among system calls.
Your task is to write a C program that measures the latencies of various system calls. In particular, you want to know 1) the cost of CPU mode switch by measuring a light-weight system call which does very little thing in the kernel, and 2) the cost of heavier system calls which triggers a lot of activities inside the kernel.
Your program should measure the latencies of three system calls: getpid(), open(), and read(). getpid() represents lightweight call, and open()/read() represent heavy system calls. For high-resolution latency measurements, you should use gettimeofday() system call. See the man page for details.
Because individual calls are too fast to accurately measure with the resolution provided with gettimeofday(), you need to measure the execution time of repetition of system calls. You then divide the time taken with how many times to arrive the individual system call latency.
Note that getpid() value may be cached by C runtime library you may need to explicitly invoke system call. (see man page of getpid).
For open(), you need to use /dev/null as the target. Beware that there is a limit in the number of open files, so you have to manage it carefully when repeating the calls. You need to close() the files in case you are nearing the limit, but you dont want to include the cost of close() call in your measurement.
For read(), you need to use /dev/zero special file as the source file.
Measurements should take a few seconds for each of the system calls. After measurement, your program must print out the result to standard output using following format:
Syscall repetitions time elapsed (micro sec) latency (nano sec)
---------------------------------------------------------------------------
getpid(): xxxxx xxxxxxxxx xxxxxx
open(): xxxxx xxxxxxxxx xxxxxx
read(): xxxxx xxxxxxxxx xxxxxx
N.B., the latency should be time elapsed divided by repetitions.
What to turn in
- Your source code named prob2_.c
- Your binary named prob2_
- makefile
- A textfile named output_.txt which contains the execution result on cardiac.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started