]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/2.6.32.17/sched-prevent-compiler-from-optimising-the-sched_avg_update-loop.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 2.6.32.17 / sched-prevent-compiler-from-optimising-the-sched_avg_update-loop.patch
CommitLineData
45426b3c
GKH
1From 0d98bb2656e9bd2dfda2d089db1fe1dbdab41504 Mon Sep 17 00:00:00 2001
2From: Will Deacon <will.deacon@arm.com>
3Date: Mon, 24 May 2010 12:11:43 -0700
4Subject: sched: Prevent compiler from optimising the sched_avg_update() loop
5
6From: Will Deacon <will.deacon@arm.com>
7
8commit 0d98bb2656e9bd2dfda2d089db1fe1dbdab41504 upstream.
9
10GCC 4.4.1 on ARM has been observed to replace the while loop in
11sched_avg_update with a call to uldivmod, resulting in the
12following build failure at link-time:
13
14kernel/built-in.o: In function `sched_avg_update':
15 kernel/sched.c:1261: undefined reference to `__aeabi_uldivmod'
16 kernel/sched.c:1261: undefined reference to `__aeabi_uldivmod'
17make: *** [.tmp_vmlinux1] Error 1
18
19This patch introduces a fake data hazard to the loop body to
20prevent the compiler optimising the loop away.
21
22Signed-off-by: Will Deacon <will.deacon@arm.com>
23Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
24Acked-by: Peter Zijlstra <peterz@infradead.org>
25Cc: Catalin Marinas <catalin.marinas@arm.com>
26Cc: Russell King <rmk@arm.linux.org.uk>
27Cc: Linus Torvalds <torvalds@linux-foundation.org>
28Signed-off-by: Ingo Molnar <mingo@elte.hu>
29Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
30
31---
32 kernel/sched.c | 6 ++++++
33 1 file changed, 6 insertions(+)
34
35--- a/kernel/sched.c
36+++ b/kernel/sched.c
37@@ -1261,6 +1261,12 @@ static void sched_avg_update(struct rq *
38 s64 period = sched_avg_period();
39
40 while ((s64)(rq->clock - rq->age_stamp) > period) {
41+ /*
42+ * Inline assembly required to prevent the compiler
43+ * optimising this loop into a divmod call.
44+ * See __iter_div_u64_rem() for another example of this.
45+ */
46+ asm("" : "+rm" (rq->age_stamp));
47 rq->age_stamp += period;
48 rq->rt_avg /= 2;
49 }