Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 Dec 2012 01:20:56 +1100 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Davide Italiano <davide@freebsd.org>
Cc:        Ian Lepore <freebsd@damnhippie.dyndns.org>, Alexander Motin <mav@freebsd.org>, phk@onelab2.iet.unipi.it, Poul-Henning Kamp <phk@phk.freebsd.dk>, freebsd-current <freebsd-current@freebsd.org>, Bruce Evans <brde@optusnet.com.au>, "freebsd-arch@freebsd.org" <freebsd-arch@freebsd.org>
Subject:   Re: API explosion (Re: [RFC/RFT] calloutng)
Message-ID:  <20121220010702.B1675@besplex.bde.org>
In-Reply-To: <CACYV=-GAu=Sdq3AD3OPYin_GspAHjkDsma228DxRU14X0k14AA@mail.gmail.com>
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> <20121219221518.E1082@besplex.bde.org> <CACYV=-GAu=Sdq3AD3OPYin_GspAHjkDsma228DxRU14X0k14AA@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 19 Dec 2012, Davide Italiano wrote:

> On Wed, Dec 19, 2012 at 4:18 AM, Bruce Evans <brde@optusnet.com.au> wrote:

>> I would have tried a 32 bit format with a variable named 'ticks'.
>> Something like:
>> - ticks >= 0.  Same meaning as now.  No changes in ABIs or APIs to use
>>   this.  The tick period would be constant but for virtual ticks and
>>   not too small.  hz = 1000 now makes the period too small, and not a
>>   power of 2.  So make the period 1/128 second.  This gives a 1.24.7
>>   binary format.  2**24 seconds is 194 days.
>> - ticks < 0.  The 31 value bits are now a cookie (descriptor) referring
>>   to a bintime or whatever.  This case should rarely be used.  I don't
>>   like it that a tickless kernel, which is needed mainly for power
>>   saving, has expanded into complications to support short timeouts
>>   which should rarely be used.
>
> Bruce, I don't really agree with this.
> The data addressed by cookie should be still stored somewhere, and KBI
> will result broken. This, indeed, is not real problem as long as
> current calloutng code heavily breaks KBI, but if that was your point,
> I don't see how your proposed change could help.

In the old API, it is an error to pass ticks < 0, so only broken old
callers are affected.  Of course, if there are any then it would be
hard to detect their garbage cookies.

Anywy, it's too later to change to this, and maybe also to a 32.32
format.

[32.32 format]
>> This would make a better general format than timevals, timespecs and
>> of course bintimes :-).  It is a bit wasteful for timeouts since
>> its extremes are rarely used.  Malicious and broken callers can
>> still cause overflow at 68 years, so you have to check for it and
>> handle it.  The limit of 194 days is just as good for timeouts.
>
> I think the phk's proposal  is better. About your overflow objection,
> I think is really unlikely to happen, but better safe than sorry.

It's very easy for applications to cause kernel overflow using valid
syscall args like tv_sec = TIME_T_MAX for a relative time in
nanosleep().  Adding TIME_T_MAX to the current time in seconds overflow
for all current times except for the first second after the Epoch.
There is no difference between the overflow for 32-bit and 64-bit
time_t's for this.  This is now mostly handled so that the behaviour is
harmless although wrong.  E.g., the timeout might become negative,
and then since it is not a cookie it is silently replaced by a timeout
of 1 tick.  In nanosleep(), IIRC there are further overflows that result
in returning early instead of retrying the 1-tick timeouts endlessly.

Bruce



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