This is an archive of the discontinued LLVM Phabricator instance.

[profile] Avoid allocating a page on the stack, NFC
ClosedPublic

Authored by vsk on Dec 10 2019, 6:45 PM.

Details

Summary

When writing out a profile, avoid allocating a page on the stack for the
purpose of writing out zeroes, as some embedded environments do not have
enough stack space to accomodate this.

Instead, use a small, fixed-size zero buffer that can be written
repeatedly.

For a synthetic file with >100,000 functions, I did not measure a
significant difference in profile write times. We are removing a
page-length zero-fill memset() in favor of several smaller buffered
fwrite() calls: in practice, I am not sure there is much of a
difference. The performance impact is only expected to affect the
continuous sync mode (%c) -- zero padding is less than 8 bytes in all
other cases.

rdar://57810014

Diff Detail

Event Timeline

vsk created this revision.Dec 10 2019, 6:45 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 10 2019, 6:45 PM
Herald added a subscriber: dexonsmith. · View Herald Transcript
This revision is now accepted and ready to land.Dec 10 2019, 11:40 PM
MaskRay added inline comments.
compiler-rt/lib/profile/InstrProfilingFile.c
136

sizeof(uint8_t) -> 1 ?

vsk marked an inline comment as done.Dec 11 2019, 9:44 AM

Thanks for the reviews!

compiler-rt/lib/profile/InstrProfilingFile.c
136

That's a reasonable alternative. However the current convention in libprofile is to write out the sizeof.

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptDec 11 2019, 10:20 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript