summaryrefslogtreecommitdiffstats
path: root/posix-timers-avoid-wakeups-when-no-timers-are-active.patch
blob: 0faf719842a03b606d2d02e8fdad1cade0dda2f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
From fb9d645bcacaced10a18726bd8c0fface2bef5bb Mon Sep 17 00:00:00 2001
From: Thomas Gleixner <tglx@linutronix.de>
Date: Fri, 3 Jul 2009 08:44:44 -0500
Subject: [PATCH] posix-timers: avoid wakeups when no timers are active

commit 4aef9893f48ad8905a35b2fbe2cc78662c0fa441 in tip.

Waking the thread even when no timers are scheduled is useless.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
---
 kernel/posix-cpu-timers.c |   21 ++++++++++++++++++---
 1 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
index a73d9f0..892f63b 100644
--- a/kernel/posix-cpu-timers.c
+++ b/kernel/posix-cpu-timers.c
@@ -1517,6 +1517,21 @@ wait_to_die:
 	return 0;
 }
 
+static inline int __fastpath_timer_check(struct task_struct *tsk)
+{
+	/* tsk == current, ensure it is safe to use ->signal/sighand */
+	if (unlikely(tsk->exit_state))
+		return 0;
+
+	if (!task_cputime_zero(&tsk->cputime_expires))
+			return 1;
+
+	if (!task_cputime_zero(&tsk->signal->cputime_expires))
+			return 1;
+
+	return 0;
+}
+
 void run_posix_cpu_timers(struct task_struct *tsk)
 {
 	unsigned long cpu = smp_processor_id();
@@ -1529,7 +1544,7 @@ void run_posix_cpu_timers(struct task_struct *tsk)
 	tasklist = per_cpu(posix_timer_tasklist, cpu);
 
 	/* check to see if we're already queued */
-	if (!tsk->posix_timer_list) {
+	if (!tsk->posix_timer_list && __fastpath_timer_check(tsk)) {
 		get_task_struct(tsk);
 		if (tasklist) {
 			tsk->posix_timer_list = tasklist;
@@ -1541,9 +1556,9 @@ void run_posix_cpu_timers(struct task_struct *tsk)
 			tsk->posix_timer_list = tsk;
 		}
 		per_cpu(posix_timer_tasklist, cpu) = tsk;
+
+		wake_up_process(per_cpu(posix_timer_task, cpu));
 	}
-	/* XXX signal the thread somehow */
-	wake_up_process(per_cpu(posix_timer_task, cpu));
 }
 
 /*
-- 
1.7.0.4