@@ -326,11 +326,11 @@ int posix_timer_event(struct k_itimer *timr, int si_private)
326326}
327327
328328/*
329- * This function gets called when a POSIX.1b interval timer expires. It
330- * is used as a callback from the kernel internal timer. The
331- * run_timer_list code ALWAYS calls with interrupts on.
332-
333- * This code is for CLOCK_REALTIME* and CLOCK_MONOTONIC* timers.
329+ * This function gets called when a POSIX.1b interval timer expires from
330+ * the HRTIMER interrupt (soft interrupt on RT kernels).
331+ *
332+ * Handles CLOCK_REALTIME, CLOCK_MONOTONIC, CLOCK_BOOTTIME and CLOCK_TAI
333+ * based timers.
334334 */
335335static enum hrtimer_restart posix_timer_fn (struct hrtimer * timer )
336336{
@@ -348,9 +348,10 @@ static enum hrtimer_restart posix_timer_fn(struct hrtimer *timer)
348348
349349 if (posix_timer_event (timr , si_private )) {
350350 /*
351- * signal was not sent because of sig_ignor
352- * we will not get a call back to restart it AND
353- * it should be restarted.
351+ * The signal was not queued due to SIG_IGN. As a
352+ * consequence the timer is not going to be rearmed from
353+ * the signal delivery path. But as a real signal handler
354+ * can be installed later the timer must be rearmed here.
354355 */
355356 if (timr -> it_interval != 0 ) {
356357 ktime_t now = hrtimer_cb_get_time (timer );
@@ -359,34 +360,35 @@ static enum hrtimer_restart posix_timer_fn(struct hrtimer *timer)
359360 * FIXME: What we really want, is to stop this
360361 * timer completely and restart it in case the
361362 * SIG_IGN is removed. This is a non trivial
362- * change which involves sighand locking
363- * (sigh !), which we don't want to do late in
364- * the release cycle.
363+ * change to the signal handling code.
364+ *
365+ * For now let timers with an interval less than a
366+ * jiffie expire every jiffie and recheck for a
367+ * valid signal handler.
368+ *
369+ * This avoids interrupt starvation in case of a
370+ * very small interval, which would expire the
371+ * timer immediately again.
365372 *
366- * For now we just let timers with an interval
367- * less than a jiffie expire every jiffie to
368- * avoid softirq starvation in case of SIG_IGN
369- * and a very small interval, which would put
370- * the timer right back on the softirq pending
371- * list. By moving now ahead of time we trick
372- * hrtimer_forward() to expire the timer
373- * later, while we still maintain the overrun
374- * accuracy, but have some inconsistency in
375- * the timer_gettime() case. This is at least
376- * better than a starved softirq. A more
377- * complex fix which solves also another related
378- * inconsistency is already in the pipeline.
373+ * Moving now ahead of time by one jiffie tricks
374+ * hrtimer_forward() to expire the timer later,
375+ * while it still maintains the overrun accuracy
376+ * for the price of a slight inconsistency in the
377+ * timer_gettime() case. This is at least better
378+ * than a timer storm.
379+ *
380+ * Only required when high resolution timers are
381+ * enabled as the periodic tick based timers are
382+ * automatically aligned to the next tick.
379383 */
380- #ifdef CONFIG_HIGH_RES_TIMERS
381- {
382- ktime_t kj = NSEC_PER_SEC / HZ ;
384+ if (IS_ENABLED (CONFIG_HIGHRES_TIMERS )) {
385+ ktime_t kj = TICK_NSEC ;
383386
384387 if (timr -> it_interval < kj )
385388 now = ktime_add (now , kj );
386389 }
387- #endif
388- timr -> it_overrun += hrtimer_forward (timer , now ,
389- timr -> it_interval );
390+
391+ timr -> it_overrun += hrtimer_forward (timer , now , timr -> it_interval );
390392 ret = HRTIMER_RESTART ;
391393 ++ timr -> it_requeue_pending ;
392394 timr -> it_active = 1 ;
0 commit comments