From: Peter Zijlstra <peterz@infradead.org>
To: Mike Galbraith <efault@gmx.de>
Cc: Li Zefan <lizf@cn.fujitsu.com>,
LKML <linux-kernel@vger.kernel.org>, Ingo Molnar <mingo@elte.hu>,
Frederic Weisbecker <fweisbec@gmail.com>,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Paul Mackerras <paulus@samba.org>
Subject: Re: [BUG] perf: hard lockup when using perf-sched
Date: Thu, 25 Mar 2010 10:54:52 +0100 [thread overview]
Message-ID: <1269510892.12097.41.camel@laptop> (raw)
In-Reply-To: <1269509241.8438.30.camel@marge.simson.net>
On Thu, 2010-03-25 at 10:27 +0100, Mike Galbraith wrote:
> On Thu, 2010-03-25 at 16:04 +0800, Li Zefan wrote:
> > Mike Galbraith wrote:
> > > On Wed, 2010-03-24 at 08:32 +0100, Mike Galbraith wrote:
> > >
> > >> I just saw this, hunted down your testcase and tried it here. Looks
> > >> like perf_output_lock() wedged box.
> > >
> > > (turns on frame pointers, and adds noinline)
> > >
> >
> > Thanks! Then who's going to fix this...
>
> Well, that kinda depends on whether I figure out how the heck it's all
> supposed to work before somebody else whacks it or not.
>
> ATM, I've instrumented, know _what's_ happening, but find myself saying
> "wtf?" a lot, especially wrt handle->locked. The act of attempting to
> lock a handle declares it unlocked, turning perf_output_unlock() into a
> noop, which looks a bit strange. We're spinning on those "unlocked"
> locks, all left genuinely locked by one CPU. I just whacked the thing,
> and am very likely about to see in yet another trace.
>
> Locking is hard, "curious construct" locking is even harder :)
Yeah, that perf_output_{un,}lock() stuff is a pain..
handle->locked should indicate if we're the outer most context
the problem this stuff is solving is that of publishing the data head
pointer, suppose two concurrent writers:
head = 0;
A: reserve N bytes
write content
commit
B: reserve M bytes
write content
commit
Now, if B happens during A, and B completes before A is done, B's commit
would expose a head pointer of N+M bytes, even though the first N aren't
completely written yet.
So the trick is to only update the head pointer once everybody is done
writing. You can model this as a recursion problem and only update once
the recursion count hits 0 again.
However, with multiple cpus and NMIs and a busy enough environment this
never needs to happen, which would be bad, since we then cannot make
progress.
Hence the curious construct which basically serializes per cpu. Since
each cpu can only have a limited nesting context, and any one cpu is
bound to make progress (unless of course there is another bug that
prevents that) we'll post regular updates to the head pointer.
next prev parent reply other threads:[~2010-03-25 9:54 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-17 7:21 [BUG] perf: hard lockup when using perf-sched Li Zefan
2010-03-24 5:52 ` Li Zefan
2010-03-24 7:32 ` Mike Galbraith
2010-03-24 8:17 ` Mike Galbraith
2010-03-25 8:04 ` Li Zefan
2010-03-25 9:27 ` Mike Galbraith
2010-03-25 9:54 ` Peter Zijlstra [this message]
2010-03-26 10:11 ` Mike Galbraith
2010-03-26 17:23 ` Frederic Weisbecker
2010-03-26 19:10 ` Mike Galbraith
2010-03-26 19:27 ` Frederic Weisbecker
2010-03-26 20:22 ` Mike Galbraith
2010-03-26 21:41 ` Frederic Weisbecker
2010-03-26 21:45 ` Frederic Weisbecker
2010-03-29 2:01 ` Li Zefan
2010-04-02 19:07 ` [tip:perf/core] perf: Fix 'perf sched record' deadlock tip-bot for Mike Galbraith
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=1269510892.12097.41.camel@laptop \
--to=peterz@infradead.org \
--cc=acme@redhat.com \
--cc=efault@gmx.de \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lizf@cn.fujitsu.com \
--cc=mingo@elte.hu \
--cc=paulus@samba.org \
/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