source: rtems/cpukit/score/src/threaddispatch.c @ c6f7e060

4.104.115
Last change on this file since c6f7e060 was c6f7e060, checked in by Glenn Humphrey <glenn.humphrey@…>, on 12/02/09 at 18:15:16

2009-12-02 Glenn Humphrey <glenn.humphrey@…>

  • configure.ac, libcsupport/src/times.c, libmisc/cpuuse/cpuusagedata.c, libmisc/cpuuse/cpuusagereport.c, libmisc/cpuuse/cpuusagereset.c, rtems/include/rtems/rtems/ratemon.h, rtems/include/rtems/rtems/types.h, rtems/src/ratemongetstatistics.c, rtems/src/ratemongetstatus.c, rtems/src/ratemonperiod.c, rtems/src/ratemonreportstatistics.c, score/include/rtems/score/thread.h, score/src/threaddispatch.c, score/src/threadinitialize.c, score/src/threadtickletimeslice.c: Changed the configuration of statistics granularity to use just one define.
  • Property mode set to 100644
File size: 4.8 KB
Line 
1/*
2 *  Thread Handler
3 *
4 *
5 *  COPYRIGHT (c) 1989-2007.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems/system.h>
20#include <rtems/score/apiext.h>
21#include <rtems/score/context.h>
22#include <rtems/score/interr.h>
23#include <rtems/score/isr.h>
24#include <rtems/score/object.h>
25#include <rtems/score/priority.h>
26#include <rtems/score/states.h>
27#include <rtems/score/sysstate.h>
28#include <rtems/score/thread.h>
29#include <rtems/score/threadq.h>
30#include <rtems/score/userext.h>
31#include <rtems/score/wkspace.h>
32
33#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
34  #include <rtems/score/timestamp.h>
35#endif
36
37/*PAGE
38 *
39 *  _Thread_Enable_dispatch
40 *
41 *  This kernel routine exits a context switch disable critical section.
42 *  This is the NOT INLINED version.
43 *
44 *  Input parameters:  NONE
45 *
46 *  Output parameters:  NONE
47 *
48 *  INTERRUPT LATENCY:
49 *    dispatch thread
50 *    no dispatch thread
51 */
52
53#if ( (defined(CPU_INLINE_ENABLE_DISPATCH) &&  \
54       (CPU_INLINE_ENABLE_DISPATCH == FALSE)) || \
55      (__RTEMS_DO_NOT_INLINE_THREAD_ENABLE_DISPATCH__ == 1) )
56void _Thread_Enable_dispatch( void )
57{
58  if ( --_Thread_Dispatch_disable_level )
59    return;
60  _Thread_Dispatch();
61}
62#endif
63
64/*PAGE
65 *
66 *  _Thread_Dispatch
67 *
68 *  This kernel routine determines if a dispatch is needed, and if so
69 *  dispatches to the heir thread.  Once the heir is running an attempt
70 *  is made to dispatch any ASRs.
71 *
72 *  ALTERNATE ENTRY POINTS:
73 *    void _Thread_Enable_dispatch();
74 *
75 *  Input parameters:  NONE
76 *
77 *  Output parameters:  NONE
78 *
79 *  INTERRUPT LATENCY:
80 *    dispatch thread
81 *    no dispatch thread
82 */
83
84void _Thread_Dispatch( void )
85{
86  Thread_Control   *executing;
87  Thread_Control   *heir;
88  ISR_Level         level;
89
90  executing   = _Thread_Executing;
91  _ISR_Disable( level );
92  while ( _Context_Switch_necessary == true ) {
93    heir = _Thread_Heir;
94    _Thread_Dispatch_disable_level = 1;
95    _Context_Switch_necessary = false;
96    _Thread_Executing = heir;
97#if __RTEMS_ADA__
98    executing->rtems_ada_self = rtems_ada_self;
99    rtems_ada_self = heir->rtems_ada_self;
100#endif
101    if ( heir->budget_algorithm == THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE )
102      heir->cpu_time_budget = _Thread_Ticks_per_timeslice;
103    _ISR_Enable( level );
104
105    #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
106      {
107        Timestamp_Control uptime, ran;
108        _TOD_Get_uptime( &uptime );
109        _Timestamp_Subtract(
110          &_Thread_Time_of_last_context_switch,
111          &uptime,
112          &ran
113        );
114        _Timestamp_Add_to( &executing->cpu_time_used, &ran );
115        _Thread_Time_of_last_context_switch = uptime;
116      }
117    #else
118      heir->cpu_time_used++;
119    #endif
120
121    /*
122     * Switch libc's task specific data.
123     */
124    if ( _Thread_libc_reent ) {
125      executing->libc_reent = *_Thread_libc_reent;
126      *_Thread_libc_reent = heir->libc_reent;
127    }
128
129    _User_extensions_Thread_switch( executing, heir );
130
131    /*
132     *  If the CPU has hardware floating point, then we must address saving
133     *  and restoring it as part of the context switch.
134     *
135     *  The second conditional compilation section selects the algorithm used
136     *  to context switch between floating point tasks.  The deferred algorithm
137     *  can be significantly better in a system with few floating point tasks
138     *  because it reduces the total number of save and restore FP context
139     *  operations.  However, this algorithm can not be used on all CPUs due
140     *  to unpredictable use of FP registers by some compilers for integer
141     *  operations.
142     */
143
144#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
145#if ( CPU_USE_DEFERRED_FP_SWITCH != TRUE )
146    if ( executing->fp_context != NULL )
147      _Context_Save_fp( &executing->fp_context );
148#endif
149#endif
150
151    _Context_Switch( &executing->Registers, &heir->Registers );
152
153#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
154#if ( CPU_USE_DEFERRED_FP_SWITCH == TRUE )
155    if ( (executing->fp_context != NULL) &&
156         !_Thread_Is_allocated_fp( executing ) ) {
157      if ( _Thread_Allocated_fp != NULL )
158        _Context_Save_fp( &_Thread_Allocated_fp->fp_context );
159      _Context_Restore_fp( &executing->fp_context );
160      _Thread_Allocated_fp = executing;
161    }
162#else
163    if ( executing->fp_context != NULL )
164      _Context_Restore_fp( &executing->fp_context );
165#endif
166#endif
167
168    executing = _Thread_Executing;
169
170    _ISR_Disable( level );
171  }
172
173  _Thread_Dispatch_disable_level = 0;
174
175  _ISR_Enable( level );
176
177  if ( _Thread_Do_post_task_switch_extension ||
178       executing->do_post_task_switch_extension ) {
179    executing->do_post_task_switch_extension = false;
180    _API_extensions_Run_postswitch();
181  }
182
183}
Note: See TracBrowser for help on using the repository browser.