[all-commits] [llvm/llvm-project] 322057: [llvm-profgen] Skip disassembling for PLT section

ictwanglei via All-commits all-commits at lists.llvm.org
Tue Dec 14 16:42:55 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 322057179316c03b2b25ce341b1e55d01890730d
      https://github.com/llvm/llvm-project/commit/322057179316c03b2b25ce341b1e55d01890730d
  Author: wlei <wlei at fb.com>
  Date:   2021-12-14 (Tue, 14 Dec 2021)

  Changed paths:
    M llvm/test/tools/llvm-profgen/inline-noprobe2.test
    M llvm/tools/llvm-profgen/ProfiledBinary.cpp

  Log Message:
  -----------
  [llvm-profgen] Skip disassembling for PLT section

Skip disassembling .plt section, then .plt section code will be treated as external code.

Reviewed By: hoy, wenlei

Differential Revision: https://reviews.llvm.org/D115699


  Commit: 3dcb60db9a538aa1b7144e0d5e37ee3b43d5d991
      https://github.com/llvm/llvm-project/commit/3dcb60db9a538aa1b7144e0d5e37ee3b43d5d991
  Author: wlei <wlei at fb.com>
  Date:   2021-12-14 (Tue, 14 Dec 2021)

  Changed paths:
    A llvm/test/tools/llvm-profgen/Inputs/external-address.perfscript
    M llvm/test/tools/llvm-profgen/Inputs/inline-cs-noprobe.perfscript
    A llvm/test/tools/llvm-profgen/cs-external-address.test
    M llvm/test/tools/llvm-profgen/cs-interrupt.test
    M llvm/test/tools/llvm-profgen/inline-noprobe2.test
    M llvm/tools/llvm-profgen/PerfReader.cpp
    M llvm/tools/llvm-profgen/PerfReader.h

  Log Message:
  -----------
  [CSSPGO][llvm-profgen] Fix external address issues of perf reader (leading external LBR part)

We can have the sampling just hit into the external addresses, in that case, both the top stack frame and the latest LBR target are external addresses. For example:
```
	        ffffffff
 0x4006c8/0xffffffff/P/-/-/0  0x40069b/0x400670/M/-/-/0

 	          ffffffff
	          40067e
0xffffffff/0xffffffff/P/-/-/0  0x4006c8/0xffffffff/P/-/-/0  0x40069b/0x400670/M/-/-/0
```
Before we will ignore the entire samples. However, we found there exists some internal LBRs in the remaining part of sample, the range between them is still a valid range, we will lose some valid LBRs. Those LBRs will be unwinded based on a empty(context-less) call stack.

This change tries to fix it, instead of ignoring the entire sample, we only ignore the leading external addresses.

Note that the first outgoing LBR is useful since there is a valid range between it's source and next LBR's target.

Reviewed By: hoy, wenlei

Differential Revision: https://reviews.llvm.org/D115538


  Commit: 30c3aba998972aa042493e26dbe8f7cca37a30dd
      https://github.com/llvm/llvm-project/commit/30c3aba998972aa042493e26dbe8f7cca37a30dd
  Author: wlei <wlei at fb.com>
  Date:   2021-12-14 (Tue, 14 Dec 2021)

  Changed paths:
    M llvm/tools/llvm-profgen/PerfReader.cpp

  Log Message:
  -----------
  [llvm-profgen] Fix to use getUntrackedCallsites outside the loop

Unwinder is hoisted out in https://reviews.llvm.org/D115550, so fix the useage of getUntrackedCallsites.

Reviewed By: hoy, wenlei

Differential Revision: https://reviews.llvm.org/D115760


  Commit: 0f53df864eb3b97fba74feb78132a38c87fa1db6
      https://github.com/llvm/llvm-project/commit/0f53df864eb3b97fba74feb78132a38c87fa1db6
  Author: wlei <wlei at fb.com>
  Date:   2021-12-14 (Tue, 14 Dec 2021)

  Changed paths:
    A llvm/test/tools/llvm-profgen/Inputs/callback-external-addr.perfbin
    A llvm/test/tools/llvm-profgen/Inputs/callback-external-addr.perfscript
    A llvm/test/tools/llvm-profgen/callback-external-addr.test
    M llvm/test/tools/llvm-profgen/inline-noprobe2.test
    M llvm/tools/llvm-profgen/PerfReader.cpp
    M llvm/tools/llvm-profgen/PerfReader.h
    M llvm/tools/llvm-profgen/ProfiledBinary.h

  Log Message:
  -----------
  [CSSPGO][llvm-profgen] Fix external address issues of perf reader (return to external addr part)

Before we have an issue with artificial LBR whose source is a return, recalling that "an internal code(A) can return to external address, then from the external address call a new internal code(B), making an artificial branch that looks like a return from A to B can confuse the unwinder". We just ignore the LBRs after this artificial LBR which can miss some samples. This change aims at fixing this by correctly unwinding them instead of ignoring them.

List some typical scenarios covered by this change.

1)  multiple sequential call back happen in external address, e.g.

```
[ext, call, foo] [foo, return, ext] [ext, call, bar]
```
Unwinder should avoid having foo return from bar. Wrong call stack is like [foo, bar]

2) the call stack before and after external call should be correctly unwinded.
```
 {call stack1}                                            {call stack2}
 [foo, call, ext]  [ext, call, bar]  [bar, return, ext]  [ext, return, foo ]
```
call stack 1 should be the same to call stack2. Both shouldn't be truncated

3) call stack should be truncated after call into external code since we can't do inlining with external code.

```
 [foo, call, ext]  [ext, call, bar]  [bar, call, baz] [baz, return, bar ] [bar, return, ext]
```
the call stack of code in baz should not include foo.

### Implementation:

We leverage artificial frame to fix #2 and #3: when we got a return artificial LBR, push an extra artificial frame to the stack. when we pop frame, check if the parent is an artificial frame to pop(fix #2). Therefore, call/ return artificial LBR is just the same as regular LBR which can keep the call stack.

While recording context on the trie, artificial frame is used as a tag indicating that we should truncate the call stack(fix #3).

To differentiate #1 and #2, we leverage `getCallAddrFromFrameAddr`.  Normally the target of the return should be the next inst of a call inst and `getCallAddrFromFrameAddr` will return the address of call inst. Otherwise, getCallAddrFromFrameAddr will return to 0 which is the case of #1.

Reviewed By: hoy, wenlei

Differential Revision: https://reviews.llvm.org/D115550


Compare: https://github.com/llvm/llvm-project/compare/d7b7b6491445...0f53df864eb3


More information about the All-commits mailing list