kernel: Minor optimization to kernel event logger timestamping

Rewrites the timestamping logic to always generate timestamps
via a function pointer that is initialized to sys_cycle_get_32(),
but can be changed to point to a user-supplied function. This
eliminates the need for an if/then/else construct in every place
that a timestamp is generated.

Change-Id: Id11f8c41b193a93cece16565978a525056010f0e
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
This commit is contained in:
Allan Stephens 2016-11-18 15:32:13 -05:00 committed by Anas Nashif
commit 66a07bbd48
2 changed files with 18 additions and 21 deletions

View file

@ -57,8 +57,6 @@ static inline void _sys_k_event_logger_interrupt(void) {};
* @{
*/
#ifdef CONFIG_KERNEL_EVENT_LOGGER_CUSTOM_TIMESTAMP
/**
* @typedef sys_k_timer_func_t
* @brief Event timestamp generator function type.
@ -74,15 +72,11 @@ typedef uint32_t (*sys_k_timer_func_t)(void);
* @cond INTERNAL_HIDDEN
*/
extern sys_k_timer_func_t _sys_k_timer_func;
static inline uint32_t _sys_k_get_time(void)
{
if (_sys_k_timer_func)
return _sys_k_timer_func();
else
return sys_cycle_get_32();
}
#ifdef CONFIG_KERNEL_EVENT_LOGGER_CUSTOM_TIMESTAMP
extern sys_k_timer_func_t _sys_k_get_time;
#else
#define _sys_k_get_time sys_cycle_get_32
#endif /* CONFIG_KERNEL_EVENT_LOGGER_CUSTOM_TIMESTAMP */
/**
* INTERNAL_HIDDEN @endcond
@ -108,11 +102,10 @@ static inline uint32_t _sys_k_get_time(void)
*
* @return N/A
*/
void sys_k_event_logger_set_timer(sys_k_timer_func_t func);
#else
static inline uint32_t _sys_k_get_time(void)
#ifdef CONFIG_KERNEL_EVENT_LOGGER_CUSTOM_TIMESTAMP
static inline void sys_k_event_logger_set_timer(sys_k_timer_func_t func)
{
return sys_cycle_get_32();
_sys_k_get_time = func;
}
#endif /* CONFIG_KERNEL_EVENT_LOGGER_CUSTOM_TIMESTAMP */

View file

@ -63,12 +63,16 @@ SYS_INIT(_sys_k_event_logger_init,
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
#ifdef CONFIG_KERNEL_EVENT_LOGGER_CUSTOM_TIMESTAMP
sys_k_timer_func_t _sys_k_timer_func;
void sys_k_event_logger_set_timer(sys_k_timer_func_t func)
{
_sys_k_timer_func = func;
}
#endif
/*
* _sys_k_get_time()
*
* This function pointer can be invoked to generate an event timestamp.
* By default it uses the kernel's hardware clock, but can be changed
* to point to an application-defined routine.
*
*/
sys_k_timer_func_t _sys_k_get_time = sys_cycle_get_32;
#endif /* CONFIG_KERNEL_EVENT_LOGGER_CUSTOM_TIMESTAMP */
void sys_k_event_logger_put_timed(uint16_t event_id)
{