From: Valdis.Kletnieks@vt.edu
To: Yann Droneaud <ydroneaud@opteya.com>
Cc: Matthias Bonne <lemonlime51@gmail.com>,
kernelnewbies@kernelnewbies.org, linux-kernel@vger.kernel.org,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>
Subject: Re: Question on mutex code
Date: Tue, 10 Mar 2015 10:59:17 -0400 [thread overview]
Message-ID: <65060.1425999557@turing-police.cc.vt.edu> (raw)
In-Reply-To: Your message of "Tue, 10 Mar 2015 14:03:59 +0100." <1425992639.3991.11.camel@opteya.com>
[-- Attachment #1: Type: text/plain, Size: 1415 bytes --]
On Tue, 10 Mar 2015 14:03:59 +0100, Yann Droneaud said:
> > Consider the following sequence of events:
> >
> > 0. Suppose a mutex is locked by task A and has no waiters.
> >
> > 1. Task B calls mutex_trylock().
> >
> > 2. mutex_trylock() calls the architecture-specific
> > __mutex_fastpath_trylock(), with __mutex_trylock_slowpath() as
> > fail_fn.
> >
> > 3. According to the description of __mutex_fastpath_trylock() (for
> > example in include/asm-generic/mutex-dec.h), "if the architecture
> > has no effective trylock variant, it should call the fail_fn
> > spinlock-based trylock variant unconditionally". So
> > __mutex_fastpath_trylock() may now call __mutex_trylock_slowpath().
> >
> > 4. Task A releases the mutex.
> >
> > 5. Task B, in __mutex_trylock_slowpath, executes:
> >
> > /* No need to trylock if the mutex is locked. */
> > if (mutex_is_locked(lock))
> > return 0;
> >
> > Since the mutex is no longer locked, the function continues.
> >
> > 6. Task C, which runs on a different cpu than task B, locks the mutex
> > again.
> >
> > 7. Task B, in __mutex_trylock_slowpath(), continues:
> >
> > 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.
[-- Attachment #2: Type: application/pgp-signature, Size: 848 bytes --]
next prev parent reply other threads:[~2015-03-10 15:01 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <54F64E10.7050801@gmail.com>
2015-03-10 13:03 ` Yann Droneaud
2015-03-10 14:59 ` Valdis.Kletnieks [this message]
2015-03-14 23:08 ` Matthias Bonne
2015-03-14 23:05 ` Matthias Bonne
2015-03-15 1:03 ` Davidlohr Bueso
2015-03-15 1:09 ` Davidlohr Bueso
2015-03-15 21:49 ` Matthias Bonne
2015-03-15 22:10 ` Rabin Vincent
2015-03-16 3:40 ` Matthias Bonne
2015-03-15 22:18 ` Davidlohr Bueso
2015-03-15 22:23 ` Davidlohr Bueso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=65060.1425999557@turing-police.cc.vt.edu \
--to=valdis.kletnieks@vt.edu \
--cc=kernelnewbies@kernelnewbies.org \
--cc=lemonlime51@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=ydroneaud@opteya.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®