From owner-svn-src-head@freebsd.org Wed Jul 31 02:19:08 2019 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 8E79DB2B73; Wed, 31 Jul 2019 02:19:08 +0000 (UTC) (envelope-from bdrewery@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2610:1c1:1:6074::16:84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 634EB8A44B; Wed, 31 Jul 2019 02:19:08 +0000 (UTC) (envelope-from bdrewery@FreeBSD.org) Received: from mail.xzibition.com (unknown [127.0.1.132]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by freefall.freebsd.org (Postfix) with ESMTPS id 2B26043A; Wed, 31 Jul 2019 02:19:08 +0000 (UTC) (envelope-from bdrewery@FreeBSD.org) Received: from mail.xzibition.com (localhost [172.31.3.2]) by mail.xzibition.com (Postfix) with ESMTP id 25B06128CF; Wed, 31 Jul 2019 02:19:07 +0000 (UTC) X-Virus-Scanned: amavisd-new at mail.xzibition.com Received: from mail.xzibition.com ([172.31.3.2]) by mail.xzibition.com (mail.xzibition.com [172.31.3.2]) (amavisd-new, port 10026) with LMTP id dMY8iwK2Jd19; Wed, 31 Jul 2019 02:18:58 +0000 (UTC) Subject: Re: svn commit: r350005 - head/sys/kern DKIM-Filter: OpenDKIM Filter v2.10.3 mail.xzibition.com CD597128C6 To: Konstantin Belousov Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org References: <201907151918.x6FJIPFo077975@repo.freebsd.org> <20190730231256.GL2731@kib.kiev.ua> <20190730232714.GM2731@kib.kiev.ua> From: Bryan Drewery Openpgp: id=F9173CB2C3AAEA7A5C8A1F0935D771BB6E4697CF; url=https://zx.xk42.net/bryan.asc Autocrypt: addr=bdrewery@FreeBSD.org; prefer-encrypt=mutual; keydata= mQENBFJphmsBCADiFgmS4bIzwZijrS31SjEMzg+n5zNellgM+HkShwehpqCiyhXdWrvH6dTZ a6u50pbUIX7doTR7W7PQHCjCTqtpwvcj0eulZva+iHFp+XrbgSFHn+VVXgkYP2MFySyZRFab D2qqzJBEJofhpv4HvY6uQI5K99pMqKr1Z/lHqsijYYu4RH2OfwB5PinId7xeldzWEonVoCr+ rfxzO/UrgA6v/3layGZcKNHFjmc3NqoN1DXtdaEHqtjIozzbndVkH6lkFvIpIrI6i5ox8pwp VxsxLCr/4Musd5CWgHiet5kSw2SzNeA8FbxdLYCpXNVu+uBACEbCUP+CSNy3NVfEUxsBABEB AAG0JEJyeWFuIERyZXdlcnkgPGJkcmV3ZXJ5QEZyZWVCU0Qub3JnPokBVwQTAQoAQQIbAwUL CQgHAwUVCgkICwUWAwIBAAIeAQIXgAIZARYhBPkXPLLDqup6XIofCTXXcbtuRpfPBQJb5hLu BQkNPvODAAoJEDXXcbtuRpfP9rMH/3f7cfX5rzyEV5QNfV/wS4jFukLoPZ4+nCM/TKxH3pEX 2bLbeQbkk6La8cueQ5Lpoht5XFZ18Y5TbMittngltrlNzoDD0h9are24OkDFGim3afJU7tkj IGQa1if+re+vI5BhzYwRhj0oKXzBi39M5oePd3L1dXfx83rg2FPyZBdIejsz6fR74T3JVkbd 6k2l5/3Zk2uiNMy+eBfDRgYE1E6CP28kV0nCeGKZgSVso0kGUUHud7voKqGVpMvbd0mE4pp4 PE5YJaFPjrll9miaDAvdU8LGIq5n6+aXPLKoQ/QNl6mg6ifgI6FfKILOkTizLW8E5PBSNnCm NapQ55yjm125AQ0EUmmGawEIAKJUU9+Q19oW1RK5jTf3m56j+szIc8Y9DaLC8REUKl4UZJBK BqCl6c0cukVApOD92XoU6hJPm2rLEyp/IcYcPPNTnVu8D8h9oag2L8EiFN7+2hk0xG+lwjc8 uOIZycme7AIJsBU4AZ1v63lxm2k104hwpiatgbe71GIGl7p1MX6ousP/wGzXCOF25Dx9w02C eRe7zEMfhnFjSUhzdCC9han2+KaVB7qIqNR3b8NfbwRNlwPmHqlhXffUow9OsQjSnTK8WKNR lx7xzVccXIvWP2wECFrmqmzMmXpSrmIuiWEpFwZ9x2a0Pva8dCNRiCVTK51IlRXKjaAxiN1u IUrMm6UAEQEAAYkBPAQYAQoAJgIbDBYhBPkXPLLDqup6XIofCTXXcbtuRpfPBQJb5hL4BQkN PvONAAoJEDXXcbtuRpfPCjcH/ivBsOpdpebpgLizSNU5/X4yWN5Aixsc9VBnQhGKAKnMINJQ VMpA55sD2JSPwloXYM/B3qyPJRS/9cwIuX5LDNKKOZU3Qp+TzleynM15/xea14orWYRGRict YHBM3Cnqp7OD8K6Q1uhs0fTxyJP7PZ/G0+7Corlf1DlHhDt6C2HldRPFvAvAgl6sR9Wzgcb7 rzub2HVtbJgl6YHbgyAG7x9NpXFqzx1JLAMdpt2DIYwoi+oMdRQlBIwNuKjQjCGzuXHandd3 kGvBAsyJpQ+coEep9UzwANaV28cXrFr2R4FSOcR50rBA2Nh/vqUYfpsvBvJlwuKAoV1djVHa ihNeL5E= Organization: FreeBSD Message-ID: <47623274-f1be-7134-2f29-4941776df39f@FreeBSD.org> Date: Tue, 30 Jul 2019 19:18:56 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190730232714.GM2731@kib.kiev.ua> Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="8uyUCaTumRMJ4zEOnwjMI9AZI8qMzKRIp" X-Rspamd-Queue-Id: 634EB8A44B X-Spamd-Bar: ------ Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-6.96 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.96)[-0.964,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; REPLY(-4.00)[] 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: Wed, 31 Jul 2019 02:19:08 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --8uyUCaTumRMJ4zEOnwjMI9AZI8qMzKRIp Content-Type: multipart/mixed; boundary="H026HVpn5qTcefLIsmZMlKeUwrSTao0fy"; protected-headers="v1" From: Bryan Drewery To: Konstantin Belousov Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Message-ID: <47623274-f1be-7134-2f29-4941776df39f@FreeBSD.org> Subject: Re: svn commit: r350005 - head/sys/kern References: <201907151918.x6FJIPFo077975@repo.freebsd.org> <20190730231256.GL2731@kib.kiev.ua> <20190730232714.GM2731@kib.kiev.ua> In-Reply-To: <20190730232714.GM2731@kib.kiev.ua> --H026HVpn5qTcefLIsmZMlKeUwrSTao0fy Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 7/30/2019 4:27 PM, Konstantin Belousov wrote: > On Wed, Jul 31, 2019 at 02:13:02AM +0300, Konstantin Belousov wrote: >> On Tue, Jul 30, 2019 at 03:04:57PM -0700, Bryan Drewery wrote: >>> On 7/15/2019 12:18 PM, Konstantin Belousov wrote: >>>> Author: kib >>>> Date: Mon Jul 15 19:18:25 2019 >>>> New Revision: 350005 >>>> URL: https://svnweb.freebsd.org/changeset/base/350005 >>>> >>>> Log: >>>> In do_sem2_wait(), balance umtx_key_get() with umtx_key_release() = on retry. >>>> =20 >>> >>> Is this also needed in do_sem_wait()? A similar pattern seems to be t= here. >> No, I do not think do_sem_wait() has similar issue, because the again = label >> does not re-get the key. >> >>> >>> I ask because of what I referenced on IRC. I have some processes stuc= k >>> in here from a 10.4 jail. >>> >>>> ~/git/poudriere # procstat -kk 1498 >>>> PID TID COMM TDNAME KSTACK >>>> 1498 100710 python2.7 - mi_switch+0x174= sleepq_switch+0x110 sleepq_catch_signals+0x417 sleepq_wait_sig+0xf _slee= p+0x2d0 umtxq_sleep+0x153 do_sem_wait+0x42c __umtx_op_sem_wait+0x6e amd64= _syscall+0x2bb fast_syscall_common+0x101 >>>> 1498 101575 python2.7 - mi_switch+0x174= sleepq_switch+0x110 sleepq_catch_signals+0x417 sleepq_wait_sig+0xf _slee= p+0x2d0 umtxq_sleep+0x153 do_sem_wait+0x42c __umtx_op_sem_wait+0x6e amd64= _syscall+0x2bb fast_syscall_common+0x101 >>>> 1498 101657 python2.7 - >>> ... >>>> ~/git/poudriere # procstat -kk 1498 >>>> PID TID COMM TDNAME KSTACK >>>> 1498 100710 python2.7 - mi_switch+0x174= sleepq_switch+0x110 sleepq_catch_signals+0x417 sleepq_wait_sig+0xf _slee= p+0x2d0 umtxq_sleep+0x153 do_sem_wait+0x42c __umtx_op_sem_wait+0x6e amd64= _syscall+0x2bb fast_syscall_common+0x101 >>>> 1498 101575 python2.7 - mi_switch+0x174= sleepq_switch+0x110 sleepq_catch_signals+0x417 sleepq_wait_sig+0xf _slee= p+0x2d0 umtxq_sleep+0x153 do_sem_wait+0x42c __umtx_op_sem_wait+0x6e amd64= _syscall+0x2bb fast_syscall_common+0x101 >>>> 1498 101657 python2.7 - do_sem_wait+0x1= b6 __umtx_op_sem_wait+0x6e amd64_syscall+0x2bb fast_syscall_common+0x101 >>> ... >>>> ~/git/poudriere # procstat -kk 94392 >>>> PID TID COMM TDNAME KSTACK >>>> 94392 101815 python2.7 - mi_switch+0x174= sleepq_switch+0x110 sleepq_catch_signals+0x417 sleepq_wait_sig+0xf _slee= p+0x2d0 umtxq_sleep+0x153 do_sem_wait+0x42c __umtx_op_sem_wait+0x6e amd64= _syscall+0x2bb fast_syscall_common+0x101 >>>> 94392 101816 python2.7 - __mtx_lock_slee= p+0x118 __mtx_lock_flags+0x102 _sleep+0x334 umtxq_busy+0xb7 do_sem_wait+0= x161 __umtx_op_sem_wait+0x6e amd64_syscall+0x2bb fast_syscall_common+0x10= 1 >>>> 94392 102076 python2.7 - __mtx_lock_flag= s+0x94 do_sem_wait+0x228 __umtx_op_sem_wait+0x6e amd64_syscall+0x2bb fast= _syscall_common+0x101 >> >> Try this. We should only retry casueword if it failed spuriously. >> >> diff --git a/sys/kern/kern_umtx.c b/sys/kern/kern_umtx.c >> index bb998457975..6c914ab6f3e 100644 >> --- a/sys/kern/kern_umtx.c >> +++ b/sys/kern/kern_umtx.c >> @@ -3229,7 +3229,8 @@ do_sem_wait(struct thread *td, struct _usem *sem= , struct _umtx_time *timeout) >> rv =3D casueword32(&sem->_has_waiters, 0, &count1, 1); >> if (rv =3D=3D 0) >> rv1 =3D fueword32(&sem->_count, &count); >> - if (rv =3D=3D -1 || (rv =3D=3D 0 && (rv1 =3D=3D -1 || count !=3D 0))= || rv =3D=3D 1) { >> + if (rv =3D=3D -1 || (rv =3D=3D 0 && (rv1 =3D=3D -1 || count !=3D 0))= || >> + (rv =3D=3D 1 && count1 =3D=3D 0)) { >> umtxq_lock(&uq->uq_key); >> umtxq_unbusy(&uq->uq_key); >> umtxq_remove(uq); >=20 > I think there is another problem, since even despite our intent of loop= ing > just because of casueword returned 1, the umtxq_check_susp() should hav= e > terminated the loop. I believe the following update would fix that. >=20 > If you have time, can you please apply only the umtxq_check_susp() chun= k > and see if it helps as well ? [Both chunks are needed for correctness, = but > the umtxq_check_susp() is almost impossible to test in combination] What is the expected "working" test for the umtxq_check_susp() change? I get the 100% CPU and kill -9 does not kill it. > ~ # procstat -kk 19150 > PID TID COMM TDNAME KSTACK > 19150 101524 python2.7 - do_sem_wait+0x150 = __umtx_op_sem_wait+0x6e amd64_syscall+0x2bb fast_syscall_common+0x101 > 19150 101553 python2.7 - mi_switch+0x174 sl= eepq_switch+0x110 sleepq_catch_signals+0x417 sleepq_wait_sig+0xf _sleep+0= x2d0 umtxq_sleep+0x153 do_sem_wait+0x41c __umtx_op_sem_wait+0x6e amd64_sy= scall+0x2bb fast_syscall_common+0x101 > 19150 101554 python2.7 - __mtx_lock_sleep+0= x118 __mtx_lock_flags+0x102 _sleep+0x334 umtxq_busy+0xb7 do_sem_wait+0x15= 0 __umtx_op_sem_wait+0x6e amd64_syscall+0x2bb fast_syscall_common+0x101 >=20 > diff --git a/sys/kern/kern_umtx.c b/sys/kern/kern_umtx.c > index bb998457975..08bdd1a1a9a 100644 > --- a/sys/kern/kern_umtx.c > +++ b/sys/kern/kern_umtx.c > @@ -723,13 +723,11 @@ umtxq_check_susp(struct thread *td, bool sleep) > error =3D 0; > p =3D td->td_proc; > PROC_LOCK(p); > - if (P_SHOULDSTOP(p) || > - ((p->p_flag & P_TRACED) && (td->td_dbgflags & TDB_SUSPEND))) { > - if (p->p_flag & P_SINGLE_EXIT) > - error =3D EINTR; > - else > - error =3D sleep ? thread_suspend_check(0) : ERESTART; > - } > + if (p->p_flag & P_SINGLE_EXIT) > + error =3D EINTR; > + else if (P_SHOULDSTOP(p) || > + ((p->p_flag & P_TRACED) && (td->td_dbgflags & TDB_SUSPEND))) > + error =3D sleep ? thread_suspend_check(0) : ERESTART; > PROC_UNLOCK(p); > return (error); > } > @@ -3229,7 +3227,8 @@ do_sem_wait(struct thread *td, struct _usem *sem,= struct _umtx_time *timeout) > rv =3D casueword32(&sem->_has_waiters, 0, &count1, 1); > if (rv =3D=3D 0) > rv1 =3D fueword32(&sem->_count, &count); > - if (rv =3D=3D -1 || (rv =3D=3D 0 && (rv1 =3D=3D -1 || count !=3D 0)) = || rv =3D=3D 1) { > + if (rv =3D=3D -1 || (rv =3D=3D 0 && (rv1 =3D=3D -1 || count !=3D 0)) = || > + (rv =3D=3D 1 && count1 =3D=3D 0)) { > umtxq_lock(&uq->uq_key); > umtxq_unbusy(&uq->uq_key); > umtxq_remove(uq); >=20 --=20 Regards, Bryan Drewery --H026HVpn5qTcefLIsmZMlKeUwrSTao0fy-- --8uyUCaTumRMJ4zEOnwjMI9AZI8qMzKRIp Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQGTBAEBCgB9FiEE+Rc8ssOq6npcih8JNddxu25Gl88FAl1A+pFfFIAAAAAALgAo aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldEY5 MTczQ0IyQzNBQUVBN0E1QzhBMUYwOTM1RDc3MUJCNkU0Njk3Q0YACgkQNddxu25G l89ouwgAj8TT0zduz0lz1I388JEkfuITnm0qhBwXdNQGAixRzLCLn61GJtFgXnDC j/7MBqC23he6mS+hx1XnzCV+6fLfQlG4Tyr1Ae3ywfTYF5aB4t4xZzXi0bHlMmeQ aaVU0cY5Q7MmIe65JPQY8uZw+Jg2b8kYxMYTGZwtRYFcbyo5Ql7mxZIPTt+dkPVp d5+bmMf0HYoqcF9f4rrFLfLoD5FeN9vw2/87st+rf3A2JZu2bOMJRa8SvChh/ydC NjaO1RLoHQ01/fJDO6kZaUiMNDGC/ZiaZ66ilI3lJwyUYhoquth3XyXzRJtiF0Hw bCzc35dBAJYiNnllMzYRXZPfOMzqHA== =btpK -----END PGP SIGNATURE----- --8uyUCaTumRMJ4zEOnwjMI9AZI8qMzKRIp--