From owner-freebsd-current@FreeBSD.ORG Tue May 28 23:31:14 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 BE48A541; Tue, 28 May 2013 23:31:14 +0000 (UTC) (envelope-from asmrookie@gmail.com) Received: from mail-ie0-x22b.google.com (mail-ie0-x22b.google.com [IPv6:2607:f8b0:4001:c03::22b]) by mx1.freebsd.org (Postfix) with ESMTP id 8A40D26E; Tue, 28 May 2013 23:31:14 +0000 (UTC) Received: by mail-ie0-f171.google.com with SMTP id s9so5240585iec.16 for ; Tue, 28 May 2013 16:31:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=0mKzfBUkVj+ZPlearUT9WbyQ7pV9M+CbcfIcGihxfRQ=; b=arVMNLsLmbm1eQmaL9d9tjior3FfGAb2HSOp3c1KqSeclduWLT7qNwJte31P7ON7a+ evoNvkPAgQY2Tv+3HrfIolPW58dgpx7Mj81OmhK9soaTrN0WP4Nha9vDyOXG4NStoZNq p6hGBBIYCgQU3ZuwBOEzrB0FDc7gxAnOWC7WC6LXFNmgLMWIUJYwm2qMbB/Gfxwega+V GKY4TJZ7cic0tjn++l3/qcQDDAoQnNc3F6zVfpS2YeKBY4KatmSEjtb1KVhZMEIEEX8K gOEjTKHJnSKTTA/NPBBau9avI7P+ETGWC1+NwoxeitHNa+U5aEUeYQfVRPvpoVQ4V1YC 56fA== MIME-Version: 1.0 X-Received: by 10.50.18.80 with SMTP id u16mr8016376igd.13.1369783873706; Tue, 28 May 2013 16:31:13 -0700 (PDT) Sender: asmrookie@gmail.com Received: by 10.42.253.129 with HTTP; Tue, 28 May 2013 16:31:13 -0700 (PDT) In-Reply-To: References: <1369776586.1258.19.camel@revolution.hippie.lan> Date: Wed, 29 May 2013 01:31:13 +0200 X-Google-Sender-Auth: OlKjpUAScpjUq4k-XgMSI-JWAgs Message-ID: Subject: Re: Incorrect comparison of ticks in deadlkres From: Attilio Rao To: Ryan Stone Content-Type: text/plain; charset=UTF-8 Cc: FreeBSD Current , Ian Lepore , arao@freebsd.og X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: attilio@FreeBSD.org 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:31:14 -0000 On Wed, May 29, 2013 at 1:18 AM, Ryan Stone wrote: > 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. I'm not sure if there was a comparison between the 2 values (ticks, td_slpticks) somewhere, but if there is not and only add/sub to the relative values then it is good to be removed. Attilio -- Peace can only be achieved by understanding - A. Einstein