From: Thomas Gleixner <tglx@linutronix.de>
To: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@elte.hu>,
john stultz <johnstul@us.ibm.com>
Subject: Re: [PATCH] optimized ktime_get[_ts] for GENERIC_TIME=y
Date: Mon, 6 Jul 2009 22:31:39 +0200 (CEST) [thread overview]
Message-ID: <alpine.LFD.2.00.0907062215380.19480@localhost.localdomain> (raw)
In-Reply-To: <20090706154933.5a1f8990@skybase>
On Mon, 6 Jul 2009, Martin Schwidefsky wrote:
> +ktime_t ktime_get(void)
> +{
> + cycle_t cycle_now, cycle_delta;
> + struct timespec time;
> + unsigned long seq;
> + s64 nsecs;
> +
> + do {
> + seq = read_seqbegin(&xtime_lock);
> + time.tv_sec = xtime.tv_sec + wall_to_monotonic.tv_sec;
> + time.tv_nsec = xtime.tv_nsec + wall_to_monotonic.tv_nsec;
That's actually a violation of the timespec semantics. tv_nsec can end
up greater than (10^9 - 1). Please use separate sec and nsec variables.
secs = xtime.tv_sec + wall_to_monotonic.tv_sec;
nsecs = xtime.tv_nsec + wall_to_monotonic.tv_nsec;
> + /* read clocksource: */
> + cycle_now = clocksource_read(clock);
> +
> + /* calculate the delta since the last update_wall_time: */
> + cycle_delta = (cycle_now - clock->cycle_last) & clock->mask;
> +
> + /* convert to nanoseconds: */
> + nsecs = cyc2ns(clock, cycle_delta);
So that needs to be changed to:
nsecs += cyc2ns(clock, cycle_delta);
> +
> + } while (read_seqretry(&xtime_lock, seq));
> + nsecs += time.tv_sec * 1000000000ULL + time.tv_nsec;
> + return (ktime_t) { .tv64 = nsecs };
This will break all 32bit architectures which do not have
CONFIG_KTIME_SCALAR set.
With the above changes applied:
return ktime_add_ns(ktime_set(secs, 0), nsecs);
will do the trick. Might need some comments though :)
Thanks,
tglx
next prev parent reply other threads:[~2009-07-06 20:31 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-06 13:49 Martin Schwidefsky
2009-07-06 14:07 ` Eric Dumazet
2009-07-06 14:15 ` Martin Schwidefsky
2009-07-06 18:41 ` john stultz
2009-07-06 20:31 ` Thomas Gleixner [this message]
2009-07-07 7:40 ` Martin Schwidefsky
2009-07-07 8:08 ` Thomas Gleixner
2009-07-07 9:27 ` Martin Schwidefsky
2009-07-07 12:06 ` [tip:timers/core] timekeeping: " tip-bot for Martin Schwidefsky
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=alpine.LFD.2.00.0907062215380.19480@localhost.localdomain \
--to=tglx@linutronix.de \
--cc=johnstul@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=schwidefsky@de.ibm.com \
/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
Powered by JetHome