[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.LFD.1.10.0809011501450.3243@apollo.tec.linutronix.de>
Date: Mon, 1 Sep 2008 15:06:23 +0200 (CEST)
From: Thomas Gleixner <tglx@...utronix.de>
To: Matt Fleming <mattjfleming@...glemail.com>
cc: linux-kernel@...r.kernel.org
Subject: Re: ktime_set() does not check for nanoseconds > one second
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;
> }
>
> /**
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists