diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2014-03-10 10:04:09 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2014-03-14 08:46:49 +0100 |
commit | f980561ee073a7f24f65ed572852fa96edfa1708 (patch) | |
tree | a2e62dd469acbe201388c9b8a3e0ebd9d7277e9f /cpukit/score/include/rtems/score | |
parent | sapi: Add SMP lock profiling app. level data (diff) | |
download | rtems-f980561ee073a7f24f65ed572852fa96edfa1708.tar.bz2 |
score: Add per-CPU profiling
Add per-CPU profiling stats API. Implement the thread dispatch disable
level profiling. The interrupt profiling must be implemented in CPU
port specific parts (mostly assembler code). Add a support function
_Profiling_Outer_most_interrupt_entry_and_exit() for this purpose.
Diffstat (limited to 'cpukit/score/include/rtems/score')
-rw-r--r-- | cpukit/score/include/rtems/score/percpu.h | 74 | ||||
-rw-r--r-- | cpukit/score/include/rtems/score/profiling.h | 113 | ||||
-rw-r--r-- | cpukit/score/include/rtems/score/threaddispatch.h | 37 |
3 files changed, 216 insertions, 8 deletions
diff --git a/cpukit/score/include/rtems/score/percpu.h b/cpukit/score/include/rtems/score/percpu.h index 067cb84a29..5ba463e812 100644 --- a/cpukit/score/include/rtems/score/percpu.h +++ b/cpukit/score/include/rtems/score/percpu.h @@ -155,6 +155,78 @@ typedef enum { #endif /* defined( RTEMS_SMP ) */ /** + * @brief Per-CPU statistics. + */ +typedef struct { +#if defined( RTEMS_PROFILING ) + /** + * @brief The thread dispatch disabled begin instant in CPU counter ticks. + * + * This value is used to measure the time of disabled thread dispatching. + */ + CPU_Counter_ticks thread_dispatch_disabled_instant; + + /** + * @brief The maximum time of disabled thread dispatching in CPU counter + * ticks. + */ + CPU_Counter_ticks max_thread_dispatch_disabled_time; + + /** + * @brief The maximum time spent to process a single sequence of nested + * interrupts in CPU counter ticks. + * + * This is the time interval between the change of the interrupt nest level + * from zero to one and the change back from one to zero. + */ + CPU_Counter_ticks max_interrupt_time; + + /** + * @brief The maximum interrupt delay in CPU counter ticks if supported by + * the hardware. + */ + CPU_Counter_ticks max_interrupt_delay; + + /** + * @brief Count of times when the thread dispatch disable level changes from + * zero to one in thread context. + * + * This value may overflow. + */ + uint64_t thread_dispatch_disabled_count; + + /** + * @brief Total time of disabled thread dispatching in CPU counter ticks. + * + * The average time of disabled thread dispatching is the total time of + * disabled thread dispatching divided by the thread dispatch disabled + * count. + * + * This value may overflow. + */ + uint64_t total_thread_dispatch_disabled_time; + + /** + * @brief Count of times when the interrupt nest level changes from zero to + * one. + * + * This value may overflow. + */ + uint64_t interrupt_count; + + /** + * @brief Total time of interrupt processing in CPU counter ticks. + * + * The average time of interrupt processing is the total time of interrupt + * processing divided by the interrupt count. + * + * This value may overflow. + */ + uint64_t total_interrupt_time; +#endif /* defined( RTEMS_PROFILING ) */ +} Per_CPU_Stats; + +/** * @brief Per CPU Core Structure * * This structure is used to hold per core state information. @@ -236,6 +308,8 @@ typedef struct { */ Per_CPU_State state; #endif + + Per_CPU_Stats Stats; } Per_CPU_Control; #if defined( RTEMS_SMP ) diff --git a/cpukit/score/include/rtems/score/profiling.h b/cpukit/score/include/rtems/score/profiling.h new file mode 100644 index 0000000000..468c124450 --- /dev/null +++ b/cpukit/score/include/rtems/score/profiling.h @@ -0,0 +1,113 @@ +/** + * @file + * + * @ingroup ScoreProfiling + * + * @brief Profiling Support API + */ + +/* + * Copyright (c) 2014 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * <rtems@embedded-brains.de> + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + */ + +#ifndef _RTEMS_SCORE_PROFILING +#define _RTEMS_SCORE_PROFILING + +#include <rtems/score/percpu.h> + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @defgroup ScoreProfiling Profiling Support + * + * @brief Profiling support. + * + * @{ + */ + +static inline void _Profiling_Thread_dispatch_disable( + Per_CPU_Control *per_cpu, + uint32_t previous_thread_dispatch_disable_level +) +{ +#if defined( RTEMS_PROFILING ) + if ( previous_thread_dispatch_disable_level == 0 ) { + Per_CPU_Stats *stats = &per_cpu->Stats; + + stats->thread_dispatch_disabled_instant = _CPU_Counter_read(); + ++stats->thread_dispatch_disabled_count; + } +#else + (void) per_cpu; + (void) previous_thread_dispatch_disable_level; +#endif +} + +static inline void _Profiling_Thread_dispatch_enable( + Per_CPU_Control *per_cpu, + uint32_t new_thread_dispatch_disable_level +) +{ +#if defined( RTEMS_PROFILING ) + if ( new_thread_dispatch_disable_level == 0 ) { + Per_CPU_Stats *stats = &per_cpu->Stats; + CPU_Counter_ticks now = _CPU_Counter_read(); + CPU_Counter_ticks delta = _CPU_Counter_difference( + now, + stats->thread_dispatch_disabled_instant + ); + + stats->total_thread_dispatch_disabled_time += delta; + + if ( stats->max_thread_dispatch_disabled_time < delta ) { + stats->max_thread_dispatch_disabled_time = delta; + } + } +#else + (void) per_cpu; + (void) new_thread_dispatch_disable_level; +#endif +} + +static inline void _Profiling_Update_max_interrupt_delay( + Per_CPU_Control *per_cpu, + CPU_Counter_ticks interrupt_delay +) +{ +#if defined( RTEMS_PROFILING ) + Per_CPU_Stats *stats = &per_cpu->Stats; + + if ( stats->max_interrupt_delay < interrupt_delay ) { + stats->max_interrupt_delay = interrupt_delay; + } +#else + (void) per_cpu; + (void) interrupt_delay; +#endif +} + +void _Profiling_Outer_most_interrupt_entry_and_exit( + Per_CPU_Control *per_cpu, + CPU_Counter_ticks interrupt_entry_instant, + CPU_Counter_ticks interrupt_exit_instant +); + +/** @} */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _RTEMS_SCORE_PROFILING */ diff --git a/cpukit/score/include/rtems/score/threaddispatch.h b/cpukit/score/include/rtems/score/threaddispatch.h index 5b25212de9..7e616d69f7 100644 --- a/cpukit/score/include/rtems/score/threaddispatch.h +++ b/cpukit/score/include/rtems/score/threaddispatch.h @@ -16,6 +16,7 @@ #include <rtems/score/percpu.h> #include <rtems/score/smplock.h> +#include <rtems/score/profiling.h> #ifdef __cplusplus extern "C" { @@ -140,12 +141,22 @@ RTEMS_INLINE_ROUTINE void _Thread_Dispatch_initialization( void ) */ RTEMS_INLINE_ROUTINE uint32_t _Thread_Dispatch_increment_disable_level(void) { - uint32_t level = _Thread_Dispatch_disable_level; + uint32_t disable_level = _Thread_Dispatch_disable_level; +#if defined( RTEMS_PROFILING ) + ISR_Level level; - ++level; - _Thread_Dispatch_disable_level = level; + _ISR_Disable( level ); + _Profiling_Thread_dispatch_disable( _Per_CPU_Get(), disable_level ); +#endif + + ++disable_level; + _Thread_Dispatch_disable_level = disable_level; + +#if defined( RTEMS_PROFILING ) + _ISR_Enable( level ); +#endif - return level; + return disable_level; } /** @@ -155,12 +166,22 @@ RTEMS_INLINE_ROUTINE void _Thread_Dispatch_initialization( void ) */ RTEMS_INLINE_ROUTINE uint32_t _Thread_Dispatch_decrement_disable_level(void) { - uint32_t level = _Thread_Dispatch_disable_level; + uint32_t disable_level = _Thread_Dispatch_disable_level; +#if defined( RTEMS_PROFILING ) + ISR_Level level; - --level; - _Thread_Dispatch_disable_level = level; + _ISR_Disable( level ); +#endif + + --disable_level; + _Thread_Dispatch_disable_level = disable_level; + +#if defined( RTEMS_PROFILING ) + _Profiling_Thread_dispatch_enable( _Per_CPU_Get(), disable_level ); + _ISR_Enable( level ); +#endif - return level; + return disable_level; } #endif /* RTEMS_SMP */ |