public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Prevent the loop in timespec_add_ns() to be optimised away
@ 2008-02-22 21:40 Segher Boessenkool
  2008-02-27 23:43 ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: Segher Boessenkool @ 2008-02-22 21:40 UTC (permalink / raw)
  To: linux-kernel; +Cc: Segher Boessenkool

...since some architectures don't support __udivdi3() (and
we don't want to use that, anyway).

Signed-off-by: Segher Boessenkool <segher@kernel.crashing.org>
---
 include/linux/time.h |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/include/linux/time.h b/include/linux/time.h
index 2091a19..d32ef0a 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -174,6 +174,10 @@ static inline void timespec_add_ns(struct timespec *a, u64 ns)
 {
 	ns += a->tv_nsec;
 	while(unlikely(ns >= NSEC_PER_SEC)) {
+		/* The following asm() prevents the compiler from
+		 * optimising this loop into a modulo operation.  */
+		asm("" : "+r"(ns));
+
 		ns -= NSEC_PER_SEC;
 		a->tv_sec++;
 	}
-- 
1.5.4.2.184.gb23b


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

end of thread, other threads:[~2008-02-28 22:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-22 21:40 [PATCH] Prevent the loop in timespec_add_ns() to be optimised away Segher Boessenkool
2008-02-27 23:43 ` Andrew Morton
2008-02-28 21:58   ` Thomas Gleixner
2008-02-28 22:13     ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox