Page 1 of 1
UNIX V6 Process Switch
Posted: Wed May 15, 2013 12:39 pm
by mghis
Hello.
I am reading the Lions' Commentary to Sixth Edition UNIX and I'm a bit perplexed about the clock() function (line 3725 in the Commentary printout). clock() gets called when the timer interrupt is fired. I assumed it would directly perform a context switch, calling sleep() or swtch(), but it doesn't. Using clock interrupt is the sole way I can think of to get reliable context switching and prevent the computer from being locked in a tight loop if a user process does a "br ." instruction.
Could anyone clarify this point?
--mghis
PS: Please forgive me for my poor English. I'm not a native speaker.
Re: UNIX V6 Process Switch
Posted: Wed May 15, 2013 1:48 pm
by bluemoon
It's better to think PIT or APIC timer is just one of the sources to interrupt a process, other sources may include IRQ from keyboard, mouse, NIC or disk controller.
So, when these source interrupt a process, get into kernel to perform necessary handling, upon return the system may:
1. resume process
1a. optionally adjust priority of current process or the process blocking for such event.
2. reschedule new process
By the way, a tight loop is not locking up a system, although it may make your computer not responsive or catch fire.
Re: UNIX V6 Process Switch
Posted: Wed May 15, 2013 2:22 pm
by mghis
@bluemoon: Thank you for your reply. So you think that Sixth Edition UNIX didn't use the clock to interrupt the running process? Can you point me to the most used swtch()s in the kernel? I have found some in I/O operations. Do you think that they suffice and a process was switched only if it performed such an operation?
By the way, I can say with reasonable confidence that UNIX couldn't be locked up by a single process, neither it could "being unresponsive or catch fire"
. And I'm not sure I can explain this if the clock interrupt couldn't switch process.
Re: UNIX V6 Process Switch
Posted: Thu May 16, 2013 11:00 am
by mghis
Don't mind. I think I got it. swtch() gets called before entering the clock() function. In fact, interrupt vector of the clocks at 0100 and 0104 (lines 534-535 of printout) have the address of a "kwlp" label, which is at line 570, and before calling _clock (clock() in C -- leading underscore) does a subroutine jump to "call" label (jsr instruction). "call" is a convenience subroutine called for any hardware trap, and begins at line 776. After testing some values, (if there are runnable processes), call does at line 0791 a subroutine jump to _swtch, which perform the context switch.
Please tell me if I'm wrong.