From: Herbert Poetzl <herbert@13thfloor.at>
To: Andrew Morton <akpm@osdl.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: do_posix_clock_monotonic_gettime() returns negative nsec
Date: Fri, 3 Dec 2004 04:20:25 +0100 [thread overview]
Message-ID: <20041203032024.GA29553@mail.13thfloor.at> (raw)
In-Reply-To: <20041202190823.4f287617.akpm@osdl.org>
On Thu, Dec 02, 2004 at 07:08:23PM -0800, Andrew Morton wrote:
> Herbert Poetzl <herbert@13thfloor.at> wrote:
> >
> >
> > Hi Folks!
> >
> > recent kernels (tested 2.6.10-rc2 and 2.6.10-rc2-bk15)
> > produce funny output in /proc/uptime like this:
> >
> > # cat /proc/uptime
> > 12.4294967218 9.05
> > # cat /proc/uptime
> > 13.4294967251 10.33
> > # cat /proc/uptime
> > 14.4294967295 11.73
> >
> > a short investigation of the issue, ended at
> > do_posix_clock_monotonic_gettime() which can (and
> > often does) return negative nsec values (within
> > one second), so while the actual 'time' returned
> > is correct, some parts of the kernel assume that
> > those part is within the range (0 - NSEC_PER_SEC)
> >
> > len = sprintf(page,"%lu.%02lu %lu.%02lu\n",
> > (unsigned long) uptime.tv_sec,
> > (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
> >
> > as the function itself corrects overflows, it would
> > make sense to me to correct underflows too, for
> > example with the following patch:
> >
> > --- ./kernel/posix-timers.c.orig 2004-11-19 21:11:05.000000000 +0100
> > +++ ./kernel/posix-timers.c 2004-12-03 02:23:56.000000000 +0100
> > @@ -1208,7 +1208,10 @@ int do_posix_clock_monotonic_gettime(str
> > tp->tv_sec += wall_to_mono.tv_sec;
> > tp->tv_nsec += wall_to_mono.tv_nsec;
> >
> > - if ((tp->tv_nsec - NSEC_PER_SEC) > 0) {
> > + if (tp->tv_nsec < 0) {
> > + tp->tv_nsec += NSEC_PER_SEC;
> > + tp->tv_sec--;
> > + } else if ((tp->tv_nsec - NSEC_PER_SEC) > 0) {
> > tp->tv_nsec -= NSEC_PER_SEC;
> > tp->tv_sec++;
> > }
>
> Doesn't this imply that do_posix_clock_monotonic_gettime_parts() is
> returning a negative tv_nsec?
nope, not necessarily, because after that ...
tp->tv_sec += wall_to_mono.tv_sec;
tp->tv_nsec += wall_to_mono.tv_nsec;
might add a negative value, which explains the
underflow ...
and if you look closer:
xtime.tv_sec = get_cmos_time();
wall_to_monotonic.tv_sec = -xtime.tv_sec;
xtime.tv_nsec = (INITIAL_JIFFIES % HZ) * (NSEC_PER_SEC / HZ);
wall_to_monotonic.tv_nsec = -xtime.tv_nsec;
#define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
which might need a fix too ... but that's a
different story ...
> If so, that would point back at getnstimeofday(). What is your setting of
> CONFIG_TIME_INTERPOLATION?
# grep TIME .config
# CONFIG_HPET_TIMER is not set
# CONFIG_HANGCHECK_TIMER is not set
best,
Herbert
next prev parent reply other threads:[~2004-12-03 3:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-12-03 2:03 do_posix_clock_monotonic_gettime() returns negative nsec Herbert Poetzl
2004-12-03 3:00 ` john stultz
2004-12-03 8:43 ` George Anzinger
2004-12-03 8:56 ` Andrew Morton
2004-12-03 3:08 ` Andrew Morton
2004-12-03 3:20 ` Herbert Poetzl [this message]
2004-12-03 8:53 ` George Anzinger
2004-12-03 17:22 ` Herbert Poetzl
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=20041203032024.GA29553@mail.13thfloor.at \
--to=herbert@13thfloor.at \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.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