Patch "hrtimer: Handle remaining time proper for TIME_LOW_RES" has been added to the 4.4-stable tree
This is a note to let you know that I've just added the patch titled
hrtimer: Handle remaining time proper for TIME_LOW_RES
to the 4.4-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
hrtimer-handle-remaining-time-proper-for-time_low_res.patch
and it can be found in the queue-4.4 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From
203cbf77de59fc8f13502dcfd11350c6d4a5c95fMon Sep 17 00:00:00 2001
From: Thomas Gleixner <[email protected]>
Date: Thu, 14 Jan 2016 16:54:46 +0000
Subject: hrtimer: Handle remaining time proper for TIME_LOW_RES
From: Thomas Gleixner <[email protected]>
commit 203cbf77de59fc8f13502dcfd11350c6d4a5c95f upstream.
If CONFIG_TIME_LOW_RES is enabled we add a jiffie to the relative timeout to prevent short sleeps, but we do not account for that in interfaces which retrieve the remaining time.
Helge observed that timerfd can return a remaining time larger than the relative timeout. That's not expected and breaks userland test programs.
Store the information that the timer was armed relative and provide functions to adjust the remaining time. To avoid bloating the hrtimer struct make state a u8, which as a bonus results in better code on x86 at least.
--- include/linux/hrtimer.h | 34 ++++++++++++++++++++++++++--- kernel/time/hrtimer.c | 55 +++++++++++++++++++++++++++++++---------------- kernel/time/timer_list.c | 2 - 3 files changed, 69 insertions(+), 22 deletions(-)
include/linux/hrtimer.h +31 -3
@@ -87,7 +87,8 @@ enum hrtimer_restart {* @function: timer expiry callback function * @base: pointer to the timer base (per cpu and per clock) * @state: state information (See bit values above) -* @start_pid: timer statistics field to store the pid of the task which +* @is_rel: Set if the timer was armed relative +* @start_pid: timer statistics field to store the pid of the task which * started the timer * @start_site: timer statistics field to store the site where the timer * was started
@@ -101,7 +102,8 @@ struct hrtimer {ktime_t _softexpires;enum hrtimer_restart (*function)(struct hrtimer *);struct hrtimer_clock_base *base; -unsigned long state; +u8 state; +u8 is_rel;#ifdef CONFIG_TIMER_STATS int start_pid;void *start_site;
@@ -321,6 +323,27 @@ static inline void clock_was_set_delayed#endif +static inline ktime_t +__hrtimer_expires_remaining_adjusted (const struct hrtimer *timer,ktime_t now) +{ +ktime_t rem =ktime_sub (timer->node.expires, now); + +/* +* Adjust relative timers for the extra we added in +* hrtimer_start_range_ns() to prevent short timeouts. +*/ +if (IS_ENABLED (CONFIG_TIME_LOW_RES ) && timer->is_rel) + rem.tv64 -= hrtimer_resolution; +return rem; +} + +static inline ktime_t +hrtimer_expires_remaining_adjusted (const struct hrtimer *timer) +{ +return __hrtimer_expires_remaining_adjusted (timer, + timer->base->get_time ()); +} +extern void clock_was_set (void );#ifdef CONFIG_TIMERFD extern void timerfd_clock_was_set (void );
@@ -390,7 +413,12 @@ static inline void hrtimer_restart(struc }/* Query timers: */ -extern ktime_t hrtimer_get_remaining (const struct hrtimer *timer); +extern ktime_t __hrtimer_get_remaining (const struct hrtimer *timer,bool adjust); + +static inline ktime_t hrtimer_get_remaining (const struct hrtimer *timer) +{ +return __hrtimer_get_remaining (timer, false); +}extern u64 hrtimer_get_next_event (void );
kernel/time/hrtimer.c +37 -18
104 lines not on this page · raw message
kernel/time/timer_list.c +1 -1
@@ -69,7 +69,7 @@ print_timer(struct seq_file *m, struct hprint_name_offset (m, taddr);SEQ_printf (m,", " );print_name_offset (m, timer->function); -SEQ_printf (m,", S:%02lx" , timer->state); +SEQ_printf (m,", S:%02x" , timer->state);#ifdef CONFIG_TIMER_STATS SEQ_printf (m,", " );print_name_offset (m, timer->start_site);
Patches currently in stable-queue which might be from [email protected] are
queue-4.4/hrtimer-handle-remaining-time-proper-for-time_low_res.patch