sys_clock: Make clock_always_on true by default
This flag is an indication to the timer driver that the OS doesn't care about rollover conditions of the tick count while idling, so the system doesn't need to wake up once per counter flip[1]. Obviously in that circumstance values returned from k_uptime_get_32() are going to be wrong, so the implementation had an assert to check for misuse. But no one understood that from the docs, so the only place these APIs were used in practice were as "guards" around code that needed to call k_uptime_get_32(), even though that's 100% wrong per docs! Clarify the docs. Remove the incorrect guards. Change the flag to initialize to true so that uptime isn't broken-by-default in tickless mode. Also move the implemenations of the functions out of the header, as there's no good reason for these to need to be inlined. [1] Which can be significant. A 100MHz ARM using the 24 bit SysTick counter rolls over at about 6 Hz, and if it had to come out of idle at that rate it would be a significant power issue that would swamp the gains from tickless. Obviously systems with slow counters like nRF or 64 bit ones like RISC-V or x86's TSC aren't as affected. Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
This commit is contained in:
parent
b2e4283555
commit
b8ffd9acd6
4 changed files with 30 additions and 28 deletions
|
@ -1562,26 +1562,16 @@ __syscall s64_t k_uptime_get(void);
|
|||
/**
|
||||
* @brief Enable clock always on in tickless kernel
|
||||
*
|
||||
* This routine enables keeping the clock running when
|
||||
* there are no timer events programmed in tickless kernel
|
||||
* scheduling. This is necessary if the clock is used to track
|
||||
* passage of time.
|
||||
* This routine enables keeping the clock running (that is, it always
|
||||
* keeps an active timer interrupt scheduled) when there are no timer
|
||||
* events programmed in tickless kernel scheduling. This is necessary
|
||||
* if the clock is used to track passage of time (e.g. via
|
||||
* k_uptime_get_32()), otherwise the internal hardware counter may
|
||||
* roll over between interrupts.
|
||||
*
|
||||
* @retval prev_status Previous status of always on flag
|
||||
*/
|
||||
static inline int k_enable_sys_clock_always_on(void)
|
||||
{
|
||||
#ifdef CONFIG_TICKLESS_KERNEL
|
||||
int prev_status = _sys_clock_always_on;
|
||||
|
||||
_sys_clock_always_on = 1;
|
||||
_enable_sys_clock();
|
||||
|
||||
return prev_status;
|
||||
#else
|
||||
return -ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
int k_enable_sys_clock_always_on(void);
|
||||
|
||||
/**
|
||||
* @brief Disable clock always on in tickless kernel
|
||||
|
@ -1591,12 +1581,7 @@ static inline int k_enable_sys_clock_always_on(void)
|
|||
* scheduling. To save power, this routine should be called
|
||||
* immediately when clock is not used to track time.
|
||||
*/
|
||||
static inline void k_disable_sys_clock_always_on(void)
|
||||
{
|
||||
#ifdef CONFIG_TICKLESS_KERNEL
|
||||
_sys_clock_always_on = 0;
|
||||
#endif
|
||||
}
|
||||
void k_disable_sys_clock_always_on(void);
|
||||
|
||||
/**
|
||||
* @brief Get system uptime (32-bit version).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue