All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched, time: cmpxchg does not work on 64-bit variable
@ 2014-09-30 11:56 ` Arnd Bergmann
  0 siblings, 0 replies; 25+ messages in thread
From: Arnd Bergmann @ 2014-09-30 11:56 UTC (permalink / raw)
  To: Rik van Riel
  Cc: Peter Zijlstra, Linus Torvalds, umgwanakikbuti, fweisbec, akpm,
	srao, lwoodman, atheurer, oleg, Ingo Molnar, linux-kernel,
	linux-arm-kernel

A recent change to update the stime/utime members of task_struct
using atomic cmpxchg broke configurations on 32-bit machines with
CONFIG_VIRT_CPU_ACCOUNTING_GEN set, because that uses 64-bit
nanoseconds, leading to a link-time error:

kernel/built-in.o: In function `cputime_adjust':
:(.text+0x25234): undefined reference to `__bad_cmpxchg'

This reverts the change that caused the problem, I suspect the real fix
is to conditionally use cmpxchg64 instead, but I have not checked if
that will work on all architectures.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: eb1b4af0a64a ("sched, time: Atomically increment stime & utime")
---
found in ARM randconfig builds on linux-next

diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 64492dff8a81..e99e7e54131c 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -603,12 +603,9 @@ static void cputime_adjust(struct task_cputime *curr,
 	 * If the tick based count grows faster than the scheduler one,
 	 * the result of the scaling may go backward.
 	 * Let's enforce monotonicity.
-	 * Atomic exchange protects against concurrent cputime_adjust().
 	 */
-	while (stime > (rtime = ACCESS_ONCE(prev->stime)))
-		cmpxchg(&prev->stime, rtime, stime);
-	while (utime > (rtime = ACCESS_ONCE(prev->utime)))
-		cmpxchg(&prev->utime, rtime, utime);
+	prev->stime = max(prev->stime, stime);
+	prev->utime = max(prev->utime, utime);
 
 out:
 	*ut = prev->utime;


^ permalink raw reply related	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2014-10-03  5:29 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-30 11:56 [PATCH] sched, time: cmpxchg does not work on 64-bit variable Arnd Bergmann
2014-09-30 11:56 ` Arnd Bergmann
2014-09-30 12:34 ` Rik van Riel
2014-09-30 12:34   ` Rik van Riel
2014-09-30 12:43   ` Dietmar Eggemann
2014-09-30 12:43     ` Dietmar Eggemann
2014-09-30 13:26   ` Arnd Bergmann
2014-09-30 13:26     ` Arnd Bergmann
2014-09-30 13:37   ` Peter Zijlstra
2014-09-30 13:37     ` Peter Zijlstra
2014-09-30 19:59     ` [PATCH v2] sched, time: fix build error with 64 bit cputime_t on 32 bit systems Rik van Riel
2014-09-30 19:59       ` Rik van Riel
2014-09-30 20:07       ` Arnd Bergmann
2014-09-30 20:07         ` Arnd Bergmann
2014-10-03  5:27       ` [tip:sched/core] sched, time: Fix " tip-bot for Rik van Riel
2014-09-30 17:40 ` [PATCH] sched, time: fix " Rik van Riel
2014-09-30 17:40   ` Rik van Riel
2014-09-30 18:49   ` Arnd Bergmann
2014-09-30 18:49     ` Arnd Bergmann
2014-09-30 19:19     ` Rik van Riel
2014-09-30 19:19       ` Rik van Riel
2014-09-30 19:06   ` Frederic Weisbecker
2014-09-30 19:06     ` Frederic Weisbecker
2014-09-30 19:08     ` Peter Zijlstra
2014-09-30 19:08       ` Peter Zijlstra

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.