From owner-freebsd-current@FreeBSD.ORG Fri Jun 5 18:52:46 2015 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 67344976 for ; Fri, 5 Jun 2015 18:52:46 +0000 (UTC) (envelope-from hps@selasky.org) Received: from mail.turbocat.net (mail.turbocat.net [IPv6:2a01:4f8:d16:4514::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2C88410CA for ; Fri, 5 Jun 2015 18:52:46 +0000 (UTC) (envelope-from hps@selasky.org) Received: from laptop015.home.selasky.org (cm-176.74.213.204.customer.telag.net [176.74.213.204]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.turbocat.net (Postfix) with ESMTPSA id 2B3851FE023; Fri, 5 Jun 2015 20:52:44 +0200 (CEST) Message-ID: <5571F02B.4080907@selasky.org> Date: Fri, 05 Jun 2015 20:53:31 +0200 From: Hans Petter Selasky User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Neel Natu CC: FreeBSD Current Subject: Re: [CFR] Replacing while loops with proper division and multiplication References: <55714B26.6060802@selasky.org> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.20 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: Fri, 05 Jun 2015 18:52:46 -0000 On 06/05/15 20:31, Neel Natu wrote: >>> - runs = 0; >>> >>- while (now >= state->nexthard) { >>> >>- state->nexthard += tick_sbt; >>> >>- runs++; >>> >>- } >>> >>- if (runs) { >>> >>+ runs = (now - state->nexthard) / tick_sbt; >>> >>+ if (runs > 0) { >>> >>+ printf("R%d ", (int)runs); >>> >>+ state->nexthard += tick_sbt * runs; >>> >> hct = DPCPU_PTR(hardclocktime); >>> >> *hct = state->nexthard - tick_sbt; >>> >> if (fake < 2) { > There is a difference in behavior in the two implementations when 'now > == state->nexthard'. In the loop-based implementation this would end > up with 'runs = 1' whereas in the division-based implementation it > would end up with 'runs = 0'. > > I am not sure if this is intentional or just an oversight. Hi Neel, The nexthard is mainly updated in this piece of code. We can assume that "state->nexthard" is aligned to "ticks_sbt". If "state->nexthard % ticks_sbt == 0", is that still an issue? --HPS