Changeset 9b83a66 in rtems


Ignore:
Timestamp:
Oct 2, 2012, 2:13:00 PM (7 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
c17d0b3
Parents:
cb7b57e1
git-author:
Sebastian Huber <sebastian.huber@…> (10/02/12 14:13:00)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/07/12 12:40:49)
Message:

score: Critical fix for thread dispatching

The changes in _Thread_Dispatch() of commits
dad36c52b8be5d7b46bc7af85655055db7208652 and
d4dc7c8196355f08044e67a3f5c1e19485f17ff1 introduced a severe bug which
destroys the real-time properties of RTEMS completely.

Consider the following scenario. We have three tasks L (lowest
priority), M (middle priority), and H (highest priority). Now let a
thread dispatch from M to L happen. An interrupt occurs in
_Thread_Dispatch() here:

void _Thread_Dispatch( void )
{

[...]

post_switch:

_ISR_Enable( level );

<-- INTERRUPT
<-- AFTER INTERRUPT

_Thread_Unnest_dispatch();

_API_extensions_Run_postswitch();

}

The interrupt event makes task H ready. The interrupt code will see
_Thread_Dispatch_disable_level > 0 and thus doesn't perform a
_Thread_Dispatch(). Now we return to position "AFTER INTERRUPT". This
means task L executes now although task H is ready! Task H will execute
once someone calls _Thread_Dispatch().

Files:
4 added
3 edited

Legend:

Unmodified
Added
Removed
  • cpukit/score/src/threaddispatch.c

    rcb7b57e1 r9b83a66  
    5656  ISR_Level         level;
    5757
    58   _Thread_Disable_dispatch();
    5958  #if defined(RTEMS_SMP)
     59    /*
     60     * WARNING: The SMP sequence has severe defects regarding the real-time
     61     * performance.
     62     *
     63     * Consider the following scenario.  We have three tasks L (lowest
     64     * priority), M (middle priority), and H (highest priority).  Now let a
     65     * thread dispatch from M to L happen.  An interrupt occurs in
     66     * _Thread_Dispatch() here:
     67     *
     68     * void _Thread_Dispatch( void )
     69     * {
     70     *   [...]
     71     *
     72     * post_switch:
     73     *
     74     *   _ISR_Enable( level );
     75     *
     76     *   <-- INTERRUPT
     77     *   <-- AFTER INTERRUPT
     78     *
     79     *   _Thread_Unnest_dispatch();
     80     *
     81     *   _API_extensions_Run_postswitch();
     82     * }
     83     *
     84     * The interrupt event makes task H ready.  The interrupt code will see
     85     * _Thread_Dispatch_disable_level > 0 and thus doesn't perform a
     86     * _Thread_Dispatch().  Now we return to position "AFTER INTERRUPT".  This
     87     * means task L executes now although task H is ready!  Task H will execute
     88     * once someone calls _Thread_Dispatch().
     89     */
     90    _Thread_Disable_dispatch();
     91
    6092    /*
    6193     *  If necessary, send dispatch request to other cores.
     
    70102  _ISR_Disable( level );
    71103  while ( _Thread_Dispatch_necessary == true ) {
    72 
    73104    heir = _Thread_Heir;
     105    #ifndef RTEMS_SMP
     106      _Thread_Dispatch_set_disable_level( 1 );
     107    #endif
    74108    _Thread_Dispatch_necessary = false;
    75109    _Thread_Executing = heir;
     
    168202
    169203post_switch:
     204  #ifndef RTEMS_SMP
     205    _Thread_Dispatch_set_disable_level( 0 );
     206  #endif
    170207
    171208  _ISR_Enable( level );
    172209
    173   _Thread_Unnest_dispatch();
    174  
     210  #ifdef RTEMS_SMP
     211    _Thread_Unnest_dispatch();
     212  #endif
     213
    175214  _API_extensions_Run_postswitch();
    176215}
  • testsuites/sptests/Makefile.am

    rcb7b57e1 r9b83a66  
    2525    spintrcritical09 spintrcritical10 spintrcritical11 spintrcritical12 \
    2626    spintrcritical13 spintrcritical14 spintrcritical15 spintrcritical16 \
    27     spintrcritical17 spmkdir spmountmgr01 spheapprot \
     27    spintrcritical17 spintrcritical18 spmkdir spmountmgr01 spheapprot \
    2828    spsimplesched01 spsimplesched02 spsimplesched03 spnsext01 \
    2929    spedfsched01 spedfsched02 spedfsched03 \
  • testsuites/sptests/configure.ac

    rcb7b57e1 r9b83a66  
    2828# Explicitly list all Makefiles here
    2929AC_CONFIG_FILES([Makefile
     30spintrcritical18/Makefile
    3031sp01/Makefile
    3132sp02/Makefile
Note: See TracChangeset for help on using the changeset viewer.