From owner-freebsd-hackers@freebsd.org Fri Mar 1 07:39:19 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 337BC1511C81 for ; Fri, 1 Mar 2019 07:39:19 +0000 (UTC) (envelope-from marklmi@yahoo.com) Received: from sonic317-36.consmr.mail.ne1.yahoo.com (sonic317-36.consmr.mail.ne1.yahoo.com [66.163.184.47]) (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 508668EBBA for ; Fri, 1 Mar 2019 07:39:18 +0000 (UTC) (envelope-from marklmi@yahoo.com) X-YMail-OSG: GQvOgkcVM1nNAdUTGoEw1LalJgadNmUZXhiKmIkRvgZI7BkoUJoHv34lA0Up7xQ w3HYK.VTKqcOo29ou5xBJW0z_4qWucPaM7U25UJON6jbWkDTH.RKfBw_iOj6X6JPW.QprdNaSTnp v08Tjov1e2STDGCipg30jM4.CFAweMHN_Y9AuJzFHMUwPMKsOjw74i4I4N5zoT9Rg2xRNhimLtf2 EvLpC_.j9203EhmF3DnnxPYEwNSCUT7O17PyxfkYffNBoujEAYY5R.YV3wyCwDGsVgwv9jOrCFwi tmew_b5luMNiugXoc4ZVJnq1HENueQ9j2FhpcDENRVYBWLvmyHHpEbP67JNeuyZyEGFEfYfljGBF hSslaqfN7gvS.tl__16S3EFAutsk9i48voOX0KwHwGJd1TAkZQYyWhMWvjCFuFJufJqNNPEzYkFR HN9yYMvcfgojXPJjABinpt0.xIlr6V7Ug2Z6SweEAVtq_HQtU360hRMUzyWqgbFKUJ8dNlLj87VP FgR.lUjr.R.7lRzOBVkJKo.QWtjzY2kjIn8.uqf_jNAGetbTFYzuRCIOWz45PcEkwlfXHXMkerHP tvPwdWUK8dHp6HgqXiQkda6TfwUfOCL1R31dGcwINTaAKttO_2XtO.EsGTCIwDtmazxxtoNBbNKu 6qpQXE34VRVkifFz.14NaBpt11CFll4EWAStl8tQNZ6G3Hqj0Q58HEBvHO8AkmgpSw57KEAfmeST K6p_Hwa3qachQG0MJ8EjJLS60DoS0aSu2UXJ4R0PRDMiJQZUF8v3u0lFIZ72G6NmKHEomxtJ8iRP 12AS6LCoriLvt_nS4exRvVThWf0M4t1E7j.6LL05cp.ahYpa2qQLU_.p0yUVMvdKHEYaEXWj0XwE kbtLBJuXKwp1nXuWaX9MvRzO44MrROBw6W3G12nb458gnlB6qqtr8pEt4YXzxmdgVGw2XLu4nKxF zUBQ1wLeCMkgaIezR5LyYOySgP4yEyOaYNJ3KHfzhtohCdinwHrtZu5piDcKGDjJmEntx1Dh2Ame SxyZSkPV.9oGVORlwNeHzrzsG_wvQ0iFPUJUUPC40PwDjSLYOON91vi6xc2I3gWCcr0dgUw-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Fri, 1 Mar 2019 07:39:11 +0000 Received: from c-67-170-167-181.hsd1.or.comcast.net (EHLO [192.168.1.115]) ([67.170.167.181]) by smtp401.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID e0b5cb1f365c3e7b491adcee9e36fbab; Fri, 01 Mar 2019 07:39:08 +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 [patched failed] From: Mark Millard In-Reply-To: <962D78C3-65BE-40C1-BB50-A0088223C17B@yahoo.com> Date: Thu, 28 Feb 2019 23:39:06 -0800 Cc: freebsd-hackers Hackers , FreeBSD PowerPC ML Content-Transfer-Encoding: quoted-printable Message-Id: <28C2BB0A-3DAA-4D18-A317-49A8DD52778F@yahoo.com> References: <20190228145542.GT2420@kib.kiev.ua> <20190228150811.GU2420@kib.kiev.ua> <962D78C3-65BE-40C1-BB50-A0088223C17B@yahoo.com> To: Konstantin Belousov X-Mailer: Apple Mail (2.3445.102.3) X-Rspamd-Queue-Id: 508668EBBA X-Spamd-Bar: ++ X-Spamd-Result: default: False [2.99 / 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)[]; DKIM_TRACE(0.00)[yahoo.com:+]; MX_GOOD(-0.01)[cached: mta6.am0.yahoodns.net]; 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:36646, ipnet:66.163.184.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.97)[0.973,0]; MIME_GOOD(-0.10)[text/plain]; IP_SCORE(1.36)[ip: (4.52), ipnet: 66.163.184.0/21(1.30), asn: 36646(1.04), country: US(-0.07)]; NEURAL_SPAM_MEDIUM(0.53)[0.531,0]; TO_MATCH_ENVRCPT_SOME(0.00)[]; NEURAL_SPAM_LONG(0.64)[0.638,0]; RCVD_IN_DNSWL_NONE(0.00)[47.184.163.66.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: Fri, 01 Mar 2019 07:39:19 -0000 [The new, trial code also has truncation occurring.] On 2019-Feb-28, at 17:55, Mark Millard wrote: > [The PowerMac becomes non-responsive for significant periods of time.] >=20 > 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; >> + bt->sec +=3D x >> 32; >> + bintime_addx(bt, x << 32); >> + } >> + 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; >> + bt->sec +=3D x >> 32; >> + bintime_addx(bt, x << 32); >> + } >> + bintime_addx(bt, scale * delta); >> atomic_thread_fence_acq(); >> } while (gen =3D=3D 0 || gen !=3D th->th_generation); >> } >=20 > The PowerPC G5 ends up not responsive for long periods and > responsive for only very short periods, such as being able > to type in a few letters and have them show up at the time. >=20 > I've only barely started investigating what is going on > and I'll be rechecking my instrumented variant for stupid > mistakes and such. I"ll try your un-instrumented binuptime > as well. >=20 > As stands I'll be updating the kernel via booting a 2nd > disk that is not being experimented with. >=20 > My information gathering may not be very timely. >=20 Live experimenting and inspection has proved problematical. Below I experiment with the prior scale_factor and tim_diff figures from my oroginal code that recorded such, but showing some of what your new code does for them. (In part the below is text from the original list submittal to have a context.) Observed consistently for tc->tc_frequency: tc->tc_frequency =3D=3D 0x1fca055 (i.e., 33333333) ( tc->tc_counter_mask is 0xfffffffful as well. ) An example observation of diff_scaled having an overflowed value was: scale_factor =3D=3D 0x80da2067ac scale_factor*freq overflows unsigned, 64 bit representation. tim_offset =3D=3D 0x3da0eaeb tim_cnt =3D=3D 0x42dea3c4 tim_diff =3D=3D 0x53db8d9 For reference: 0x1fc9d43 =3D=3D = 0xffffffffffffffffull/scale_factor scaled_diff =3D=3D 0xA353A5BF3FF780CC (truncated to 64 bits) But for the new, trail code: 0x80da2067ac is 40 bits 0x53db8d9 is 27 bits So 67 bits, more than 63. Then: x =3D=3D (0x80da2067ac>>32) * 0x53db8d9 =3D=3D 0x80 * 0x53db8d9 =3D=3D 0x29EDC6C80 x>>32 =3D=3D 0x2 x<<32 =3D=3D 0x9EDC6C8000000000 (limited to 64 bits) Note the truncation of: 0x29EDC6C8000000000. Thus the "bintime_addx(bt, x << 32)" is still based on a truncated value. I'll not bother with the other two examples unless you want such. =3D=3D=3D Mark Millard marklmi at yahoo.com ( dsl-only.net went away in early 2018-Mar)