From owner-svn-src-head@freebsd.org Mon Feb 11 05:58:41 2019 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2693D14EA08A; Mon, 11 Feb 2019 05:58:41 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: from mail-it1-f182.google.com (mail-it1-f182.google.com [209.85.166.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id A5A4085397; Mon, 11 Feb 2019 05:58:40 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: by mail-it1-f182.google.com with SMTP id i145so23396275ita.4; Sun, 10 Feb 2019 21:58:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:reply-to :from:date:message-id:subject:to:cc; bh=rMpZa7zg6gta2/tixdaYDkwyud1UPtZfU8CrDDVKvnI=; b=TII9ME87i9K3ZxMtjatfxLM1vofMvJpwy47h3nSCDF/ArZi8TaiWFcnxZKcbicKVUv bfo+ufg8nupzimS6j7ehb3D5qEspWPpFIV9xJaY3x6j5Qap+RBPc+GK4Vz4svLUwNl4H TBf6+9dc+ZIF67Kz6XR9s/ir2W7FkYo4PAQlaf1f5yAX7eh60U3+C2sn5wk7lZwwrO/6 2/BS0VV7CfDak4c1u8bodSMTqWX7+PgwJx2L6xcCsOnxKlz61D1cecFYOkQuBGy7InyV AH6DO4QDq7mV0CNpQNNHxAKkpVmwBJvYnBKhjn5A6hQeo2IlWmHiYn0OfUF4CH1f4GkK LGhg== X-Gm-Message-State: AHQUAuZOkn7ODQji5qLnRW6r9iMLUwl24Jmvv8juAOy+JcrCWBHffHtL furIIYz5MDsoCG4OiA/RNRh5XUY7 X-Google-Smtp-Source: AHgI3IZYLwSAik7k8E2UKpnNB0vocBsJRZE+s6Ym18xDAHyRTiNULs/874jS+ChPT3x9++//KppHtA== X-Received: by 2002:a6b:1604:: with SMTP id 4mr17201954iow.29.1549864713513; Sun, 10 Feb 2019 21:58:33 -0800 (PST) Received: from mail-it1-f176.google.com (mail-it1-f176.google.com. [209.85.166.176]) by smtp.gmail.com with ESMTPSA id 24sm3981940iog.25.2019.02.10.21.58.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Feb 2019 21:58:33 -0800 (PST) Received: by mail-it1-f176.google.com with SMTP id i145so23396233ita.4; Sun, 10 Feb 2019 21:58:33 -0800 (PST) X-Received: by 2002:a6b:ee16:: with SMTP id i22mr17525547ioh.124.1549864713209; Sun, 10 Feb 2019 21:58:33 -0800 (PST) MIME-Version: 1.0 References: <201902102307.x1AN7lj8011617@repo.freebsd.org> <20190211141730.Y1118@besplex.bde.org> In-Reply-To: <20190211141730.Y1118@besplex.bde.org> Reply-To: cem@freebsd.org From: Conrad Meyer Date: Sun, 10 Feb 2019 21:58:22 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: svn commit: r343985 - head/sys/kern To: Bruce Evans Cc: src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: A5A4085397 X-Spamd-Bar: ------ Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-6.97 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-0.998,0]; NEURAL_HAM_SHORT(-0.98)[-0.975,0]; REPLY(-4.00)[]; TAGGED_FROM(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Feb 2019 05:58:41 -0000 Hi Bruce, On Sun, Feb 10, 2019 at 9:18 PM Bruce Evans wrote: > > On Sun, 10 Feb 2019, Conrad Meyer wrote: > > > Log: > > Prevent overflow for usertime/systime in caclru1 > > > > PR: 76972 and duplicates > ... > I wrote a much better version, > following the hints in my review of PR 76972. Great. If your version is better (and correct), please go ahead and commit it. I noticed this bug had been languishing for over a decade with a reasonable patch attached; verified it was correct; and went ahead and committed it. If there's something even better, fantastic. > This is the slowest correct fix in the PR followup. kib predicted > that I wouldn't like it. It does 2 64-bit divmods (after optimization) > and many multiplications per call. Times 2 calls. clang will probably > inline this, giving only 3 64-bit divmods instead of 4. Did you measure any of this, or is this speculation? I plugged both versions into Godbolt just for amusement: https://godbolt.org/z/KE_FF8 (GCC 8.2), https://godbolt.org/z/WSepYg (Clang 7.0.0). Andrey's version has no branches; yours has two conditional branches as well as a large NOP to align the branch target (GCC); Clang manages only a single branch and doesn't pad the branch target. Andrey's version has five divs at gcc8.2 -O2, and six imuls. In the happy case, your version has two cmp+ja, two divs, and two imuls. In the unhappy case, your version has two cmp+ja, three div, and four imul. Just eyeballing it, your code might be marginally larger, but it's fairly similar. Does it matter? I doubt it. Modern CPUs are crazy superscalar OOO magic and as long as there aren't bad data dependencies, it can cruise along. All values reside in registers and imul isn't much slower than add. div is a bit slower, but probably cheaper than an L1 miss. Feel free to measure and demonstrate a difference if you feel it is important. I don't care, as long as it's correct (which it was not for the past 14 years). Conrad