Incorrect comparison of ticks in deadlkres

Ryan Stone rysto32 at gmail.com
Tue May 28 23:18:15 UTC 2013


On Tue, May 28, 2013 at 5:29 PM, Ian Lepore <ian at freebsd.org> wrote:

> ticks is defined as a signed integer but conceptually it is unsigned --
> it increments from 0 to UINT_MAX (not INT_MAX) then rolls over.  If
> td->td_blktick is captured while ticks = UINT_MAX and later ticks has
> rolled over and counted back up to 15, then ticks - td->td_blktick gives
> an elapsed time of 16, as it should be.  Whether exploiting this
> property of signed overflow is elegant or ugly is in the eye of the
> beholder. :)
>
> If the intent of the "ticks < td->td_blktick" is to avoid the deadlock
> check until "after enough time has passed," then I guess it should
> probably be something more like "(ticks - td->blktick) > SOME_THRESHOLD"
> so that it also uses the signed overflow trick.
>
> -- Ian
>

It already does this later on to actually detect the deadlock.  The test is
reversed but was intended to bail and not calculate the time elapsed at all
if ticks had overflowed after td_blktick was captured, but as you say this
is unnecessary.


More information about the freebsd-current mailing list