[论文解读] Hardware Counted Profile-Guided Optimization
本文提出了一种基于采样的GCC Profile-Guided Optimization(PGO)技术,利用硬件性能计数器——特别是最后分支记录(LBR)采样——结合调试符号,重建源代码级别的性能轮廓。该方法仅产生1.06%的平均性能分析开销,而传统基于插桩的PGO开销为16%,却实现了插桩PGO 93%的性能提升,使PGO在生产环境中具备实际可行性。
Profile-Guided Optimization (PGO) is an excellent means to improve the performance of a compiled program. Indeed, the execution path data it provides helps the compiler to generate better code and better cacheline packing. At the time of this writing, compilers only support instrumentation-based PGO. This proved effective for optimizing programs. However, few projects use it, due to its complicated dual-compilation model and its high overhead. Our solution of sampling Hardware Performance Counters overcome these drawbacks. In this paper, we propose a PGO solution for GCC by sampling Last Branch Record (LBR) events and using debug symbols to recreate source locations of binary instructions. By using LBR-Sampling, the generated profiles are very accurate. This solution achieved an average of 83% of the gains obtained with instrumentation-based PGO and 93% on C++ benchmarks only. The profiling overhead is only 1.06% on average whereas instrumentation incurs a 16% overhead on average.
研究动机与目标
- 解决基于插桩的PGO存在的高开销和复杂的双编译模型问题。
- 通过降低性能分析开销,推动PGO在真实项目中的实际应用。
- 开发一种兼容GCC的工具链,利用硬件性能计数器进行性能轮廓收集。
- 在SPEC 2006基准测试上评估基于采样的PGO的准确性和性能表现。
- 实现对优化后二进制文件的PGO支持,且无需为性能分析重新编译。
提出的方法
- 从性能监控单元(PMU)采样最后分支记录(LBR)事件,以捕获执行轨迹。
- 利用调试符号将采样的程序计数器(PC)值映射回源代码位置。
- 使用最小控制流算法,从LBR采样中重建基本块和边的频率。
- 对采样计数进行归一化处理,以补偿基本块大小差异,避免对较大块产生偏差。
- 通过AutoFDO(AFDO)补丁将采样得到的轮廓集成到GCC中,以支持基于轮廓的优化。
- 使用perf工具收集采样数据,并通过gooda-to-afdo-converter工具将原始采样数据转换为GCOV兼容的轮廓文件。
实验结果
研究问题
- RQ1基于硬件性能计数器的采样能否实现与基于插桩的PGO相当的轮廓精度?
- RQ2基于采样的PGO能否将性能分析开销降低到适合生产环境的水平?
- RQ3LBR采样与调试符号的使用如何影响轮廓重建的准确性?
- RQ4所提出的方法能否在不需特殊编译模式的情况下集成到现有的GCC工具链中?
- RQ5基于采样的PGO对真实世界应用程序性能有何影响,特别是在C++工作负载中?
主要发现
- 所提出的基于硬件采样的PGO在SPEC 2006基准测试集上,平均实现了基于插桩PGO 83%的性能增益。
- 在C++基准测试中,该技术实现了基于插桩PGO 93%的性能增益。
- 平均性能分析开销仅为1.06%,远低于基于插桩PGO的16%。
- 该方法支持优化后的二进制文件,避免了基于插桩PGO所必需的双编译模型。
- 该工具链已具备生产环境可用性,并通过AutoFDO补丁集成到GCC中。
- 该方法为未来利用低级别硬件事件(如加载延迟和分支预测错误)探索新的优化机会提供了可能。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。