From patchwork Sun Sep 14 13:06:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laszlo Ersek X-Patchwork-Id: 37386 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4EE5D202A1 for ; Sun, 14 Sep 2014 13:07:31 +0000 (UTC) Received: by mail-la0-f69.google.com with SMTP id ty20sf1503222lab.8 for ; Sun, 14 Sep 2014 06:07:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:reply-to:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=GCOvKnle08QXP1HIbmkXc3wv+AzBOnWgjmNfLzvzfXU=; b=jm+NdEa5UXnz3Ak2QLc1wPIqTOPUC88dY58JpzFkiy0POL4gRtiIeKaDGXE5as1am/ uVkQOIHhi5a8CBh9Pm0h+lY258rstYu9myctlEH1TUyPWBcCBhSAOHoe64b8Nwf/RA67 8ai/CaUYggVxKzs7WTiE1/mFoY+J8B17dYqUagTXANyD2nEkYS+jnsC7JldV6RMsYXD6 xIdyq2kpoXGm4LrBLzZ7cmqVkZ92La27nuqu7f1kzaZONPi9ZpU9TSdFY0o3l9j7pqgv tcZzRRyNDaSH84Fx3FpLPXYAEFOdzSNdli01/QxlqDsRhuIM7k5kfWYSJKaqYGc8+OXw MMZg== X-Gm-Message-State: ALoCoQkcF1bdcIIBCzbovN0XwXjWntIPwWQAVMqW1kw7siIZW0l6GtfBC2lRAPEJwYd+m8hqg6rw X-Received: by 10.181.8.226 with SMTP id dn2mr4010672wid.4.1410700049624; Sun, 14 Sep 2014 06:07:29 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.29.8 with SMTP id f8ls23129lah.85.gmail; Sun, 14 Sep 2014 06:07:29 -0700 (PDT) X-Received: by 10.112.150.106 with SMTP id uh10mr20322706lbb.11.1410700049346; Sun, 14 Sep 2014 06:07:29 -0700 (PDT) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com [209.85.217.176]) by mx.google.com with ESMTPS id j8si14950018lag.57.2014.09.14.06.07.29 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 14 Sep 2014 06:07:29 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) client-ip=209.85.217.176; Received: by mail-lb0-f176.google.com with SMTP id z11so3186319lbi.35 for ; Sun, 14 Sep 2014 06:07:29 -0700 (PDT) X-Received: by 10.112.53.230 with SMTP id e6mr1648683lbp.100.1410700049235; Sun, 14 Sep 2014 06:07:29 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.130.169 with SMTP id of9csp80135lbb; Sun, 14 Sep 2014 06:07:28 -0700 (PDT) X-Received: by 10.51.17.66 with SMTP id gc2mr15465324igd.40.1410700047982; Sun, 14 Sep 2014 06:07:27 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id p14si7093842igr.5.2014.09.14.06.07.27 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 14 Sep 2014 06:07:27 -0700 (PDT) Received-SPF: pass (google.com: domain of edk2-devel-bounces@lists.sourceforge.net designates 216.34.181.88 as permitted sender) client-ip=216.34.181.88; Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XT9WJ-0007UB-1H; Sun, 14 Sep 2014 13:07:11 +0000 Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XT9WH-0007U4-Gn for edk2-devel@lists.sourceforge.net; Sun, 14 Sep 2014 13:07:09 +0000 Received-SPF: pass (sog-mx-4.v43.ch3.sourceforge.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=lersek@redhat.com; helo=mx1.redhat.com; Received: from mx1.redhat.com ([209.132.183.28]) by sog-mx-4.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1XT9WG-0005A8-6i for edk2-devel@lists.sourceforge.net; Sun, 14 Sep 2014 13:07:09 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8ED72sd011034 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Sun, 14 Sep 2014 09:07:02 -0400 Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-29.ams2.redhat.com [10.36.116.29]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s8ED6xtj011371 for ; Sun, 14 Sep 2014 09:07:01 -0400 From: Laszlo Ersek To: edk2-devel@lists.sourceforge.net Date: Sun, 14 Sep 2014 15:06:54 +0200 Message-Id: <1410700015-23791-2-git-send-email-lersek@redhat.com> In-Reply-To: <1410700015-23791-1-git-send-email-lersek@redhat.com> References: <1410700015-23791-1-git-send-email-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Spam-Score: -2.2 (--) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain X-Headers-End: 1XT9WG-0005A8-6i Subject: [edk2] [PATCH 1/2] MdeModulePkg: CoreStall: prove safety of round-up in non-iterating branch X-BeenThere: edk2-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list Reply-To: edk2-devel@lists.sourceforge.net List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.sourceforge.net X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lersek@redhat.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 The non-iterating branch of CoreStall() rounds up the number of ticks if Remainder is nonzero. Explain in a comment why this is safe. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek --- MdeModulePkg/Core/Dxe/Misc/Stall.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/MdeModulePkg/Core/Dxe/Misc/Stall.c b/MdeModulePkg/Core/Dxe/Misc/Stall.c index 73e9078..aae54fd 100644 --- a/MdeModulePkg/Core/Dxe/Misc/Stall.c +++ b/MdeModulePkg/Core/Dxe/Misc/Stall.c @@ -97,17 +97,30 @@ CoreStall ( // Counter = DivU64x32Remainder ( MultU64x32 (Microseconds, 10), gMetronome->TickPeriod, &Remainder ); if (Remainder != 0) { // // If Remainder is not zero, then round Counter up by one tick. // + // This is safe, because the "worst case" (the largest quotient) emerges + // from the following values (largest numerator, smallest denominator): + // + // Microseconds == 0x1999_9999_9999_9999; therefore + // Numerator == 0xFFFF_FFFF_FFFF_FFFA, after multiplying by 0xA. + // + // Denominator == TickPeriod == 2 (with TickPeriod == 1, Remainder would + // be zero); therefore + // Quotient == 0x7FFF_FFFF_FFFF_FFFD, after division by 2. + // + // Hence the maximum pre-increment value of Counter is + // 0x7FFF_FFFF_FFFF_FFFD. + // Counter++; } CoreInternalWaitForTick (Counter); } return EFI_SUCCESS; }