Changeset 4025a60f in rtems


Ignore:
Timestamp:
Apr 19, 2016, 3:02:54 PM (4 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
2dd5e6fb
Parents:
b5a21bf1
git-author:
Sebastian Huber <sebastian.huber@…> (04/19/16 15:02:54)
git-committer:
Sebastian Huber <sebastian.huber@…> (04/22/16 07:25:08)
Message:

score: Avoid Giant lock for CORE mtx/sem

Avoid Giant lock for CORE mutex and semaphore flush and delete
operations.

Update #2555.

Location:
cpukit
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • cpukit/posix/include/rtems/posix/semaphoreimpl.h

    rb5a21bf1 r4025a60f  
    2323#include <rtems/posix/posixapi.h>
    2424#include <rtems/score/coresemimpl.h>
    25 
    26 #include <errno.h>
     25#include <rtems/seterr.h>
    2726
    2827#ifdef __cplusplus
     
    6261}
    6362
    64 /**
    65  *  @brief POSIX Semaphore Get
    66  *
    67  *  This function maps semaphore IDs to semaphore control blocks.
    68  *  If ID corresponds to a local semaphore, then it returns
    69  *  the_semaphore control pointer which maps to ID and location
    70  *  is set to OBJECTS_LOCAL.  if the semaphore ID is global and
    71  *  resides on a remote node, then location is set to OBJECTS_REMOTE,
    72  *  and the_semaphore is undefined.  Otherwise, location is set
    73  *  to OBJECTS_ERROR and the_semaphore is undefined.
    74  */
    75 RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *_POSIX_Semaphore_Get (
    76   sem_t             *id,
    77   Objects_Locations *location
    78 )
    79 {
    80   return (POSIX_Semaphore_Control *)
    81     _Objects_Get( &_POSIX_Semaphore_Information, (Objects_Id)*id, location );
    82 }
    83 
    8463RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *
    8564_POSIX_Semaphore_Get_interrupt_disable(
     
    11796 */
    11897void _POSIX_Semaphore_Delete(
    119   POSIX_Semaphore_Control *the_semaphore
     98  POSIX_Semaphore_Control *the_semaphore,
     99  ISR_lock_Context        *lock_context
    120100);
    121101
  • cpukit/posix/src/semaphoredeletesupp.c

    rb5a21bf1 r4025a60f  
    1919#endif
    2020
    21 #include <stdarg.h>
    22 
    23 #include <errno.h>
    24 #include <fcntl.h>
    25 #include <pthread.h>
    26 #include <semaphore.h>
    27 #include <limits.h>
    28 
    29 #include <rtems/system.h>
    3021#include <rtems/posix/semaphoreimpl.h>
    31 #include <rtems/seterr.h>
    3222
    3323void _POSIX_Semaphore_Delete(
    34   POSIX_Semaphore_Control *the_semaphore
     24  POSIX_Semaphore_Control *the_semaphore,
     25  ISR_lock_Context        *lock_context
    3526)
    3627{
    3728  if ( !the_semaphore->linked && !the_semaphore->open_count ) {
    3829    _Objects_Close( &_POSIX_Semaphore_Information, &the_semaphore->Object );
    39     _CORE_semaphore_Destroy( &the_semaphore->Semaphore, NULL, 0 );
     30    _CORE_semaphore_Destroy(
     31      &the_semaphore->Semaphore,
     32      NULL,
     33      0,
     34      lock_context
     35    );
    4036    _POSIX_Semaphore_Free( the_semaphore );
     37  } else {
     38    _CORE_semaphore_Release( &the_semaphore->Semaphore, lock_context );
    4139  }
    4240}
  • cpukit/posix/src/semclose.c

    rb5a21bf1 r4025a60f  
    1919#endif
    2020
    21 #include <stdarg.h>
     21#include <semaphore.h>
    2222
    23 #include <errno.h>
    24 #include <fcntl.h>
    25 #include <pthread.h>
    26 #include <semaphore.h>
    27 #include <limits.h>
    28 
    29 #include <rtems/system.h>
    3023#include <rtems/posix/semaphoreimpl.h>
    31 #include <rtems/seterr.h>
    3224
    3325int sem_close(
     
    3729  POSIX_Semaphore_Control          *the_semaphore;
    3830  Objects_Locations                 location;
     31  ISR_lock_Context                  lock_context;
    3932
    4033  _Objects_Allocator_lock();
    41   the_semaphore = _POSIX_Semaphore_Get( sem, &location );
     34  the_semaphore = _POSIX_Semaphore_Get_interrupt_disable(
     35    sem,
     36    &location,
     37    &lock_context
     38  );
    4239  switch ( location ) {
    4340
    4441    case OBJECTS_LOCAL:
     42      _CORE_semaphore_Acquire_critical(
     43        &the_semaphore->Semaphore,
     44        &lock_context
     45      );
    4546      the_semaphore->open_count -= 1;
    46       _POSIX_Semaphore_Delete( the_semaphore );
    47       _Objects_Put( &the_semaphore->Object );
     47      _POSIX_Semaphore_Delete( the_semaphore, &lock_context );
    4848      _Objects_Allocator_unlock();
    4949      return 0;
  • cpukit/posix/src/semdestroy.c

    rb5a21bf1 r4025a60f  
    1919#endif
    2020
    21 #include <stdarg.h>
     21#include <semaphore.h>
    2222
    23 #include <errno.h>
    24 #include <fcntl.h>
    25 #include <pthread.h>
    26 #include <semaphore.h>
    27 #include <limits.h>
    28 
    29 #include <rtems/system.h>
    3023#include <rtems/posix/semaphoreimpl.h>
    31 #include <rtems/seterr.h>
    3224
    3325int sem_destroy(
     
    3729  POSIX_Semaphore_Control          *the_semaphore;
    3830  Objects_Locations                 location;
     31  ISR_lock_Context                  lock_context;
    3932
    4033  _Objects_Allocator_lock();
    41   the_semaphore = _POSIX_Semaphore_Get( sem, &location );
     34  the_semaphore = _POSIX_Semaphore_Get_interrupt_disable(
     35    sem,
     36    &location,
     37    &lock_context
     38  );
    4239  switch ( location ) {
    4340
    4441    case OBJECTS_LOCAL:
     42      _CORE_semaphore_Acquire_critical(
     43        &the_semaphore->Semaphore,
     44        &lock_context
     45      );
     46
    4547      /*
    4648       *  Undefined operation on a named semaphore. Release the object
    4749       *  and fall to the EINVAL return at the bottom.
    4850       */
    49       if ( the_semaphore->named == true ) {
    50         _Objects_Put( &the_semaphore->Object );
     51      if ( the_semaphore->named ) {
     52        _CORE_semaphore_Release( &the_semaphore->Semaphore, &lock_context );
    5153      } else {
    52         _POSIX_Semaphore_Delete( the_semaphore );
    53         _Objects_Put( &the_semaphore->Object );
     54        _POSIX_Semaphore_Delete( the_semaphore, &lock_context );
    5455        _Objects_Allocator_unlock();
    5556        return 0;
  • cpukit/posix/src/semunlink.c

    rb5a21bf1 r4025a60f  
    2222
    2323#include <rtems/posix/semaphoreimpl.h>
    24 #include <rtems/seterr.h>
    2524
    2625int sem_unlink(
     
    3029  POSIX_Semaphore_Control   *the_semaphore;
    3130  Objects_Get_by_name_error  error;
     31  ISR_lock_Context           lock_context;
    3232
    3333  _Objects_Allocator_lock();
     
    3939  }
    4040
     41  _POSIX_Semaphore_Namespace_remove( the_semaphore );
     42
     43  _ISR_lock_ISR_disable( &lock_context );
     44  _CORE_semaphore_Acquire_critical( &the_semaphore->Semaphore, &lock_context );
    4145  the_semaphore->linked = false;
    42   _POSIX_Semaphore_Namespace_remove( the_semaphore );
    43   _POSIX_Semaphore_Delete( the_semaphore );
     46  _POSIX_Semaphore_Delete( the_semaphore, &lock_context );
    4447
    4548  _Objects_Allocator_unlock();
  • cpukit/rtems/src/semdelete.c

    rb5a21bf1 r4025a60f  
    3838  Semaphore_Control          *the_semaphore;
    3939  Objects_Locations           location;
     40  ISR_lock_Context            lock_context;
    4041  rtems_attribute             attribute_set;
    4142
    4243  _Objects_Allocator_lock();
    4344
    44   the_semaphore = _Semaphore_Get( id, &location );
     45  the_semaphore = _Semaphore_Get_interrupt_disable(
     46    id,
     47    &location,
     48    &lock_context
     49  );
    4550  switch ( location ) {
    4651
     
    5156        MRSP_Status mrsp_status;
    5257
     58        _MRSP_Acquire_critical(
     59          &the_semaphore->Core_control.mrsp,
     60          &lock_context
     61        );
    5362        mrsp_status = _MRSP_Can_destroy( &the_semaphore->Core_control.mrsp );
    5463        if ( mrsp_status != MRSP_SUCCESSFUL ) {
    55           _Objects_Put( &the_semaphore->Object );
     64          _MRSP_Release(
     65            &the_semaphore->Core_control.mrsp,
     66            &lock_context
     67          );
    5668          _Objects_Allocator_unlock();
    5769          return _Semaphore_Translate_MRSP_status_code( mrsp_status );
     
    5971      } else
    6072#endif
    61       if (
    62         !_Attributes_Is_counting_semaphore( attribute_set )
    63           && _CORE_mutex_Is_locked( &the_semaphore->Core_control.mutex )
    64           && !_Attributes_Is_simple_binary_semaphore( attribute_set )
    65       ) {
    66         _Objects_Put( &the_semaphore->Object );
    67         _Objects_Allocator_unlock();
    68         return RTEMS_RESOURCE_IN_USE;
     73      if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
     74        _CORE_mutex_Acquire_critical(
     75          &the_semaphore->Core_control.mutex,
     76          &lock_context
     77        );
     78
     79        if (
     80          _CORE_mutex_Is_locked( &the_semaphore->Core_control.mutex )
     81            && !_Attributes_Is_simple_binary_semaphore( attribute_set )
     82        ) {
     83          _CORE_mutex_Release(
     84            &the_semaphore->Core_control.mutex,
     85            &lock_context
     86          );
     87          _Objects_Allocator_unlock();
     88          return RTEMS_RESOURCE_IN_USE;
     89        }
     90      } else {
     91        _CORE_semaphore_Acquire_critical(
     92          &the_semaphore->Core_control.semaphore,
     93          &lock_context
     94        );
    6995      }
    7096
    7197      _Objects_Close( &_Semaphore_Information, &the_semaphore->Object );
    7298
    73 #if defined(RTEMS_MULTIPROCESSING)
    74       if ( _Attributes_Is_global( attribute_set ) ) {
    75 
    76         _Objects_MP_Close( &_Semaphore_Information, the_semaphore->Object.id );
    77 
    78         _Semaphore_MP_Send_process_packet(
    79           SEMAPHORE_MP_ANNOUNCE_DELETE,
    80           the_semaphore->Object.id,
    81           0,                         /* Not used */
    82           0                          /* Not used */
    83         );
    84       }
    85 #endif
    86 
    8799#if defined(RTEMS_SMP)
    88100      if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
    89         _MRSP_Destroy( &the_semaphore->Core_control.mrsp );
     101        _MRSP_Destroy( &the_semaphore->Core_control.mrsp, &lock_context );
    90102      } else
    91103#endif
     
    95107          _CORE_mutex_Was_deleted,
    96108          _Semaphore_MP_Send_object_was_deleted,
    97           id
     109          id,
     110          &lock_context
    98111        );
    99112        _CORE_mutex_Destroy( &the_semaphore->Core_control.mutex );
     
    102115          &the_semaphore->Core_control.semaphore,
    103116          _Semaphore_MP_Send_object_was_deleted,
    104           id
     117          id,
     118          &lock_context
    105119        );
    106120      }
    107121
    108       _Objects_Put( &the_semaphore->Object );
     122#if defined(RTEMS_MULTIPROCESSING)
     123      if ( _Attributes_Is_global( attribute_set ) ) {
     124
     125        _Objects_MP_Close( &_Semaphore_Information, id );
     126
     127        _Semaphore_MP_Send_process_packet(
     128          SEMAPHORE_MP_ANNOUNCE_DELETE,
     129          id,
     130          0,                         /* Not used */
     131          0                          /* Not used */
     132        );
     133      }
     134#endif
     135
    109136      _Semaphore_Free( the_semaphore );
    110137      _Objects_Allocator_unlock();
  • cpukit/rtems/src/semflush.c

    rb5a21bf1 r4025a60f  
    3838  Semaphore_Control          *the_semaphore;
    3939  Objects_Locations           location;
     40  ISR_lock_Context            lock_context;
    4041  rtems_attribute             attribute_set;
    4142
    42   the_semaphore = _Semaphore_Get( id, &location );
     43  the_semaphore = _Semaphore_Get_interrupt_disable(
     44    id,
     45    &location,
     46    &lock_context
     47  );
    4348  switch ( location ) {
    4449
     
    4752#if defined(RTEMS_SMP)
    4853      if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
    49         _Objects_Put( &the_semaphore->Object );
     54        _ISR_lock_ISR_enable( &lock_context );
    5055        return RTEMS_NOT_DEFINED;
    5156      } else
    5257#endif
    5358      if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
     59        _CORE_mutex_Acquire_critical(
     60          &the_semaphore->Core_control.mutex,
     61          &lock_context
     62        );
    5463        _CORE_mutex_Flush(
    5564          &the_semaphore->Core_control.mutex,
    5665          _CORE_mutex_Unsatisfied_nowait,
    5766          _Semaphore_MP_Send_object_was_deleted,
    58           id
     67          id,
     68          &lock_context
    5969        );
    6070      } else {
     71        _CORE_semaphore_Acquire_critical(
     72          &the_semaphore->Core_control.semaphore,
     73          &lock_context
     74        );
    6175        _CORE_semaphore_Flush(
    6276          &the_semaphore->Core_control.semaphore,
    6377          _Semaphore_MP_Send_object_was_deleted,
    64           id
     78          id,
     79          &lock_context
    6580        );
    6681      }
    67       _Objects_Put( &the_semaphore->Object );
    6882      return RTEMS_SUCCESSFUL;
    6983
    7084#if defined(RTEMS_MULTIPROCESSING)
    7185    case OBJECTS_REMOTE:
    72       _Thread_Dispatch();
    7386      return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
    7487#endif
  • cpukit/score/include/rtems/score/coremuteximpl.h

    rb5a21bf1 r4025a60f  
    356356  filter, \
    357357  mp_callout, \
    358   mp_id \
     358  mp_id, \
     359  lock_context \
    359360) \
    360   do { \
    361     ISR_lock_Context _core_mutex_flush_lock_context; \
    362     _Thread_queue_Acquire( \
    363       &( the_mutex )->Wait_queue, \
    364       &_core_mutex_flush_lock_context \
    365     ); \
    366     _Thread_queue_Flush_critical( \
    367       &( the_mutex )->Wait_queue.Queue, \
    368       ( the_mutex )->operations, \
    369       filter, \
    370       mp_callout, \
    371       mp_id, \
    372       &_core_mutex_flush_lock_context \
    373     ); \
    374   } while ( 0 )
     361  _Thread_queue_Flush_critical( \
     362    &( the_mutex )->Wait_queue.Queue, \
     363    ( the_mutex )->operations, \
     364    filter, \
     365    mp_callout, \
     366    mp_id, \
     367    lock_context \
     368  )
    375369
    376370/**
  • cpukit/score/include/rtems/score/coresemimpl.h

    rb5a21bf1 r4025a60f  
    8787);
    8888
     89RTEMS_INLINE_ROUTINE void _CORE_semaphore_Acquire_critical(
     90  CORE_semaphore_Control *the_semaphore,
     91  ISR_lock_Context       *lock_context
     92)
     93{
     94  _Thread_queue_Acquire_critical( &the_semaphore->Wait_queue, lock_context );
     95}
     96
     97RTEMS_INLINE_ROUTINE void _CORE_semaphore_Release(
     98  CORE_semaphore_Control *the_semaphore,
     99  ISR_lock_Context       *lock_context
     100)
     101{
     102  _Thread_queue_Release( &the_semaphore->Wait_queue, lock_context );
     103}
     104
    89105Thread_Control *_CORE_semaphore_Was_deleted(
    90106  Thread_Control     *the_thread,
     
    102118  the_semaphore, \
    103119  mp_callout, \
    104   mp_id \
     120  mp_id, \
     121  lock_context \
    105122) \
    106123  do { \
    107     ISR_lock_Context _core_semaphore_destroy_lock_context; \
    108     _Thread_queue_Acquire( \
    109       &( the_semaphore )->Wait_queue, \
    110       &_core_semaphore_destroy_lock_context \
    111     ); \
    112124    _Thread_queue_Flush_critical( \
    113125      &( the_semaphore )->Wait_queue.Queue, \
     
    116128      mp_callout, \
    117129      mp_id, \
    118       &_core_semaphore_destroy_lock_context \
     130      lock_context \
    119131    ); \
    120132    _Thread_queue_Destroy( &( the_semaphore )->Wait_queue ); \
     
    135147  status = CORE_SEMAPHORE_STATUS_SUCCESSFUL;
    136148
    137   _Thread_queue_Acquire_critical( &the_semaphore->Wait_queue, lock_context );
     149  _CORE_semaphore_Acquire_critical( the_semaphore, lock_context );
    138150
    139151  the_thread = _Thread_queue_First_locked(
     
    156168      status = CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED;
    157169
    158     _Thread_queue_Release( &the_semaphore->Wait_queue, lock_context );
     170    _CORE_semaphore_Release( the_semaphore, lock_context );
    159171  }
    160172
     
    209221  the_semaphore, \
    210222  mp_callout, \
    211   mp_id \
     223  mp_id, \
     224  lock_context \
    212225) \
    213226  do { \
    214     ISR_lock_Context _core_semaphore_flush_lock_context; \
    215     _Thread_queue_Acquire( \
    216       &( the_semaphore )->Wait_queue, \
    217       &_core_semaphore_flush_lock_context \
    218     ); \
    219227    _Thread_queue_Flush_critical( \
    220228      &( the_semaphore )->Wait_queue.Queue, \
     
    223231      mp_callout, \
    224232      mp_id, \
    225       &_core_semaphore_flush_lock_context \
     233      lock_context \
    226234    ); \
    227235  } while ( 0 )
     
    269277
    270278  executing->Wait.return_code = CORE_SEMAPHORE_STATUS_SUCCESSFUL;
    271   _Thread_queue_Acquire_critical( &the_semaphore->Wait_queue, lock_context );
     279  _CORE_semaphore_Acquire_critical( the_semaphore, lock_context );
    272280  if ( the_semaphore->count != 0 ) {
    273281    the_semaphore->count -= 1;
    274     _Thread_queue_Release( &the_semaphore->Wait_queue, lock_context );
     282    _CORE_semaphore_Release( the_semaphore, lock_context );
    275283    return;
    276284  }
    277285
    278286  if ( !wait ) {
    279     _Thread_queue_Release( &the_semaphore->Wait_queue, lock_context );
     287    _CORE_semaphore_Release( the_semaphore, lock_context );
    280288    executing->Wait.return_code = CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT;
    281289    return;
  • cpukit/score/include/rtems/score/mrspimpl.h

    rb5a21bf1 r4025a60f  
    5454}
    5555
     56RTEMS_INLINE_ROUTINE void _MRSP_Acquire_critical(
     57  MRSP_Control     *mrsp,
     58  ISR_lock_Context *lock_context
     59)
     60{
     61  _ISR_lock_Acquire( &mrsp->Lock, lock_context );
     62}
     63
     64RTEMS_INLINE_ROUTINE void _MRSP_Release(
     65  MRSP_Control     *mrsp,
     66  ISR_lock_Context *lock_context
     67)
     68{
     69  _ISR_lock_Release_and_ISR_enable( &mrsp->Lock, lock_context );
     70}
     71
    5672RTEMS_INLINE_ROUTINE bool _MRSP_Restore_priority_filter(
    5773  Thread_Control   *thread,
     
    104120
    105121  cpu_self = _Thread_Dispatch_disable_critical( lock_context );
    106   _ISR_lock_Release_and_ISR_enable( &mrsp->Lock, lock_context );
     122  _MRSP_Release( mrsp, lock_context );
    107123
    108124  _Thread_Raise_priority( new_owner, ceiling_priority );
     
    167183  ISR_lock_Context lock_context;
    168184
    169   _ISR_lock_ISR_disable_and_acquire( &mrsp->Lock, &lock_context );
     185  _ISR_lock_ISR_disable( &lock_context );
     186  _MRSP_Acquire_critical( mrsp, &lock_context );
    170187
    171188  if ( rival->status == MRSP_WAIT_FOR_OWNERSHIP ) {
     
    184201    rival->status = MRSP_TIMEOUT;
    185202
    186     _ISR_lock_Release_and_ISR_enable( &mrsp->Lock, &lock_context );
     203    _MRSP_Release( mrsp, &lock_context );
    187204  } else {
    188     _ISR_lock_Release_and_ISR_enable( &mrsp->Lock, &lock_context );
     205    _MRSP_Release( mrsp, &lock_context );
    189206  }
    190207}
     
    228245
    229246  cpu_self = _Thread_Dispatch_disable_critical( lock_context );
    230   _ISR_lock_Release_and_ISR_enable( &mrsp->Lock, lock_context );
     247  _MRSP_Release( mrsp, lock_context );
    231248
    232249  _Thread_Raise_priority( executing, ceiling_priority );
     
    294311  }
    295312
    296   _ISR_lock_Acquire( &mrsp->Lock, lock_context );
     313  _MRSP_Acquire_critical( mrsp, lock_context );
    297314  owner = _Resource_Get_owner( &mrsp->Resource );
    298315  if ( owner == NULL ) {
     
    319336    );
    320337  } else {
    321     _ISR_lock_Release_and_ISR_enable( &mrsp->Lock, lock_context );
     338    _MRSP_Release( mrsp, lock_context );
    322339    /* Not available, nested access or deadlock */
    323340    status = MRSP_UNSATISFIED;
     
    354371  initial_priority = mrsp->initial_priority_of_owner;
    355372
    356   _ISR_lock_Acquire( &mrsp->Lock, lock_context );
     373  _MRSP_Acquire_critical( mrsp, lock_context );
    357374
    358375  _MRSP_Giant_acquire( &giant_lock_context );
     
    390407
    391408  cpu_self = _Thread_Dispatch_disable_critical( lock_context );
    392   _ISR_lock_Release_and_ISR_enable( &mrsp->Lock, lock_context );
     409  _MRSP_Release( mrsp, lock_context );
    393410
    394411  _MRSP_Restore_priority( executing, initial_priority );
     
    408425}
    409426
    410 RTEMS_INLINE_ROUTINE void _MRSP_Destroy( MRSP_Control *mrsp )
    411 {
     427RTEMS_INLINE_ROUTINE void _MRSP_Destroy(
     428  MRSP_Control     *mrsp,
     429  ISR_lock_Context *lock_context
     430)
     431{
     432  _MRSP_Release( mrsp, lock_context );
    412433  _ISR_lock_Destroy( &mrsp->Lock );
    413434  _Workspace_Free( mrsp->ceiling_priorities );
Note: See TracChangeset for help on using the changeset viewer.