This is an archive of the discontinued LLVM Phabricator instance.

[llvm-profgen] Ignore broken LBR samples
ClosedPublic

Authored by hoy on Sep 10 2021, 4:37 PM.

Details

Summary

Perf script can sometimes give disordered LBR samples like below.

          b022500
          32de0044
          3386e1d1
      7f118e05720c
      7f118df2d81f
 0x2a0b9622/0x2a0b9610/P/-/-/1  0x2a0b79ff/0x2a0b9618/P/-/-/2  0x2a0b7a4a/0x2a0b79e8/P/-/-/1  0x2a0b7a33/0x2a0b7a46/P/-/-/1  0x2a0b7a42/0x2a0b7a23/P/-/-/1  0x2a0b7a21/0x2a0b7a37/P/-/-/2  0x2a0b79e6/0x2a0b7a07/P/-/-/1  0x2a0b79d4/0x2a0b79dc/P/-/-/2  0x2a0b7a03/0x2a0b79aa/P/-/-/1  0x2a0b79a8/0x2a0b7a00/P/-/-/234  0x2a0b9613/0x2a0b7930/P/-/-/1  0x2a0b9622/0x2a0b9610/P/-/-/1  0x2a0b79ff/0x2a0b9618/P/-/-/2  0x2a0b7a4a/0x2aWarning:
Processed 10263226 events and lost 1 chunks!

Note that the last LBR record 0x2a0b7a4a/0x2aWarning: . Currently llvm-profgen does not detect that and as a result an uninitialized branch target value will be used. The uninitialized value can cause creepy instruction ranges created which which in turn will result in a completely wrong profile. An example is like

.... @ _ZN5folly13loadUnalignedIsEET_PKv]:18446744073709551615:18446744073709551615
1: 18446744073709551615
!CFGChecksum: 4294967295
!Attributes: 0

Diff Detail

Event Timeline

hoy created this revision.Sep 10 2021, 4:37 PM
hoy requested review of this revision.Sep 10 2021, 4:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 10 2021, 4:37 PM
hoy edited the summary of this revision. (Show Details)Sep 10 2021, 4:38 PM
hoy added reviewers: wenlei, wlei, wmi.
hoy edited the summary of this revision. (Show Details)
wlei added inline comments.Sep 13 2021, 12:57 PM
llvm/tools/llvm-profgen/PerfReader.cpp
643–644

Please help to remove this line since it's already done in recordRangeCount.

llvm/tools/llvm-profgen/PerfReader.h
376

Nit: invalid --> Invalid , same for other assert message.

hoy added inline comments.Sep 13 2021, 2:13 PM
llvm/tools/llvm-profgen/PerfReader.cpp
643–644

Good catch. Assert removed.

llvm/tools/llvm-profgen/PerfReader.h
376

Fixed.

hoy updated this revision to Diff 372341.Sep 13 2021, 2:13 PM

Addressing Lei's comments.

hoy updated this revision to Diff 372342.Sep 13 2021, 2:14 PM

Updating D109637: [llvm-profgen] Ignore broken LBR samples

wlei accepted this revision.Sep 13 2021, 2:38 PM

LGTM, thanks!

This revision is now accepted and ready to land.Sep 13 2021, 2:38 PM
wenlei added inline comments.Sep 14 2021, 9:49 AM
llvm/tools/llvm-profgen/PerfReader.cpp
428

Print a warning so we know when this happens? Ideally the warning should also include the invalid Line TraceIt.getCurrentLine(), so we know what is the cause.

Thanks for the fix. It's unfortunate that perf script does not support redirecting its output all to a file, and it always uses stderr for both output and warning.

hoy added inline comments.Sep 14 2021, 10:32 AM
llvm/tools/llvm-profgen/PerfReader.cpp
428

Sounds good. Warning added in place to be more specific about LBR.

hoy updated this revision to Diff 372513.Sep 14 2021, 10:32 AM

Addressing Wenlei's comment.

wenlei added inline comments.Sep 14 2021, 10:38 AM
llvm/tools/llvm-profgen/PerfReader.cpp
430

Can we have the content of the line printed? I think that helps users know what is going on immediately. We can have both line number and content, but I think content is more important.
nit: "line" -> "line: " (add a white space between "line" and its content)

hoy added inline comments.Sep 14 2021, 10:42 AM
llvm/tools/llvm-profgen/PerfReader.cpp
430

Sounds good. Full line printed.

hoy updated this revision to Diff 372516.Sep 14 2021, 10:42 AM

Printing full line content in warning.

wenlei accepted this revision.Sep 14 2021, 10:49 AM

lgtm, thanks.

This revision was automatically updated to reflect the committed changes.