AMD Branch Sampling "BRS" Feature To Land With Linux 5.19
Last year I wrote about Google engineers working on AMD Branch Sampling support for Linux with Zen 3 processors. This is about making use of the processor-exposed information about branches taken during code execution. In turn this AMD Branch Sampling information will be exposed via Linux's perf subsystem for collection. This AMD Branch Sampling support can be leveraged for better compiler optimizations on AMD processors by analyzing the collected hardware data for making more informed/accurate optimization decisions like with AutoFDO. See the aforelinked article for more commentary.
While it's been some months since last talking about the AMD Branch Sampling support, based on the information within the public AMD programmer reference manual they were able to get the support ironed out and is now ready for mainlining. After re-basing against Linux 5.18-rc1, pulled into TIP's perf/core branch is the AMD Zen 3 Branch Sampling code. In turn these perf/core patches along with whatever patches accumulate over the next month and a half will in turn be submitted for the Linux 5.19 merge window when that kicks off around the end of May.
With Zen 3 processors there is 16-deep branch sampling accessible via CPU MSR registers. With the perf tool the RETIRED_BRANCH_INSTRUCTIONS can be used for matching the BRS behavior or the new branch-brs event. The AMD Zen 3 BRS support is going to be an opt-in feature with the Linux CONFIG_PERF_EVENTS_AMD_BRS switch at build-time. It's great that AMD BRS is now being exposed under Linux but unfortunate it's taken so long after Zen 3 CPUs premiered with this feature, at least it should still prove useful with Zen 4 and beyond for profiling / AutoFDO-like optimizing.