From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752435AbbKKJkP (ORCPT ); Wed, 11 Nov 2015 04:40:15 -0500 Received: from mail-ob0-f195.google.com ([209.85.214.195]:34957 "EHLO mail-ob0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752254AbbKKJkJ (ORCPT ); Wed, 11 Nov 2015 04:40:09 -0500 Date: Wed, 11 Nov 2015 17:39:40 +0800 From: Boqun Feng To: Oleg Nesterov Cc: Peter Zijlstra , mingo@kernel.org, linux-kernel@vger.kernel.org, paulmck@linux.vnet.ibm.com, corbet@lwn.net, mhocko@kernel.org, dhowells@redhat.com, torvalds@linux-foundation.org, will.deacon@arm.com Subject: Re: [PATCH 4/4] locking: Introduce smp_cond_acquire() Message-ID: <20151111093939.GA6314@fixme-laptop.cn.ibm.com> References: <20151102132901.157178466@infradead.org> <20151102134941.005198372@infradead.org> <20151103175958.GA4800@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="ZPt4rx8FFjLCG7dd" Content-Disposition: inline In-Reply-To: <20151103175958.GA4800@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --ZPt4rx8FFjLCG7dd Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi Oleg, On Tue, Nov 03, 2015 at 06:59:58PM +0100, Oleg Nesterov wrote: [snip] >=20 > Unfortunately this doesn't look exactly right... >=20 > spin_unlock_wait() is not equal to "while (locked) relax", the latter > is live-lockable or at least sub-optimal: we do not really need to spin Just be curious, should spin_unlock_wait() semantically be an ACQUIRE? Because spin_unlock_wait() is used for us to wait for a certain lock to RELEASE so that we can do something *after* we observe the RELEASE. Considering the follow example: CPU 0 CPU 1 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D { X =3D 0 } WRITE_ONCE(X, 1); spin_unlock(&lock); spin_unlock_wait(&lock) r1 =3D READ_ONCE(X); If spin_unlock_wait() is not an ACQUIRE, r1 can be 0 in this case, right? Am I missing something subtle here? Or spin_unlock_wait() itself doesn't have the ACQUIRE semantics, but it should always come with a smp_mb() *following* it to achieve the ACQUIRE semantics? However in do_exit(), an smp_mb() is preceding raw_spin_unlock_wait() rather than following, which makes me confused... could you explain that? Thank you ;-) Regards, Boqun > until we observe !spin_is_locked(), we only need to synchronize with the > current owner of this lock. Once it drops the lock we can proceed, we > do not care if another thread takes the same lock right after that. >=20 > Oleg. >=20 --ZPt4rx8FFjLCG7dd Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAABCAAGBQJWQwzYAAoJEEl56MO1B/q4P9QH/02f28DoxeyCJQqBBhqpdRMN OhZYC+lvWRzbnHGgIV7l+KbiXa6UjWioyUSzh7Mw5sfokWUrDI7clFigDTqxM6BX K8SirKvmcmWS7hfsEgAGYYifafQVpMZweMwBIaVV+opxY6PTLWJoyYMpIrPgQBfq g7065+aw8r2vpKrTFO31Sb84MT5qK3TqAe6W6dEKA/zAuKgCjuIagMIGV0laUbzx x9tIEf63QNqq0t6zDsgzPTUG4OoenFj+jGXNSKbwb1RLMeqLdZX+MICbIlNZlYNv E6R57yihuspibz5pJYS4bCCfvjXvRkHRUQqIsZ+r954SamIX1tIqPZQQ5B2gyg0= =LAGj -----END PGP SIGNATURE----- --ZPt4rx8FFjLCG7dd--