From: Will Deacon Date: Mon, 24 May 2010 19:11:43 +0000 (-0700) Subject: sched: Prevent compiler from optimising the sched_avg_update() loop X-Git-Tag: v2.6.32.17~118 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=2d216ac392eea6c6b85d038dc7788bfe44b77040;p=karo-tx-linux.git sched: Prevent compiler from optimising the sched_avg_update() loop commit 0d98bb2656e9bd2dfda2d089db1fe1dbdab41504 upstream. GCC 4.4.1 on ARM has been observed to replace the while loop in sched_avg_update with a call to uldivmod, resulting in the following build failure at link-time: kernel/built-in.o: In function `sched_avg_update': kernel/sched.c:1261: undefined reference to `__aeabi_uldivmod' kernel/sched.c:1261: undefined reference to `__aeabi_uldivmod' make: *** [.tmp_vmlinux1] Error 1 This patch introduces a fake data hazard to the loop body to prevent the compiler optimising the loop away. Signed-off-by: Will Deacon Signed-off-by: Andrew Morton Acked-by: Peter Zijlstra Cc: Catalin Marinas Cc: Russell King Cc: Linus Torvalds Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- diff --git a/kernel/sched.c b/kernel/sched.c index 34d924e9f66d..e1cfb6c4f644 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -1261,6 +1261,12 @@ static void sched_avg_update(struct rq *rq) s64 period = sched_avg_period(); while ((s64)(rq->clock - rq->age_stamp) > period) { + /* + * Inline assembly required to prevent the compiler + * optimising this loop into a divmod call. + * See __iter_div_u64_rem() for another example of this. + */ + asm("" : "+rm" (rq->age_stamp)); rq->age_stamp += period; rq->rt_avg /= 2; }