From owner-svn-src-all@freebsd.org Mon Nov 19 07:53:40 2018 Return-Path: Delivered-To: svn-src-all@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 1B5681137DFA for ; Mon, 19 Nov 2018 07:53:40 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: from mail-it1-x135.google.com (mail-it1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) (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 0D9B86A07D for ; Mon, 19 Nov 2018 07:53:39 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: by mail-it1-x135.google.com with SMTP id o19so6815545itg.5 for ; Sun, 18 Nov 2018 23:53:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=SRcFAQiEIPYSgeWigGLjI07QJmtsb6Cx4hSzo8mHQqs=; b=bdTTfiOtJLLfR80cqGx2Cq1t0gTdSW7VWzW1nHzP6JGuCgkhzvrs8Kl3xxlqx9+ZFA 3I8UeqkKBE5BOE2QEyQXSCu3OMQ2RVvVZKypR8p8GEKfPPl5tuMcvkf85l/kei+jO1/j PELcsx5UOfRuxS5jtjPrWznKekl14fYYELr64SWsw6V5YO7vN5LerLiUBswaVKjt2x00 HKaS9Z1oriEaUYwnfSgQl86XKj2X/voBzB5TtUshEhVGKZkzKMfYh+ZKRYXl+aDx4zxq pLTFF0eju1SqIlo2OWubKePzELvB8R0FjzFw7/A8W609OZnE2m4BO/oNrPUHxqtwmZ+G NYCg== 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:from:date :message-id:subject:to:cc; bh=SRcFAQiEIPYSgeWigGLjI07QJmtsb6Cx4hSzo8mHQqs=; b=ZmqMqFuKtHoDHKdxUwbLpJ+N+VC9wYmKfLnZJJ2G0rL9IDdbZqkXhjYXNZDDWnVbYm it5SoznPZES0h4784irEavZ/ESuFMBfzzCDo/kiJFhwUwqJpA2XEWhvov84219WObMWz FjK3oWovqxZuosZum+3oQRh4REyCntq2yTVOWkNta9h0OR28kWnbyJmypjUgQxc2ACOQ 00PGCQ8VqJ8e/K4V3RX6Oljl7X7C92Oytx9jzDFXqA18w8gCDVp4x4KLTjbFTVntyCFu BDEd9XAd0sWzcK9o2ReSWalBdwwg2Zuh18O4O74sgNP9Irsw+TaVMRfzktb1s+c80Cg1 +uHg== X-Gm-Message-State: AGRZ1gJuzSmIRcUY2flHTIhVfQp4y1/E8XOwblXDqPuSQsGVIMXDDxcF F8XYR7tETGXl8bNYzrpvNolAsmrANruJtfmq/Eif7A== X-Google-Smtp-Source: AJdET5deYEpRCnoH7aU/8qRDsAVwKdmx0mfeQ2NvrqU1QI6uheg3oMq3ARwIJ6gF/rSXjlQz6RJa+1uMNu+4l0NT2lY= X-Received: by 2002:a24:4fcb:: with SMTP id c194mr7234019itb.47.1542614018232; Sun, 18 Nov 2018 23:53:38 -0800 (PST) MIME-Version: 1.0 References: <201811190104.wAJ14CaE059062@pdx.rh.CN85.dnsmgr.net> <5e227743-6463-d395-f2ba-da8d4ba248ca@FreeBSD.org> In-Reply-To: <5e227743-6463-d395-f2ba-da8d4ba248ca@FreeBSD.org> From: Warner Losh Date: Mon, 19 Nov 2018 00:53:27 -0700 Message-ID: Subject: Re: svn commit: r340450 - head/sys/sys To: Andriy Gapon Cc: "Rodney W. Grimes" , Allan Jude , Warner Losh , src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org X-Rspamd-Queue-Id: 0D9B86A07D X-Spamd-Result: default: False [-4.27 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-0.99)[-0.992,0]; R_DKIM_ALLOW(-0.20)[bsdimp-com.20150623.gappssmtp.com]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; NEURAL_HAM_SHORT(-0.99)[-0.991,0]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; PREVIOUSLY_DELIVERED(0.00)[svn-src-all@freebsd.org]; DMARC_NA(0.00)[bsdimp.com]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[bsdimp-com.20150623.gappssmtp.com:+]; MX_GOOD(-0.01)[cached: ALT1.aspmx.l.google.com]; RCPT_COUNT_SEVEN(0.00)[7]; RCVD_IN_DNSWL_NONE(0.00)[5.3.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.4.6.8.4.0.b.8.f.7.0.6.2.list.dnswl.org : 127.0.5.0]; R_SPF_NA(0.00)[]; FORGED_SENDER(0.30)[imp@bsdimp.com,wlosh@bsdimp.com]; RCVD_TLS_LAST(0.00)[]; IP_SCORE(-2.28)[ip: (-7.05), ipnet: 2607:f8b0::/32(-2.53), asn: 15169(-1.71), country: US(-0.09)]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; FROM_NEQ_ENVFROM(0.00)[imp@bsdimp.com,wlosh@bsdimp.com]; RCVD_COUNT_TWO(0.00)[2] X-Rspamd-Server: mx1.freebsd.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Nov 2018 07:53:40 -0000 On Mon, Nov 19, 2018 at 12:31 AM Andriy Gapon wrote: > On 19/11/2018 03:38, Warner Losh wrote: > > I'll talk to Allan to see if he can test that. the bare 1 should be > handled > > properly because of C's promotion rules. 1ull << 32 is an unsigned long > long. > > What I really wanted was "~(uint32_t)0" but that construct has bit me in > the past. > > I think that you could just do (unsigned int)-1 or UINT_MAX. > Perhaps. > As a side note, I wonder if those functions are ever used on negative > values, > given the type of the argument, and if anyone checked their correctness in > that > case. > I don't think so, but an assert would be good to make sure. But I think I understand the problem now. mstosbt(1000) is overflowing with my change, but not without because we're adding 2^32 to a number that's ~900 away from overflowing changing a very large sleep of 1 second to a tiny sleep of 0 (which is 1ms at the default Hz). I think we get this in the mlx code because there's a msleep(1000) in at least one place. msleep(1001) would have failed before my change. Now I think msleep(999) works, but msleep(1000) fails. Since the code is waiting a second for hardware to initialize, a 1ms instead is likely to catch the hardware before it's finished. I think this will cause problems no matter cold or not, since it's all pause_sbt() under the covers and a delay of 0 is still 0 either way. The fix I think is something like: diff --git a/sys/sys/time.h b/sys/sys/time.h index 2207767813f2..00c6bb4a20fb 100644 --- a/sys/sys/time.h +++ b/sys/sys/time.h @@ -204,8 +204,12 @@ sbttoms(sbintime_t _sbt) static __inline sbintime_t mstosbt(int64_t _ms) { + sbintime_t sb; - return ((_ms * (((uint64_t)1 << 63) / 500) + (1ull << 32) - 1) >> 32); + sb = (_ms / 1000) * SBT_1S; + _ms = _ms % 1000; + sb += (_ms * (((uint64_t)1 << 42) / 1000) + 1023) >> 10; + return (sb); } /*- so we add the whole number of seconds first, then with the remainder we do the math so we have enough precision to represent 1000 correctly. This lets us then do the math with plenty of bits to spare. I need to reevaluate this in the morning when I'm not so tired. It might be safe to not do the whole seconds first, and I might need 11 bits instead of 10 to be safe, so I'll hold off committing until I can probe the edge cases more thoroughly. I thought long and hard about the tiny part of the edge case and never stopped to think about what 1000ms would do... Warner