Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:13

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RTEMSScoreProfiling
0007  *
0008  * @brief This header file provides the interfaces of the
0009  *   @ref RTEMSScoreProfiling.
0010  */
0011 
0012 /*
0013  * Copyright (c) 2014 embedded brains GmbH & Co. KG
0014  *
0015  * Redistribution and use in source and binary forms, with or without
0016  * modification, are permitted provided that the following conditions
0017  * are met:
0018  * 1. Redistributions of source code must retain the above copyright
0019  *    notice, this list of conditions and the following disclaimer.
0020  * 2. Redistributions in binary form must reproduce the above copyright
0021  *    notice, this list of conditions and the following disclaimer in the
0022  *    documentation and/or other materials provided with the distribution.
0023  *
0024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0027  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0028  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0029  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0030  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0031  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0032  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0033  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0034  * POSSIBILITY OF SUCH DAMAGE.
0035  */
0036 
0037 #ifndef _RTEMS_SCORE_PROFILING
0038 #define _RTEMS_SCORE_PROFILING
0039 
0040 #include <rtems/score/percpu.h>
0041 #include <rtems/score/isrlock.h>
0042 
0043 #ifdef __cplusplus
0044 extern "C" {
0045 #endif /* __cplusplus */
0046 
0047 /**
0048  * @defgroup RTEMSScoreProfiling Profiling Support
0049  * 
0050  * @ingroup RTEMSScore
0051  *
0052  * @brief This group contains the implementation to support profiling.
0053  *
0054  * @{
0055  */
0056 
0057 /**
0058  * @brief Disables the thread dispatch if the previous thread dispatch
0059  *      disable level is zero.
0060  *
0061  * @param[out] cpu The cpu control.
0062  * @param previous_thread_dispatch_disable_level The dispatch disable
0063  *      level of the previous thread.
0064  */
0065 static inline void _Profiling_Thread_dispatch_disable(
0066   Per_CPU_Control *cpu,
0067   uint32_t previous_thread_dispatch_disable_level
0068 )
0069 {
0070 #if defined( RTEMS_PROFILING )
0071   if ( previous_thread_dispatch_disable_level == 0 ) {
0072     Per_CPU_Stats *stats = &cpu->Stats;
0073 
0074     stats->thread_dispatch_disabled_instant = _CPU_Counter_read();
0075     ++stats->thread_dispatch_disabled_count;
0076   }
0077 #else
0078   (void) cpu;
0079   (void) previous_thread_dispatch_disable_level;
0080 #endif
0081 }
0082 
0083 /**
0084  * @brief Disables the thread dispatch.
0085  *
0086  * Only if the previous thread dispatch disable level is zero.  This
0087  * method also takes into account the lock_context.
0088  *
0089  * @param[out] cpu The cpu control.
0090  * @param previous_thread_dispatch_disable_level The dispatch disable
0091  *      level of the previous thread.
0092  * @param lock_context The lock context.
0093  */
0094 static inline void _Profiling_Thread_dispatch_disable_critical(
0095   Per_CPU_Control        *cpu,
0096   uint32_t                previous_thread_dispatch_disable_level,
0097   const ISR_lock_Context *lock_context
0098 )
0099 {
0100 #if defined( RTEMS_PROFILING )
0101   if ( previous_thread_dispatch_disable_level == 0 ) {
0102     Per_CPU_Stats *stats = &cpu->Stats;
0103 
0104     stats->thread_dispatch_disabled_instant = lock_context->ISR_disable_instant;
0105     ++stats->thread_dispatch_disabled_count;
0106   }
0107 #else
0108   (void) cpu;
0109   (void) previous_thread_dispatch_disable_level;
0110   (void) lock_context;
0111 #endif
0112 }
0113 
0114 /**
0115  * @brief Enables the thread dispatch.
0116  *
0117  * Only if the @a new_thread_dispatch_disable_level is 0.
0118  *
0119  * @param[out] cpu The cpu control.
0120  * @param new_thread_dispatch_disable_level The dispatch disable level
0121  *      of the new thread.
0122  */
0123 static inline void _Profiling_Thread_dispatch_enable(
0124   Per_CPU_Control *cpu,
0125   uint32_t new_thread_dispatch_disable_level
0126 )
0127 {
0128 #if defined( RTEMS_PROFILING )
0129   if ( new_thread_dispatch_disable_level == 0 ) {
0130     Per_CPU_Stats *stats = &cpu->Stats;
0131     CPU_Counter_ticks now = _CPU_Counter_read();
0132     CPU_Counter_ticks delta = now - stats->thread_dispatch_disabled_instant;
0133 
0134     stats->total_thread_dispatch_disabled_time += delta;
0135 
0136     if ( stats->max_thread_dispatch_disabled_time < delta ) {
0137       stats->max_thread_dispatch_disabled_time = delta;
0138     }
0139   }
0140 #else
0141   (void) cpu;
0142   (void) new_thread_dispatch_disable_level;
0143 #endif
0144 }
0145 
0146 /**
0147  * @brief Updates the maximum interrupt delay.
0148  *
0149  * @param[out] cpu The cpu control.
0150  * @param interrupt_delay The new interrupt delay.
0151  */
0152 static inline void _Profiling_Update_max_interrupt_delay(
0153   Per_CPU_Control *cpu,
0154   CPU_Counter_ticks interrupt_delay
0155 )
0156 {
0157 #if defined( RTEMS_PROFILING )
0158   Per_CPU_Stats *stats = &cpu->Stats;
0159 
0160   if ( stats->max_interrupt_delay < interrupt_delay ) {
0161     stats->max_interrupt_delay = interrupt_delay;
0162   }
0163 #else
0164   (void) cpu;
0165   (void) interrupt_delay;
0166 #endif
0167 }
0168 
0169 /**
0170  * @brief Updates the interrupt profiling statistics.
0171  *
0172  * Must be called with the interrupt stack and before the thread dispatch
0173  * disable level is decremented.
0174  *
0175  * @param cpu The cpu control.
0176  * @param interrupt_entry_instant The instant that the interrupt occurred.
0177  * @param interrupt_exit_instant The instant in which the interrupt was exited.
0178  */
0179 void _Profiling_Outer_most_interrupt_entry_and_exit(
0180   Per_CPU_Control *cpu,
0181   CPU_Counter_ticks interrupt_entry_instant,
0182   CPU_Counter_ticks interrupt_exit_instant
0183 );
0184 
0185 /** @} */
0186 
0187 #ifdef __cplusplus
0188 }
0189 #endif /* __cplusplus */
0190 
0191 #endif /* _RTEMS_SCORE_PROFILING */