source: rtems/cpukit/score/src/threadstartmultitasking.c @ 25f5730f

4.11
Last change on this file since 25f5730f was 38b59a6, checked in by Sebastian Huber <sebastian.huber@…>, on May 2, 2014 at 8:31:09 AM

score: Implement forced thread migration

The current implementation of task migration in RTEMS has some
implications with respect to the interrupt latency. It is crucial to
preserve the system invariant that a task can execute on at most one
processor in the system at a time. This is accomplished with a boolean
indicator in the task context. The processor architecture specific
low-level task context switch code will mark that a task context is no
longer executing and waits that the heir context stopped execution
before it restores the heir context and resumes execution of the heir
task. So there is one point in time in which a processor is without a
task. This is essential to avoid cyclic dependencies in case multiple
tasks migrate at once. Otherwise some supervising entity is necessary to
prevent life-locks. Such a global supervisor would lead to scalability
problems so this approach is not used. Currently the thread dispatch is
performed with interrupts disabled. So in case the heir task is
currently executing on another processor then this prolongs the time of
disabled interrupts since one processor has to wait for another
processor to make progress.

It is difficult to avoid this issue with the interrupt latency since
interrupts normally store the context of the interrupted task on its
stack. In case a task is marked as not executing we must not use its
task stack to store such an interrupt context. We cannot use the heir
stack before it stopped execution on another processor. So if we enable
interrupts during this transition we have to provide an alternative task
independent stack for this time frame. This issue needs further
investigation.

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Start Thread Multitasking
5 *  @ingroup ScoreThread
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2006.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/score/threadimpl.h>
22
23void _Thread_Start_multitasking( void )
24{
25  Per_CPU_Control *cpu_self = _Per_CPU_Get();
26  Thread_Control  *heir;
27
28#if defined(RTEMS_SMP)
29  _Per_CPU_State_change( cpu_self, PER_CPU_STATE_UP );
30
31  /*
32   * Threads begin execution in the _Thread_Handler() function.   This
33   * function will set the thread dispatch disable level to zero.
34   */
35  cpu_self->thread_dispatch_disable_level = 1;
36#endif
37
38  heir = _Thread_Get_heir_and_make_it_executing( cpu_self );
39
40   /*
41    * Get the init task(s) running.
42    *
43    * Note: Thread_Dispatch() is normally used to dispatch threads.  As
44    *       part of its work, Thread_Dispatch() restores floating point
45    *       state for the heir task.
46    *
47    *       This code avoids Thread_Dispatch(), and so we have to restore
48    *       (actually initialize) the floating point state "by hand".
49    *
50    *       Ignore the CPU_USE_DEFERRED_FP_SWITCH because we must always
51    *       switch in the first thread if it is FP.
52    */
53#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
54   /*
55    *  don't need to worry about saving BSP's floating point state
56    */
57
58   if ( heir->fp_context != NULL )
59     _Context_Restore_fp( &heir->fp_context );
60#endif
61
62  _Profiling_Thread_dispatch_disable( cpu_self, 0 );
63
64#if defined(_CPU_Start_multitasking)
65  _CPU_Start_multitasking( &heir->Registers );
66#else
67  _CPU_Context_Restart_self( &heir->Registers );
68#endif
69}
Note: See TracBrowser for help on using the repository browser.