Commit 84999b8b authored by Thomas Gleixner's avatar Thomas Gleixner

posix-timers: Clarify posix_timer_fn() comments

Make the issues vs. SIG_IGN understandable and remove the 15 years old
promise that a proper solution is already on the horizon.
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/874jnrdmrq.ffs@tglx
parent 02972d79
...@@ -326,11 +326,11 @@ int posix_timer_event(struct k_itimer *timr, int si_private) ...@@ -326,11 +326,11 @@ int posix_timer_event(struct k_itimer *timr, int si_private)
} }
/* /*
* This function gets called when a POSIX.1b interval timer expires. It * This function gets called when a POSIX.1b interval timer expires from
* is used as a callback from the kernel internal timer. The * the HRTIMER interrupt (soft interrupt on RT kernels).
* run_timer_list code ALWAYS calls with interrupts on. *
* Handles CLOCK_REALTIME, CLOCK_MONOTONIC, CLOCK_BOOTTIME and CLOCK_TAI
* This code is for CLOCK_REALTIME* and CLOCK_MONOTONIC* timers. * based timers.
*/ */
static enum hrtimer_restart posix_timer_fn(struct hrtimer *timer) static enum hrtimer_restart posix_timer_fn(struct hrtimer *timer)
{ {
...@@ -348,9 +348,10 @@ static enum hrtimer_restart posix_timer_fn(struct hrtimer *timer) ...@@ -348,9 +348,10 @@ static enum hrtimer_restart posix_timer_fn(struct hrtimer *timer)
if (posix_timer_event(timr, si_private)) { if (posix_timer_event(timr, si_private)) {
/* /*
* signal was not sent because of sig_ignor * The signal was not queued due to SIG_IGN. As a
* we will not get a call back to restart it AND * consequence the timer is not going to be rearmed from
* it should be restarted. * the signal delivery path. But as a real signal handler
* can be installed later the timer must be rearmed here.
*/ */
if (timr->it_interval != 0) { if (timr->it_interval != 0) {
ktime_t now = hrtimer_cb_get_time(timer); ktime_t now = hrtimer_cb_get_time(timer);
...@@ -359,34 +360,35 @@ static enum hrtimer_restart posix_timer_fn(struct hrtimer *timer) ...@@ -359,34 +360,35 @@ static enum hrtimer_restart posix_timer_fn(struct hrtimer *timer)
* FIXME: What we really want, is to stop this * FIXME: What we really want, is to stop this
* timer completely and restart it in case the * timer completely and restart it in case the
* SIG_IGN is removed. This is a non trivial * SIG_IGN is removed. This is a non trivial
* change which involves sighand locking * change to the signal handling code.
* (sigh !), which we don't want to do late in *
* the release cycle. * For now let timers with an interval less than a
* jiffie expire every jiffie and recheck for a
* valid signal handler.
*
* This avoids interrupt starvation in case of a
* very small interval, which would expire the
* timer immediately again.
* *
* For now we just let timers with an interval * Moving now ahead of time by one jiffie tricks
* less than a jiffie expire every jiffie to * hrtimer_forward() to expire the timer later,
* avoid softirq starvation in case of SIG_IGN * while it still maintains the overrun accuracy
* and a very small interval, which would put * for the price of a slight inconsistency in the
* the timer right back on the softirq pending * timer_gettime() case. This is at least better
* list. By moving now ahead of time we trick * than a timer storm.
* hrtimer_forward() to expire the timer *
* later, while we still maintain the overrun * Only required when high resolution timers are
* accuracy, but have some inconsistency in * enabled as the periodic tick based timers are
* the timer_gettime() case. This is at least * automatically aligned to the next tick.
* better than a starved softirq. A more
* complex fix which solves also another related
* inconsistency is already in the pipeline.
*/ */
#ifdef CONFIG_HIGH_RES_TIMERS if (IS_ENABLED(CONFIG_HIGHRES_TIMERS)) {
{ ktime_t kj = TICK_NSEC;
ktime_t kj = NSEC_PER_SEC / HZ;
if (timr->it_interval < kj) if (timr->it_interval < kj)
now = ktime_add(now, kj); now = ktime_add(now, kj);
} }
#endif
timr->it_overrun += hrtimer_forward(timer, now, timr->it_overrun += hrtimer_forward(timer, now, timr->it_interval);
timr->it_interval);
ret = HRTIMER_RESTART; ret = HRTIMER_RESTART;
++timr->it_requeue_pending; ++timr->it_requeue_pending;
timr->it_active = 1; timr->it_active = 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment