From: Lin Ming <ming.m.lin@intel.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
Arnaldo Carvalho de Melo <acme@infradead.org>,
Frederic Weisbecker <fweisbec@gmail.com>,
LKML <linux-kernel@vger.kernel.org>,
"2nddept-manager@sdl.hitachi.co.jp"
<2nddept-manager@sdl.hitachi.co.jp>
Subject: Re: [RFC PATCH] perf report: add sort by file lines
Date: Thu, 31 Mar 2011 22:51:55 +0800 [thread overview]
Message-ID: <1301583115.2271.27.camel@localhost> (raw)
In-Reply-To: <1301582056.2271.15.camel@localhost>
On Thu, 2011-03-31 at 22:34 +0800, Lin Ming wrote:
> On Thu, 2011-03-31 at 22:01 +0800, Peter Zijlstra wrote:
> > On Thu, 2011-03-31 at 16:45 +0800, Lin Ming wrote:
> > > I am considering if it is possible to do "instruction unwind" to get a
> > > map from (temporarily used) register to a specific member of a data
> > > structure pointed by a pointer.
> > >
> > > 4004a0: movq -8(%rbp), %rax /* load foo arg from stack
> > > */
> > > 4004a4: movq 24(%rax), %rax /* load foo->bar */
> > > 4004a8: movq -16(%rbp), %rdx /* load tmp arg from stack
> > > */
> > > 4004ac: movl 32(%rdx), %edx /* load tmp->blah */
> > > 4004af: movl %edx, 20(%rax) /* store bar->fubar */
> > >
> > > foo: -8(%rbp)
> > > tmp: -16(%rbp)
> > >
> > > Assume we are now at ip 4004af, from the instruction decoder, we know
> > > it's a store operation, and we want to find out what %rax is.
> > >
> > > 1. unwind to 4004ac
> > > Ignore this, because it does not touch %rax
> > >
> > > 2. unwind to 4004a8
> > > Ignore this, because it does not touch %rax
> > >
> > > 3. unwind to 4004a4
> > > 20(%rax) => 20(24(%rax)), continue to unwind because we still
> > > have no idea what %rax is
> > >
> > > 4. unwind to 4004a0
> > > 20(24(%rax)) => 20(24(-8(%rbp))), stop unwind, because we now know
> > > -8(%rbp) is foo.
> > >
> > > So the original 20(%rax) is replace as 20(24(-8(%rbp))), and it means
> > > foo->bar->fubar
> > >
> > > Does this make sense?
> >
> > Yes and no, the problem is that you cannot unwind an x86 instruction
> > stream. Therefore its easier to start at the beginning of a function
> > where DWARF should be able to tell you everything you need and then do a
> > single fwd scan to propagate the information until you reach the point
> > of interest.
>
> I'm afraid that fwd scan may not work, because of branch instruction.
>
> void foo(struct foo *foo, struct tmp *tmp, int flag)
> {
> if (flag)
> foo->bar->fubar = tmp->blah;
> else
> tmp->blah = foo->bar->fubar;
> }
>
> ===>
>
> void foo(struct foo *foo, struct tmp *tmp, int flag)
> {
> 400494: 55 push %rbp
> 400495: 48 89 e5 mov %rsp,%rbp
> 400498: 48 89 7d f8 mov %rdi,-0x8(%rbp)
> 40049c: 48 89 75 f0 mov %rsi,-0x10(%rbp)
> 4004a0: 89 55 ec mov %edx,-0x14(%rbp)
> if (flag)
> 4004a3: 83 7d ec 00 cmpl $0x0,-0x14(%rbp)
> 4004a7: 74 14 je 4004bd <foo+0x29>
> foo->bar->fubar = tmp->blah;
> 4004a9: 48 8b 45 f8 mov -0x8(%rbp),%rax
> 4004ad: 48 8b 40 18 mov 0x18(%rax),%rax
> 4004b1: 48 8b 55 f0 mov -0x10(%rbp),%rdx
> 4004b5: 8b 52 20 mov 0x20(%rdx),%edx
> 4004b8: 89 50 14 mov %edx,0x14(%rax)
> 4004bb: eb 12 jmp 4004cf <foo+0x3b>
> else
> tmp->blah = foo->bar->fubar;
> 4004bd: 48 8b 45 f8 mov -0x8(%rbp),%rax
> 4004c1: 48 8b 40 18 mov 0x18(%rax),%rax
> 4004c5: 8b 50 14 mov 0x14(%rax),%edx
> 4004c8: 48 8b 45 f0 mov -0x10(%rbp),%rax
> 4004cc: 89 50 20 mov %edx,0x20(%rax)
> }
> 4004cf: c9 leaveq
> 4004d0: c3 retq
>
> Assume we are at ip 4004c5, the fwd scan from the beginning of
> function(400494) to 4004c5 will not get what we want about %rax.
In contrast, we can scan from 4004c5 toward to the beginning of the
function to get the info about 0x14(%rax)
We already know foo is -0x8(%rbp)
Scan 4004c1: 0x14(%rax) -> 0x14(0x18(%rax))
Scan 4004bd: 0x14(0x18(%rax)) -> 0x14(0x18(-0x8(%rbp))), stop scan
because we already know -0x8(%rbp) is foo.
And with other dwarf info, we finally know 0x14(%rax) at ip 4004c5 means
foo->bar->fubar.
Lin Ming
>
> Lin Ming
next prev parent reply other threads:[~2011-03-31 14:52 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-29 9:32 [RFC PATCH] perf report: add sort by file lines Lin Ming
2011-03-29 9:46 ` Masami Hiramatsu
2011-03-29 9:54 ` Peter Zijlstra
2011-03-29 16:45 ` Lin Ming
2011-03-29 17:03 ` Peter Zijlstra
2011-03-29 17:06 ` Peter Zijlstra
2011-03-29 17:08 ` Peter Zijlstra
2011-03-29 17:45 ` Arnaldo Carvalho de Melo
2011-03-30 1:04 ` Masami Hiramatsu
2011-03-30 2:18 ` Arnaldo Carvalho de Melo
2011-03-31 6:57 ` Lin Ming
2011-04-01 10:48 ` Masami Hiramatsu
2011-03-31 8:45 ` Lin Ming
2011-03-31 13:46 ` Arnaldo Carvalho de Melo
2011-03-31 14:19 ` Lin Ming
2011-03-31 15:35 ` Arnaldo Carvalho de Melo
2011-03-31 14:01 ` Peter Zijlstra
2011-03-31 14:34 ` Lin Ming
2011-03-31 14:51 ` Lin Ming [this message]
2011-03-31 16:28 ` Peter Zijlstra
2011-03-31 16:32 ` Peter Zijlstra
2011-04-01 13:02 ` Lin Ming
2011-04-01 13:48 ` Peter Zijlstra
2011-04-01 10:44 ` Masami Hiramatsu
2011-04-01 11:05 ` Peter Zijlstra
2011-04-01 13:22 ` Lin Ming
2011-04-01 13:49 ` Peter Zijlstra
2011-04-01 13:57 ` Lin Ming
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=1301583115.2271.27.camel@localhost \
--to=ming.m.lin@intel.com \
--cc=2nddept-manager@sdl.hitachi.co.jp \
--cc=acme@infradead.org \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=peterz@infradead.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