From owner-freebsd-hackers@freebsd.org Thu Feb 28 21:50:57 2019 Return-Path: Delivered-To: freebsd-hackers@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 6ADFB151AA91 for ; Thu, 28 Feb 2019 21:50:57 +0000 (UTC) (envelope-from marklmi@yahoo.com) Received: from sonic301-4.consmr.mail.bf2.yahoo.com (sonic301-4.consmr.mail.bf2.yahoo.com [74.6.129.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 663D68B15E for ; Thu, 28 Feb 2019 21:50:56 +0000 (UTC) (envelope-from marklmi@yahoo.com) X-YMail-OSG: YhBD9cQVM1m4p0osGu5oRLz1yqBtp_MDtFkIOTKUx5klwK3bPHLl4H.zMWngptV d3xFpCSg0S9i9cCDPFn8LLRv7oJDwki2J26NnIib4B0QUYkqyGORM8sLN.0GK9m11gmOrBvqceo7 YUJpjgW3r1kYSem_nEL1NwjRGZy1wBZST9SQ5l3FfEGRQxWN21dHcgNWmJBdUyoG74bCh.ER791N sv9uDLiAJeKPWAG95TJAzZSj5gxfyIaSG1EOTBB5svjZNsgc1AMNnLttwCEFnejqW2V0Iilih6jS YX6fZhYVkSBg9TMV_VLS2lWHgnmR2dLLG04ob789ByPaTTfDsvIIi3kD8vzNZ2vlXE25c1IK7Ew8 MBrwcvIAjmnbu44eu3UGpM4xoL2DeqMxTcRij6rRWPOtzrDpydN6S9XAF5peVwqaUVRDscZ5KSM1 ZLAhxycppl1Qjp09jXcTxmWvNZXjQ2Gfs_RzNg58uymtNekTsWYZqxBeWd0ptUsGq43.NzIZ3zOZ 2GDg3QX3T4.8Ygzwdn0d.QL1VcdRxspa3q9vwATEC6EhA61s420YTlz1JcXhTpePJd9GghsY2mvR 413oSFjZ22MZJ7tG8lBfj0Iqbo4cHYtgEXnTnw97o6gdG2zoOa5GeVn8mRNOunqtqr01UxKZT0uV iwU6qbKt2TfGTgUXXStBH9CRxs0RwyAwsUeIdiMAR2lBOGoisDcWI6q170rM1db94HIVQfvPkC7W OB3xsYDwWgMA.lqvxpVbsFHn8yHe9eyf0K0CeUS3elqCojsY9PCUNCPtP1TXwgBakPJmPBa7UDvV epDrCHwV1xrbadA3F_daZVaZ1nCX6hz74Cs8L_rV.Y3EZBbTQ_0S4pUKngv8lMvI5mZgXYnU5o2k ILgHfM264VpkgUPWW.Lnf3Eb6uMJfBHHa1.dFKZxlmwmhhGhFmNQz_5YWBBjkzgCuDfY7Gx.Awik kSWZ00d1vHH5njMr6g2jcnBgUAWSoiFnjnTBup448bXvM2pwnAFcPLPEaeXPUxq94_ZYvzTHr.kb t79WIta2BoK2wBok_PdsYtKw6RYxXkZhn8lgV0P7i_uN3dM3m Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.bf2.yahoo.com with HTTP; Thu, 28 Feb 2019 21:50:55 +0000 Received: from c-67-170-167-181.hsd1.or.comcast.net (EHLO [192.168.1.113]) ([67.170.167.181]) by smtp426.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 3349b256950a530d4ab78852d54d1707; Thu, 28 Feb 2019 21:50:51 +0000 (UTC) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 12.2 \(3445.102.3\)) Subject: Re: powerpc64 head -r344018 stuck sleeping problems: th->th_scale * tc_delta(th) overflows unsigned 64 bits sometimes From: Mark Millard In-Reply-To: <0A345E1F-7675-4B4B-8A74-ACD59E90E72F@yahoo.com> Date: Thu, 28 Feb 2019 13:50:49 -0800 Cc: freebsd-hackers Hackers , FreeBSD PowerPC ML Content-Transfer-Encoding: quoted-printable Message-Id: References: <20190228145542.GT2420@kib.kiev.ua> <20190228150811.GU2420@kib.kiev.ua> <0A345E1F-7675-4B4B-8A74-ACD59E90E72F@yahoo.com> To: Konstantin Belousov X-Mailer: Apple Mail (2.3445.102.3) X-Rspamd-Queue-Id: 663D68B15E X-Spamd-Bar: +++ X-Spamd-Result: default: False [3.00 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_SPF_ALLOW(-0.20)[+ptr:yahoo.com]; MV_CASE(0.50)[]; FREEMAIL_FROM(0.00)[yahoo.com]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_ALL(0.00)[]; MX_GOOD(-0.01)[cached: mta6.am0.yahoodns.net]; DKIM_TRACE(0.00)[yahoo.com:+]; DMARC_POLICY_ALLOW(-0.50)[yahoo.com,reject]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVFROM(0.00)[yahoo.com]; ASN(0.00)[asn:26101, ipnet:74.6.128.0/21, country:US]; MID_RHS_MATCH_FROM(0.00)[]; DWL_DNSWL_NONE(0.00)[yahoo.com.dwl.dnswl.org : 127.0.5.0]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[yahoo.com:s=s2048]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; NEURAL_SPAM_SHORT(0.99)[0.993,0]; MIME_GOOD(-0.10)[text/plain]; IP_SCORE(1.36)[ip: (4.13), ipnet: 74.6.128.0/21(1.53), asn: 26101(1.22), country: US(-0.07)]; NEURAL_SPAM_MEDIUM(0.54)[0.540,0]; TO_MATCH_ENVRCPT_SOME(0.00)[]; NEURAL_SPAM_LONG(0.62)[0.619,0]; RCVD_IN_DNSWL_NONE(0.00)[43.129.6.74.list.dnswl.org : 127.0.5.0] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Feb 2019 21:50:57 -0000 [I left implicit that I was summarizing for x!=3D0.] On 2019-Feb-28, at 13:46, Mark Millard wrote: > On 2019-Feb-28, at 07:08, Konstantin Belousov = wrote: >=20 >> On Thu, Feb 28, 2019 at 04:55:42PM +0200, Konstantin Belousov wrote: >>> On Thu, Feb 28, 2019 at 05:06:23AM -0800, Mark Millard via = freebsd-ppc wrote: >>>> . . . >>>=20 >>> . . . >>=20 >> Of course I botched the formula, please try this instead: >>=20 >> diff --git a/sys/kern/kern_tc.c b/sys/kern/kern_tc.c >> index 2656fb4d22f..fdd4f4f6a52 100644 >> --- a/sys/kern/kern_tc.c >> +++ b/sys/kern/kern_tc.c >> @@ -355,13 +355,22 @@ void >> binuptime(struct bintime *bt) >> { >> struct timehands *th; >> - u_int gen; >> + uint64_t scale, x; >> + u_int delta, gen; >>=20 >> do { >> th =3D timehands; >> gen =3D atomic_load_acq_int(&th->th_generation); >> *bt =3D th->th_offset; >> - bintime_addx(bt, th->th_scale * tc_delta(th)); >> + scale =3D th->th_scale; >> + delta =3D tc_delta(th); >> + if (fls(scale) + fls(delta) > 63) { >> + x =3D (scale >> 32) * delta; >> + scale &=3D UINT_MAX; >=20 > The following two lines confuse me overall: >=20 >> + bt->sec +=3D x >> 32; >> + bintime_addx(bt, x << 32); >=20 > bintime_addx does: >=20 > static __inline void > bintime_addx(struct bintime *_bt, uint64_t _x) > { > uint64_t _u; >=20 > _u =3D _bt->frac; > _bt->frac +=3D _x; > if (_u > _bt->frac) > _bt->sec++; > } >=20 > So I'd expect: I forgot to indicate the context: when x!-0 > bintime_addx(bt, x << 32) >=20 > to find _u > _bt->frac and to also do _bt->sec++ . > So overall (as a means of summarizing for > bt->sec): >=20 > bt->sec +=3D (x >> 32) + 1; >=20 > Is that the intent? >=20 >=20 >> + } >> + bintime_addx(bt, scale * delta); >> atomic_thread_fence_acq(); >> } while (gen =3D=3D 0 || gen !=3D th->th_generation); >> } >> @@ -388,13 +397,22 @@ void >> bintime(struct bintime *bt) >> { >> struct timehands *th; >> - u_int gen; >> + uint64_t scale, x; >> + u_int delta, gen; >>=20 >> do { >> th =3D timehands; >> gen =3D atomic_load_acq_int(&th->th_generation); >> *bt =3D th->th_bintime; >> - bintime_addx(bt, th->th_scale * tc_delta(th)); >> + scale =3D th->th_scale; >> + delta =3D tc_delta(th); >> + if (fls(scale) + fls(delta) > 63) { >> + x =3D (scale >> 32) * delta; >> + scale &=3D UINT_MAX; >=20 > The same for the below two lines: >=20 >> + bt->sec +=3D x >> 32; >> + bintime_addx(bt, x << 32); >=20 >=20 >> + } >> + bintime_addx(bt, scale * delta); >> atomic_thread_fence_acq(); >> } while (gen =3D=3D 0 || gen !=3D th->th_generation); >> } >=20 =3D=3D=3D Mark Millard marklmi at yahoo.com ( dsl-only.net went away in early 2018-Mar)