Threads

Bhosle, Mayur N mbhosle3 at gatech.edu
Wed Sep 24 21:59:30 PDT 2008


----- Original Message -----
From: Matthew Dillon <dillon at apollo.backplane.com>
Sent: Thu, 25 Sep 2008 00:37:45 -0400 (EDT)
Subject: Re: Threads


:Hi Everyone,
:             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?

    Yes.

: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
    back in.

    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.
:Mayur

    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
    spin locks.

    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.

					-Matt
					Matthew Dillon 
					<dillon at backplane.com>

Thanks. Regarding MP Lock, i was actually going through lwkt_switch() function
in lwkt_thread.c. there mpheld is used and MP_LOCK_HELD()assign value to that variable. The 
paragraph above it tries to explain it, but it confused me.

So i was asking when MP Lock comes into play? when to check if mp lock is held or not and so on.

--Mayur






More information about the Kernel mailing list