From: Thomas Gleixner <tglx@linutronix.de>
To: Matt Fleming <mattjfleming@googlemail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: ktime_set() does not check for nanoseconds > one second
Date: Mon, 1 Sep 2008 15:06:23 +0200 (CEST) [thread overview]
Message-ID: <alpine.LFD.1.10.0809011501450.3243@apollo.tec.linutronix.de> (raw)
In-Reply-To: <5ff4a1e50809010457l7051b7e8vc7f86d68ae42e529@mail.gmail.com>
On Mon, 1 Sep 2008, Matt Fleming wrote:
> > Yeah, a check for this in ktime_set() might make sense. Currently it's
> > up to the programmer to provide sane values. :)
> >
> > Thanks,
> >
> > tglx
> >
>
> How about the attached patch?
Won't work with arbitrary numbers. i.e. >= 2* NSEC_PER_SEC. Looking at
it, I'm even less convinced that it is a good idea.
tglx
> Matt
>
> diff --git a/include/linux/ktime.h b/include/linux/ktime.h
> index ce59832..7c0ad35 100644
> --- a/include/linux/ktime.h
> +++ b/include/linux/ktime.h
> @@ -150,7 +150,19 @@ static inline ktime_t timeval_to_ktime(struct timeval tv)
> /* Set a ktime_t variable to a value in sec/nsec representation: */
> static inline ktime_t ktime_set(const long secs, const unsigned long nsecs)
> {
> - return (ktime_t) { .tv = { .sec = secs, .nsec = nsecs } };
> + ktime_t res = { .tv = { .sec = secs, .nsec = nsecs }};;
> +
> + /*
> + * performance trick: the (u32) -NSEC gives 0x00000000Fxxxxxxx
> + * so we subtract NSEC_PER_SEC and add 1 to the upper 32 bit.
> + *
> + * it's equivalent to:
> + * tv.nsec -= NSEC_PER_SEC
> + * tv.sec ++;
> + */
> + if (nsecs >= NSEC_PER_SEC)
> + res.tv64 += (u32)-NSEC_PER_SEC;
> + return res;
> }
>
> /**
>
next prev parent reply other threads:[~2008-09-01 13:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-01 10:38 Matt Fleming
2008-09-01 11:20 ` Thomas Gleixner
2008-09-01 11:57 ` Matt Fleming
2008-09-01 13:06 ` Thomas Gleixner [this message]
2008-09-01 13:11 ` Matt Fleming
2008-09-01 13:16 ` Thomas Gleixner
2008-09-01 13:33 ` Matt Fleming
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.1.10.0809011501450.3243@apollo.tec.linutronix.de \
--to=tglx@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=mattjfleming@googlemail.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
all inboxes | Powered by JetHome®