Subject: Saving current process state in locore.s
To: None <port-alpha@netbsd.org>
From: Jeff Roberson <nomad@nop.aliensystems.com>
List: port-alpha
Date: 12/19/1999 06:04:47
I was reading the code for cpu_switch in locore.s when I noticed the
following;  NetBSD saves the current process's context before checking the
run queue.  If the processes are the same then none of this is neccisary.
cpu_switch does check this before unloading/loading the vmspace.   I
believe the context switches would be faster if someone changed this.
Here are the cases which are evident to me:

1)  Switching from process X to process Y.  
No performance difference would happen here, because you have to do all of
the work anyway.

2)  Switching from process X to process X.  
You save 20 or so instructions.

3) Switching from idle loop to process Y.
You do the operations while a process is ready to run, instead of before a
process is ready to run, which delays it a bit. You could negate this by
waiting until you decide to idle to store the context so that you are
ready to load another, and you waste no time because the cpu would be idling anyway.

4) Switching back to process X after idling.  
Again, you save an extra 20 instructions. 

What case is the most common?  If we are switching to the same process
more often than not this would give us a boost.  Otherwise if we are going
from idle to another process more often this might not be so important.
Is there something I overlooked that prohibits this?  Or is it perhaps
such a negligable performance difference that no one else cares? :-)

Jeff