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

4.8
Last change on this file since b72e847b was c3330a8, checked in by Joel Sherrill <joel.sherrill@…>, on 05/17/07 at 22:46:45

2007-05-17 Joel Sherrill <joel.sherrill@…>

  • ChangeLog?, configure.ac, libcsupport/src/times.c, libmisc/cpuuse/cpuuse.c, libmisc/stackchk/check.c, rtems/include/rtems/rtems/ratemon.h, rtems/src/ratemongetstatus.c, rtems/src/ratemonperiod.c, rtems/src/ratemonreportstatistics.c, rtems/src/ratemonresetall.c, rtems/src/ratemontimeout.c, score/Makefile.am, score/include/rtems/score/thread.h, score/include/rtems/score/timespec.h, score/src/threaddispatch.c, score/src/threadinitialize.c, score/src/threadtickletimeslice.c, score/src/timespecdivide.c: Add nanoseconds granularity to the rate monotonic period statistics and CPU usage statistics. This capability is enabled by default although may be conditionally disabled by the user. It could be too much overhead on small targets but it does not appear to be bad in early testing. Its impact on code size has not been evaluated either. It is possible that both forms of statistics gathering could be disabled with further tweaking of the conditional compilation.
  • score/src/timespecdividebyinteger.c: New file.
  • Property mode set to 100644
File size: 4.4 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#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
34
35  #include <rtems/score/timespec.h>
36#endif
37
38/*PAGE
39 *
40 *  _Thread_Dispatch
41 *
42 *  This kernel routine determines if a dispatch is needed, and if so
43 *  dispatches to the heir thread.  Once the heir is running an attempt
44 *  is made to dispatch any ASRs.
45 *
46 *  ALTERNATE ENTRY POINTS:
47 *    void _Thread_Enable_dispatch();
48 *
49 *  Input parameters:  NONE
50 *
51 *  Output parameters:  NONE
52 *
53 *  INTERRUPT LATENCY:
54 *    dispatch thread
55 *    no dispatch thread
56 */
57
58#if ( CPU_INLINE_ENABLE_DISPATCH == FALSE )
59void _Thread_Enable_dispatch( void )
60{
61  if ( --_Thread_Dispatch_disable_level )
62    return;
63  _Thread_Dispatch();
64}
65#endif
66
67void _Thread_Dispatch( void )
68{
69  Thread_Control   *executing;
70  Thread_Control   *heir;
71  ISR_Level         level;
72
73  executing   = _Thread_Executing;
74  _ISR_Disable( level );
75  while ( _Context_Switch_necessary == TRUE ) {
76    heir = _Thread_Heir;
77    _Thread_Dispatch_disable_level = 1;
78    _Context_Switch_necessary = FALSE;
79    _Thread_Executing = heir;
80    executing->rtems_ada_self = rtems_ada_self;
81    rtems_ada_self = heir->rtems_ada_self;
82    if ( heir->budget_algorithm == THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE )
83      heir->cpu_time_budget = _Thread_Ticks_per_timeslice;
84    _ISR_Enable( level );
85
86    #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
87      {
88        struct timespec uptime, ran;
89        _TOD_Get_uptime( &uptime );
90        _Timespec_Subtract(&_Thread_Time_of_last_context_switch, &uptime, &ran);
91        _Timespec_Add_to( &executing->cpu_time_used, &ran );
92        _Thread_Time_of_last_context_switch = uptime;
93      }
94    #else
95      heir->ticks_executed++;
96    #endif
97
98    /*
99     * Switch libc's task specific data.
100     */
101    if ( _Thread_libc_reent ) {
102      executing->libc_reent = *_Thread_libc_reent;
103      *_Thread_libc_reent = heir->libc_reent;
104    }
105
106    _User_extensions_Thread_switch( executing, heir );
107
108    /*
109     *  If the CPU has hardware floating point, then we must address saving
110     *  and restoring it as part of the context switch.
111     *
112     *  The second conditional compilation section selects the algorithm used
113     *  to context switch between floating point tasks.  The deferred algorithm
114     *  can be significantly better in a system with few floating point tasks
115     *  because it reduces the total number of save and restore FP context
116     *  operations.  However, this algorithm can not be used on all CPUs due
117     *  to unpredictable use of FP registers by some compilers for integer
118     *  operations.
119     */
120
121#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
122#if ( CPU_USE_DEFERRED_FP_SWITCH != TRUE )
123    if ( executing->fp_context != NULL )
124      _Context_Save_fp( &executing->fp_context );
125#endif
126#endif
127
128    _Context_Switch( &executing->Registers, &heir->Registers );
129
130#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
131#if ( CPU_USE_DEFERRED_FP_SWITCH == TRUE )
132    if ( (executing->fp_context != NULL) &&
133         !_Thread_Is_allocated_fp( executing ) ) {
134      if ( _Thread_Allocated_fp != NULL )
135        _Context_Save_fp( &_Thread_Allocated_fp->fp_context );
136      _Context_Restore_fp( &executing->fp_context );
137      _Thread_Allocated_fp = executing;
138    }
139#else
140    if ( executing->fp_context != NULL )
141      _Context_Restore_fp( &executing->fp_context );
142#endif
143#endif
144
145    executing = _Thread_Executing;
146
147    _ISR_Disable( level );
148  }
149
150  _Thread_Dispatch_disable_level = 0;
151
152  _ISR_Enable( level );
153
154  if ( _Thread_Do_post_task_switch_extension ||
155       executing->do_post_task_switch_extension ) {
156    executing->do_post_task_switch_extension = FALSE;
157    _API_extensions_Run_postswitch();
158  }
159
160}
Note: See TracBrowser for help on using the repository browser.