Operating Systems [ KG ] Homeworks and assignments -
Homework 0
-
Do the following: Go to any Linux 2.x system and cd /proc. Read the on-line
manual for info on the proc filesystem (do man proc). Find out the foll
info on your system using the proc filesystem: the type of CPU, whether
mmx is supported, how many context switches have taken place since boot
of the machine, the load average, etc.
-
Find out when the machine was booted using /proc fs.
-
Why is that while "ls" reports zero as the file size for many of the non-directory
files in /proc but "more" indicates that there is info?
-
Look at ksyms and report on the format of the entries.
-
Look at process 1 and find out all the info you can on it as a non-privileged
user and summarize it.
-
Do a man on cscope. Copy the sources of Linux2.2.5 src/kernel into your
home dir and build cscope. How big is the database? Search for do_exit
using cscope.
Homework 1
-
Do "man query_module". Trace the system call for query_module (ie. look
for the function sys_query_module) in the Linux source. Write a small C
program to get the list of modules in the Linux system you are running.
Using a slightly different program, find the address where "getblk" is
stored. Verify this with /proc fs. What is the stuff after getblk_ ?
-
Locate the file entry.S (Intel version). Study the part of the file marked
ENTRY(system_call). Write a summary of the code for system call. You may
need to learn and understand the assembler syntax (on your own!). Find
out what the bottom halves are.
-
Study switch_to and __switch_to and summarize them. What is the difference
between a procedure call, a mode switch and a context switch in terms of
the number of instructions executed? Try to find out from the Linux source
code.
Homework 2
-
Look at proc.h/user.h in Solaris. Does Linux have this type of division?
What is proc info in Linux and what is user? Where is the kernel stack
in Linux?
-
In the solution given in the class for avoiding a zombie, there could still
be a zombie if the 1st child exits soon after creating the second child.
Can this be avoided? Sketch a solution.
-
Do Ex. 7.11.1 (Bach). Use strace -vf and explain. Try to make sense of
the strace output and give the best interpretation that you can come up
with.
-
Study vfork() on Solaris. What is its equivalent in Linux, if any? Do Ex.
9.5.8 Bach.
-
Read the two docs elf1/2.htm in http://agni/Standards/exec-format. Compile
your solution for assg0 so that it can be a shared object for either one
of sorting or finding maximum (you have to make some small changes; what
are these?). Locate its GOT/PLT. What is the GOT/PLT for your original
unmodifed solution?
-
Do Ex. 7.11.11 Bach.
-
Do Ex. 7.11.13 Bach. Try this out in Linux. Trace the kernel code and explain.
-
Do Ex. 7.11.14 Bach. Again, trace the Linux kernel code and explain.
-
Do Ex. 7.11.20 & 7.11.21 Bach. Do not try this out on a Linux machine
unless you know what you are doing.
Assignment 0
-
First find out all the calls avlbl in a Linux 2.2.5 system related to pthreads
(do "apropos pthread"). Use pthreads to implement the following parallel
program: Find the maximum value in an integer array a[1..1000] by searching
even and odd subscripts of a in parallel. Report the execution time when
done serially and when done in parallel. If you have access to a multiprocessor
machine (say what you used), try this out on that machine and report the
timings again. Increase the parallelism from 2 to 4 and report what happens.
-
Do "man clone". After understanding (most? of the) the man page, repeat
the above but now using the clone system call. Report the times just like
above. (Do this only on Linux 2.2.5 systems; 1.x will not work and 2.0.x
might have problems...)
-
Using clone syscall, implement quicksort. Again use an array a[1..1000].
At what size of the array is a serial impl better than parallel? Using
this info, give your complete solution for quicksort along with the times.
Repeat this again with pthreads.
-
Repeat 2) on a multiprocessor machine.
Note: After getting the programs working, measure the times when the machine
is lightly loaded (ie not more than 2 users, say). Find out how to
get the load on a system.
Assignment 1
-
The fetch&add atomic instruction is as follows: FA(var, incr): <temp=var;
var += incr; return(temp)> Design a system call for FA & implement
this in the Linux kernel. Give all the modifications to the Linux source.
Reimplement this thru pthreads rather than as a syscall. What is the diff
in their capabilities?
-
Implement the pselect system call in Linux. Refer to Stevens, Unix Netw
Prog 2nd ed, '98, p. 168 & p. 482 for details. Give all the modifications
to the Linux source. You have to first study how select call is implemented.
Is it possible to use pthreads instead for a correct impl?
-
A concurrent queue is a queue in which insert and delete ops can execute
in parallel. Assume the queue is stored in an array q[1..n]. Two vars front
and rear point to the first full element and the next empty slot, respectively.
The delete op delays until there is an element in q[front], then removes
it and increments front (mod n). The insert op delays until there is an
empty slot, then puts a new element in q[rear] and increments rear (mod
n). Design algs for queue insertion and deletion that maximize parallelism.
In particular, except at critical points where they access shared variables,
inserts and deletes ought to be able to proceed in parallel with each other
and with themselves. Use pthreads & give the solution. Next use FA
and give the solution.
Assignment 2
-
Implement a simple flat FS within a single process in Linux so that different
pthreads can do various file ops (read, write, creat, open, close, lseek
only) using an already allocated large Linux file, say a MB, as storage
for your FS. You should also support mount (with no args) and umount ops.
One or more threads can serve as "server threads" for handling these calls
or you can design a serverless model. However, concurrency aspects have
to be taken care of. When you link, make sure that your version of read,
etc are linked in rather than the std ones. Your attempt will be
to use the kernel infrastructure as far as possible, though everything
you do will be at user level. For example, copy and use such data
structures as file_operations, etc. See /usr/src/linux/fs/romfs for an
example of the structure. Do not buffer any files (so no need to
implement a buffer cache). We will run 1+ scripts to see if your program
runs correctly. Your code will not be reviewed. You should submit a design
document with what works and what does not as per your testing.
-
Using the following insts from MIPS, devise a spinlock. load linked inst:
loads a value from mem to reg & sets a flag that causes
HW to monitor the loc. If any process writes to such a loc, HW clears flag
store conditional: stores a new val into the loc provided the flag is set
also sets another reg to indicate if store succeeded
-
Does the semaphore impl (this is officially not part of pthreads but part
of realtime extensions) in LinuxThreads (sem_init, sem_wait, sem_trywait,
sem_post, sem_getvalue, sem_destroy) have convoy-avoiding logic? If it
does not, create a convoy and check the slowdown (with 5 or 10 processes).
Find the dispatch time (ie time for one process to be scheduled out and
another scheduled in, here actually threads). Contrast this with time required
to lock and unlock.
