Subject: Context switch revamp
To: None <>
From: Gregory McGarry <>
List: tech-kern
Date: 09/13/2002 08:33:39
I'm keen to separate the scheduler and the context switching
functionality.  This is useful for the following reasons:

	- simplifies the possibility of replacing the scheduler;
	- aligns better with the scheduler activations changes;
	- allows microtime optimisations if switching to self; and
	- cleans up the horrendous cpu_switch() code.

To achieve this, I propose changing the following function:

	 * void cpu_switch(struct proc *curp, struct proc *newp)
	 * Switch from process curp to process newp.  Scheduler
	 * lock must be held and interrupts disabled.

and the addition of the following functions:

	 * struct proc *chooseproc(void)
	 * Find a runnable process.  Wait if necessary.  Scheduler
	 * lock must be held.

	 * void cpu_idle(void)
	 * Idle.  Scheduler lock must be held and interrupts
	 * disabled.

With these changes I have been able to make chooseproc() largely
machine independent and push it up into mi_switch().  The ultimate
goal would be to push it even higher out of mi_switch().  I have
kept chooseproc() as an assembler routine ATM.

These changes are easy to do piecemeal.  So I suggest introducing
something like __HAVE_CHOOSEPROC to simplify a changeover for
each architecture.

I have done this successfully on i386 and mips.  A first-go
proof-of-concept for i386 is available at:

Shouldn't take much to get the patch going.  The i386 stuff still
needs a cleanup.  In fact, I think the i386 code is overly aggressive
with interrupt blocking, but its not clear what the run queue
requirements are with respect to interrupt protection.

I'm looking for a "Let's do it, clean it up", or a "I don't think so".

	-- Gregory McGarry <>