Referring to (both sparc and intel x86) have the same algorithm of
using the idle thread:

http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/sun4/ml/swtch.s#53

     74 /* ARGSUSED */
     75 void
     76 resume(kthread_id_t t)

<....>

    160
    161         !
    162         ! Temporarily switch to idle thread's stack
    163         !
    164         ldn     [%i1 + CPU_IDLE_THREAD], %o0    ! idle thread pointer
    165         ldn     [%o0 + T_SP], %o1               ! get onto idle thread 
stack
    166         sub     %o1, SA(MINFRAME), %sp          ! save room for ins and 
locals
    167         clr     %fp
    168
    169         !
    170         ! Set the idle thread as the current thread
    171         !
    172         mov     THREAD_REG, %l3                 ! save %g7 (current 
thread)
    173         mov     %o0, THREAD_REG                 ! set %g7 to idle
    174         stn     %o0, [%i1 + CPU_THREAD]         ! set CPU's thread to 
idle
    175
    176         !
    177         ! Clear and unlock previous thread's t_lock
    178         ! to allow it to be dispatched by another processor.
    179         !
    180         clrb    [%l3 + T_LOCK]                  ! clear tp->t_lock
    181
    182         !


My question is:   why is process switching involving the idle thread?
 ie, why can't we just switch directly from the old to new thread?

I asked this, because in Linux Kernel, it also involved three process
in any process switch.   But I had difficulty understanding its
reason...which as the author of Understanding the Linux Kernel
mentioned as "not easy" to understand.

(http://www.mail-archive.com/kernelnewbies at nl.linux.org/msg07344.html)

Why the added complexity?   Hopefully the answer for Opensolaris will
help me to understand that of Linux Kernel.

Thanks.

Reply via email to