From owner-freebsd-current@FreeBSD.ORG Tue May 28 23:18:15 2013 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 531F49C; Tue, 28 May 2013 23:18:15 +0000 (UTC) (envelope-from rysto32@gmail.com) Received: from mail-oa0-f49.google.com (mail-oa0-f49.google.com [209.85.219.49]) by mx1.freebsd.org (Postfix) with ESMTP id 080BC1D1; Tue, 28 May 2013 23:18:14 +0000 (UTC) Received: by mail-oa0-f49.google.com with SMTP id k14so10643556oag.22 for ; Tue, 28 May 2013 16:18:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=mQ776Ghy1vQlQFe2RSHg8xkrIfgG0CJaZ/Fz88+U6Dw=; b=QAUpdmXLksZDHLZanIMc86/3RCNu3Ucc+9f1xdpaKqMvm+68OtZuo/1+1LqiC8MSII 4zxZkUp5oEmgUDbN3caQxdLAo/X5Ul9/Ohh6/l2lpeAiBFpBaUykw9reQp3CWswXYoq3 5uugGz0vaRwgOhJaWBUSEKavnfMybrg0VHzGbH5VAkYOzOAQqZO0lrNpU1JJBy5r54ao +Xxc65SpRjJCh5Mqo51aRiOHguY9w91ce2Ri9P57RiPBnqyJEvPiYnSSfHVd0kzrmwCk LclXTzML1hKJLC4wXFLI4fxDf4Uh5xWyYbHZnRi3xAY66ebSIPYUncRKuuoI9+b9gl7L hTyQ== MIME-Version: 1.0 X-Received: by 10.60.142.67 with SMTP id ru3mr57901oeb.44.1369783088061; Tue, 28 May 2013 16:18:08 -0700 (PDT) Received: by 10.76.91.163 with HTTP; Tue, 28 May 2013 16:18:07 -0700 (PDT) In-Reply-To: <1369776586.1258.19.camel@revolution.hippie.lan> References: <1369776586.1258.19.camel@revolution.hippie.lan> Date: Tue, 28 May 2013 19:18:07 -0400 Message-ID: Subject: Re: Incorrect comparison of ticks in deadlkres From: Ryan Stone To: Ian Lepore Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 Cc: Attilio Rao , FreeBSD Current , arao@freebsd.og X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 May 2013 23:18:15 -0000 On Tue, May 28, 2013 at 5:29 PM, Ian Lepore 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.