Changeset 24399ad in rtems


Ignore:
Timestamp:
Jul 24, 2009, 7:17:54 PM (10 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, master
Children:
a3e4a58
Parents:
cd62f7a
Message:

2009-07-24 Joel Sherrill <joel.sherrill@…>

  • posix/src/killinfo.c: Rework to make easier to analyze for code coverage and to simplify so it is easier to analyze for correctness.
Location:
cpukit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    rcd62f7a r24399ad  
     12009-07-24      Joel Sherrill <joel.sherrill@OARcorp.com>
     2
     3        * posix/src/killinfo.c: Rework to make easier to analyze for code
     4        coverage and to simplify so it is easier to analyze for correctness.
     5
    162009-07-24      Roxana Leontie <roxana.leontie@gmail.com>
    27
  • cpukit/posix/src/killinfo.c

    rcd62f7a r24399ad  
    2626#include <rtems/score/isr.h>
    2727
    28 /*PAGE
    29  *
     28/*
     29 *  If you enable this, then you get printk() feedback on each path
     30 *  and the input to the decision that lead to the decision.  Hopefully
     31 *  this will help in debugging the algorithm that distributes process
     32 *  signals to individual threads.
     33 */
     34
     35/* #define DEBUG_SIGNAL_PROCESSING */
     36#if defined(DEBUG_SIGNAL_PROCESSING)
     37  #include <rtems/bspIo.h>
     38  #define DEBUG_STEP(_x) printk(_x)
     39#else
     40  #define DEBUG_STEP(_x)
     41#endif
     42
     43/*
    3044 *  3.3.2 Send a Signal to a Process, P1003.1b-1993, p. 68
    3145 *
     
    5064  Objects_Control            **object_table;
    5165  Thread_Control              *the_thread;
    52   Thread_Control              *interested_thread;
     66  Thread_Control              *interested;
    5367  Priority_Control             interested_priority;
    5468  Chain_Control               *the_chain;
     
    116130  /*
    117131   *  Is an interested thread waiting for this signal (sigwait())?
     132   *
     133   *  There is no requirement on the order of threads pending on a sigwait().
    118134   */
    119135
    120136  /* XXX violation of visibility -- need to define thread queue support */
    121137
    122   for( index=0 ;
    123        index < TASK_QUEUE_DATA_NUMBER_OF_PRIORITY_HEADERS ;
    124        index++ ) {
    125 
    126     the_chain = &_POSIX_signals_Wait_queue.Queues.Priority[ index ];
    127 
    128     for ( the_node = the_chain->first ;
    129           !_Chain_Is_tail( the_chain, the_node ) ;
    130           the_node = the_node->next ) {
    131 
    132       the_thread = (Thread_Control *)the_node;
    133       api = the_thread->API_Extensions[ THREAD_API_POSIX ];
    134 
    135       /*
    136        * Is this thread is actually blocked waiting for the signal?
    137        */
    138       if (the_thread->Wait.option & mask)
    139         goto process_it;
    140 
    141       /*
    142        * Is this thread is blocked waiting for another signal but has
    143        * not blocked this one?
    144        */
    145       if (~api->signals_blocked & mask)
    146         goto process_it;
    147     }
     138  the_chain = &_POSIX_signals_Wait_queue.Queues.Fifo;
     139
     140  for ( the_node = the_chain->first ;
     141        !_Chain_Is_tail( the_chain, the_node ) ;
     142        the_node = the_node->next ) {
     143
     144    the_thread = (Thread_Control *)the_node;
     145    api = the_thread->API_Extensions[ THREAD_API_POSIX ];
     146
     147    /*
     148     * Is this thread is actually blocked waiting for the signal?
     149     */
     150    if (the_thread->Wait.option & mask)
     151      goto process_it;
     152
     153    /*
     154     * Is this thread is blocked waiting for another signal but has
     155     * not blocked this one?
     156     */
     157    if (~api->signals_blocked & mask)
     158      goto process_it;
    148159  }
    149160
     
    163174   *    + rtems internal threads do not receive signals.
    164175   */
    165   interested_thread = NULL;
     176  interested = NULL;
    166177  interested_priority = PRIORITY_MAXIMUM + 1;
    167178
    168   for ( the_api = OBJECTS_CLASSIC_API;
    169         the_api <= OBJECTS_APIS_LAST;
    170         the_api++ ) {
     179  for (the_api = OBJECTS_CLASSIC_API; the_api <= OBJECTS_APIS_LAST; the_api++) {
    171180
    172181    /*
     
    185194       */
    186195      if ( !the_info )
    187         continue;
     196        continue;
    188197    #endif
    189198
     
    197206        continue;
    198207
     208      #if defined(DEBUG_SIGNAL_PROCESSING)
     209        printk("\n 0x%08x/0x%08x %d/%d 0x%08x 1",
     210          the_thread->Object.id,
     211          ((interested) ? interested->Object.id : 0),
     212          the_thread->current_priority, interested_priority,
     213          the_thread->current_state
     214        );
     215      #endif
     216
    199217      /*
    200218       *  If this thread is of lower priority than the interested thread,
     
    203221      if ( the_thread->current_priority > interested_priority )
    204222        continue;
     223      DEBUG_STEP("2");
    205224
    206225      /*
     
    216235      if ( !_POSIX_signals_Is_interested( api, mask ) )
    217236        continue;
    218 
    219       /*
    220        *  If we have not seen a thread interested in this signal yet,
    221        *  then we have found the first one.
    222        */
    223       if ( !interested_thread ) {
    224         interested_thread   = the_thread;
    225         interested_priority = the_thread->current_priority;
    226         continue;
    227       }
     237      DEBUG_STEP("3");
    228238
    229239      /*
     
    231241       *  If the thread under consideration is of higher priority, then
    232242       *  it becomes the interested thread.
     243       *
     244       *  NOTE: We initialized interested_priority to PRIORITY_MAXIMUM + 1
     245       *        so we never have to worry about deferencing a NULL
     246       *        interested thread.
    233247       */
    234248      if ( the_thread->current_priority < interested_priority ) {
    235         interested_thread   = the_thread;
     249        interested   = the_thread;
    236250        interested_priority = the_thread->current_priority;
    237251        continue;
    238252      }
     253      DEBUG_STEP("4");
    239254
    240255      /*
    241256       *  Now the thread and the interested thread have the same priority.
    242        *  If the interested thread is ready, then we don't need to send it
    243        *  to a blocked thread.
    244        */
    245       if ( _States_Is_ready( interested_thread->current_state ) )
    246         continue;
    247 
    248       /*
    249        *  Now the interested thread is blocked.
    250        *  If the thread we are considering is not, the it becomes the
    251        *  interested thread.
    252        */
    253       if ( _States_Is_ready( the_thread->current_state ) ) {
    254         interested_thread   = the_thread;
    255         interested_priority = the_thread->current_priority;
    256         continue;
    257       }
    258 
    259       /*
    260        *  Now we know both threads are blocked.
    261        *  If the interested thread is interruptible, then just use it.
    262        */
    263       if (_States_Is_interruptible_by_signal(interested_thread->current_state))
    264         continue;
    265 
    266       /*
    267        *  Now both threads are blocked and the interested thread is not
    268        *  interruptible.
    269        *  If the thread under consideration is interruptible by a signal,
    270        *  then it becomes the interested thread.
    271        */
    272       if ( _States_Is_interruptible_by_signal(the_thread->current_state) ) {
    273         interested_thread   = the_thread;
    274         interested_priority = the_thread->current_priority;
     257       *  We have to sort through the combinations of blocked/not blocked
     258       *  and blocking interruptibutable by signal.
     259       *
     260       *  If the interested thread is ready, don't think about changing.
     261       */
     262
     263      if ( !_States_Is_ready( interested->current_state ) ) {
     264        /* preferred ready over blocked */
     265        DEBUG_STEP("5");
     266        if ( _States_Is_ready( the_thread->current_state ) ) {
     267          interested          = the_thread;
     268          interested_priority = the_thread->current_priority;
     269          continue;
     270        }
     271 
     272        DEBUG_STEP("6");
     273        /* prefer blocked/interruptible over blocked/not interruptible */
     274        if ( !_States_Is_interruptible_by_signal(interested->current_state) ) {
     275          DEBUG_STEP("7");
     276          if ( _States_Is_interruptible_by_signal(the_thread->current_state) ) {
     277            DEBUG_STEP("8");
     278            interested          = the_thread;
     279            interested_priority = the_thread->current_priority;
     280            continue;
     281          }
     282        }
    275283      }
    276284    }
    277285  }
    278286
    279   if ( interested_thread ) {
    280     the_thread = interested_thread;
     287  if ( interested ) {
     288    the_thread = interested;
    281289    goto process_it;
    282290  }
     
    333341  }
    334342
     343  DEBUG_STEP("\n");
    335344  _Thread_Enable_dispatch();
    336345  return 0;
Note: See TracChangeset for help on using the changeset viewer.