12/01/2006


Apparently, yesterday's email was not clear to everyone.
A student wrote to my TA, who kicked it to me:

        Dr. Patt,

        Here's an email that a student sent me about interrupts. It's a little
        involved but I think it's a pretty smart question. I have my opinion about
        it but I wanted to be sure, so I thought I would forward it to you.

        Thank you and have a good weekend,
        <<name withheld to protect the reputation of the TA>>

        ---------------------------- Original Message ----------------------------

        hey,
         so here goes the email about the question i asked in the ta session
        earlier today...just to remind you it was about what would happen if you
        had a...well for instance: priority level 1 program running, then a level
        8 caused the level one to be pushed on the stack, then a level 5 wanted
        to run when the level 8 was still executing--the level 5 is pushed on the
        stack, then a level 4 wants to run (the level 8 is still executing) so it
        gets pushed on the stack....so the problem is that they are out of order
        on the stack--from top to bottom of the stack level 4, level 5, then the
        level 1....so when the level 8 finishes (assuming no other programs try
        to interupt) the stack will be popped and the level 4 will execute before
        the level 5....

        feel free to forward this to dr patt...he will probably send it out to
        the entire class with your/his reply

        <<name withheld to protect the student who knew I would send this to the class>>

The point that you are missing is: When does the process gets pushed onto the stack?
Recall my answer to the question yesterday -- that the interrupt signal persists 
until the interrupting process gets initiated, at which point it start executing.

So, in this context, let us take the example the student raised (repeated here), 
and go through it step by step:

                priority level 1 program running, then a level
                8 caused the level one to be pushed on the stack, 

So we have the level 8 running, and level 1 on the stack.

                then a level 5 wanted to run when the level 8 was 
                still executing--the level 5 is pushed on the stack, 

Ooops.  NO!  The level 5 is not pushed on the stack.  The level 5 is ignored
since its priority is less than the priority of the level 8 that is running.
The good news is that the interrupt signal from the level 5 continues to be
asserted.

                then a level 4 wants to run (the level 8 is still executing) so it
                gets pushed on the stack

No, the process state (PC and PSR) only get pushed on the stack if (a) it is
executing, and (b) a higher priority interrupt pre-empts it.  So, the level 4
is ignored, but it continues to assert its interrupt signal.  So, we have level 8
running and level 1 on the stack.

                ....so the problem is that they are out of order
                on the stack--from top to bottom of the stack level 4, level 5, 
                then the level 1....so when the level 8 finishes (assuming no other 
                programs try to interupt) the stack will be popped and the level 4 
                will execute before the level 5....

Nope!  When level 8 finishes with the RTI, the stack is popped and the level 1 is
ready to execute.  However, the interrupt signals from the level 4 and level 5 are
still being asserted.

Since level 5 is higher than level 1 and level 4, level 1 gets pushed back onto the 
stack, level 5 executes, and level 4 just sits there continuing to assert its
interrupt signal.  When level 5 finishes, level 1 is popped, but since level 4 is still
asserted, level 1 is again pushed, and level 4 executes.  When level 4 finishes,
level 1
is again popped and this time it can execute.

Two things are important to remember:  (1) The interrupt persists until it is
handled, and (2) a process gets pushed on the stack if (a) it running and (b) a
higher level process wants to interrupt it.  The operative word here is IF IT IS
RUNNING.

Hope this helps.

Yale Patt