Changeset e366f77 in rtems


Ignore:
Timestamp:
Jan 31, 2017, 7:08:24 AM (2 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
f7ba2945
Parents:
70488f5
git-author:
Sebastian Huber <sebastian.huber@…> (01/31/17 07:08:24)
git-committer:
Sebastian Huber <sebastian.huber@…> (01/31/17 08:38:07)
Message:

score: Add _Thread_queue_Object_name

Add the special thread queue name _Thread_queue_Object_name to mark
thread queues embedded in an object with identifier. Using the special
thread state STATES_THREAD_QUEUE_WITH_IDENTIFIER is not reliable for
this purpose since the thread wait information and thread state are
protected by different SMP locks in separate critical sections. Remove
STATES_THREAD_QUEUE_WITH_IDENTIFIER.

Add and use _Thread_queue_Object_initialize().

Update #2858.

Location:
cpukit
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libcsupport/src/assocthreadstatestostring.c

    r70488f5 re366f77  
    1515
    1616static const rtems_assoc_32_pair state_pairs[] = {
    17   { STATES_THREAD_QUEUE_WITH_IDENTIFIER,   "ID" },
    1817  { STATES_WAITING_FOR_MUTEX,              "MTX" },
    1918  { STATES_WAITING_FOR_SEMAPHORE,          "SEM" },
  • cpukit/libmisc/monitor/mon-task.c

    r70488f5 re366f77  
    2121)
    2222{
    23     Thread_queue_Context queue_context;
     23    Thread_queue_Context      queue_context;
     24    const Thread_queue_Queue *queue;
    2425
    2526    _Thread_queue_Context_initialize( &queue_context );
    2627    _Thread_Wait_acquire( rtems_thread, &queue_context );
    2728
    28     canonical_task->state = rtems_thread->current_state;
    29     canonical_task->wait_id = _Thread_Wait_get_id( rtems_thread );
    30     canonical_task->wait_queue = rtems_thread->Wait.queue;
    31     canonical_task->wait_operations = rtems_thread->Wait.operations;
     29    queue = rtems_thread->Wait.queue;
     30
     31    if ( queue != NULL ) {
     32      _Thread_queue_Queue_get_name_and_id(
     33        queue,
     34        canonical_task->wait_name,
     35        sizeof(canonical_task->wait_name),
     36        &canonical_task->wait_id
     37      );
     38    } else {
     39      canonical_task->wait_id = 0;
     40      canonical_task->wait_name[0] = '\0';
     41    }
    3242
    3343    _Thread_Wait_release( rtems_thread, &queue_context );
     
    5666    rtems_monitor_task_wait_info( canonical_task, rtems_thread );
    5767
     68    canonical_task->state = rtems_thread->current_state;
    5869    canonical_task->entry = rtems_thread->Start.Entry;
    5970    canonical_task->stack = rtems_thread->Start.Initial_stack.area;
     
    118129    length += rtems_monitor_dump_id(monitor_task->wait_id);
    119130    length += rtems_monitor_pad(62, length);
    120     length += rtems_monitor_dump_addr(monitor_task->wait_queue);
    121     if (monitor_task->wait_operations == &_Thread_queue_Operations_default) {
    122         length += fprintf(stdout, " [DFLT]");
    123     } else if (monitor_task->wait_operations == &_Thread_queue_Operations_FIFO) {
    124         length += fprintf(stdout, " [FIFO]");
    125     } else if (monitor_task->wait_operations == &_Thread_queue_Operations_priority) {
    126         length += fprintf(stdout, " [PRIO]");
    127     } else if (monitor_task->wait_operations == &_Thread_queue_Operations_priority_inherit) {
    128         length += fprintf(stdout, " [PINH]");
    129     } else {
    130         length += fprintf(stdout, " [?]");
    131     }
     131    length += fprintf(stdout, "%s", monitor_task->wait_name);
    132132
    133133    fprintf(stdout,"\n");
  • cpukit/libmisc/monitor/monitor.h

    r70488f5 re366f77  
    107107    rtems_attribute            attributes;
    108108    rtems_id                   wait_id;
    109     const void                *wait_queue;
    110     const void                *wait_operations;
     109    char                       wait_name[17];
    111110    uint32_t                   ticks;
    112111} rtems_monitor_task_t;
  • cpukit/posix/include/rtems/posix/condimpl.h

    r70488f5 re366f77  
    5656)
    5757{
    58   _Thread_queue_Initialize( &the_cond->Wait_queue );
     58  _Thread_queue_Object_initialize( &the_cond->Wait_queue );
    5959  the_cond->mutex = POSIX_CONDITION_VARIABLES_NO_MUTEX;
    6060  the_cond->clock = the_attr->clock;
  • cpukit/posix/src/condwaitsupp.c

    r70488f5 re366f77  
    120120    _Thread_queue_Context_set_thread_state(
    121121      &queue_context,
    122       STATES_THREAD_QUEUE_WITH_IDENTIFIER
    123         | STATES_WAITING_FOR_CONDITION_VARIABLE
     122      STATES_WAITING_FOR_CONDITION_VARIABLE
    124123    );
    125124    _Thread_queue_Context_set_enqueue_callout(
  • cpukit/rtems/src/regioncreate.c

    r70488f5 re366f77  
    7272
    7373    else {
    74       _Thread_queue_Initialize( &the_region->Wait_queue );
     74      _Thread_queue_Object_initialize( &the_region->Wait_queue );
    7575
    7676      if ( _Attributes_Is_priority( attribute_set ) ) {
  • cpukit/score/include/rtems/score/coremuteximpl.h

    r70488f5 re366f77  
    4444)
    4545{
    46   _Thread_queue_Initialize( &the_mutex->Wait_queue );
     46  _Thread_queue_Object_initialize( &the_mutex->Wait_queue );
    4747}
    4848
  • cpukit/score/include/rtems/score/coresemimpl.h

    r70488f5 re366f77  
    187187  _Thread_queue_Context_set_thread_state(
    188188    queue_context,
    189     STATES_THREAD_QUEUE_WITH_IDENTIFIER | STATES_WAITING_FOR_SEMAPHORE
     189    STATES_WAITING_FOR_SEMAPHORE
    190190  );
    191191  _Thread_queue_Context_set_do_nothing_enqueue_callout( queue_context );
  • cpukit/score/include/rtems/score/mrspimpl.h

    r70488f5 re366f77  
    224224  }
    225225
    226   _Thread_queue_Initialize( &mrsp->Wait_queue );
     226  _Thread_queue_Object_initialize( &mrsp->Wait_queue );
    227227  return STATUS_SUCCESSFUL;
    228228}
  • cpukit/score/include/rtems/score/statesimpl.h

    r70488f5 re366f77  
    4242#define STATES_READY                           0x00000000
    4343
    44 /**
    45  * @brief This macro corresponds to a task which is blocked on a thread queue
    46  * embedded in an object with an identifier.
    47  *
    48  * This thread state bit is intended to ease debugging and improve system
    49  * diagnostics, see _Thread_Wait_get_id().
    50  */
    51 #define STATES_THREAD_QUEUE_WITH_IDENTIFIER    0x00000001
    52 
    5344/** This macro corresponds to a task waiting for a mutex. */
    54 #define STATES_WAITING_FOR_MUTEX               0x00000002
     45#define STATES_WAITING_FOR_MUTEX               0x00000001
    5546
    5647/** This macro corresponds to a task waiting for a semaphore. */
    57 #define STATES_WAITING_FOR_SEMAPHORE           0x00000004
     48#define STATES_WAITING_FOR_SEMAPHORE           0x00000002
    5849
    5950/** This macro corresponds to a task waiting for an event. */
    60 #define STATES_WAITING_FOR_EVENT               0x00000008
     51#define STATES_WAITING_FOR_EVENT               0x00000004
    6152
    6253/** This macro corresponds to a task waiting for a system event. */
    63 #define STATES_WAITING_FOR_SYSTEM_EVENT        0x00000010
     54#define STATES_WAITING_FOR_SYSTEM_EVENT        0x00000008
    6455
    6556/** This macro corresponds to a task waiting for a message. */
    66 #define STATES_WAITING_FOR_MESSAGE             0x00000020
     57#define STATES_WAITING_FOR_MESSAGE             0x00000010
    6758
    6859/** This macro corresponds to a task waiting for a condition variable. */
    69 #define STATES_WAITING_FOR_CONDITION_VARIABLE  0x00000040
     60#define STATES_WAITING_FOR_CONDITION_VARIABLE  0x00000020
    7061
    7162/** This macro corresponds to a task waiting for a futex. */
    72 #define STATES_WAITING_FOR_FUTEX               0x00000080
     63#define STATES_WAITING_FOR_FUTEX               0x00000040
    7364
    7465/** This macro corresponds to a task waiting for BSD wakeup. */
    75 #define STATES_WAITING_FOR_BSD_WAKEUP          0x00000100
     66#define STATES_WAITING_FOR_BSD_WAKEUP          0x00000080
    7667
    7768/**
     
    7970 * absolute timeout.
    8071 */
    81 #define STATES_WAITING_FOR_TIME                0x00000200
     72#define STATES_WAITING_FOR_TIME                0x00000100
    8273
    8374/** This macro corresponds to a task waiting for a period. */
    84 #define STATES_WAITING_FOR_PERIOD              0x00000400
     75#define STATES_WAITING_FOR_PERIOD              0x00000200
    8576
    8677/** This macro corresponds to a task waiting for a signal. */
    87 #define STATES_WAITING_FOR_SIGNAL              0x00000800
     78#define STATES_WAITING_FOR_SIGNAL              0x00000400
    8879
    8980/** This macro corresponds to a task waiting for a barrier. */
    90 #define STATES_WAITING_FOR_BARRIER             0x00001000
     81#define STATES_WAITING_FOR_BARRIER             0x00000800
    9182
    9283/** This macro corresponds to a task waiting for a RWLock. */
    93 #define STATES_WAITING_FOR_RWLOCK              0x00002000
     84#define STATES_WAITING_FOR_RWLOCK              0x00001000
    9485
    9586/** This macro corresponds to a task waiting for a join while exiting. */
    96 #define STATES_WAITING_FOR_JOIN_AT_EXIT        0x00004000
     87#define STATES_WAITING_FOR_JOIN_AT_EXIT        0x00002000
    9788
    9889/** This macro corresponds to a task waiting for a join. */
    99 #define STATES_WAITING_FOR_JOIN                0x00008000
     90#define STATES_WAITING_FOR_JOIN                0x00004000
    10091
    10192/** This macro corresponds to a task being suspended. */
    102 #define STATES_SUSPENDED                       0x00010000
     93#define STATES_SUSPENDED                       0x00008000
    10394
    10495/** This macro corresponds to a task waiting for a fixed size segment. */
    105 #define STATES_WAITING_FOR_SEGMENT             0x00020000
     96#define STATES_WAITING_FOR_SEGMENT             0x00010000
    10697
    10798/** This macro corresponds to a task those life is changing. */
    108 #define STATES_LIFE_IS_CHANGING                0x00040000
     99#define STATES_LIFE_IS_CHANGING                0x00020000
    109100
    110101/** This macro corresponds to a task being held by the debugger. */
     
    126117
    127118/** This macro corresponds to a task waiting for a local object operation. */
    128 #define STATES_LOCALLY_BLOCKED ( STATES_THREAD_QUEUE_WITH_IDENTIFIER   | \
    129                                  STATES_WAITING_FOR_SEGMENT            | \
     119#define STATES_LOCALLY_BLOCKED ( STATES_WAITING_FOR_SEGMENT            | \
    130120                                 STATES_WAITING_FOR_MESSAGE            | \
    131121                                 STATES_WAITING_FOR_SEMAPHORE          | \
  • cpukit/score/include/rtems/score/threadqimpl.h

    r70488f5 re366f77  
    354354
    355355RTEMS_INLINE_ROUTINE void _Thread_queue_Queue_initialize(
    356   Thread_queue_Queue *queue
     356  Thread_queue_Queue *queue,
     357  const char         *name
    357358)
    358359{
     
    362363  queue->heads = NULL;
    363364  queue->owner = NULL;
     365  queue->name = name;
    364366}
    365367
     
    418420  _ISR_lock_ISR_enable( lock_context );
    419421}
     422
     423/**
     424 * @brief Copies the thread queue name to the specified buffer.
     425 *
     426 * @param[in] queue The actual thread queue.
     427 * @param[in] buffer The buffer for the thread queue name copy.
     428 * @param[in] buffer_size The buffer size in characters.
     429 * @param[in] id The object identifier in case the thread queue is embedded in
     430 *   an object with identifier, otherwise it is set to 0.
     431 *
     432 * @retval The length of the thread queue name.  May be greater than or equal
     433 *   to the buffer size if truncation occurred.
     434 */
     435size_t _Thread_queue_Queue_get_name_and_id(
     436  const Thread_queue_Queue *queue,
     437  char                     *buffer,
     438  size_t                    buffer_size,
     439  Objects_Id               *id
     440);
    420441
    421442#if defined(RTEMS_SMP)
     
    10121033);
    10131034
    1014 void _Thread_queue_Initialize( Thread_queue_Control *the_thread_queue );
     1035void _Thread_queue_Initialize(
     1036  Thread_queue_Control *the_thread_queue,
     1037  const char           *name
     1038);
    10151039
    10161040#if defined(RTEMS_SMP) && defined(RTEMS_DEBUG) && defined(RTEMS_PROFILING)
     
    11381162extern const Thread_queue_Operations _Thread_queue_Operations_priority_inherit;
    11391163
     1164/**
     1165 * @brief The special thread queue name to indicated that the thread queue is
     1166 * embedded in an object with identifier.
     1167 *
     1168 * @see _Thread_queue_Object_initialize().
     1169 */
     1170extern const char _Thread_queue_Object_name[];
     1171
     1172/**
     1173 * @brief Initializes a thread queue embedded in an object with identifier.
     1174 *
     1175 * The object must have the layout specified by Thread_queue_Object.  It should
     1176 * be ensured with the THREAD_QUEUE_OBJECT_ASSERT() static assertion.
     1177 *
     1178 * @param[in] the_thread_queue The thread queue.
     1179 */
     1180void _Thread_queue_Object_initialize(
     1181  Thread_queue_Control *the_thread_queue
     1182);
     1183
    11401184/**@}*/
    11411185
  • cpukit/score/src/corebarrier.c

    r70488f5 re366f77  
    3030  the_barrier->number_of_waiting_threads = 0;
    3131
    32   _Thread_queue_Initialize( &the_barrier->Wait_queue );
     32  _Thread_queue_Object_initialize( &the_barrier->Wait_queue );
    3333}
  • cpukit/score/src/corebarrierwait.c

    r70488f5 re366f77  
    4747    _Thread_queue_Context_set_thread_state(
    4848      queue_context,
    49       STATES_THREAD_QUEUE_WITH_IDENTIFIER | STATES_WAITING_FOR_BARRIER
     49      STATES_WAITING_FOR_BARRIER
    5050    );
    5151    _Thread_queue_Context_set_do_nothing_enqueue_callout( queue_context );
  • cpukit/score/src/coremsg.c

    r70488f5 re366f77  
    105105  _Chain_Initialize_empty( &the_message_queue->Pending_messages );
    106106
    107   _Thread_queue_Initialize( &the_message_queue->Wait_queue );
     107  _Thread_queue_Object_initialize( &the_message_queue->Wait_queue );
    108108
    109109  if ( discipline == CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY ) {
  • cpukit/score/src/coremsgseize.c

    r70488f5 re366f77  
    116116  _Thread_queue_Context_set_thread_state(
    117117    queue_context,
    118     STATES_THREAD_QUEUE_WITH_IDENTIFIER | STATES_WAITING_FOR_MESSAGE
     118    STATES_WAITING_FOR_MESSAGE
    119119  );
    120120  _Thread_queue_Context_set_do_nothing_enqueue_callout( queue_context );
  • cpukit/score/src/coremsgsubmit.c

    r70488f5 re366f77  
    134134    _Thread_queue_Context_set_thread_state(
    135135      queue_context,
    136       STATES_THREAD_QUEUE_WITH_IDENTIFIER | STATES_WAITING_FOR_MESSAGE
     136      STATES_WAITING_FOR_MESSAGE
    137137    );
    138138    _Thread_queue_Context_set_do_nothing_enqueue_callout( queue_context );
  • cpukit/score/src/coremutexseize.c

    r70488f5 re366f77  
    3535    _Thread_queue_Context_set_thread_state(
    3636      queue_context,
    37       STATES_THREAD_QUEUE_WITH_IDENTIFIER | STATES_WAITING_FOR_MUTEX
     37      STATES_WAITING_FOR_MUTEX
    3838    );
    3939    _Thread_queue_Context_set_do_nothing_enqueue_callout( queue_context );
  • cpukit/score/src/corerwlock.c

    r70488f5 re366f77  
    2929  the_rwlock->current_state = CORE_RWLOCK_UNLOCKED;
    3030
    31   _Thread_queue_Initialize( &the_rwlock->Wait_queue );
     31  _Thread_queue_Object_initialize( &the_rwlock->Wait_queue );
    3232}
  • cpukit/score/src/corerwlockobtainread.c

    r70488f5 re366f77  
    8181  _Thread_queue_Context_set_thread_state(
    8282    queue_context,
    83    STATES_THREAD_QUEUE_WITH_IDENTIFIER | STATES_WAITING_FOR_RWLOCK
     83   STATES_WAITING_FOR_RWLOCK
    8484  );
    8585  _Thread_queue_Context_set_do_nothing_enqueue_callout( queue_context );
  • cpukit/score/src/corerwlockobtainwrite.c

    r70488f5 re366f77  
    6969  _Thread_queue_Context_set_thread_state(
    7070    queue_context,
    71     STATES_THREAD_QUEUE_WITH_IDENTIFIER | STATES_WAITING_FOR_RWLOCK
     71    STATES_WAITING_FOR_RWLOCK
    7272  );
    7373  _Thread_queue_Context_set_do_nothing_enqueue_callout( queue_context );
  • cpukit/score/src/coresem.c

    r70488f5 re366f77  
    2828  the_semaphore->count = initial_value;
    2929
    30   _Thread_queue_Initialize( &the_semaphore->Wait_queue );
     30  _Thread_queue_Object_initialize( &the_semaphore->Wait_queue );
    3131}
  • cpukit/score/src/threadinitialize.c

    r70488f5 re366f77  
    251251  _RBTree_Initialize_node( &the_thread->Wait.Link.Registry_node );
    252252  _SMP_lock_Stats_initialize( &the_thread->Potpourri_stats, "Thread Potpourri" );
     253  _SMP_lock_Stats_initialize( &the_thread->Join_queue.Lock_stats, "Thread State" );
    253254#endif
    254255
    255256  /* Initialize the CPU for the non-SMP schedulers */
    256257  _Thread_Set_CPU( the_thread, cpu );
    257 
    258   _Thread_queue_Initialize( &the_thread->Join_queue );
    259258
    260259  the_thread->current_state           = STATES_DORMANT;
  • cpukit/score/src/threadq.c

    r70488f5 re366f77  
    131131#endif
    132132
    133 void _Thread_queue_Initialize( Thread_queue_Control *the_thread_queue )
     133const char _Thread_queue_Object_name[] = { '\0' };
     134
     135void _Thread_queue_Initialize(
     136  Thread_queue_Control *the_thread_queue,
     137  const char           *name
     138)
    134139{
    135   _Thread_queue_Queue_initialize( &the_thread_queue->Queue );
     140  _Thread_queue_Queue_initialize( &the_thread_queue->Queue, name );
    136141#if defined(RTEMS_SMP)
    137142  _SMP_lock_Stats_initialize( &the_thread_queue->Lock_stats, "Thread Queue" );
    138143#endif
     144}
     145
     146void _Thread_queue_Object_initialize( Thread_queue_Control *the_thread_queue )
     147{
     148  _Thread_queue_Initialize( the_thread_queue, _Thread_queue_Object_name );
    139149}
    140150
     
    148158}
    149159#endif
     160
     161size_t _Thread_queue_Queue_get_name_and_id(
     162  const Thread_queue_Queue *queue,
     163  char                     *buffer,
     164  size_t                    buffer_size,
     165  Objects_Id               *id
     166)
     167{
     168  const char *name;
     169
     170  name = queue->name;
     171
     172  if ( name == _Thread_queue_Object_name ) {
     173    const Thread_queue_Object *queue_object;
     174
     175    queue_object = THREAD_QUEUE_QUEUE_TO_OBJECT( queue );
     176    *id = queue_object->Object.id;
     177    return _Objects_Name_to_string(
     178      queue_object->Object.name,
     179      false,
     180      buffer,
     181      buffer_size
     182    );
     183  } else {
     184    if ( name == NULL ) {
     185      name = _Thread_queue_Object_name;
     186    }
     187
     188    *id = 0;
     189    return strlcpy( buffer, name, buffer_size );
     190  }
     191}
  • cpukit/score/src/threadwaitgetid.c

    r70488f5 re366f77  
    11/*
    2  * Copyright (c) 2016 embedded brains GmbH.  All rights reserved.
     2 * Copyright (c) 2016, 2017 embedded brains GmbH.  All rights reserved.
    33 *
    44 *  embedded brains GmbH
     
    2121Objects_Id _Thread_Wait_get_id( const Thread_Control *the_thread )
    2222{
    23   States_Control current_state;
    24 
    25   current_state = the_thread->current_state;
     23  const Thread_queue_Queue *queue;
    2624
    2725#if defined(RTEMS_MULTIPROCESSING)
    28   if ( ( current_state & STATES_WAITING_FOR_RPC_REPLY ) != 0 ) {
     26  if ( _States_Is_waiting_for_rpc_reply( the_thread->current_state ) ) {
    2927    return the_thread->Wait.remote_id;
    3028  }
    3129#endif
    3230
    33   if ( ( current_state & STATES_THREAD_QUEUE_WITH_IDENTIFIER ) != 0 ) {
     31  queue = the_thread->Wait.queue;
     32
     33  if ( queue != NULL && queue->name == _Thread_queue_Object_name ) {
    3434    const Thread_queue_Object *queue_object;
    3535
    36     queue_object = THREAD_QUEUE_QUEUE_TO_OBJECT( the_thread->Wait.queue );
    37 
     36    queue_object = THREAD_QUEUE_QUEUE_TO_OBJECT( queue );
    3837    return queue_object->Object.id;
    3938  }
Note: See TracChangeset for help on using the changeset viewer.