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

4.104.114.84.95
Last change on this file since ca7858bb was ca7858bb, checked in by Joel Sherrill <joel.sherrill@…>, on Jul 26, 2000 at 7:28:11 PM

Port of RTEMS to the Texas Instruments C3x/C4x DSP families including
a BSP (c4xsim) supporting the simulator included with gdb. This port
was done by Joel Sherrill and Jennifer Averett of OAR Corporation.
Also included with this port is a space/time optimization to eliminate
FP context switch management on CPUs without hardware or software FP.

An issue with this port was that sizeof(unsigned32) = sizeof(unsigned8)
on this CPU. This required addressing alignment checks and assumptions
as well as fixing code that assumed sizeof(unsigned32) == 4.

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 *  Thread Handler
3 *
4 *
5 *  COPYRIGHT (c) 1989-1999.
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.OARcorp.com/rtems/license.html.
11 *
12 *  $Id$
13 */
14
15#include <rtems/system.h>
16#include <rtems/score/apiext.h>
17#include <rtems/score/context.h>
18#include <rtems/score/interr.h>
19#include <rtems/score/isr.h>
20#include <rtems/score/object.h>
21#include <rtems/score/priority.h>
22#include <rtems/score/states.h>
23#include <rtems/score/sysstate.h>
24#include <rtems/score/thread.h>
25#include <rtems/score/threadq.h>
26#include <rtems/score/userext.h>
27#include <rtems/score/wkspace.h>
28
29/*PAGE
30 *
31 *  _Thread_Dispatch
32 *
33 *  This kernel routine determines if a dispatch is needed, and if so
34 *  dispatches to the heir thread.  Once the heir is running an attempt
35 *  is made to dispatch any ASRs.
36 *
37 *  ALTERNATE ENTRY POINTS:
38 *    void _Thread_Enable_dispatch();
39 *
40 *  Input parameters:  NONE
41 *
42 *  Output parameters:  NONE
43 *
44 *  INTERRUPT LATENCY:
45 *    dispatch thread
46 *    no dispatch thread
47 */
48
49#if ( CPU_INLINE_ENABLE_DISPATCH == FALSE )
50void _Thread_Enable_dispatch( void )
51{
52  if ( --_Thread_Dispatch_disable_level )
53    return;
54  _Thread_Dispatch();
55}
56#endif
57
58void _Thread_Dispatch( void )
59{
60  Thread_Control   *executing;
61  Thread_Control   *heir;
62  ISR_Level         level;
63
64  executing   = _Thread_Executing;
65  _ISR_Disable( level );
66  while ( _Context_Switch_necessary == TRUE ) {
67    heir = _Thread_Heir;
68    _Thread_Dispatch_disable_level = 1;
69    _Context_Switch_necessary = FALSE;
70    _Thread_Executing = heir;
71    executing->rtems_ada_self = rtems_ada_self;
72    rtems_ada_self = heir->rtems_ada_self;
73    _ISR_Enable( level );
74
75    heir->ticks_executed++;
76
77    _User_extensions_Thread_switch( executing, heir );
78
79    if ( heir->budget_algorithm == THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE )
80      heir->cpu_time_budget = _Thread_Ticks_per_timeslice;
81
82    /*
83     *  If the CPU has hardware floating point, then we must address saving
84     *  and restoring it as part of the context switch.
85     *
86     *  The second conditional compilation section selects the algorithm used
87     *  to context switch between floating point tasks.  The deferred algorithm
88     *  can be significantly better in a system with few floating point tasks
89     *  because it reduces the total number of save and restore FP context
90     *  operations.  However, this algorithm can not be used on all CPUs due
91     *  to unpredictable use of FP registers by some compilers for integer
92     *  operations.
93     */
94
95#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
96#if ( CPU_USE_DEFERRED_FP_SWITCH == TRUE )
97    if ( (heir->fp_context != NULL) && !_Thread_Is_allocated_fp( heir ) ) {
98      if ( _Thread_Allocated_fp != NULL )
99        _Context_Save_fp( &_Thread_Allocated_fp->fp_context );
100      _Context_Restore_fp( &heir->fp_context );
101      _Thread_Allocated_fp = heir;
102    }
103#else
104    if ( executing->fp_context != NULL )
105      _Context_Save_fp( &executing->fp_context );
106
107    if ( heir->fp_context != NULL )
108      _Context_Restore_fp( &heir->fp_context );
109#endif
110#endif
111
112    _Context_Switch( &executing->Registers, &heir->Registers );
113
114    executing = _Thread_Executing;
115
116    _ISR_Disable( level );
117  }
118
119  _Thread_Dispatch_disable_level = 0;
120
121  _ISR_Enable( level );
122
123  if ( _Thread_Do_post_task_switch_extension ||
124       executing->do_post_task_switch_extension ) {
125    executing->do_post_task_switch_extension = FALSE;
126    _API_extensions_Run_postswitch();
127  }
128 
129}
Note: See TracBrowser for help on using the repository browser.