linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: George Anzinger <george@mvista.com>
To: john stultz <johnstul@us.ibm.com>
Cc: Roman Zippel <zippel@linux-m68k.org>, linux-kernel@vger.kernel.org
Subject: new time code problem
Date: Tue, 10 Jan 2006 15:58:52 -0800	[thread overview]
Message-ID: <43C44A3C.6010803@mvista.com> (raw)
In-Reply-To: <1136935211.2890.11.camel@cog.beaverton.ibm.com>

[-- Attachment #1: Type: text/plain, Size: 708 bytes --]

The 64-bit conversion routine to convert 64-bit nsec time to a time spec. 
gives an unnormalized result if the value being converted is negative.  I 
think there are two ways to go about fixing this.  Most systems will give a 
negative remainder and so need to just normalize.  On the other hand, some 
systems will use div64 to do the division and, I think, it expects unsigned 
numbers.  The attached patch uses the conservative approach of expecting the 
div to be set up for unsigned numbers.

I came accross this when one of my tests set a time near 1 Jan 1970, i.e. it 
is a real problem.
-- 
George Anzinger   george@mvista.com
HRT (High-res-timers):  http://sourceforge.net/projects/high-res-timers/

[-- Attachment #2: ktime_conversion.patch --]
[-- Type: text/plain, Size: 910 bytes --]

 kernel/time.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

Index: linux-2.6.16-rc/kernel/time.c
===================================================================
--- linux-2.6.16-rc.orig/kernel/time.c
+++ linux-2.6.16-rc/kernel/time.c
@@ -702,16 +702,19 @@ void set_normalized_timespec(struct time
  *
  * Returns the timespec representation of the nsec parameter.
  */
-inline struct timespec ns_to_timespec(const nsec_t nsec)
+struct timespec ns_to_timespec(const nsec_t nsec)
 {
 	struct timespec ts;
 
-	if (nsec)
+	if (nsec) return (struct timespec){0, 0};
+
+	if (nsec < 0) {
+		ts.tv_sec = div_long_long_rem_signed(-nsec, NSEC_PER_SEC,
+						     &ts.tv_nsec);
+		set_normalized_timespec(&ts, -ts.tv_sec, -ts.tv_nsec);
+	} else
 		ts.tv_sec = div_long_long_rem_signed(nsec, NSEC_PER_SEC,
 						     &ts.tv_nsec);
-	else
-		ts.tv_sec = ts.tv_nsec = 0;
-
 	return ts;
 }
 

  reply	other threads:[~2006-01-10 23:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-21 23:20 [PATCH 1/10] NTP: Remove pps support Roman Zippel
2006-01-10 23:20 ` john stultz
2006-01-10 23:58   ` George Anzinger [this message]
2006-01-11  0:23     ` new time code problem Thomas Gleixner
2006-01-11  1:37       ` George Anzinger
2006-01-11  9:18   ` [PATCH 1/10] NTP: Remove pps support Ulrich Windl
2006-01-12 11:58     ` Roman Zippel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=43C44A3C.6010803@mvista.com \
    --to=george@mvista.com \
    --cc=johnstul@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=zippel@linux-m68k.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).