Subject: Re: gmcgarry_ctxsw problems
To: Jason R Thorpe <thorpej@wasabisystems.com>
From: Gregory McGarry <g.mcgarry@ieee.org>
List: tech-kern
Date: 02/06/2003 12:04:52
Jason R Thorpe wrote:

> I've been looking at Greg's new context switch code on the above-mentioned
> branch, and have identified some problems with it:
> 
> 	1. sched_lock is released too early.  Specifically, it is released
> 	   before having completely switched away from the outgoing proc.
> 	   This is a race condition that will break MP systems (and has
> 	   in the past, until cpu_switch() was fixed on i386 and alpha).
> 
> 	2. It does not properly handle switching to an idle context.  On
> 	   UP systems, this means proc0's PCB.  On MP systems, this means
> 	   the CPU's idle PCB.  On the VAX, this means the CPU's interrupt
> 	   stack.
> 
> 	3. It doesn't not have any way to communicate the info that can
> 	   currently be passed between cpu_switch() and idle().  For the
> 	   most part, that means "remembering if we're switching to the
> 	   same process again" -- this is more complicated in MP systems.
> 
> For this reason, I think the approach taken by Greg's new code needs
> to be reexamined.  I think probably a better way to handle it is for
> cpu_switch() to actually call an MI C function to get the new process
> to switch to.  That is, leave it mostly the same as it is now, just
> replace the code that looks at the run queues with a function call.

Certainly I didn't completely consider that MP ports were switching to
an idle context.  The solution was bogus for that case.

I was trying to avoid a callback, only to simplify that cpu_switch()
does only the switch, nothing more.  I still like the idea of
cpu_idle(), only because it makes the code more readable.

A callback is what FreeBSD does.  I'm happy enough with that solution.
At least we can progress from there.

	-- Gregory McGarry <g.mcgarry@ieee.org>