Thread Execution Control

Sebastian Huber sebastian.huber at
Wed Nov 20 12:19:36 UTC 2013


the following text tries to explain a problem with the current SMP 
implementation and presents one possible solution.

==== Thread Execution Control ====

Currently threads are assigned to processors for execution by the scheduler
responsible for this thread.  It is unknown to the system when a thread
actually starts or terminates execution.  The termination event is important
for the following features
* explicit thread migration, e.g. if a thread should move from one scheduler 
domain to another,
* thread deletion, since the thread stack is in use until the thread stopped 
execution, or
* restart of threads executing on a remote processor.

One approach could be to spin on the per-processor variable reflecting the
executing thread.  This has at least two problems
# it doesn't work if the executing thread wants to alter its own state, and
# this spinning must be done with the scheduler lock held and interrupts 
disabled, this is a disaster for the interrupt latency,

The proposed solution is to use an optional event handler which is active in
case the thread execution termination matters.  In _Thread_Dispatch() we have
already the post-switch extensions invoked after a thread switch.  The only
restriction is here that we cannot block since the executing thread might be an
idle thread and it would be dramatic for the thread dispatch latency.  We can
now on demand prepend an event handler to the post-switch extensions and perform
the actions necessary after the thread of interest stopped execution.
Currently the post-switch extensions are registered in a global list, but we
have to introduce per-processor lists for our purpose.  This gives rise to
locking issues.  We have to consider the following requirements
* prepending to and removal from the list should be performed under protection 
of the per-processor lock,
* forward iteration through the list should be possible without locking (atomic 
operations are required here),
* removal of nodes during iteration must be possible,
* it is acceptable that nodes added after iteration begin are not visited 
during the iteration in progress.

The execution time of post-switch event handlers increases the worst-case
thread dispatch latency.

On demand post-switch handlers help to implement the Multiprocessor Resource
Sharing Protocol (MrsP) proposed by Burns and Wellings.  Threads executing a
global critical section can add a post-switch handler which will trigger the
thread migration in case of pre-emption by a local high-priority thread.

Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber at
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.

More information about the devel mailing list