Changeset 53ad908 in rtems


Ignore:
Timestamp:
Mar 7, 2014, 1:36:22 PM (6 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
de5d6d0
Parents:
f980561
git-author:
Sebastian Huber <sebastian.huber@…> (03/07/14 13:36:22)
git-committer:
Sebastian Huber <sebastian.huber@…> (03/14/14 07:46:49)
Message:

score: Add SMP lock profiling support

Files:
1 added
24 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/sparc/leon3/amba/amba.c

    rf980561 r53ad908  
    2424struct ambapp_bus ambapp_plb;
    2525
    26 rtems_interrupt_lock LEON3_IrqCtrl_Lock = RTEMS_INTERRUPT_LOCK_INITIALIZER;
     26rtems_interrupt_lock LEON3_IrqCtrl_Lock =
     27  RTEMS_INTERRUPT_LOCK_INITIALIZER("LEON3 IrqCtrl");
    2728
    2829/* Pointers to Interrupt Controller configuration registers */
  • cpukit/libblock/src/diskdevs.c

    rf980561 r53ad908  
    5858static volatile bool diskdevs_protected;
    5959
    60 static rtems_interrupt_lock diskdevs_lock = RTEMS_INTERRUPT_LOCK_INITIALIZER;
     60static rtems_interrupt_lock diskdevs_lock =
     61  RTEMS_INTERRUPT_LOCK_INITIALIZER("diskdevs");
    6162
    6263static rtems_status_code
  • cpukit/libcsupport/src/sup_fs_location.c

    rf980561 r53ad908  
    3030
    3131rtems_interrupt_lock rtems_filesystem_mt_entry_lock_control =
    32   RTEMS_INTERRUPT_LOCK_INITIALIZER;
     32  RTEMS_INTERRUPT_LOCK_INITIALIZER("mount table entry");
    3333
    3434static rtems_filesystem_global_location_t *deferred_released_global_locations;
  • cpukit/libcsupport/src/termios.c

    rf980561 r53ad908  
    231231    tty->device = *callbacks;
    232232
    233     rtems_interrupt_lock_initialize (&tty->interrupt_lock);
     233    rtems_interrupt_lock_initialize (&tty->interrupt_lock, "Termios");
    234234
    235235    /*
  • cpukit/posix/src/psignal.c

    rf980561 r53ad908  
    4646/*** PROCESS WIDE STUFF ****/
    4747
    48 ISR_lock_Control _POSIX_signals_Lock = ISR_LOCK_INITIALIZER;
     48ISR_lock_Control _POSIX_signals_Lock = ISR_LOCK_INITIALIZER("POSIX signals");
    4949
    5050sigset_t  _POSIX_signals_Pending;
  • cpukit/rtems/include/rtems/rtems/asrimpl.h

    rf980561 r53ad908  
    4747  asr->signals_pending = 0;
    4848  asr->nest_level      = 0;
    49   _ISR_lock_Initialize( &asr->Lock );
     49  _ISR_lock_Initialize( &asr->Lock, "ASR" );
    5050}
    5151
  • cpukit/rtems/include/rtems/rtems/intr.h

    rf980561 r53ad908  
    168168 * @brief Initializer for static initialization of interrupt locks.
    169169 */
    170 #define RTEMS_INTERRUPT_LOCK_INITIALIZER ISR_LOCK_INITIALIZER
     170#define RTEMS_INTERRUPT_LOCK_INITIALIZER( _name ) ISR_LOCK_INITIALIZER( _name )
    171171
    172172/**
     
    176176 *
    177177 * @param[in,out] _lock The interrupt lock.
    178  */
    179 #define rtems_interrupt_lock_initialize( _lock ) \
    180   _ISR_lock_Initialize( _lock )
     178 * @param[in] _name The name for the interrupt lock.  This name must be
     179 * persistent throughout the life time of this lock.
     180 */
     181#define rtems_interrupt_lock_initialize( _lock, _name ) \
     182  _ISR_lock_Initialize( _lock, _name )
    181183
    182184/**
  • cpukit/sapi/src/chainsmp.c

    rf980561 r53ad908  
    2323#include <rtems/score/smplock.h>
    2424
    25 static SMP_lock_Control chain_lock = SMP_LOCK_INITIALIZER;
     25static SMP_lock_Control chain_lock = SMP_LOCK_INITIALIZER("chains");
    2626
    2727static void chain_acquire( SMP_lock_Context *lock_context )
  • cpukit/sapi/src/profilingiterate.c

    rf980561 r53ad908  
    1919#include <rtems/profiling.h>
    2020#include <rtems/counter.h>
     21#include <rtems/score/smplock.h>
    2122#include <rtems.h>
    2223
     
    7778}
    7879
     80#if defined(RTEMS_PROFILING) && defined(RTEMS_SMP)
     81RTEMS_STATIC_ASSERT(
     82  RTEMS_PROFILING_SMP_LOCK_CONTENTION_COUNTS
     83    == SMP_LOCK_STATS_CONTENTION_COUNTS,
     84  smp_lock_contention_counts
     85);
     86#endif
     87
     88static void smp_lock_stats_iterate(
     89  rtems_profiling_visitor visitor,
     90  void *visitor_arg,
     91  rtems_profiling_data *data
     92)
     93{
     94#if defined(RTEMS_PROFILING) && defined(RTEMS_SMP)
     95  SMP_lock_Stats_iteration_context iteration_context;
     96  SMP_lock_Stats snapshot;
     97  char name[64];
     98
     99  memset(data, 0, sizeof(*data));
     100  data->header.type = RTEMS_PROFILING_SMP_LOCK;
     101
     102  _SMP_lock_Stats_iteration_start(&iteration_context);
     103  while (
     104    _SMP_lock_Stats_iteration_next(
     105      &iteration_context,
     106      &snapshot,
     107      &name[0],
     108      sizeof(name)
     109    )
     110  ) {
     111    rtems_profiling_smp_lock *smp_lock_data = &data->smp_lock;
     112
     113    smp_lock_data->name = name;
     114    smp_lock_data->max_acquire_time =
     115      rtems_counter_ticks_to_nanoseconds(snapshot.max_acquire_time);
     116    smp_lock_data->max_section_time =
     117      rtems_counter_ticks_to_nanoseconds(snapshot.max_section_time);
     118    smp_lock_data->usage_count = snapshot.usage_count;
     119    smp_lock_data->total_acquire_time =
     120      rtems_counter_ticks_to_nanoseconds(snapshot.total_acquire_time);
     121    smp_lock_data->total_section_time =
     122      rtems_counter_ticks_to_nanoseconds(snapshot.total_section_time);
     123
     124    memcpy(
     125      &smp_lock_data->contention_counts[0],
     126      &snapshot.contention_counts[0],
     127      sizeof(smp_lock_data->contention_counts)
     128    );
     129
     130    (*visitor)(visitor_arg, data);
     131  }
     132  _SMP_lock_Stats_iteration_stop(&iteration_context);
     133#else
     134  (void) visitor;
     135  (void) visitor_arg;
     136  (void) data;
     137#endif
     138}
     139
    79140void rtems_profiling_iterate(
    80141  rtems_profiling_visitor visitor,
     
    85146
    86147  per_cpu_stats_iterate(visitor, visitor_arg, &data);
     148  smp_lock_stats_iterate(visitor, visitor_arg, &data);
    87149}
  • cpukit/score/Makefile.am

    rf980561 r53ad908  
    124124
    125125if HAS_SMP
     126libscore_a_SOURCES += src/profilingsmplock.c
    126127libscore_a_SOURCES += src/schedulerprioritysmp.c
    127128libscore_a_SOURCES += src/schedulersimplesmp.c
  • cpukit/score/include/rtems/score/isrlock.h

    rf980561 r53ad908  
    7272 */
    7373#if defined( RTEMS_SMP )
    74   #define ISR_LOCK_INITIALIZER \
    75     { SMP_LOCK_INITIALIZER }
    76 #else
    77   #define ISR_LOCK_INITIALIZER \
     74  #define ISR_LOCK_INITIALIZER( name ) \
     75    { SMP_LOCK_INITIALIZER( name ) }
     76#else
     77  #define ISR_LOCK_INITIALIZER( name ) \
    7878    { }
    7979#endif
     
    8585 *
    8686 * @param[in,out] lock The ISR lock control.
    87  */
    88 static inline void _ISR_lock_Initialize( ISR_lock_Control *lock )
    89 {
    90 #if defined( RTEMS_SMP )
    91   _SMP_lock_Initialize( &lock->lock );
    92 #else
    93   (void) lock;
     87 * @param[in] name The name for the ISR lock.  This name must be persistent
     88 * throughout the life time of this lock.
     89 */
     90static inline void _ISR_lock_Initialize(
     91  ISR_lock_Control *lock,
     92  const char *name
     93)
     94{
     95#if defined( RTEMS_SMP )
     96  _SMP_lock_Initialize( &lock->lock, name );
     97#else
     98  (void) lock;
     99  (void) name;
    94100#endif
    95101}
  • cpukit/score/include/rtems/score/percpu.h

    rf980561 r53ad908  
    4141   * processor.
    4242   */
    43   #define PER_CPU_CONTROL_SIZE_LOG2 7
     43  #if defined( RTEMS_PROFILING )
     44    #define PER_CPU_CONTROL_SIZE_LOG2 8
     45  #else
     46    #define PER_CPU_CONTROL_SIZE_LOG2 7
     47  #endif
    4448
    4549  #define PER_CPU_CONTROL_SIZE ( 1 << PER_CPU_CONTROL_SIZE_LOG2 )
     
    288292
    289293    /**
     294     * @brief Lock statistics context for the per-CPU lock.
     295     */
     296    SMP_lock_Stats_context Lock_stats_context;
     297
     298    /**
    290299     * @brief Context for the Giant lock acquire and release pair of this
    291300     * processor.
     
    334343#if defined( RTEMS_SMP )
    335344#define _Per_CPU_Acquire( per_cpu ) \
    336   _SMP_ticket_lock_Acquire( &( per_cpu )->Lock )
     345  _SMP_ticket_lock_Acquire( \
     346    &( per_cpu )->Lock, \
     347    &( per_cpu )->Lock_stats_context \
     348  )
    337349#else
    338350#define _Per_CPU_Acquire( per_cpu ) \
     
    344356#if defined( RTEMS_SMP )
    345357#define _Per_CPU_Release( per_cpu ) \
    346   _SMP_ticket_lock_Release( &( per_cpu )->Lock )
     358  _SMP_ticket_lock_Release( \
     359    &( per_cpu )->Lock, \
     360    &( per_cpu )->Lock_stats_context \
     361  )
    347362#else
    348363#define _Per_CPU_Release( per_cpu ) \
  • cpukit/score/include/rtems/score/smplock.h

    rf980561 r53ad908  
    2828#include <rtems/score/isrlevel.h>
    2929
     30#if defined( RTEMS_PROFILING )
     31#include <rtems/score/chainimpl.h>
     32#include <string.h>
     33#endif
     34
    3035#ifdef __cplusplus
    3136extern "C" {
     
    5156
    5257/**
     58 * @brief Count of lock contention counters for lock statistics.
     59 */
     60#define SMP_LOCK_STATS_CONTENTION_COUNTS 4
     61
     62/**
     63 * @brief SMP lock statistics.
     64 *
     65 * The lock acquire attempt instant is the point in time right after the
     66 * interrupt disable action in the lock acquire sequence.
     67 *
     68 * The lock acquire instant is the point in time right after the lock
     69 * acquisition.  This is the begin of the critical section code execution.
     70 *
     71 * The lock release instant is the point in time right before the interrupt
     72 * enable action in the lock release sequence.
     73 *
     74 * The lock section time is the time elapsed between the lock acquire instant
     75 * and the lock release instant.
     76 *
     77 * The lock acquire time is the time elapsed between the lock acquire attempt
     78 * instant and the lock acquire instant.
     79 */
     80typedef struct {
     81#if defined( RTEMS_PROFILING )
     82  /**
     83   * @brief Node for SMP lock statistics chain.
     84   */
     85  Chain_Node Node;
     86
     87  /**
     88   * @brief The maximum lock acquire time in CPU counter ticks.
     89   */
     90  CPU_Counter_ticks max_acquire_time;
     91
     92  /**
     93   * @brief The maximum lock section time in CPU counter ticks.
     94   */
     95  CPU_Counter_ticks max_section_time;
     96
     97  /**
     98   * @brief The count of lock uses.
     99   *
     100   * This value may overflow.
     101   */
     102  uint64_t usage_count;
     103
     104  /**
     105   * @brief Total lock acquire time in nanoseconds.
     106   *
     107   * The average lock acquire time is the total acquire time divided by the
     108   * lock usage count.  The ration of the total section and total acquire times
     109   * gives a measure for the lock contention.
     110   *
     111   * This value may overflow.
     112   */
     113  uint64_t total_acquire_time;
     114
     115  /**
     116   * @brief The counts of lock acquire operations by contention.
     117   *
     118   * The contention count for index N corresponds to a lock acquire attempt
     119   * with an initial queue length of N.  The last index corresponds to all
     120   * lock acquire attempts with an initial queue length greater than or equal
     121   * to SMP_LOCK_STATS_CONTENTION_COUNTS minus one.
     122   *
     123   * The values may overflow.
     124   */
     125  uint64_t contention_counts[SMP_LOCK_STATS_CONTENTION_COUNTS];
     126
     127  /**
     128   * @brief Total lock section time in CPU counter ticks.
     129   *
     130   * The average lock section time is the total section time divided by the
     131   * lock usage count.
     132   *
     133   * This value may overflow.
     134   */
     135  uint64_t total_section_time;
     136
     137  /**
     138   * @brief The lock name.
     139   */
     140  const char *name;
     141#endif /* defined( RTEMS_PROFILING ) */
     142} SMP_lock_Stats;
     143
     144/**
     145 * @brief Local context for SMP lock statistics.
     146 */
     147typedef struct {
     148#if defined( RTEMS_PROFILING )
     149  /**
     150   * @brief The last lock acquire instant in CPU counter ticks.
     151   *
     152   * This value is used to measure the lock section time.
     153   */
     154  CPU_Counter_ticks acquire_instant;
     155#endif
     156} SMP_lock_Stats_context;
     157
     158/**
     159 * @brief SMP lock statistics initializer for static initialization.
     160 */
     161#if defined( RTEMS_PROFILING )
     162#define SMP_LOCK_STATS_INITIALIZER( name ) \
     163  { { NULL, NULL }, 0, 0, 0, 0, { 0, 0, 0, 0 }, 0, name }
     164#else
     165#define SMP_LOCK_STATS_INITIALIZER( name ) \
     166  { }
     167#endif
     168
     169/**
     170 * @brief Initializes an SMP lock statistics block.
     171 *
     172 * @param[in, out] stats The SMP lock statistics block.
     173 * @param[in] name The name for the SMP lock statistics.  This name must be
     174 * persistent throughout the life time of this statistics block.
     175 */
     176static inline void _SMP_lock_Stats_initialize(
     177  SMP_lock_Stats *stats,
     178  const char *name
     179)
     180{
     181  SMP_lock_Stats init = SMP_LOCK_STATS_INITIALIZER( name );
     182
     183  *stats = init;
     184}
     185
     186/**
     187 * @brief Destroys an SMP lock statistics block.
     188 *
     189 * @param[in,out] stats The SMP lock statistics block.
     190 */
     191static inline void _SMP_lock_Stats_destroy( SMP_lock_Stats *stats );
     192
     193/**
     194 * @brief Destroys an SMP lock statistics block.
     195 *
     196 * @param[in,out] stats The SMP lock statistics block.
     197 * @param[in] stats_context The SMP lock statistics context.
     198 */
     199static inline void _SMP_lock_Stats_release_update(
     200  SMP_lock_Stats *stats,
     201  const SMP_lock_Stats_context *stats_context
     202);
     203
     204/**
    53205 * @brief SMP ticket lock control.
    54206 */
     
    56208  Atomic_Uint next_ticket;
    57209  Atomic_Uint now_serving;
     210  SMP_lock_Stats Stats;
    58211} SMP_ticket_lock_Control;
    59212
     
    61214 * @brief SMP ticket lock control initializer for static initialization.
    62215 */
    63 #define SMP_TICKET_LOCK_INITIALIZER \
    64   { ATOMIC_INITIALIZER_UINT( 0U ), ATOMIC_INITIALIZER_UINT( 0U ) }
     216#define SMP_TICKET_LOCK_INITIALIZER( name ) \
     217  { \
     218    ATOMIC_INITIALIZER_UINT( 0U ), \
     219    ATOMIC_INITIALIZER_UINT( 0U ), \
     220    SMP_LOCK_STATS_INITIALIZER( name ) \
     221  }
    65222
    66223/**
     
    70227 *
    71228 * @param[in,out] lock The SMP ticket lock control.
    72  */
    73 static inline void _SMP_ticket_lock_Initialize( SMP_ticket_lock_Control *lock )
     229 * @param[in] name The name for the SMP ticket lock.  This name must be
     230 * persistent throughout the life time of this lock.
     231 */
     232static inline void _SMP_ticket_lock_Initialize(
     233  SMP_ticket_lock_Control *lock,
     234  const char *name
     235)
    74236{
    75237  _Atomic_Init_uint( &lock->next_ticket, 0U );
    76238  _Atomic_Init_uint( &lock->now_serving, 0U );
     239  _SMP_lock_Stats_initialize( &lock->Stats, name );
    77240}
    78241
     
    86249static inline void _SMP_ticket_lock_Destroy( SMP_ticket_lock_Control *lock )
    87250{
    88   (void) lock;
     251  _SMP_lock_Stats_destroy( &lock->Stats );
    89252}
    90253
     
    97260 *
    98261 * @param[in,out] lock The SMP ticket lock control.
    99  */
    100 static inline void _SMP_ticket_lock_Acquire( SMP_ticket_lock_Control *lock )
    101 {
    102   unsigned int my_ticket =
     262 * @param[out] stats_context The SMP lock statistics context.
     263 */
     264static inline void _SMP_ticket_lock_Acquire(
     265  SMP_ticket_lock_Control *lock,
     266  SMP_lock_Stats_context *stats_context
     267)
     268{
     269  unsigned int my_ticket;
     270  unsigned int now_serving;
     271
     272#if defined( RTEMS_PROFILING )
     273  SMP_lock_Stats *stats = &lock->Stats;
     274  CPU_Counter_ticks first;
     275  CPU_Counter_ticks second;
     276  CPU_Counter_ticks delta;
     277  unsigned int initial_queue_length;
     278
     279  first = _CPU_Counter_read();
     280#endif
     281
     282  my_ticket =
    103283    _Atomic_Fetch_add_uint( &lock->next_ticket, 1U, ATOMIC_ORDER_RELAXED );
    104   unsigned int now_serving;
    105 
    106   do {
    107     now_serving =
    108       _Atomic_Load_uint( &lock->now_serving, ATOMIC_ORDER_ACQUIRE );
    109   } while ( now_serving != my_ticket );
     284
     285#if defined( RTEMS_PROFILING )
     286  now_serving =
     287    _Atomic_Load_uint( &lock->now_serving, ATOMIC_ORDER_ACQUIRE );
     288  initial_queue_length = my_ticket - now_serving;
     289
     290  if ( initial_queue_length > 0 ) {
     291#endif
     292
     293    do {
     294      now_serving =
     295        _Atomic_Load_uint( &lock->now_serving, ATOMIC_ORDER_ACQUIRE );
     296    } while ( now_serving != my_ticket );
     297
     298#if defined( RTEMS_PROFILING )
     299  }
     300
     301  second = _CPU_Counter_read();
     302  stats_context->acquire_instant = second;
     303  delta = _CPU_Counter_difference( second, first );
     304
     305  ++stats->usage_count;
     306
     307  stats->total_acquire_time += delta;
     308
     309  if ( stats->max_acquire_time < delta ) {
     310    stats->max_acquire_time = delta;
     311  }
     312
     313  if ( initial_queue_length >= SMP_LOCK_STATS_CONTENTION_COUNTS ) {
     314    initial_queue_length = SMP_LOCK_STATS_CONTENTION_COUNTS - 1;
     315  }
     316  ++stats->contention_counts[initial_queue_length];
     317#else
     318  (void) stats_context;
     319#endif
    110320}
    111321
     
    114324 *
    115325 * @param[in,out] lock The SMP ticket lock control.
    116  */
    117 static inline void _SMP_ticket_lock_Release( SMP_ticket_lock_Control *lock )
     326 * @param[in] stats_context The SMP lock statistics context.
     327 */
     328static inline void _SMP_ticket_lock_Release(
     329  SMP_ticket_lock_Control *lock,
     330  const SMP_lock_Stats_context *stats_context
     331)
    118332{
    119333  unsigned int current_ticket =
     
    121335  unsigned int next_ticket = current_ticket + 1U;
    122336
     337  _SMP_lock_Stats_release_update( &lock->Stats, stats_context );
     338
    123339  _Atomic_Store_uint( &lock->now_serving, next_ticket, ATOMIC_ORDER_RELEASE );
    124340}
     
    136352typedef struct {
    137353  ISR_Level isr_level;
     354  SMP_lock_Stats_context Stats_context;
    138355} SMP_lock_Context;
    139356
     
    141358 * @brief SMP lock control initializer for static initialization.
    142359 */
    143 #define SMP_LOCK_INITIALIZER { SMP_TICKET_LOCK_INITIALIZER }
     360#define SMP_LOCK_INITIALIZER( name ) { SMP_TICKET_LOCK_INITIALIZER( name ) }
    144361
    145362/**
     
    149366 *
    150367 * @param[in,out] lock The SMP lock control.
    151  */
    152 static inline void _SMP_lock_Initialize( SMP_lock_Control *lock )
    153 {
    154   _SMP_ticket_lock_Initialize( &lock->ticket_lock );
     368 * @param[in] name The name for the SMP lock statistics.  This name must be
     369 * persistent throughout the life time of this statistics block.
     370 */
     371static inline void _SMP_lock_Initialize(
     372  SMP_lock_Control *lock,
     373  const char *name
     374)
     375{
     376  _SMP_ticket_lock_Initialize( &lock->ticket_lock, name );
    155377}
    156378
     
    184406{
    185407  (void) context;
    186   _SMP_ticket_lock_Acquire( &lock->ticket_lock );
     408  _SMP_ticket_lock_Acquire( &lock->ticket_lock, &context->Stats_context );
    187409}
    188410
     
    200422{
    201423  (void) context;
    202   _SMP_ticket_lock_Release( &lock->ticket_lock );
     424  _SMP_ticket_lock_Release( &lock->ticket_lock, &context->Stats_context );
    203425}
    204426
     
    235457}
    236458
     459#if defined( RTEMS_PROFILING )
     460typedef struct {
     461  SMP_lock_Control Lock;
     462  Chain_Control Stats_chain;
     463  Chain_Control Iterator_chain;
     464} SMP_lock_Stats_control;
     465
     466typedef struct {
     467  Chain_Node Node;
     468  SMP_lock_Stats *current;
     469} SMP_lock_Stats_iteration_context;
     470
     471extern SMP_lock_Stats_control _SMP_lock_Stats_control;
     472
     473static inline void _SMP_lock_Stats_iteration_start(
     474  SMP_lock_Stats_iteration_context *iteration_context
     475)
     476{
     477  SMP_lock_Stats_control *control = &_SMP_lock_Stats_control;
     478  SMP_lock_Context lock_context;
     479
     480  _SMP_lock_ISR_disable_and_acquire( &control->Lock, &lock_context );
     481
     482  _Chain_Append_unprotected(
     483    &control->Iterator_chain,
     484    &iteration_context->Node
     485  );
     486  iteration_context->current =
     487    (SMP_lock_Stats *) _Chain_First( &control->Stats_chain );
     488
     489  _SMP_lock_Release_and_ISR_enable( &control->Lock, &lock_context );
     490}
     491
     492static inline bool _SMP_lock_Stats_iteration_next(
     493  SMP_lock_Stats_iteration_context *iteration_context,
     494  SMP_lock_Stats *snapshot,
     495  char *name,
     496  size_t name_size
     497)
     498{
     499  SMP_lock_Stats_control *control = &_SMP_lock_Stats_control;
     500  SMP_lock_Context lock_context;
     501  SMP_lock_Stats *current;
     502  bool valid;
     503
     504  _SMP_lock_ISR_disable_and_acquire( &control->Lock, &lock_context );
     505
     506  current = iteration_context->current;
     507  if ( !_Chain_Is_tail( &control->Stats_chain, &current->Node ) ) {
     508    size_t name_len = strlen(current->name);
     509
     510    valid = true;
     511
     512    iteration_context->current = (SMP_lock_Stats *)
     513      _Chain_Next( &current->Node );
     514
     515    *snapshot = *current;
     516    snapshot->name = name;
     517
     518    if ( name_len >= name_size ) {
     519      name_len = name_size - 1;
     520    }
     521
     522    name[name_len] = '\0';
     523    memcpy(name, current->name, name_len);
     524  } else {
     525    valid = false;
     526  }
     527
     528  _SMP_lock_Release_and_ISR_enable( &control->Lock, &lock_context );
     529
     530  return valid;
     531}
     532
     533static inline void _SMP_lock_Stats_iteration_stop(
     534  SMP_lock_Stats_iteration_context *iteration_context
     535)
     536{
     537  SMP_lock_Stats_control *control = &_SMP_lock_Stats_control;
     538  SMP_lock_Context lock_context;
     539
     540  _SMP_lock_ISR_disable_and_acquire( &control->Lock, &lock_context );
     541  _Chain_Extract_unprotected( &iteration_context->Node );
     542  _SMP_lock_Release_and_ISR_enable( &control->Lock, &lock_context );
     543}
     544#endif
     545
     546static inline void _SMP_lock_Stats_destroy( SMP_lock_Stats *stats )
     547{
     548#if defined( RTEMS_PROFILING )
     549  if ( !_Chain_Is_node_off_chain( &stats->Node ) ) {
     550    SMP_lock_Stats_control *control = &_SMP_lock_Stats_control;
     551    SMP_lock_Context lock_context;
     552    SMP_lock_Stats_iteration_context *iteration_context;
     553    SMP_lock_Stats_iteration_context *iteration_context_tail;
     554    SMP_lock_Stats *next_stats;
     555
     556    _SMP_lock_ISR_disable_and_acquire( &control->Lock, &lock_context );
     557
     558    next_stats = (SMP_lock_Stats *) _Chain_Next( &stats->Node );
     559    _Chain_Extract_unprotected( &stats->Node );
     560
     561    iteration_context = (SMP_lock_Stats_iteration_context *)
     562      _Chain_First( &control->Iterator_chain );
     563    iteration_context_tail = (SMP_lock_Stats_iteration_context *)
     564      _Chain_Tail( &control->Iterator_chain );
     565
     566    while ( iteration_context != iteration_context_tail ) {
     567      if ( iteration_context->current == stats ) {
     568        iteration_context->current = next_stats;
     569      }
     570
     571      iteration_context = (SMP_lock_Stats_iteration_context *)
     572        _Chain_Next( &iteration_context->Node );
     573    }
     574
     575    _SMP_lock_Release_and_ISR_enable( &control->Lock, &lock_context );
     576  }
     577#else
     578  (void) stats;
     579#endif
     580}
     581
     582static inline void _SMP_lock_Stats_release_update(
     583  SMP_lock_Stats *stats,
     584  const SMP_lock_Stats_context *stats_context
     585)
     586{
     587#if defined( RTEMS_PROFILING )
     588  CPU_Counter_ticks first = stats_context->acquire_instant;
     589  CPU_Counter_ticks second = _CPU_Counter_read();
     590  CPU_Counter_ticks delta = _CPU_Counter_difference( second, first );
     591
     592  stats->total_section_time += delta;
     593
     594  if ( stats->max_section_time < delta ) {
     595    stats->max_section_time = delta;
     596
     597    if ( _Chain_Is_node_off_chain( &stats->Node ) ) {
     598      SMP_lock_Stats_control *control = &_SMP_lock_Stats_control;
     599      SMP_lock_Context lock_context;
     600
     601      _SMP_lock_ISR_disable_and_acquire( &control->Lock, &lock_context );
     602      _Chain_Append_unprotected( &control->Stats_chain, &stats->Node );
     603      _SMP_lock_Release_and_ISR_enable( &control->Lock, &lock_context );
     604    }
     605  }
     606#else
     607  (void) stats;
     608  (void) stats_context;
     609#endif
     610}
     611
    237612/**@}*/
    238613
  • cpukit/score/src/coretod.c

    rf980561 r53ad908  
    3030  TOD_Control *tod = &_TOD;
    3131
    32   _ISR_lock_Initialize( &tod->lock );
     32  _ISR_lock_Initialize( &tod->lock, "TOD" );
    3333
    3434  _Timestamp_Set( &tod->now, TOD_SECONDS_1970_THROUGH_1988, 0 );
  • cpukit/score/src/percpu.c

    rf980561 r53ad908  
    2727#if defined(RTEMS_SMP)
    2828
    29 static SMP_lock_Control _Per_CPU_State_lock = SMP_LOCK_INITIALIZER;
     29static SMP_lock_Control _Per_CPU_State_lock =
     30  SMP_LOCK_INITIALIZER("per-CPU state");
    3031
    3132static void _Per_CPU_State_busy_wait(
  • cpukit/score/src/smp.c

    rf980561 r53ad908  
    3333    Per_CPU_Control *per_cpu = _Per_CPU_Get_by_index( cpu );
    3434
    35     _SMP_ticket_lock_Initialize( &per_cpu->Lock );
     35    _SMP_ticket_lock_Initialize( &per_cpu->Lock, "per-CPU" );
    3636  }
    3737
  • cpukit/score/src/threaddispatchdisablelevel.c

    rf980561 r53ad908  
    3030
    3131static Giant_Control _Giant = {
    32   .lock = SMP_LOCK_INITIALIZER,
     32  .lock = SMP_LOCK_INITIALIZER("Giant"),
    3333  .owner_cpu = NO_OWNER_CPU,
    3434  .nest_level = 0
  • cpukit/score/src/threadhandler.c

    rf980561 r53ad908  
    5757
    5858    #if defined(RTEMS_SMP)
    59       static SMP_lock_Control constructor_lock = SMP_LOCK_INITIALIZER;
     59      static SMP_lock_Control constructor_lock =
     60        SMP_LOCK_INITIALIZER("constructor");
    6061
    6162      SMP_lock_Context lock_context;
  • testsuites/smptests/smplock01/init.c

    rf980561 r53ad908  
    4949  .state = ATOMIC_INITIALIZER_UINT(INITIAL),
    5050  .barrier = SMP_BARRIER_CONTROL_INITIALIZER,
    51   .lock = SMP_LOCK_INITIALIZER
     51  .lock = SMP_LOCK_INITIALIZER("global")
    5252};
    5353
     
    142142  SMP_lock_Context lock_context;
    143143
    144   _SMP_lock_Initialize(&lock);
     144  _SMP_lock_Initialize(&lock, "local");
    145145
    146146  while (assert_state(ctx, START_TEST)) {
     
    167167  SMP_lock_Context lock_context;
    168168
    169   _SMP_lock_Initialize(&lock);
     169  _SMP_lock_Initialize(&lock, "local");
    170170
    171171  while (assert_state(ctx, START_TEST)) {
  • testsuites/sptests/sp37/init.c

    rf980561 r53ad908  
    161161{
    162162  ISR_Level normal_interrupt_level = _ISR_Get_level();
    163   ISR_lock_Control initialized = ISR_LOCK_INITIALIZER;
     163  ISR_lock_Control initialized = ISR_LOCK_INITIALIZER("test");
    164164  ISR_lock_Control lock;
    165165  ISR_lock_Context lock_context;
    166166
    167   _ISR_lock_Initialize( &lock );
     167  _ISR_lock_Initialize( &lock, "test" );
    168168  rtems_test_assert( memcmp( &lock, &initialized, sizeof( lock ) ) == 0 );
    169169
     
    198198{
    199199  rtems_mode normal_interrupt_level = get_interrupt_level();
    200   rtems_interrupt_lock initialized = RTEMS_INTERRUPT_LOCK_INITIALIZER;
     200  rtems_interrupt_lock initialized = RTEMS_INTERRUPT_LOCK_INITIALIZER("test");
    201201  rtems_interrupt_lock lock;
    202202  rtems_interrupt_lock_context lock_context;
    203203
    204   rtems_interrupt_lock_initialize( &lock );
     204  rtems_interrupt_lock_initialize( &lock, "test" );
    205205  rtems_test_assert( memcmp( &lock, &initialized, sizeof( lock ) ) == 0 );
    206206
  • testsuites/sptests/spcache01/init.c

    rf980561 r53ad908  
    4949    printf("data cache flush and invalidate test\n");
    5050
    51     rtems_interrupt_lock_initialize(&lock);
     51    rtems_interrupt_lock_initialize(&lock, "test");
    5252    rtems_interrupt_lock_acquire(&lock, &lock_context);
    5353
     
    169169  size_t cache_size;
    170170
    171   rtems_interrupt_lock_initialize(&lock);
     171  rtems_interrupt_lock_initialize(&lock, "test");
    172172
    173173  printf(
  • testsuites/sptests/spnsext01/init.c

    rf980561 r53ad908  
    5252  n = (3 * n) / 2;
    5353
    54   rtems_interrupt_lock_initialize(&lock);
     54  rtems_interrupt_lock_initialize(&lock, "test");
    5555  rtems_interrupt_lock_acquire(&lock, &lock_context);
    5656  sc = rtems_clock_get_uptime(&uptime);
  • testsuites/sptests/spprofiling01/init.c

    rf980561 r53ad908  
    2222
    2323#include <stdio.h>
     24#include <string.h>
    2425
    2526#include "tmacros.h"
    2627
    27 static void test(void)
     28typedef struct {
     29  rtems_interrupt_lock a;
     30  rtems_interrupt_lock b;
     31  rtems_interrupt_lock c;
     32  rtems_interrupt_lock d;
     33  enum {
     34    WAIT_FOR_A,
     35    EXPECT_B,
     36    EXPECT_D,
     37    DONE
     38  } state;
     39} visitor_context;
     40
     41static bool is_equal(const rtems_profiling_smp_lock *psl, const char *name)
     42{
     43  return strcmp(psl->name, name) == 0;
     44}
     45
     46static void visitor(void *arg, const rtems_profiling_data *data)
     47{
     48  visitor_context *ctx = arg;
     49
     50  if (data->header.type == RTEMS_PROFILING_SMP_LOCK) {
     51    const rtems_profiling_smp_lock *psl = &data->smp_lock;
     52
     53    switch (ctx->state) {
     54      case WAIT_FOR_A:
     55        rtems_test_assert(!is_equal(psl, "b"));
     56        rtems_test_assert(!is_equal(psl, "c"));
     57        rtems_test_assert(!is_equal(psl, "d"));
     58
     59        if (is_equal(psl, "a")) {
     60          ctx->state = EXPECT_B;
     61        }
     62        break;
     63      case EXPECT_B:
     64        rtems_test_assert(is_equal(psl, "b"));
     65        rtems_interrupt_lock_destroy(&ctx->c);
     66        ctx->state = EXPECT_D;
     67        break;
     68      case EXPECT_D:
     69        rtems_test_assert(is_equal(psl, "d"));
     70        ctx->state = DONE;
     71        break;
     72      case DONE:
     73        rtems_test_assert(!is_equal(psl, "a"));
     74        rtems_test_assert(!is_equal(psl, "b"));
     75        rtems_test_assert(!is_equal(psl, "c"));
     76        rtems_test_assert(!is_equal(psl, "d"));
     77        break;
     78    }
     79  }
     80}
     81
     82static void lock_init(rtems_interrupt_lock *lock, const char *name)
     83{
     84  rtems_interrupt_lock_context lock_context;
     85
     86  rtems_interrupt_lock_initialize(lock, name);
     87  rtems_interrupt_lock_acquire(lock, &lock_context);
     88  rtems_interrupt_lock_release(lock, &lock_context);
     89}
     90
     91static void test_iterate(void)
     92{
     93  visitor_context ctx_instance;
     94  visitor_context *ctx = &ctx_instance;
     95
     96  ctx->state = WAIT_FOR_A;
     97  lock_init(&ctx->a, "a");
     98  lock_init(&ctx->b, "b");
     99  lock_init(&ctx->c, "c");
     100  lock_init(&ctx->d, "d");
     101
     102  rtems_profiling_iterate(visitor, ctx);
     103
     104  rtems_interrupt_lock_destroy(&ctx->a);
     105  rtems_interrupt_lock_destroy(&ctx->b);
     106
     107  if (ctx->state != DONE) {
     108    rtems_interrupt_lock_destroy(&ctx->c);
     109  }
     110
     111  rtems_interrupt_lock_destroy(&ctx->d);
     112}
     113
     114static void test_report_xml(void)
    28115{
    29116  rtems_status_code sc;
     
    41128  puts("\n\n*** TEST SPPROFILING 1 ***");
    42129
    43   test();
     130  test_iterate();
     131  test_report_xml();
    44132
    45133  puts("*** END OF TEST SPPROFILING 1 ***");
  • testsuites/tmtests/tmcontext01/init.c

    rf980561 r53ad908  
    139139  uint64_t max;
    140140
    141   rtems_interrupt_lock_initialize(&lock);
     141  rtems_interrupt_lock_initialize(&lock, "test");
    142142  rtems_interrupt_lock_acquire(&lock, &lock_context);
    143143
Note: See TracChangeset for help on using the changeset viewer.