Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 Dec 2012 02:44:07 +1100 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Luigi Rizzo <rizzo@iet.unipi.it>
Cc:        Davide Italiano <davide@freebsd.org>, Ian Lepore <freebsd@damnhippie.dyndns.org>, Alexander Motin <mav@freebsd.org>, Poul-Henning Kamp <phk@phk.freebsd.dk>, freebsd-current <freebsd-current@freebsd.org>, "freebsd-arch@freebsd.org" <freebsd-arch@freebsd.org>
Subject:   Re: API explosion (Re: [RFC/RFT] calloutng)
Message-ID:  <20121220022926.C1961@besplex.bde.org>
In-Reply-To: <20121219150809.GA98673@onelab2.iet.unipi.it>
References:  <50CF88B9.6040004@FreeBSD.org> <20121218173643.GA94266@onelab2.iet.unipi.it> <50D0B00D.8090002@FreeBSD.org> <50D0E42B.6030605@FreeBSD.org> <20121218225823.GA96962@onelab2.iet.unipi.it> <1355873265.1198.183.camel@revolution.hippie.lan> <14604.1355910848@critter.freebsd.dk> <CACYV=-Eg542iHm9KfujPvCzZrA4TqepEBVA8RzT1YOHnCgfJnA@mail.gmail.com> <15882.1355914308@critter.freebsd.dk> <20121219150809.GA98673@onelab2.iet.unipi.it>

next in thread | previous in thread | raw e-mail | index | archive | help
I finally remembered to remove the .it phk :-).

On Wed, 19 Dec 2012, Luigi Rizzo wrote:

> On Wed, Dec 19, 2012 at 10:51:48AM +0000, Poul-Henning Kamp wrote:
>> ...
>> As I said in my previous email:
>>
>>
>>         typedef dur_t   int64_t;        /* signed for bug catching */
>>         #define DURSEC  ((dur_t)1 << 32)
>>         #define DURMIN  (DURSEC * 60)
>>         #define DURMSEC (DURSEC / 1000)
>>         #define DURUSEC (DURSEC / 10000000)
>>         #define DURNSEC (DURSEC / 10000000000)
>>
>> (Bikeshed the names at your convenience)
>>
>> Then you can say
>>
>> 	callout_foo(34 * DURSEC)
>> 	callout_foo(2400 * DURMSEC)
>> or
>> 	callout_foo(500 * DURNSEC)
>
> only thing, we must be careful with the parentheses
>
> For instance, in your macro, DURNSEC evaluates to 0 and so
> does any multiple of it.
> We should define them as
>
> #define DURNSEC DURSEC / 10000000000
> ...
>
> so DURNSEC is still 0 and 500*DURNSEC gives 214
>
> I am curious that Bruce did not mention this :)

Er, he was careful.  DURNSEC gives 4, not 0.  This is not very accurate,
but probably good enough.

Your version without parentheses is not so careful and depends on
a magic order of operations and no overflow from this.  E.g.:

500*DURNSEC = 500*DURSEC / 1000000000 = 500*((dur_t)1 << 32) / 1000000000

This is very accurate and happens not to overflow.  But 5 seconds represented
a little strangely in nanoseconds would overflow:

5000000000*DURNSEC = 5000000000*((dur_t)1 << 32) / 1000000000

So would 5 billion times DURSEC, but 5 billion seconds is more unreasobable
than 5 billion nanoseconds and the format just can't represent that.

>
> (btw the typedef is swapped, should be "typedef int64_t dur_t")

Didn't notice this.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20121220022926.C1961>