source: rtems/cpukit/score/src/threadstartmultitasking.c @ d19cce29

4.115
Last change on this file since d19cce29 was d19cce29, checked in by Sebastian Huber <sebastian.huber@…>, on 08/05/13 at 12:54:11

score: Per-CPU thread dispatch disable level

Use a per-CPU thread dispatch disable level. So instead of one global
thread dispatch disable level we have now one instance per processor.
This is a major performance improvement for SMP. On non-SMP
configurations this may simplifiy the interrupt entry/exit code.

The giant lock is still present, but it is now decoupled from the thread
dispatching in _Thread_Dispatch(), _Thread_Handler(),
_Thread_Restart_self() and the interrupt entry/exit. Access to the
giant lock is now available via _Giant_Acquire() and _Giant_Release().
The giant lock is still implicitly acquired via
_Thread_Dispatch_decrement_disable_level().

The giant lock is only acquired for high-level operations in interrupt
handlers (e.g. release of a semaphore, sending of an event).

As a side-effect this change fixes the lost thread dispatch necessary
indication bug in _Thread_Dispatch().

A per-CPU thread dispatch disable level greatly simplifies the SMP
support for the interrupt entry/exit code since no spin locks have to be
acquired in this area. It is only necessary to get the current
processor index and use this to calculate the address of the own per-CPU
control. This reduces the interrupt latency considerably.

All elements for the interrupt entry/exit code are now part of the
Per_CPU_Control structure: thread dispatch disable level, ISR nest level
and thread dispatch necessary. Nothing else is required (except CPU
port specific stuff like on SPARC).

  • Property mode set to 100644
File size: 2.1 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.com/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( Context_Control *context )
24{
25  Per_CPU_Control *self_cpu = _Per_CPU_Get();
26  Thread_Control  *heir = self_cpu->heir;
27
28#if defined(RTEMS_SMP)
29  _Per_CPU_Change_state( self_cpu, PER_CPU_STATE_UP );
30
31  _Per_CPU_Acquire( self_cpu );
32
33  self_cpu->executing->is_executing = false;
34  heir->is_executing = true;
35#endif
36
37  self_cpu->dispatch_necessary = false;
38  self_cpu->executing = heir;
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#if defined(RTEMS_SMP)
63  if ( context != NULL ) {
64#endif
65
66#if defined(_CPU_Start_multitasking)
67    _CPU_Start_multitasking( context, &heir->Registers );
68#else
69    _Context_Switch( context, &heir->Registers );
70#endif
71
72#if defined(RTEMS_SMP)
73  } else {
74    /*
75     * Threads begin execution in the _Thread_Handler() function.   This
76     * function will set the thread dispatch disable level to zero and calls
77     * _Per_CPU_Release().
78     */
79    self_cpu->thread_dispatch_disable_level = 1;
80
81    _CPU_Context_switch_to_first_task_smp( &heir->Registers );
82  }
83#endif
84}
Note: See TracBrowser for help on using the repository browser.