git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6040 35acf78f-673a-0410-8e92-d51de3d6d3f4

This commit is contained in:
gdisirio 2013-07-29 15:13:52 +00:00
parent ca4b2f91b7
commit f569bcec23
6 changed files with 79 additions and 67 deletions

View File

@ -55,12 +55,15 @@
* @brief Type of a kernel statistics structure. * @brief Type of a kernel statistics structure.
*/ */
typedef struct { typedef struct {
ucnt_t nirq; /**< @brief IRQ number. time_measurement_t *current; /**< @brief Currently under measurement.*/
@note Fast Interrupts are not ucnt_t n_irq; /**< @brief Number of IRQs. */
accounted for. */ ucnt_t n_ctxswc; /**< @brief Number of context switches. */
ucnt_t nctxswc; /**< @brief Context switch number. */ time_measurement_t m_crit_thd; /**< @brief Measurement of threads
time_measurement_t critical; /**< @brief Critical zones measurement. */ critical zones duration. */
time_measurement_t isr; /**< @brief ISR measurement. */ time_measurement_t m_crit_isr; /**< @brief Measurement of ISRs critical
zones duration. */
time_measurement_t m_isr; /**< @brief Measurement of ISRs total
duration. */
} kernel_stats_t; } kernel_stats_t;
/*===========================================================================*/ /*===========================================================================*/
@ -70,12 +73,12 @@ typedef struct {
/** /**
* @brief Increases the IRQ counter. * @brief Increases the IRQ counter.
*/ */
#define _stats_increase_irq() kernel_stats.nirq++ #define _stats_increase_irq() kernel_stats.n_irq++
/** /**
* @brief Increases the context switch counter. * @brief Increases the context switch counter.
*/ */
#define _stats_increase_ctxswc() kernel_stats.nctxswc++ #define _stats_increase_ctxswc() kernel_stats.n_ctxswc++
/*===========================================================================*/ /*===========================================================================*/
/* External declarations. */ /* External declarations. */

View File

@ -182,18 +182,16 @@
/** /**
* @brief Returns the current value of the system real time counter. * @brief Returns the current value of the system real time counter.
* @note This function can be called from any context. * @note This function is only available if the port layer supports the
* option @p CH_PORT_SUPPORTS_RT.
* *
* @return The value of the system realtime counter of * @return The value of the system realtime counter of
* type rtcnt_t. If the port does not support a * type rtcnt_t.
* realtime counter then zero is returned.
* *
* @xclass * @xclass
*/ */
#if CH_PORT_SUPPORTS_RT || defined(__DOXYGEN__) #if CH_PORT_SUPPORTS_RT || defined(__DOXYGEN__)
#define chSysGetRealtimeCounterX() (rtcnt_t)port_rt_get_counter_value() #define chSysGetRealtimeCounterX() (rtcnt_t)port_rt_get_counter_value()
#else
#define chSysGetRealtimeCounterX() 0
#endif #endif
/*===========================================================================*/ /*===========================================================================*/
@ -208,6 +206,10 @@ extern "C" {
void chSysTimerHandlerI(void); void chSysTimerHandlerI(void);
syssts_t chSysGetAndLockX(void); syssts_t chSysGetAndLockX(void);
void chSysRestoreLockX(syssts_t sts); void chSysRestoreLockX(syssts_t sts);
#if CH_PORT_SUPPORTS_RT
bool chSysIsCounterWithinX(rtcnt_t cnt, rtcnt_t start, rtcnt_t end);
void chSysPolledDelayX(rtcnt_t cycles);
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -81,12 +81,10 @@ typedef struct {
extern "C" { extern "C" {
#endif #endif
void _tm_init(void); void _tm_init(void);
bool chTMIsCounterWithinX(rtcnt_t cnt, rtcnt_t start, rtcnt_t end);
void chTMPolledDelayX(rtcnt_t cycles);
void chTMObjectInit(time_measurement_t *tmp); void chTMObjectInit(time_measurement_t *tmp);
NOINLINE void chTMStartX(time_measurement_t *tmp); NOINLINE void chTMStartMeasurementX(time_measurement_t *tmp);
NOINLINE void chTMStopX(time_measurement_t *tmp); NOINLINE void chTMStopMeasurementX(time_measurement_t *tmp);
NOINLINE void chTMChainToX(time_measurement_t *tmp1, NOINLINE void chTMChainMeasurementToX(time_measurement_t *tmp1,
time_measurement_t *tmp2); time_measurement_t *tmp2);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -67,10 +67,11 @@ kernel_stats_t kernel_stats;
*/ */
void _stats_init(void) { void _stats_init(void) {
kernel_stats.nirq = 0; kernel_stats.n_irq = 0;
kernel_stats.nctxswc = 0; kernel_stats.n_ctxswc = 0;
chTMObjectInit(&kernel_stats.isr); chTMObjectInit(&kernel_stats.m_isr);
chTMObjectInit(&kernel_stats.critical); chTMObjectInit(&kernel_stats.m_crit_thd);
chTMObjectInit(&kernel_stats.m_crit_isr);
} }
#endif /* CH_DBG_STATISTICS */ #endif /* CH_DBG_STATISTICS */

View File

@ -29,6 +29,7 @@
* - Interrupt Handling. * - Interrupt Handling.
* - Power Management. * - Power Management.
* - Abnormal Termination. * - Abnormal Termination.
* - Realtime counter.
* . * .
* @{ * @{
*/ */
@ -245,4 +246,49 @@ void chSysRestoreLockX(syssts_t sts) {
} }
} }
#if CH_PORT_SUPPORTS_RT || defined(__DOXYGEN__)
/**
* @brief Realtime window test.
* @details This function verifies if the current realtime counter value
* lies within the specified range or not. The test takes care
* of the realtime counter wrapping to zero on overflow.
* @note When start==end then the function returns always true because the
* whole time range is specified.
* @note This function is only available if the port layer supports the
* option @p CH_PORT_SUPPORTS_RT.
*
* @param[in] cnt the counter value to be tested
* @param[in] start the start of the time window (inclusive)
* @param[in] end the end of the time window (non inclusive)
* @retval true current time within the specified time window.
* @retval false current time not within the specified time window.
*
* @xclass
*/
bool chSysIsCounterWithinX(rtcnt_t cnt, rtcnt_t start, rtcnt_t end) {
return end > start ? (cnt >= start) && (cnt < end) :
(cnt >= start) || (cnt < end);
}
/**
* @brief Polled delay.
* @note The real delay is always few cycles in excess of the specified
* value.
* @note This function is only available if the port layer supports the
* option @p CH_PORT_SUPPORTS_RT.
*
* @param[in] cycles number of cycles
*
* @xclass
*/
void chSysPolledDelayX(rtcnt_t cycles) {
rtcnt_t start = chSysGetRealtimeCounterX();
rtcnt_t end = start + cycles;
while (chSysIsCounterWithinX(chSysGetRealtimeCounterX(), start, end))
;
}
#endif /* CH_PORT_SUPPORTS_RT */
/** @} */ /** @} */

View File

@ -83,49 +83,11 @@ void _tm_init(void) {
measurements.*/ measurements.*/
measurement_offset = 0; measurement_offset = 0;
chTMObjectInit(&tm); chTMObjectInit(&tm);
chTMStartX(&tm); chTMStartMeasurementX(&tm);
chTMStopX(&tm); chTMStopMeasurementX(&tm);
measurement_offset = tm.last; measurement_offset = tm.last;
} }
/**
* @brief Realtime window test.
* @details This function verifies if the current realtime counter value
* lies within the specified range or not. The test takes care
* of the realtime counter wrapping to zero on overflow.
* @note When start==end then the function returns always true because the
* whole time range is specified.
*
* @param[in] cnt the counter value to be tested
* @param[in] start the start of the time window (inclusive)
* @param[in] end the end of the time window (non inclusive)
* @retval true current time within the specified time window.
* @retval false current time not within the specified time window.
*
* @xclass
*/
bool chTMIsCounterWithinX(rtcnt_t cnt, rtcnt_t start, rtcnt_t end) {
return end > start ? (cnt >= start) && (cnt < end) :
(cnt >= start) || (cnt < end);
}
/**
* @brief Polled delay.
* @note The real delay is always few cycles in excess of the specified
* value.
*
* @param[in] cycles number of cycles
*
* @xclass
*/
void chTMPolledDelayX(rtcnt_t cycles) {
rtcnt_t start = chSysGetRealtimeCounterX();
rtcnt_t end = start + cycles;
while (chTMIsCounterWithinX(chSysGetRealtimeCounterX(), start, end))
;
}
/** /**
* @brief Initializes a @p TimeMeasurement object. * @brief Initializes a @p TimeMeasurement object.
* *
@ -149,7 +111,7 @@ void chTMObjectInit(time_measurement_t *tmp) {
* *
* @xclass * @xclass
*/ */
NOINLINE void chTMStartX(time_measurement_t *tmp) { NOINLINE void chTMStartMeasurementX(time_measurement_t *tmp) {
tmp->last = chSysGetRealtimeCounterX(); tmp->last = chSysGetRealtimeCounterX();
} }
@ -162,7 +124,7 @@ NOINLINE void chTMStartX(time_measurement_t *tmp) {
* *
* @xclass * @xclass
*/ */
NOINLINE void chTMStopX(time_measurement_t *tmp) { NOINLINE void chTMStopMeasurementX(time_measurement_t *tmp) {
tm_stop(tmp, chSysGetRealtimeCounterX()); tm_stop(tmp, chSysGetRealtimeCounterX());
} }
@ -181,7 +143,7 @@ NOINLINE void chTMStopX(time_measurement_t *tmp) {
* *
* @xclass * @xclass
*/ */
NOINLINE void chTMChainToX(time_measurement_t *tmp1, NOINLINE void chTMChainMeasurementToX(time_measurement_t *tmp1,
time_measurement_t *tmp2) { time_measurement_t *tmp2) {
/* Starts new measurement.*/ /* Starts new measurement.*/