From 64403d8f188725bc5814813371382bc148956a83 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 30 Jul 2013 14:23:37 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6048 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/include/chstats.h | 56 +++++----------------------------------- os/kernel/include/chsys.h | 38 +++++++++++++-------------- os/kernel/include/chtm.h | 2 -- os/kernel/src/chdebug.c | 2 +- os/kernel/src/chstats.c | 50 ++++++++++++++++++++++++++++++++++- os/kernel/src/chsys.c | 2 +- os/ports/GCC/ARMCMx/chcore_v7m.c | 6 +++-- os/ports/GCC/ARMCMx/chcore_v7m.h | 10 +++++++ 8 files changed, 89 insertions(+), 77 deletions(-) (limited to 'os') diff --git a/os/kernel/include/chstats.h b/os/kernel/include/chstats.h index a62eba0cc..d40117882 100644 --- a/os/kernel/include/chstats.h +++ b/os/kernel/include/chstats.h @@ -62,60 +62,12 @@ typedef struct { critical zones duration. */ 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; /*===========================================================================*/ /* Module macros. */ /*===========================================================================*/ -/** - * @brief Increases the IRQ counter. - */ -#define _stats_increase_irq() kernel_stats.n_irq++ - -/** - * @brief Increases the context switch counter. - */ -#define _stats_increase_ctxswc() kernel_stats.n_ctxswc++ - -/** - * @brief Starts the measurement of a thread critical zone. - */ -#define _stats_start_measure_crit_thd() \ - chTMStartMeasurementX(&kernel_stats.m_crit_thd) - -/** - * @brief Stops the measurement of a thread critical zone. - */ -#define _stats_stop_measure_crit_thd() \ - chTMStopMeasurementX(&kernel_stats.m_crit_thd) - -/** - * @brief Starts the measurement of an ISR critical zone. - */ -#define _stats_start_measure_crit_isr() \ - chTMStartMeasurementX(&kernel_stats.m_crit_isr) - -/** - * @brief Stops the measurement of an ISR critical zone. - */ -#define _stats_stop_measure_crit_isr() \ - chTMStopMeasurementX(&kernel_stats.m_crit_isr) - -/** - * @brief Starts the measurement of an ISR duration. - */ -#define _stats_start_measure_isr() \ - chTMStartMeasurementX(&kernel_stats.m_crit_isr) - -/** - * @brief Stops the measurement of an ISR duration. - */ -#define _stats_stop_measure_isr() \ - chTMStopMeasurementX(&kernel_stats.m_crit_isr) - /*===========================================================================*/ /* External declarations. */ /*===========================================================================*/ @@ -128,6 +80,12 @@ extern kernel_stats_t kernel_stats; extern "C" { #endif void _stats_init(void); + void _stats_increase_irq(void); + void _stats_increase_ctxswc(void); + void _stats_start_measure_crit_thd(void); + void _stats_stop_measure_crit_thd(void); + void _stats_start_measure_crit_isr(void); + void _stats_stop_measure_crit_isr(void); #ifdef __cplusplus } #endif @@ -145,8 +103,6 @@ extern "C" { #define _stats_stop_measure_crit_thd() #define _stats_start_measure_crit_isr() #define _stats_stop_measure_crit_isr() -#define _stats_start_measure_isr() -#define _stats_stop_measure_isr() #endif /* !CH_DBG_STATISTICS */ diff --git a/os/kernel/include/chsys.h b/os/kernel/include/chsys.h index 9663e85ac..bfb521d65 100644 --- a/os/kernel/include/chsys.h +++ b/os/kernel/include/chsys.h @@ -61,7 +61,6 @@ */ #define CH_IRQ_PROLOGUE() \ PORT_IRQ_PROLOGUE(); \ - _stats_start_measure_isr(); \ _stats_increase_irq(); \ dbg_check_enter_isr() @@ -75,7 +74,6 @@ */ #define CH_IRQ_EPILOGUE() \ dbg_check_leave_isr(); \ - _stats_stop_measure_isr(); \ PORT_IRQ_EPILOGUE() /** @@ -196,6 +194,24 @@ #define chSysGetRealtimeCounterX() (rtcnt_t)port_rt_get_counter_value() #endif +/** + * @brief Performs a context switch. + * @note Not a user function, it is meant to be invoked by the scheduler + * itself or from within the port layer. + * + * @param[in] ntp the thread to be switched in + * @param[in] otp the thread to be switched out + * + * @special + */ +#define chSysSwitch(ntp, otp) { \ + \ + dbg_trace(otp); \ + _stats_increase_ctxswc(); \ + CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp); \ + port_switch(ntp, otp); \ +} + /*===========================================================================*/ /* External declarations. */ /*===========================================================================*/ @@ -220,24 +236,6 @@ extern "C" { /* Module inline functions. */ /*===========================================================================*/ -/** - * @brief Performs a context switch. - * @note Not a user function, it is meant to be invoked by the scheduler - * itself or from within the port layer. - * - * @param[in] ntp the thread to be switched in - * @param[in] otp the thread to be switched out - * - * @special - */ -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); -} - /** * @brief Raises the system interrupt priority mask to the maximum level. * @details All the maskable interrupt sources are disabled regardless their diff --git a/os/kernel/include/chtm.h b/os/kernel/include/chtm.h index 8d8d021fd..b72bff8e6 100644 --- a/os/kernel/include/chtm.h +++ b/os/kernel/include/chtm.h @@ -31,8 +31,6 @@ #if CH_CFG_USE_TM || defined(__DOXYGEN__) -#define port_rt_get_counter_value() 0 - /*===========================================================================*/ /* Module constants. */ /*===========================================================================*/ diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c index 44058dff8..ba9c469b9 100644 --- a/os/kernel/src/chdebug.c +++ b/os/kernel/src/chdebug.c @@ -234,7 +234,7 @@ void _trace_init(void) { */ void dbg_trace(thread_t *otp) { - dbg_trace_buffer.tb_ptr->se_time = chTimeNow(); + dbg_trace_buffer.tb_ptr->se_time = chVTGetSystemTimeX(); dbg_trace_buffer.tb_ptr->se_tp = currp; dbg_trace_buffer.tb_ptr->se_wtobjp = otp->p_u.wtobjp; dbg_trace_buffer.tb_ptr->se_state = (uint8_t)otp->p_state; diff --git a/os/kernel/src/chstats.c b/os/kernel/src/chstats.c index eb2023c93..93739da17 100644 --- a/os/kernel/src/chstats.c +++ b/os/kernel/src/chstats.c @@ -69,11 +69,59 @@ void _stats_init(void) { kernel_stats.n_irq = 0; kernel_stats.n_ctxswc = 0; - chTMObjectInit(&kernel_stats.m_isr); chTMObjectInit(&kernel_stats.m_crit_thd); chTMObjectInit(&kernel_stats.m_crit_isr); } + +/** + * @brief Increases the IRQ counter. + */ +void _stats_increase_irq(void) { + + kernel_stats.n_irq++; +} + +/** + * @brief Increases the context switch counter. + */ +void _stats_increase_ctxswc(void) { + + kernel_stats.n_ctxswc++; +} + +/** + * @brief Starts the measurement of a thread critical zone. + */ +void _stats_start_measure_crit_thd(void) { + + chTMStartMeasurementX(&kernel_stats.m_crit_thd); +} + +/** + * @brief Stops the measurement of a thread critical zone. + */ +void _stats_stop_measure_crit_thd(void) { + + chTMStopMeasurementX(&kernel_stats.m_crit_thd); +} + +/** + * @brief Starts the measurement of an ISR critical zone. + */ +void _stats_start_measure_crit_isr(void) { + + chTMStartMeasurementX(&kernel_stats.m_crit_isr); +} + +/** + * @brief Stops the measurement of an ISR critical zone. + */ +void _stats_stop_measure_crit_isr(void) { + + chTMStopMeasurementX(&kernel_stats.m_crit_isr); +} + #endif /* CH_DBG_STATISTICS */ /** @} */ diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index 168bd1376..7057a7e01 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -163,7 +163,7 @@ void chSysInit(void) { */ void chSysHalt(void) { - chSysDisable(); + port_disable(); #if defined(CH_CFG_SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) CH_CFG_SYSTEM_HALT_HOOK(); diff --git a/os/ports/GCC/ARMCMx/chcore_v7m.c b/os/ports/GCC/ARMCMx/chcore_v7m.c index bb099e50c..821f2403e 100644 --- a/os/ports/GCC/ARMCMx/chcore_v7m.c +++ b/os/ports/GCC/ARMCMx/chcore_v7m.c @@ -62,9 +62,9 @@ CH_IRQ_HANDLER(SysTickVector) { CH_IRQ_PROLOGUE(); - chSysLockFromIsr(); + chSysLockFromISR(); chSysTimerHandlerI(); - chSysUnlockFromIsr(); + chSysUnlockFromISR(); CH_IRQ_EPILOGUE(); } @@ -191,9 +191,11 @@ __attribute__((naked)) #endif void _port_switch_from_isr(void) { + _stats_start_measure_crit_thd(); dbg_check_lock(); chSchDoReschedule(); dbg_check_unlock(); + _stats_stop_measure_crit_thd(); asm volatile ("_port_exit_from_isr:" : : : "memory"); #if !CORTEX_SIMPLIFIED_PRIORITY || defined(__DOXYGEN__) asm volatile ("svc #0"); diff --git a/os/ports/GCC/ARMCMx/chcore_v7m.h b/os/ports/GCC/ARMCMx/chcore_v7m.h index 6cd461408..b9b30dad2 100644 --- a/os/ports/GCC/ARMCMx/chcore_v7m.h +++ b/os/ports/GCC/ARMCMx/chcore_v7m.h @@ -421,6 +421,10 @@ static inline void port_init(void) { SCB_VTOR = CORTEX_VTOR_INIT; SCB_AIRCR = AIRCR_VECTKEY | AIRCR_PRIGROUP(CORTEX_PRIGROUP_INIT); + /* DWT cycle counter enable.*/ + SCS_DEMCR |= SCS_DEMCR_TRCENA; + DWT_CTRL |= DWT_CTRL_CYCCNTENA; + /* Initialization of the system vectors used by the port.*/ nvicSetSystemHandlerPriority(HANDLER_SVCALL, CORTEX_PRIORITY_MASK(CORTEX_PRIORITY_SVCALL)); @@ -595,6 +599,12 @@ static inline void port_wait_for_interrupt(void) { #endif } + +static inline rtcnt_t port_rt_get_counter_value(void) { + + return DWT_CYCCNT; +} + #endif /* _FROM_ASM_ */ #endif /* _CHCORE_V7M_H_ */ -- cgit v1.2.3