From owner-freebsd-current@FreeBSD.ORG Fri Jun 5 19:05:02 2015 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B8E813A0 for ; Fri, 5 Jun 2015 19:05:02 +0000 (UTC) (envelope-from neelnatu@gmail.com) Received: from mail-wg0-x231.google.com (mail-wg0-x231.google.com [IPv6:2a00:1450:400c:c00::231]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 5268513A2 for ; Fri, 5 Jun 2015 19:05:02 +0000 (UTC) (envelope-from neelnatu@gmail.com) Received: by wgbgq6 with SMTP id gq6so63533475wgb.3 for ; Fri, 05 Jun 2015 12:05:00 -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=8gXakzI1hqyjzicCmLkuRmcSYHLzXdoZld/sTagEvAw=; b=QGlcrs4VHGK2VC02PtS4i4R+tm5X92lp932unWknhq0Km1Tv1aCaIRcGMUAdlPQxzC Ut4F+EBDzm/noTzZtiGcry/ZlmuLygY+28zG1Rn4zx5iJETVRtQzd1LLXI4gBM3eb4Zh 6G81GvU9vifX+HF1cF3W4sE6RxBRhkkNpazTk6FLav74NaDTlCTdj5y6oWYTWictjvTA C3mu6D8+O3iKJhlfVzcq+sC5DFNVQ2OOBovULpwWhxya2Ui/4+NysMjng4qJjYxjcmwa YcXP16s8s3JDlJFZGJwZYWHcjGh67uPvb219ffmcVg8PajLC2NZN0bXALuVyJU2rHbBO zZHg== MIME-Version: 1.0 X-Received: by 10.194.23.197 with SMTP id o5mr9033558wjf.75.1433531100733; Fri, 05 Jun 2015 12:05:00 -0700 (PDT) Received: by 10.27.52.18 with HTTP; Fri, 5 Jun 2015 12:05:00 -0700 (PDT) In-Reply-To: <5571F02B.4080907@selasky.org> References: <55714B26.6060802@selasky.org> <5571F02B.4080907@selasky.org> Date: Fri, 5 Jun 2015 12:05:00 -0700 Message-ID: Subject: Re: [CFR] Replacing while loops with proper division and multiplication From: Neel Natu To: Hans Petter Selasky Cc: FreeBSD Current Content-Type: text/plain; charset=UTF-8 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 19:05:02 -0000 Hi Hans, On Fri, Jun 5, 2015 at 11:53 AM, Hans Petter Selasky wrote: > 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? > I am not very familiar with this subsystem to make the call (mav@ or davide@ would know for sure though). I just noticed a discrepancy in the patch and wanted to highlight that in case it might be an issue. best Neel > --HPS