Skip to contentSkip to conversation

high-res timers: core, do itimer rearming in process context, fix

PATCH New Ingo Molnar 2 participants 2 messages Dec 19, 2006 – Dec 21, 2006 High-resolution timers, timer wheel, clockevents

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 high-res timers: core, do itimer rearming in process context, fix

Subject: [patch] high-res timers: core, do itimer rearming in process context, fix
From: Ingo Molnar <[email protected]>

restart itimers when they are not queued. (a non-queued hrtimer might be callback-pending - but in that case we already missed the rearming so the SIGALRM branch has to rearm.)

this fixes a threaded itimers stress-test hang.

---
 include/linux/hrtimer.h |    9 +++++++++
 kernel/hrtimer.c        |    9 ---------
 kernel/signal.c         |    2 +-
 3 files changed, 10 insertions(+), 10 deletions(-)
include/linux/hrtimer.h +9 -0
Index: linux/include/linux/hrtimer.h
===================================================================
@@ -309,6 +309,15 @@ static inline int hrtimer_active(const s
 	return timer->state != HRTIMER_STATE_INACTIVE;
 }
 
+/*
+ * Helper function to check, whether the timer is on one of the queues
+ */
+static inline int hrtimer_is_queued(struct hrtimer *timer)
+{
+	return timer->state &
+		(HRTIMER_STATE_ENQUEUED | HRTIMER_STATE_PENDING);
+}
+
 /* Forward a hrtimer so it expires after now: */
 extern unsigned long
 hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval);
kernel/hrtimer.c +0 -9
Index: linux/kernel/hrtimer.c
===================================================================
@@ -152,15 +152,6 @@ static void hrtimer_get_softirq_time(str
 }
 
 /*
- * Helper function to check, whether the timer is on one of the queues
- */
-static inline int hrtimer_is_queued(struct hrtimer *timer)
-{
-	return timer->state &
-		(HRTIMER_STATE_ENQUEUED | HRTIMER_STATE_PENDING);
-}
-
-/*
  * Helper function to check, whether the timer is running the callback
  * function
  */
kernel/signal.c +1 -1
Index: linux/kernel/signal.c
===================================================================
@@ -475,7 +475,7 @@ int dequeue_signal(struct task_struct *t
 		if (unlikely(signr == SIGALRM)) {
 			struct hrtimer *tmr = &tsk->signal->real_timer;
 
-			if (!hrtimer_active(tmr) &&
+			if (!hrtimer_is_queued(tmr) &&
 			    tsk->signal->it_real_incr.tv64 != 0) {
 				hrtimer_forward(tmr, hrtimer_cb_get_time(tmr),
 						tsk->signal->it_real_incr);
#1 lore raw

PATCH 1/1 high-res timers: core, do itimer rearming in process context, fix2

Subject: [patch] high-res timers: core, do itimer rearming in process context, fix2
From: Thomas Gleixner <[email protected]>

The rearming code in signal.c has to read the time and can not rely on the timer->base->softirq time anymore, as it is not longer running in softirq context.

Ensure, that the it_real_incr variable in the shared signal struct is set to zero, when setitimer disables the itimer. Otherwise it could happen that an inactive itimer gets rearmed by a SIGALRM.

---
 kernel/signal.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/signal.c +1 -1
Index: 2.6.19-git19/kernel/signal.c
===================================================================
@@ -477,7 +477,7 @@ int dequeue_signal(struct task_struct *t
 
 			if (!hrtimer_is_queued(tmr) &&
 			    tsk->signal->it_real_incr.tv64 != 0) {
-				hrtimer_forward(tmr, hrtimer_cb_get_time(tmr),
+				hrtimer_forward(tmr, tmr->base->get_time(),
 						tsk->signal->it_real_incr);
 				hrtimer_restart(tmr);
 			}
kernel/itimer.c +6 -3
Index: 2.6.19-git19/kernel/itimer.c
===================================================================
@@ -226,11 +226,14 @@ again:
 			spin_unlock_irq(&tsk->sighand->siglock);
 			goto again;
 		}
-		tsk->signal->it_real_incr =
-			timeval_to_ktime(value->it_interval);
 		expires = timeval_to_ktime(value->it_value);
-		if (expires.tv64 != 0)
+		if (expires.tv64 != 0) {
+			tsk->signal->it_real_incr =
+				timeval_to_ktime(value->it_interval);
 			hrtimer_start(timer, expires, HRTIMER_MODE_REL);
+		} else
+			tsk->signal->it_real_incr.tv64 = 0;
+
 		spin_unlock_irq(&tsk->sighand->siglock);
 		break;
 	case ITIMER_VIRTUAL: