Você está na página 1de 3

EECS 343: Homework 2

Processes and Threads

Fall 2010

Important Dates
Out: October 12, 2010.

Due: October 19, 2010, 11:59PM CDT.

Submitting your assignment: Please use the course submission site. There is a link to it from the class site.
Submit only ASCII text files.

xv6

Most homework assignments will have a section on xv6, an x86-based re-implementation of UNIX v6 that we will
read during the course. In this particular assignment you will investigate how xv6 kernel switches between two
processes. You may want to read the chapters on processes and scheduling found in the xv6 site (link available
from the course website - http://pdos.csail.mit.edu/6.828/2009/xv6-book/index.html#v6); be careful
that the line numbers may not match.
Suppose a process that is running in the kernel calls sched(), which ends up jumping into scheduler().

Turn in: Where is the stack that sched() executes on?

Turn in: Where is the stack that scheduler() executes on?

Turn in: When sched() calls swtch(), does that call to swtch() ever return? If so, when?
Surround the call to swtch() in scheduler() with calls to cprintf() like this:

cprintf("A:");
swtch(&cpu->scheduler, &proc->context);
cprintf("B:");

Similarly, surround the call to swtch() in sched() with calls to cprintf() like this:

1
Process Priority ERT
A 3 10
B 5 6
C 2 2
D 1 4
E 4 8

cprintf("C:");
swtch(&proc->context, cpu->scheduler);
cprintf("D:");

Rebuild your kernel and boot it on QEMU. With a few exceptions you should see a regular four-character
pattern repeated over and over.

Turn in: What is the four-character pattern?

Turn in: The very first characters are ”A:C:”. Why does this happen?

Problems
1. If a multithreaded process forks, a problem occurs if the child gets copies of all the parent’s threads. Suppose
that one of the original threads was waiting for keyboard input. Now two threads are waiting for keyboard
input, one in each process. Does this problem ever occur in single-threaded processes?

2. Measurements of a certain system have shown that the average process runs for a time T before blocking for
I/O. A process switch requires a time S, which is effectively wasted (overhead). For round-robin scheduling
with quantum Q, give a formula for the CPU efficiency for each of the following.

(a) Q = ∞
(b) Q > T
(c) S < Q < T
(d) Q = S
(e) Q → 0

3. Consider the following set of processes with the indicated (externally determined) priorities (5 being the
highest). For each of the following scheduling algorithms, determine the mean process turnaround time and
mean waiting time. Ignore process switching overhead.

(a) Round Robin


(b) Priority scheduling
(c) First-Come, First-Served (run in alphabetical order)
(d) Shortest Job First

For (a), assume that the system is multiprogrammed, and that each job gets its fair share of the CPU. For
(b) through (d) assume that jobs run one at a time, until completion. All jobs are completely CPU bound.

2
4. Can two threads in the same process synchronize using a kernel semaphore if the threads are implemented
by the kernel? What if they are implemented in user space? Assume that no threads in any other processes
have access to the semaphores.
5. Show that, if the wait() and signal() semaphore operations are not executed atomically, then mutual
exclusion may be violated.

Você também pode gostar