Difference between revisions of "Xv6 homework 8"

From Computer History Wiki
Jump to: navigation, search
(Created page with "Since this has gone missing... <pre> Lecture 8 homework: Threads and Context Switching Handed out: Wednesday, September 28, 2005 Due: Wednesday, October 5, 2005 Read: setjmp.S ...")
 
m (+cat)
 
Line 53: Line 53:
 
   setjmp in scheduler returned 0; longjmp
 
   setjmp in scheduler returned 0; longjmp
 
but then some lines seem to be missing: this first longjmp does not behave like the others.
 
but then some lines seem to be missing: this first longjmp does not behave like the others.
 +
 
Turn in: In the repeated six-line pattern, where does the longjmp in the scheduler return to (which line number in the printout)? Where does the very first longjmp in the scheduler return to (which line number in the printout)?
 
Turn in: In the repeated six-line pattern, where does the longjmp in the scheduler return to (which line number in the printout)? Where does the very first longjmp in the scheduler return to (which line number in the printout)?
  
 
(Feel free to set a breakpoint at the return statement in longjmp to answer this question.)
 
(Feel free to set a breakpoint at the return statement in longjmp to answer this question.)
  
This completes the homework.</pre>
+
This completes the homework.
 +
 
 +
</pre>
 +
 
 +
[[Category: Documentation]]

Latest revision as of 15:02, 30 December 2018

Since this has gone missing...

Lecture 8 homework: Threads and Context Switching

Handed out: Wednesday, September 28, 2005
Due: Wednesday, October 5, 2005
Read: setjmp.S and proc.c (focus on the code that switches between processes, specifically scheduler and sched).

Hand-In Procedure

You are to turn in this homework during lecture. Please write up your answers to the exercises below and hand them in to a 6.828 staff member by the end of the lecture.

Introduction

In this homework you will investigate how the kernel switches between two processes.

Assignment:

In proc.c's scheduler there are two lines:

      if(setjmp(&cpus[cpu()].jmpbuf) == 0)
        longjmp(&p->jmpbuf);
Replace these with:
      cprintf("setjmp called in scheduler\n");
      if(setjmp(&cpus[cpu()].jmpbuf) == 0){
        cprintf("setjmp in scheduler returned 0; longjmp\n");
        longjmp(&p->jmpbuf);
      }else
        cprintf("setjmp in scheduler returned 1\n");
Similarly, in sched, replace:

  if(setjmp(&p->jmpbuf) == 0)
    longjmp(&cpus[cpu()].jmpbuf);
with
  cprintf("setjmp called in sched\n");
  if(setjmp(&p->jmpbuf) == 0){
    cprintf("setjmp in sched returned 0; longjmp\n");
    longjmp(&cpus[cpu()].jmpbuf);
  }else
    cprintf("setjmp in sched returned 1\n");
Rebuild your kernel and boot it on bochs. You will get around 150 printed lines about setjmp as the kernel boots.

For now, ignore the first few lines of output. You should see a regular six-line pattern repeated over and over in the printed lines.

Turn in: What is the six-line pattern? (The first line is setjmp called in scheduler.)

Turn in: Why are there two setjmp returned prints for each setjmp called print?

Now look at the first three lines of output about setjmp. You will notice that they do not follow the pattern. The first two lines are:

  setjmp called in scheduler
  setjmp in scheduler returned 0; longjmp
but then some lines seem to be missing: this first longjmp does not behave like the others.

Turn in: In the repeated six-line pattern, where does the longjmp in the scheduler return to (which line number in the printout)? Where does the very first longjmp in the scheduler return to (which line number in the printout)?

(Feel free to set a breakpoint at the return statement in longjmp to answer this question.)

This completes the homework.