Step 2: How it works
Given the topic complexity and the length of this article I have split it in 3 three different blog-post:
- What is PGO
- How PGO it works
- Why my sysbench-trained build loses and how to do it right.
How PGO works: PGO is a two-pass build. First pass
compiles with instrumentation (-fprofile-generate): every
basic block and branch gets a counter.
You run a training workload, counters are dumped to
profraw files.
Second pass recompiles using those counts to drive inlining
decisions, branch layout (hot path falls through, cold path jumps
away), hot/cold …