This is an archive of the discontinued LLVM Phabricator instance.

[Profile][NFC] Clean up initializeProfileForContinuousMode
ClosedPublic

Authored by zequanwu on Aug 5 2021, 12:10 PM.

Details

Summary

Merge two versions of initializeProfileForContinuousMode function into one.

Diff Detail

Event Timeline

zequanwu requested review of this revision.Aug 5 2021, 12:10 PM
zequanwu created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptAug 5 2021, 12:10 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
vsk added a comment.Aug 5 2021, 3:03 PM

Thanks!

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

Why not keep the 'Grow the profile ...' comment?

555–556

These checks are useful for debugging, and should be safe to keep in the useBiasVar == 0 path. Any reason to delete them?

555–556

The new "CountersOffset" cannot be used when useBiasVar == 0, so I suggest renaming it (maybe "CountersOffsetInBiasMode") and sinking it closer to its use.

556

Will these defines be needed in your follow-up patches? If so, it might be worth moving them to the global namespace now. If not, 'static' can be dropped.

557

The difference in fileOpenMode ('a+b' vs. 'w+b') is probably worth a TODO or FIXME. But it makes sense to keep this patch NFC.

568–569

I guess warnIfNonZero can also be deleted.

650–651

Why not keep the 'so long as there is at least one counter' comment?

zequanwu updated this revision to Diff 364643.Aug 5 2021, 3:47 PM
zequanwu marked 6 inline comments as done.

Address comments.

zequanwu added inline comments.Aug 5 2021, 3:49 PM
compiler-rt/lib/profile/InstrProfilingFile.c
531

Added.

555–556

Those checks failed when running profile tests on Linux.
Moved to the useBiasVar == 0 path.

556

Yes, those checks will still be needed in the follow-up patches.
Moved up.

557

What would the TODO/FIXME about? Are we going to change it in the future?

zequanwu updated this revision to Diff 364645.Aug 5 2021, 4:04 PM

Fix errors.

vsk accepted this revision.Aug 6 2021, 11:19 AM

Thanks, lgtm.

compiler-rt/lib/profile/InstrProfilingFile.c
555–556

Thanks, moving the checks to the useBiasVar == 0 path is the right thing to do, since that's the path where we require certain profile sections to be page aligned.

557

If I've understood correctly, fileOpenMode is used in the !doMerging() case, and the append behavior ("a+b") is the correct one.

Consider the case where you have two instrumented DSOs, both using continuous mode with !doMerging(): then as the runtime initializer in the second DSO does initializeProfileForContinuousMode(), it will truncate + clobber the profile written by the initializer in the first DSO.

This revision is now accepted and ready to land.Aug 6 2021, 11:19 AM
zequanwu updated this revision to Diff 364864.Aug 6 2021, 12:18 PM

Capitalize first letter of global variables.

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

it will truncate + clobber the profile written by the initializer in the first DSO.

I don't understand that. If the file is opened with "a+b", it will just append new profile to the end of existing profile file.

vsk added inline comments.Aug 6 2021, 1:26 PM
compiler-rt/lib/profile/InstrProfilingFile.c
557

Right, but if the file is opened with "w+b", then the second DSO's initializer will truncate the profile, erasing the data written by the first DSO.

zequanwu updated this revision to Diff 364879.Aug 6 2021, 1:58 PM

Add a TODO.

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

Oh, I see. You are saying the non-apple platform. It is problematic in that case. Added a TODO.

This revision was landed with ongoing or failed builds.Aug 6 2021, 2:01 PM
This revision was automatically updated to reflect the committed changes.