dillon at apollo.backplane.com
Wed Sep 24 21:42:47 PDT 2008
: I had few doubts regarding the following things.
:1. Is it correct that a process can have multiple LWPs and for each LWP
: there is a LWKT created?
:2. The function crit_enter is called so that preemption is disabled, but
: it says synchronous switching and blocking, what does this mean?
It means that the thread can go to sleep (aka call tsleep()) while
holding a critical section. It can also explicitly yield to another
thread. The critical section will be atomically released when the
thread is switched away and re-acquired when the thread is switched
The preemption protection only applies to the current cpu,
interrupts and threads may continue to run on other cpus.
:3. Can anyone suggest some documentation regarding, when to use MPLOCK?
: Thanks and looking forward for the reply.
The answer to this depends on the context. What kind of code are
we talking about here, the usched_*() functions?
If we are talking about the usched API, it is expected to be MP-SAFE,
meaning it cannot make assumptions as to the state of the MP lock
and in general should not try to acquire or release it. Any global
queues (shared amoungst all the cpus) would have to be protected with
Taking usched_bsd4.c as an example, it does call rel_mplock() once
at the beginning of sched_thread(), but only because that thread
is started with the MP lock held. We could clean that up and start
the thread without it held. It then uses the bsd4_spin spin-lock
in places where it accesses the global data structures.
<dillon at backplane.com>
More information about the Kernel