diff options
author | Ramesh Thomas <ramesh.thomas@intel.com> | 2017-02-05 19:37:19 -0800 |
---|---|---|
committer | Anas Nashif <nashif@linux.intel.com> | 2017-04-27 13:46:28 +0000 |
commit | 89ffd44dfb5c6df7e12b902ef8b117fdaff0bcae (patch) | |
tree | 1412218453ccf0648c404cce80e83d18ef493f4a /include | |
parent | 62eea121b357eae64fe00d996e2193d2b4638d1e (diff) |
kernel: tickless: Add tickless kernel support
Adds event based scheduling logic to the kernel. Updates
management of timeouts, timers, idling etc. based on
time tracked at events rather than periodic ticks. Provides
interfaces for timers to announce and get next timer expiry
based on kernel scheduling decisions involving time slicing
of threads, timeouts and idling. Uses wall time units instead
of ticks in all scheduling activities.
The implementation involves changes in the following areas
1. Management of time in wall units like ms/us instead of ticks
The existing implementation already had an option to configure
number of ticks in a second. The new implementation builds on
top of that feature and provides option to set the size of the
scheduling granurality to mili seconds or micro seconds. This
allows most of the current implementation to be reused. Due to
this re-use and co-existence with tick based kernel, the names
of variables may contain the word "tick". However, in the
tickless kernel implementation, it represents the currently
configured time unit, which would be be mili seconds or
micro seconds. The APIs that take time as a parameter are not
impacted and they continue to pass time in mili seconds.
2. Timers would not be programmed in periodic mode
generating ticks. Instead they would be programmed in one
shot mode to generate events at the time the kernel scheduler
needs to gain control for its scheduling activities like
timers, timeouts, time slicing, idling etc.
3. The scheduler provides interfaces that the timer drivers
use to announce elapsed time and get the next time the scheduler
needs a timer event. It is possible that the scheduler may not
need another timer event, in which case the system would wait
for a non-timer event to wake it up if it is idling.
4. New APIs are defined to be implemented by timer drivers. Also
they need to handler timer events differently. These changes
have been done in the HPET timer driver. In future other timers
that support tickles kernel should implement these APIs as well.
These APIs are to re-program the timer, update and announce
elapsed time.
5. Philosopher and timer_api applications have been enabled to
test tickless kernel. Separate configuration files are created
which define the necessary CONFIG flags. Run these apps using
following command
make pristine && make BOARD=qemu_x86 CONF_FILE=prj_tickless.conf qemu
Jira: ZEP-339 ZEP-1946 ZEP-948
Change-Id: I7d950c31bf1ff929a9066fad42c2f0559a2e5983
Signed-off-by: Ramesh Thomas <ramesh.thomas@intel.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/drivers/system_timer.h | 10 | ||||
-rw-r--r-- | include/kernel.h | 42 | ||||
-rw-r--r-- | include/sys_clock.h | 9 |
3 files changed, 60 insertions, 1 deletions
diff --git a/include/drivers/system_timer.h b/include/drivers/system_timer.h index dbaf3d4cd..bb48712dd 100644 --- a/include/drivers/system_timer.h +++ b/include/drivers/system_timer.h @@ -38,9 +38,19 @@ extern void sys_clock_disable(void); #ifdef CONFIG_TICKLESS_IDLE extern void _timer_idle_enter(s32_t ticks); extern void _timer_idle_exit(void); +#else +#define _timer_idle_enter(ticks) do { } while ((0)) +#define _timer_idle_exit() do { } while ((0)) #endif /* CONFIG_TICKLESS_IDLE */ extern void _nano_sys_clock_tick_announce(s32_t ticks); +#ifdef CONFIG_TICKLESS_KERNEL +extern void _set_time(u32_t time); +extern u32_t _get_program_time(void); +extern u32_t _get_remaining_program_time(void); +extern u32_t _get_elapsed_program_time(void); +extern u64_t _get_elapsed_clock_time(void); +#endif extern int sys_clock_device_ctrl(struct device *device, u32_t ctrl_command, void *context); diff --git a/include/kernel.h b/include/kernel.h index 54bce4f47..826052ea2 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -864,7 +864,11 @@ static ALWAYS_INLINE s32_t _ms_to_ticks(s32_t ms) #endif /* added tick needed to account for tick in progress */ +#ifdef CONFIG_TICKLESS_KERNEL +#define _TICK_ALIGN 0 +#else #define _TICK_ALIGN 1 +#endif static inline s64_t __ticks_to_ms(s64_t ticks) { @@ -1131,6 +1135,44 @@ static inline void *k_timer_user_data_get(struct k_timer *timer) */ extern s64_t k_uptime_get(void); +#ifdef CONFIG_TICKLESS_KERNEL +/** + * @brief Enable clock always on in tickless kernel + * + * This routine enables keepng 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. + * + * @retval prev_status Previous status of always on flag + */ +static inline int k_enable_sys_clock_always_on(void) +{ + int prev_status = _sys_clock_always_on; + + _sys_clock_always_on = 1; + _enable_sys_clock(); + + return prev_status; +} + +/** + * @brief Disable clock always on in tickless kernel + * + * This routine disables keepng the clock running when + * there are no timer events programmed in tickless kernel + * 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) +{ + _sys_clock_always_on = 0; +} +#else +#define k_enable_sys_clock_always_on() do { } while ((0)) +#define k_disable_sys_clock_always_on() do { } while ((0)) +#endif + /** * @brief Get system uptime (32-bit version). * diff --git a/include/sys_clock.h b/include/sys_clock.h index e259f7a27..db4ec39c4 100644 --- a/include/sys_clock.h +++ b/include/sys_clock.h @@ -28,7 +28,14 @@ extern "C" { #error "SYS_CLOCK_HW_CYCLES_PER_SEC must be non-zero!" #endif +#ifdef CONFIG_TICKLESS_KERNEL +#define sys_clock_ticks_per_sec \ + (1000000 / (CONFIG_TICKLESS_KERNEL_TIME_UNIT_IN_MICRO_SECS)) +extern int _sys_clock_always_on; +extern void _enable_sys_clock(void); +#else #define sys_clock_ticks_per_sec CONFIG_SYS_CLOCK_TICKS_PER_SEC +#endif #if defined(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME) extern int sys_clock_hw_cycles_per_sec; @@ -100,7 +107,7 @@ extern int sys_clock_hw_cycles_per_tick; * @} end defgroup clock_apis */ -extern s64_t _sys_clock_tick_count; +extern volatile u64_t _sys_clock_tick_count; /* * Number of ticks for x seconds. NOTE: With MSEC() or USEC(), |