aboutsummaryrefslogtreecommitdiffstats
path: root/os/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'os/kernel')
-rw-r--r--os/kernel/include/ch.h3
-rw-r--r--os/kernel/include/chrt.h24
-rw-r--r--os/kernel/include/chsys.h23
-rw-r--r--os/kernel/include/chvt.h12
-rw-r--r--os/kernel/kernel.mk1
-rw-r--r--os/kernel/src/chrt.c16
-rw-r--r--os/kernel/src/chsys.c4
-rw-r--r--os/kernel/src/chvt.c4
-rw-r--r--os/kernel/templates/chconf.h9
9 files changed, 56 insertions, 40 deletions
diff --git a/os/kernel/include/ch.h b/os/kernel/include/ch.h
index 1d1e053ce..efade76bf 100644
--- a/os/kernel/include/ch.h
+++ b/os/kernel/include/ch.h
@@ -108,10 +108,11 @@ typedef struct thread thread_t;
#include "chconf.h"
#include "chtypes.h"
#include "chdebug.h"
+#include "chrt.h"
+#include "chstats.h"
#include "chcore.h"
#include "chsys.h"
#include "chvt.h"
-#include "chrt.h"
#include "chthreads.h"
#include "chlists.h"
#include "chschd.h"
diff --git a/os/kernel/include/chrt.h b/os/kernel/include/chrt.h
index dfb2a4277..caf27747e 100644
--- a/os/kernel/include/chrt.h
+++ b/os/kernel/include/chrt.h
@@ -59,9 +59,10 @@
* with interrupts enabled.
*/
typedef struct {
- rtcnt_t last; /**< @brief Last measurement. */
- rtcnt_t worst; /**< @brief Worst measurement. */
rtcnt_t best; /**< @brief Best measurement. */
+ rtcnt_t worst; /**< @brief Worst measurement. */
+ rtcnt_t cumulative; /**< @brief Cumulative measurement. */
+ rtcnt_t last; /**< @brief Last measurement. */
} time_measurement_t;
/*===========================================================================*/
@@ -149,6 +150,7 @@ typedef struct {
#ifdef __cplusplus
extern "C" {
#endif
+ void _rt_init(void);
bool chRTIsCounterWithin(rtcnt_t start, rtcnt_t end);
void chRTPolledDelay(rtcnt_t cycles);
void chRTTimeMeasurementObjectInit(time_measurement_t *tmp);
@@ -162,24 +164,6 @@ extern "C" {
/* Module inline functions. */
/*===========================================================================*/
-/**
- * @brief Returns the current value of the system real time counter.
- * @note This function can be called from any context.
- *
- * @return The value of the system free running counter of
- * type rtcnt_t.
- *
- * @special
- */
-static inline rtcnt_t chRTGetCounterValueX(void) {
-
-#if !CH_PORT_SUPPORTS_RT
- return port_rt_get_counter_value();
-#else
- return chVTGetSystemTimeX();
-#endif
-}
-
#endif /* CH_CFG_USE_RT */
#endif /* _CHRT_H_ */
diff --git a/os/kernel/include/chsys.h b/os/kernel/include/chsys.h
index 5086e0b7f..3dc6623e9 100644
--- a/os/kernel/include/chsys.h
+++ b/os/kernel/include/chsys.h
@@ -61,7 +61,8 @@
*/
#define CH_IRQ_PROLOGUE() \
PORT_IRQ_PROLOGUE(); \
- dbg_check_enter_isr();
+ dbg_check_enter_isr(); \
+ _stats_increase_irq()
/**
* @brief IRQ handler exit code.
@@ -73,7 +74,7 @@
*/
#define CH_IRQ_EPILOGUE() \
dbg_check_leave_isr(); \
- PORT_IRQ_EPILOGUE();
+ PORT_IRQ_EPILOGUE()
/**
* @brief Standard normal IRQ handler declaration.
@@ -99,6 +100,23 @@
#define CH_FAST_IRQ_HANDLER(id) PORT_FAST_IRQ_HANDLER(id)
/** @} */
+/**
+ * @brief Returns the current value of the system real time counter.
+ * @note This function can be called from any context.
+ * @note If the port does not support a realtime counter then this
+ * function returns the system time.
+ *
+ * @return The value of the system realtime counter of
+ * type rtcnt_t.
+ *
+ * @special
+ */
+#if CH_PORT_SUPPORTS_RT || defined(__DOXYGEN__)
+#define chSysGetRealtimeCounterX() (rtcnt_t)port_rt_get_counter_value()
+#else
+#define chSysGetRealtimeCounterX() (rtcnt_t)chVTGetSystemTimeX()
+#endif
+
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
@@ -132,6 +150,7 @@ extern "C" {
static inline void chSysSwitch(thread_t *ntp, thread_t *otp) {
dbg_trace(otp);
+ _stats_increase_ctxswc();
CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp);
port_switch(ntp, otp);
}
diff --git a/os/kernel/include/chvt.h b/os/kernel/include/chvt.h
index a53a3f502..10168a66e 100644
--- a/os/kernel/include/chvt.h
+++ b/os/kernel/include/chvt.h
@@ -169,7 +169,7 @@ extern virtual_timers_list_t vtlist;
extern "C" {
#endif
void _vt_init(void);
- bool chVTIsTimeWithin(systime_t time, systime_t start, systime_t end);
+ bool chVTIsTimeWithinX(systime_t time, systime_t start, systime_t end);
void chVTDoSetI(virtual_timer_t *vtp, systime_t delay,
vtfunc_t vtfunc, void *par);
void chVTDoResetI(virtual_timer_t *vtp);
@@ -208,7 +208,7 @@ static inline void chVTObjectInit(virtual_timer_t *vtp) {
*
* @return The system time in ticks.
*
- * @special
+ * @xclass
*/
static inline systime_t chVTGetSystemTimeX(void) {
@@ -249,13 +249,13 @@ static inline systime_t chVTGetSystemTime(void) {
* @retval true current time within the specified time window.
* @retval false current time not within the specified time window.
*
- * @api
+ * @xclass
*/
-static inline bool chVTIsSystemTimeWithinI(systime_t start, systime_t end) {
+static inline bool chVTIsSystemTimeWithinX(systime_t start, systime_t end) {
chDbgCheckClassI();
- return chVTIsTimeWithin(chVTGetSystemTimeX(), start, end);
+ return chVTIsTimeWithinX(chVTGetSystemTimeX(), start, end);
}
/**
@@ -273,7 +273,7 @@ static inline bool chVTIsSystemTimeWithinI(systime_t start, systime_t end) {
*/
static inline bool chVTIsSystemTimeWithin(systime_t start, systime_t end) {
- return chVTIsTimeWithin(chVTGetSystemTime(), start, end);
+ return chVTIsTimeWithinX(chVTGetSystemTime(), start, end);
}
/**
diff --git a/os/kernel/kernel.mk b/os/kernel/kernel.mk
index d0617e536..6b2dafd55 100644
--- a/os/kernel/kernel.mk
+++ b/os/kernel/kernel.mk
@@ -5,6 +5,7 @@ KERNSRC = ${CHIBIOS}/os/kernel/src/chsys.c \
${CHIBIOS}/os/kernel/src/chlists.c \
${CHIBIOS}/os/kernel/src/chvt.c \
${CHIBIOS}/os/kernel/src/chrt.c \
+ ${CHIBIOS}/os/kernel/src/chstats.c \
${CHIBIOS}/os/kernel/src/chschd.c \
${CHIBIOS}/os/kernel/src/chthreads.c \
${CHIBIOS}/os/kernel/src/chdynamic.c \
diff --git a/os/kernel/src/chrt.c b/os/kernel/src/chrt.c
index a63ce9e32..0a477de39 100644
--- a/os/kernel/src/chrt.c
+++ b/os/kernel/src/chrt.c
@@ -131,7 +131,7 @@ void _rt_init(void) {
* @special
*/
bool chRTIsCounterWithin(rtcnt_t start, rtcnt_t end) {
- rtcnt_t now = chRTGetCounterValueX();
+ rtcnt_t now = chSysGetRealtimeCounterX();
return end > start ? (now >= start) && (now < end) :
(now >= start) || (now < end);
@@ -148,7 +148,7 @@ bool chRTIsCounterWithin(rtcnt_t start, rtcnt_t end) {
* @special
*/
void chRTPolledDelay(rtcnt_t cycles) {
- rtcnt_t start = chRTGetCounterValueX();
+ rtcnt_t start = chSysGetRealtimeCounterX();
rtcnt_t end = start + cycles;
while (chRTIsCounterWithin(start, end))
;
@@ -163,9 +163,10 @@ void chRTPolledDelay(rtcnt_t cycles) {
*/
void chRTTimeMeasurementObjectInit(time_measurement_t *tmp) {
- tmp->last = (rtcnt_t)0;
- tmp->worst = (rtcnt_t)0;
- tmp->best = (rtcnt_t)-1;
+ tmp->best = (rtcnt_t)-1;
+ tmp->worst = (rtcnt_t)0;
+ tmp->cumulative = (rtcnt_t)0;
+ tmp->last = (rtcnt_t)0;
}
/**
@@ -179,7 +180,7 @@ void chRTTimeMeasurementObjectInit(time_measurement_t *tmp) {
*/
NOINLINE void chRTTimeMeasurementStartX(time_measurement_t *tmp) {
- tmp->last = chRTGetCounterValueX();
+ tmp->last = chSysGetRealtimeCounterX();
}
/**
@@ -193,8 +194,9 @@ NOINLINE void chRTTimeMeasurementStartX(time_measurement_t *tmp) {
*/
NOINLINE void chRTTimeMeasurementStopX(time_measurement_t *tmp) {
- rtcnt_t now = chRTGetCounterValueX();
+ rtcnt_t now = chSysGetRealtimeCounterX();
tmp->last = now - tmp->last - measurement_offset;
+ tmp->cumulative += tmp->last;
if (tmp->last > tmp->worst)
tmp->worst = tmp->last;
else if (tmp->last < tmp->best)
diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c
index 91277dc60..91761b66b 100644
--- a/os/kernel/src/chsys.c
+++ b/os/kernel/src/chsys.c
@@ -211,7 +211,7 @@ void chSysTimerHandlerI(void) {
* @return The previous system status, the encoding of this
* status word is architecture-dependent and opaque.
*
- * @special
+ * @xclass
*/
syssts_t chSysGetAndLockX(void) {
@@ -230,7 +230,7 @@ syssts_t chSysGetAndLockX(void) {
*
* @param[in] sts the system status to be restored.
*
- * @special
+ * @xclass
*/
void chSysRestoreLockX(syssts_t sts) {
diff --git a/os/kernel/src/chvt.c b/os/kernel/src/chvt.c
index e5d6d1aa3..3e6028f9c 100644
--- a/os/kernel/src/chvt.c
+++ b/os/kernel/src/chvt.c
@@ -88,9 +88,9 @@ void _vt_init(void) {
* @retval true current time within the specified time window.
* @retval false current time not within the specified time window.
*
- * @special
+ * @xclass
*/
-bool chVTIsTimeWithin(systime_t time, systime_t start, systime_t end) {
+bool chVTIsTimeWithinX(systime_t time, systime_t start, systime_t end) {
return end > start ? (time >= start) && (time < end) :
(time >= start) || (time < end);
diff --git a/os/kernel/templates/chconf.h b/os/kernel/templates/chconf.h
index eebd5f122..f3e04edd5 100644
--- a/os/kernel/templates/chconf.h
+++ b/os/kernel/templates/chconf.h
@@ -343,6 +343,15 @@
/*===========================================================================*/
/**
+ * @brief Debug option, kernel statistics.
+ *
+ * @note The default is @p FALSE.
+ */
+#if !defined(CH_DBG_STATISTICS) || defined(__DOXYGEN__)
+#define CH_DBG_STATISTICS TRUE
+#endif
+
+/**
* @brief Debug option, system state check.
* @details If enabled the correct call protocol for system APIs is checked
* at runtime.