Changeset d811dac in rtems


Ignore:
Timestamp:
Jun 25, 2015, 9:24:44 AM (4 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
27f08f5b
Parents:
5f31bbe
git-author:
Sebastian Huber <sebastian.huber@…> (06/25/15 09:24:44)
git-committer:
Sebastian Huber <sebastian.huber@…> (06/26/15 07:22:41)
Message:

score: Hide SMP lock profiling impl if disabled

The problem is that empty structures have a different size in C and C++.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • cpukit/score/include/rtems/score/percpu.h

    r5f31bbe rd811dac  
    320320    SMP_ticket_lock_Control Lock;
    321321
    322     /**
    323      * @brief Lock statistics context for the per-CPU lock.
    324      */
    325     SMP_lock_Stats_context Lock_stats_context;
     322    #if defined( RTEMS_PROFILING )
     323      /**
     324       * @brief Lock statistics for the per-CPU lock.
     325       */
     326      SMP_lock_Stats Lock_stats;
     327
     328      /**
     329       * @brief Lock statistics context for the per-CPU lock.
     330       */
     331      SMP_lock_Stats_context Lock_stats_context;
     332    #endif
    326333
    327334    /**
     
    386393  _SMP_ticket_lock_Acquire( \
    387394    &( cpu )->Lock, \
     395    &( cpu )->Lock_stats, \
    388396    &( cpu )->Lock_stats_context \
    389397  )
     
    399407  _SMP_ticket_lock_Release( \
    400408    &( cpu )->Lock, \
     409    &( cpu )->Lock_stats, \
    401410    &( cpu )->Lock_stats_context \
    402411  )
  • cpukit/score/include/rtems/score/smplock.h

    r5f31bbe rd811dac  
    5959 */
    6060
     61#if defined( RTEMS_PROFILING )
     62
    6163/**
    6264 * @brief Count of lock contention counters for lock statistics.
     
    8385 */
    8486typedef struct {
    85 #if defined( RTEMS_PROFILING )
    8687  /**
    8788   * @brief Node for SMP lock statistics chain.
     
    143144   */
    144145  const char *name;
    145 #endif /* defined( RTEMS_PROFILING ) */
    146146} SMP_lock_Stats;
    147147
     
    150150 */
    151151typedef struct {
    152 #if defined( RTEMS_PROFILING )
    153152  /**
    154153   * @brief The last lock acquire instant in CPU counter ticks.
     
    157156   */
    158157  CPU_Counter_ticks acquire_instant;
    159 #endif
    160158} SMP_lock_Stats_context;
    161159
     
    163161 * @brief SMP lock statistics initializer for static initialization.
    164162 */
    165 #if defined( RTEMS_PROFILING )
    166163#define SMP_LOCK_STATS_INITIALIZER( name ) \
    167164  { { NULL, NULL }, 0, 0, 0, 0, { 0, 0, 0, 0 }, 0, name }
    168 #else
    169 #define SMP_LOCK_STATS_INITIALIZER( name ) \
    170   { }
    171 #endif
    172165
    173166/**
     
    191184 * @brief Destroys an SMP lock statistics block.
    192185 *
    193  * @param[in,out] stats The SMP lock statistics block.
     186 * @param[in] stats The SMP lock statistics block.
    194187 */
    195188static inline void _SMP_lock_Stats_destroy( SMP_lock_Stats *stats );
     
    198191 * @brief Destroys an SMP lock statistics block.
    199192 *
    200  * @param[in,out] stats The SMP lock statistics block.
     193 * @param[in] stats The SMP lock statistics block.
    201194 * @param[in] stats_context The SMP lock statistics context.
    202195 */
     
    206199);
    207200
     201#else /* RTEMS_PROFILING */
     202
     203#define _SMP_lock_Stats_initialize( stats, name ) do { } while ( 0 )
     204
     205#define _SMP_lock_Stats_destroy( stats ) do { } while ( 0 )
     206
     207#endif /* RTEMS_PROFILING */
     208
    208209/**
    209210 * @brief SMP ticket lock control.
     
    212213  Atomic_Uint next_ticket;
    213214  Atomic_Uint now_serving;
    214   SMP_lock_Stats Stats;
    215215} SMP_ticket_lock_Control;
    216216
     
    218218 * @brief SMP ticket lock control initializer for static initialization.
    219219 */
    220 #define SMP_TICKET_LOCK_INITIALIZER( name ) \
     220#define SMP_TICKET_LOCK_INITIALIZER \
    221221  { \
    222222    ATOMIC_INITIALIZER_UINT( 0U ), \
    223     ATOMIC_INITIALIZER_UINT( 0U ), \
    224     SMP_LOCK_STATS_INITIALIZER( name ) \
     223    ATOMIC_INITIALIZER_UINT( 0U ) \
    225224  }
    226225
     
    230229 * Concurrent initialization leads to unpredictable results.
    231230 *
    232  * @param[in,out] lock The SMP ticket lock control.
     231 * @param[in] lock The SMP ticket lock control.
    233232 * @param[in] name The name for the SMP ticket lock.  This name must be
    234233 * persistent throughout the life time of this lock.
    235234 */
    236235static inline void _SMP_ticket_lock_Initialize(
    237   SMP_ticket_lock_Control *lock,
    238   const char *name
     236  SMP_ticket_lock_Control *lock
    239237)
    240238{
    241239  _Atomic_Init_uint( &lock->next_ticket, 0U );
    242240  _Atomic_Init_uint( &lock->now_serving, 0U );
    243   _SMP_lock_Stats_initialize( &lock->Stats, name );
    244241}
    245242
     
    249246 * Concurrent destruction leads to unpredictable results.
    250247 *
    251  * @param[in,out] lock The SMP ticket lock control.
     248 * @param[in] lock The SMP ticket lock control.
    252249 */
    253250static inline void _SMP_ticket_lock_Destroy( SMP_ticket_lock_Control *lock )
    254251{
    255   _SMP_lock_Stats_destroy( &lock->Stats );
    256 }
    257 
    258 /**
    259  * @brief Acquires an SMP ticket lock.
    260  *
    261  * This function will not disable interrupts.  The caller must ensure that the
    262  * current thread of execution is not interrupted indefinite once it obtained
    263  * the SMP ticket lock.
    264  *
    265  * @param[in,out] lock The SMP ticket lock control.
    266  * @param[out] stats_context The SMP lock statistics context.
    267  */
    268 static inline void _SMP_ticket_lock_Acquire(
    269   SMP_ticket_lock_Control *lock,
     252  (void) lock;
     253}
     254
     255static inline void _SMP_ticket_lock_Do_acquire(
     256  SMP_ticket_lock_Control *lock
     257#if defined( RTEMS_PROFILING )
     258  ,
     259  SMP_lock_Stats *stats,
    270260  SMP_lock_Stats_context *stats_context
     261#endif
    271262)
    272263{
     
    275266
    276267#if defined( RTEMS_PROFILING )
    277   SMP_lock_Stats *stats = &lock->Stats;
    278268  CPU_Counter_ticks first;
    279269  CPU_Counter_ticks second;
     
    319309  }
    320310  ++stats->contention_counts[initial_queue_length];
    321 #else
    322   (void) stats_context;
    323 #endif
    324 }
    325 
    326 /**
    327  * @brief Releases an SMP ticket lock.
    328  *
    329  * @param[in,out] lock The SMP ticket lock control.
    330  * @param[in] stats_context The SMP lock statistics context.
    331  */
    332 static inline void _SMP_ticket_lock_Release(
    333   SMP_ticket_lock_Control *lock,
     311#endif
     312}
     313
     314/**
     315 * @brief Acquires an SMP ticket lock.
     316 *
     317 * This function will not disable interrupts.  The caller must ensure that the
     318 * current thread of execution is not interrupted indefinite once it obtained
     319 * the SMP ticket lock.
     320 *
     321 * @param[in] lock The SMP ticket lock control.
     322 * @param[in] stats The SMP lock statistics.
     323 * @param[out] stats_context The SMP lock statistics context.
     324 */
     325#if defined( RTEMS_PROFILING )
     326  #define _SMP_ticket_lock_Acquire( lock, stats, stats_context ) \
     327    _SMP_ticket_lock_Do_acquire( lock, stats, stats_context )
     328#else
     329  #define _SMP_ticket_lock_Acquire( lock, stats, stats_context ) \
     330    _SMP_ticket_lock_Do_acquire( lock )
     331#endif
     332
     333static inline void _SMP_ticket_lock_Do_release(
     334  SMP_ticket_lock_Control *lock
     335#if defined( RTEMS_PROFILING )
     336  ,
     337  SMP_lock_Stats *stats,
    334338  const SMP_lock_Stats_context *stats_context
     339#endif
    335340)
    336341{
     
    339344  unsigned int next_ticket = current_ticket + 1U;
    340345
    341   _SMP_lock_Stats_release_update( &lock->Stats, stats_context );
     346#if defined( RTEMS_PROFILING )
     347  _SMP_lock_Stats_release_update( stats, stats_context );
     348#endif
    342349
    343350  _Atomic_Store_uint( &lock->now_serving, next_ticket, ATOMIC_ORDER_RELEASE );
     
    345352
    346353/**
     354 * @brief Releases an SMP ticket lock.
     355 *
     356 * @param[in] lock The SMP ticket lock control.
     357 * @param[in] stats The SMP lock statistics.
     358 * @param[in] stats_context The SMP lock statistics context.
     359 */
     360#if defined( RTEMS_PROFILING )
     361  #define _SMP_ticket_lock_Release( lock, stats, stats_context ) \
     362    _SMP_ticket_lock_Do_release( lock, stats, stats_context )
     363#else
     364  #define _SMP_ticket_lock_Release( lock, stats, stats_context ) \
     365    _SMP_ticket_lock_Do_release( lock )
     366#endif
     367
     368/**
    347369 * @brief SMP lock control.
    348370 */
    349371typedef struct {
    350   SMP_ticket_lock_Control ticket_lock;
     372  SMP_ticket_lock_Control Ticket_lock;
     373#if defined( RTEMS_PROFILING )
     374  SMP_lock_Stats Stats;
     375#endif
    351376} SMP_lock_Control;
    352377
     
    356381typedef struct {
    357382  ISR_Level isr_level;
     383#if defined( RTEMS_PROFILING )
    358384  SMP_lock_Stats_context Stats_context;
     385#endif
    359386} SMP_lock_Context;
    360387
     
    362389 * @brief SMP lock control initializer for static initialization.
    363390 */
    364 #define SMP_LOCK_INITIALIZER( name ) { SMP_TICKET_LOCK_INITIALIZER( name ) }
     391#if defined( RTEMS_PROFILING )
     392  #define SMP_LOCK_INITIALIZER( name ) \
     393    { SMP_TICKET_LOCK_INITIALIZER, SMP_LOCK_STATS_INITIALIZER( name ) }
     394#else
     395  #define SMP_LOCK_INITIALIZER( name ) { SMP_TICKET_LOCK_INITIALIZER }
     396#endif
    365397
    366398/**
     
    369401 * Concurrent initialization leads to unpredictable results.
    370402 *
    371  * @param[in,out] lock The SMP lock control.
     403 * @param[in] lock The SMP lock control.
    372404 * @param[in] name The name for the SMP lock statistics.  This name must be
    373405 * persistent throughout the life time of this statistics block.
     
    387419)
    388420{
    389   _SMP_ticket_lock_Initialize( &lock->ticket_lock, name );
     421  _SMP_ticket_lock_Initialize( &lock->Ticket_lock );
     422#if defined( RTEMS_PROFILING )
     423  _SMP_lock_Stats_initialize( &lock->Stats, name );
     424#else
     425  (void) name;
     426#endif
    390427}
    391428
     
    395432 * Concurrent destruction leads to unpredictable results.
    396433 *
    397  * @param[in,out] lock The SMP lock control.
     434 * @param[in] lock The SMP lock control.
    398435 */
    399436#if defined( RTEMS_SMP_LOCK_DO_NOT_INLINE )
     
    405442#endif
    406443{
    407   _SMP_ticket_lock_Destroy( &lock->ticket_lock );
     444  _SMP_ticket_lock_Destroy( &lock->Ticket_lock );
     445  _SMP_lock_Stats_destroy( &lock->Stats );
    408446}
    409447
     
    415453 * the SMP lock.
    416454 *
    417  * @param[in,out] lock The SMP lock control.
    418  * @param[in,out] context The local SMP lock context for an acquire and release
     455 * @param[in] lock The SMP lock control.
     456 * @param[in] context The local SMP lock context for an acquire and release
    419457 * pair.
    420458 */
     
    434472{
    435473  (void) context;
    436   _SMP_ticket_lock_Acquire( &lock->ticket_lock, &context->Stats_context );
     474  _SMP_ticket_lock_Acquire(
     475    &lock->Ticket_lock,
     476    &lock->Stats,
     477    &context->Stats_context
     478  );
    437479}
    438480
     
    440482 * @brief Releases an SMP lock.
    441483 *
    442  * @param[in,out] lock The SMP lock control.
    443  * @param[in,out] context The local SMP lock context for an acquire and release
     484 * @param[in] lock The SMP lock control.
     485 * @param[in] context The local SMP lock context for an acquire and release
    444486 * pair.
    445487 */
     
    459501{
    460502  (void) context;
    461   _SMP_ticket_lock_Release( &lock->ticket_lock, &context->Stats_context );
     503  _SMP_ticket_lock_Release(
     504    &lock->Ticket_lock,
     505    &lock->Stats,
     506    &context->Stats_context
     507  );
    462508}
    463509
     
    465511 * @brief Disables interrupts and acquires the SMP lock.
    466512 *
    467  * @param[in,out] lock The SMP lock control.
    468  * @param[in,out] context The local SMP lock context for an acquire and release
     513 * @param[in] lock The SMP lock control.
     514 * @param[in] context The local SMP lock context for an acquire and release
    469515 * pair.
    470516 */
     
    490536 * @brief Releases the SMP lock and enables interrupts.
    491537 *
    492  * @param[in,out] lock The SMP lock control.
    493  * @param[in,out] context The local SMP lock context for an acquire and release
     538 * @param[in] lock The SMP lock control.
     539 * @param[in] context The local SMP lock context for an acquire and release
    494540 * pair.
    495541 */
     
    513559
    514560#if defined( RTEMS_PROFILING )
     561
    515562typedef struct {
    516563  SMP_lock_Control Lock;
     
    597644  _SMP_lock_Release_and_ISR_enable( &control->Lock, &lock_context );
    598645}
    599 #endif
    600646
    601647static inline void _SMP_lock_Stats_destroy( SMP_lock_Stats *stats )
    602648{
    603 #if defined( RTEMS_PROFILING )
    604649  if ( !_Chain_Is_node_off_chain( &stats->Node ) ) {
    605650    SMP_lock_Stats_control *control = &_SMP_lock_Stats_control;
     
    630675    _SMP_lock_Release_and_ISR_enable( &control->Lock, &lock_context );
    631676  }
    632 #else
    633   (void) stats;
    634 #endif
    635677}
    636678
     
    640682)
    641683{
    642 #if defined( RTEMS_PROFILING )
    643684  CPU_Counter_ticks first = stats_context->acquire_instant;
    644685  CPU_Counter_ticks second = _CPU_Counter_read();
     
    659700    }
    660701  }
    661 #else
    662   (void) stats;
    663   (void) stats_context;
    664 #endif
    665 }
     702}
     703
     704#endif /* RTEMS_PROFILING */
    666705
    667706/**@}*/
  • cpukit/score/src/profilingsmplock.c

    r5f31bbe rd811dac  
    2222SMP_lock_Stats_control _SMP_lock_Stats_control = {
    2323  .Lock = {
    24     .ticket_lock = {
     24    .Ticket_lock = {
    2525      .next_ticket = ATOMIC_INITIALIZER_UINT( 0U ),
    26       .now_serving = ATOMIC_INITIALIZER_UINT( 0U ),
    27       .Stats = {
    28         .Node = CHAIN_NODE_INITIALIZER_ONE_NODE_CHAIN(
    29           &_SMP_lock_Stats_control.Stats_chain
    30         ),
    31         .name = "SMP lock stats"
    32       }
     26      .now_serving = ATOMIC_INITIALIZER_UINT( 0U )
     27    },
     28    .Stats = {
     29      .Node = CHAIN_NODE_INITIALIZER_ONE_NODE_CHAIN(
     30        &_SMP_lock_Stats_control.Stats_chain
     31      ),
     32      .name = "SMP Lock Stats"
    3333    }
    3434  },
    3535  .Stats_chain = CHAIN_INITIALIZER_ONE_NODE(
    36     &_SMP_lock_Stats_control.Lock.ticket_lock.Stats.Node
     36    &_SMP_lock_Stats_control.Lock.Stats.Node
    3737  ),
    3838  .Iterator_chain = CHAIN_INITIALIZER_EMPTY(
  • cpukit/score/src/smp.c

    r5f31bbe rd811dac  
    8181    Per_CPU_Control *cpu = _Per_CPU_Get_by_index( cpu_index );
    8282
    83     _SMP_ticket_lock_Initialize( &cpu->Lock, "per-CPU" );
     83    _SMP_ticket_lock_Initialize( &cpu->Lock );
     84    _SMP_lock_Stats_initialize( &cpu->Lock_stats, "Per-CPU" );
    8485  }
    8586
  • testsuites/sptests/sp37/init.c

    r5f31bbe rd811dac  
    162162#if defined(RTEMS_SMP) && defined(RTEMS_PROFILING)
    163163static const size_t lock_size =
    164   offsetof( ISR_lock_Control, Lock.ticket_lock.Stats.name )
    165     + sizeof( ((ISR_lock_Control *) 0)->Lock.ticket_lock.Stats.name );
     164  offsetof( ISR_lock_Control, Lock.Stats.name )
     165    + sizeof( ((ISR_lock_Control *) 0)->Lock.Stats.name );
    166166#else
    167167static const size_t lock_size = sizeof( ISR_lock_Control );
Note: See TracChangeset for help on using the changeset viewer.