From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753014AbbCJPBR (ORCPT ); Tue, 10 Mar 2015 11:01:17 -0400 Received: from omr2.cc.vt.edu ([198.82.141.100]:49365 "EHLO omr2.cc.vt.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751160AbbCJPBQ (ORCPT ); Tue, 10 Mar 2015 11:01:16 -0400 X-Mailer: exmh version 2.8.0 04/21/2012 with nmh-1.6+dev To: Yann Droneaud Cc: Matthias Bonne , kernelnewbies@kernelnewbies.org, linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar Subject: Re: Question on mutex code In-Reply-To: Your message of "Tue, 10 Mar 2015 14:03:59 +0100." <1425992639.3991.11.camel@opteya.com> From: Valdis.Kletnieks@vt.edu References: <54F64E10.7050801@gmail.com> <1425992639.3991.11.camel@opteya.com> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==_Exmh_1425999557_2160P"; micalg=pgp-sha1; protocol="application/pgp-signature" Content-Transfer-Encoding: 7bit Date: Tue, 10 Mar 2015 10:59:17 -0400 Message-ID: <65060.1425999557@turing-police.cc.vt.edu> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --==_Exmh_1425999557_2160P Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable On Tue, 10 Mar 2015 14:03:59 +0100, Yann Droneaud said: > > Consider the following sequence of events: > >=20 > > 0. Suppose a mutex is locked by task A and has no waiters. > >=20 > > 1. Task B calls mutex_trylock(). > >=20 > > 2. mutex_trylock() calls the architecture-specific > > __mutex_fastpath_trylock(), with __mutex_trylock_slowpath() as > > fail_fn. > >=20 > > 3. According to the description of __mutex_fastpath_trylock() (for > > example in include/asm-generic/mutex-dec.h), =22if the architectu= re > > has no effective trylock variant, it should call the fail_fn > > spinlock-based trylock variant unconditionally=22. So > > __mutex_fastpath_trylock() may now call __mutex_trylock_slowpath(= ). > >=20 > > 4. Task A releases the mutex. > >=20 > > 5. Task B, in __mutex_trylock_slowpath, executes: > >=20 > > /* No need to trylock if the mutex is locked. */ > > if (mutex_is_locked(lock)) > > return 0; > >=20 > > Since the mutex is no longer locked, the function continues. > >=20 > > 6. Task C, which runs on a different cpu than task B, locks the mutex= > > again. > >=20 > > 7. Task B, in __mutex_trylock_slowpath(), continues: > >=20 > > spin_lock_mutex(&lock->wait_lock, flags); B will spin here until C releases the lock. When that spin exits, C no longer holds the lock. Re-do the analysis from this point. --==_Exmh_1425999557_2160P Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Exmh version 2.5 07/13/2001 iQIVAwUBVP8GxQdmEQWDXROgAQLf1g//bZSv3D+R13RJBnDC+gSKBsmB8RxBpF5N QkSMBDaXlkA11EmI3FPY9CmUBilnEbjtrN/5BDl4qoTq4Kri6zkKsbJKQl53CQkO nVArQo5PQYjEp2KfR93rjr/ABHc2S3qAr5sTD2S4lpwYKPxy5RP3Ip7hx+nE2y94 8wXRfluqcaKs8LyyhTQe5l8Yqn3bDYXXXxRgJtnvYiXRLZkdpHHXIhjBTmCm+yyR 1lg0cDxu0lR9L9lXjDS0NEvLORZEGGhDIuSR8FCtbbxxoF8CpmbOb0HSqBB6BZcC xyeVLR8VR668DF90yEbAvL2c7+nAZHx9ZZ4Re2xI+XFw4inKjSmWvv/wX9/12aqA JiVYMMwR0ZH7QSpzUsfTG/NggDs/3mjV76p1PDx7udLvx672YhP7v6Wp6y/jtehF FrL3QEGUOnrkCafGlalrLl73NbJL4oSg+a9npmOUo1NXGXcx1wOMPHqZsM24ITvU JURL750CQPJj9ISK6Qtx3LbMRazn950772y+jxA21T7ZTQLYaSgJwZxuPPxocf+u KuKiWsNxtWatLOEYAfFARi1lxbQSqk9MPydcpSJ+W+ug+mvXOs522vHWdK2lH68k N/8dlBsPuS59jujnw6erAsxxMy9Hs1Fhs00Aff/8tFVhz5l4ixnloiQk5/z1mcPT RBsEjVPQ0mo= =2n47 -----END PGP SIGNATURE----- --==_Exmh_1425999557_2160P--