| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2003-2007, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: bint_stats.h $ |
|---|
| 11 | * $brcm_Revision: Hydra_Software_Devel/2 $ |
|---|
| 12 | * $brcm_Date: 2/9/07 5:24p $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: /magnum/basemodules/int/bint_stats.h $ |
|---|
| 19 | * |
|---|
| 20 | * Hydra_Software_Devel/2 2/9/07 5:24p albertl |
|---|
| 21 | * PR24115: Added warning messages for long executing interrupts and |
|---|
| 22 | * runaway interrupts with adjustable compile time thresholds. |
|---|
| 23 | * |
|---|
| 24 | * Hydra_Software_Devel/1 5/25/06 4:10p albertl |
|---|
| 25 | * PR21392: BINT_Stats functions now split off into bint_stats.h to solve |
|---|
| 26 | * BTMR circular dependency. |
|---|
| 27 | * |
|---|
| 28 | |
|---|
| 29 | * |
|---|
| 30 | ***************************************************************************/ |
|---|
| 31 | |
|---|
| 32 | #ifndef BINT_STATS_H |
|---|
| 33 | #define BINT_STATS_H |
|---|
| 34 | |
|---|
| 35 | #include "bstd.h" |
|---|
| 36 | #include "bint.h" |
|---|
| 37 | #include "btmr.h" |
|---|
| 38 | |
|---|
| 39 | #ifdef __cplusplus |
|---|
| 40 | extern "C" { |
|---|
| 41 | #endif |
|---|
| 42 | |
|---|
| 43 | #ifdef BDBG_DEBUG_BUILD |
|---|
| 44 | #define BINT_STATS_ENABLE |
|---|
| 45 | #endif /* BDBG_DEBUG_BUILD */ |
|---|
| 46 | |
|---|
| 47 | /*************************************************************************** |
|---|
| 48 | Summary: |
|---|
| 49 | List of errors unique to INT |
|---|
| 50 | ****************************************************************************/ |
|---|
| 51 | #define BINT_STATS_ERR_ALREADY_ENABLED BERR_MAKE_CODE(BERR_INT_ID, 0) |
|---|
| 52 | #define BINT_STATS_ERR_ALREADY_DISABLED BERR_MAKE_CODE(BERR_INT_ID, 1) |
|---|
| 53 | |
|---|
| 54 | #define BINT_P_STATS_BIN_MAX 10 /* Number of maximum bins. */ |
|---|
| 55 | #define BINT_P_STATS_SAMPLE_MAX 10000 |
|---|
| 56 | #define BINT_P_STATS_RECENT_CB_HIT_COUNT 20 /* Number of hits used to track hit frequency */ |
|---|
| 57 | #define BINT_P_STATS_EXECUTION_TIME_MAX_THRESHOLD 5000 /* Maxmim time for callback execution */ |
|---|
| 58 | #define BINT_P_STATS_AVG_PERIOD_MIN_THRESHOLD 1000 /* Minimum avg time between callback hits */ |
|---|
| 59 | |
|---|
| 60 | /* |
|---|
| 61 | This structure defines a callback statistics bin. It has a minimum and maximum range in |
|---|
| 62 | microseconds. Each time the callback associated with it executes and completes within the |
|---|
| 63 | minimum and maximum range of the bin, ulBinHitCount of the bin increments. |
|---|
| 64 | */ |
|---|
| 65 | typedef struct BINT_Stats_CallbackBin |
|---|
| 66 | { |
|---|
| 67 | uint32_t ulBinRangeMin; /* minimum bin range, in microseconds. */ |
|---|
| 68 | uint32_t ulBinRangeMax; /* maximum bin range, in microseconds. */ |
|---|
| 69 | uint32_t ulBinHitCount; /* count of times callback executed within this bin's range. */ |
|---|
| 70 | }BINT_Stats_CallbackBin; |
|---|
| 71 | |
|---|
| 72 | /* |
|---|
| 73 | This structure keeps track of a callback's statistics. It is updated every time the |
|---|
| 74 | callback executes, and can be obtained by callling BINT_Stats_Get(). It may be |
|---|
| 75 | necessary to lock this structure down when reading from it to ensure that it is |
|---|
| 76 | not updated in mid-read. |
|---|
| 77 | */ |
|---|
| 78 | typedef struct BINT_Stats_CallbackStats |
|---|
| 79 | { |
|---|
| 80 | uint32_t ulTimeMin; /* Minimum execution time. */ |
|---|
| 81 | uint32_t ulTimeMax; /* Maximum execution time. */ |
|---|
| 82 | uint32_t ulTimeAvg; /* Average execution time. Average is over ulCbHitCount |
|---|
| 83 | samples, if ulCbHitCount is less than BINT_P_STATS_SAMPLE_MAX. |
|---|
| 84 | |
|---|
| 85 | If ulCbHitCount is greater than BINT_P_STATS_SAMPLE_MAX, |
|---|
| 86 | Average is roughly equivalent to BINT_P_STATS_SAMPLE_MAX |
|---|
| 87 | samples */ |
|---|
| 88 | uint32_t ulCbHitCount; /* Number of times callback has executed. */ |
|---|
| 89 | bool bDefaultBins; /* whether default bins or user bins are being used */ |
|---|
| 90 | uint32_t ulActiveBins; /* Number of active bins */ |
|---|
| 91 | |
|---|
| 92 | BINT_Stats_CallbackBin aBinInfo[BINT_P_STATS_BIN_MAX]; /* array storing stat bins */ |
|---|
| 93 | uint32_t aulTimeStamp[BINT_P_STATS_RECENT_CB_HIT_COUNT]; /* circular array storing start times of |
|---|
| 94 | last BINT_P_STATS_RECENT_CB_HIT_COUNT |
|---|
| 95 | hits to track hit frequency */ |
|---|
| 96 | uint32_t ulTimeStampStartIdx; /* start index of above array */ |
|---|
| 97 | |
|---|
| 98 | }BINT_Stats_CallbackStats; |
|---|
| 99 | |
|---|
| 100 | /* |
|---|
| 101 | Summary: |
|---|
| 102 | Enables statistics tracking of callbacks. |
|---|
| 103 | |
|---|
| 104 | Description: |
|---|
| 105 | Enables tracking of statistics for the interrupt module. Must be called for |
|---|
| 106 | statistics to be tracked. If enabled, a call to BINT_Stats_Disable is |
|---|
| 107 | required before the module is closed with BINT_Close. |
|---|
| 108 | |
|---|
| 109 | Access to a shared freerun timer from the TMR module will be acquired when |
|---|
| 110 | stats tracking is enabled. |
|---|
| 111 | */ |
|---|
| 112 | BERR_Code BINT_Stats_Enable( |
|---|
| 113 | BINT_Handle intHandle, /* [in] Interrupt handle */ |
|---|
| 114 | BTMR_Handle hTmrHandle /* [in] Timer module handle */ |
|---|
| 115 | ); |
|---|
| 116 | |
|---|
| 117 | /* |
|---|
| 118 | Summary: |
|---|
| 119 | Disables statistics tracking of callbacks. |
|---|
| 120 | |
|---|
| 121 | Description: |
|---|
| 122 | Disables tracking of statistics for the interrupt module. Must be called before |
|---|
| 123 | the module is closed with BINT_Close if stats tracking was enabled with |
|---|
| 124 | BINT_Stats_Enable. |
|---|
| 125 | |
|---|
| 126 | Disabling stats tracking also relinquishes access to the shared freerun timer |
|---|
| 127 | acquired when tracking was enabled. |
|---|
| 128 | */ |
|---|
| 129 | BERR_Code BINT_Stats_Disable( |
|---|
| 130 | BINT_Handle intHandle /* [in] Interrupt handle */ |
|---|
| 131 | ); |
|---|
| 132 | |
|---|
| 133 | /* |
|---|
| 134 | Summary: |
|---|
| 135 | Adds a statistics bin to a callback. |
|---|
| 136 | |
|---|
| 137 | Description: |
|---|
| 138 | Adds a bin with a minimum and maximum time range in microseconds. The ulBinHitCount |
|---|
| 139 | field will be incremented in this bin everytime the execution of the callback falls |
|---|
| 140 | within the time range. Returns an error if maximum number of bins is exceeded or |
|---|
| 141 | if the max and min ranges overlap or fall within an existing bin's range. No two |
|---|
| 142 | bins can have overlapping ranges. |
|---|
| 143 | |
|---|
| 144 | Adding a bin removes the default bins for a callback. |
|---|
| 145 | */ |
|---|
| 146 | BERR_Code BINT_Stats_AddBin( |
|---|
| 147 | BINT_CallbackHandle cbHandle, /* [in] Callback handle returned by BINT_CreateCallback() */ |
|---|
| 148 | uint32_t ulRangeMin, /* [in] Minimum time range, in microseconds */ |
|---|
| 149 | uint32_t ulRangeMax /* [in] Maximum time range, in microseconds */ |
|---|
| 150 | ); |
|---|
| 151 | |
|---|
| 152 | /* |
|---|
| 153 | Summary: |
|---|
| 154 | Destroys existing stats bins of a callback. |
|---|
| 155 | |
|---|
| 156 | Description: |
|---|
| 157 | Destroys and clears out the created stats bins of a given callback. |
|---|
| 158 | */ |
|---|
| 159 | BERR_Code BINT_Stats_DestroyBins( |
|---|
| 160 | BINT_CallbackHandle cbHandle /* [in] Callback handle returned by BINT_CreateCallback() */ |
|---|
| 161 | ); |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | /* |
|---|
| 165 | Summary: |
|---|
| 166 | Gets the statistics of a callback. |
|---|
| 167 | |
|---|
| 168 | Description: |
|---|
| 169 | Gets the statistics of a specific callback. It returns the pointer to the BINT_CallbackStats |
|---|
| 170 | structure associated with the callback. The BINT_CallbackStats structure is constantly being |
|---|
| 171 | updated, each time the callback executes. It may be necessary to use critical sections when |
|---|
| 172 | reading from the callback structure to make sure the stats don't update in mid-read. |
|---|
| 173 | |
|---|
| 174 | #define BINT_STATS_ENABLE to enable stats tracking. Stats tracking functions and datastructures |
|---|
| 175 | are disabled by default. |
|---|
| 176 | */ |
|---|
| 177 | BERR_Code BINT_Stats_Get( |
|---|
| 178 | BINT_CallbackHandle cbHandle, |
|---|
| 179 | BINT_Stats_CallbackStats **ppCbStats |
|---|
| 180 | ); |
|---|
| 181 | |
|---|
| 182 | /* |
|---|
| 183 | Summary: |
|---|
| 184 | Resets the statistics of a callback. |
|---|
| 185 | |
|---|
| 186 | Description: |
|---|
| 187 | Resets the statistics of a specific callback. All stats for the callback and its bins are |
|---|
| 188 | reset when this function is called. |
|---|
| 189 | */ |
|---|
| 190 | BERR_Code BINT_Stats_Reset( |
|---|
| 191 | BINT_CallbackHandle cbHandle |
|---|
| 192 | ); |
|---|
| 193 | |
|---|
| 194 | #ifdef __cplusplus |
|---|
| 195 | } |
|---|
| 196 | #endif |
|---|
| 197 | |
|---|
| 198 | #endif |
|---|
| 199 | /* End of File */ |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | |
|---|