3

I know that most modern processors maintain a branch prediction table (BPT). I have read the gdb documentation but I could not found any command that should give desired results. Based on this, I have a couple questions:

Is there a gdb command (or some other way) to get the BPT info of a process?

If not, is it possible to view a process's BPT?

Taimoor Zaeem
  • 190
  • 1
  • 12
  • 3
    Isn't this maintained inside the CPU and not in user-visible memory? – Steve Friedl Oct 11 '22 at 17:05
  • @SteveFriedl: Yes. And there's no x86 instruction to query it. Microcode can wipe it, as we know from Spectre mitigation updates adding that capability, so hypothetically, a custom microcode update (e.g. [on Goldmont where the key was leaked/exposed](https://developers.slashdot.org/story/20/10/28/217212/hackers-can-now-reverse-engineer-intel-updates-or-write-their-own-custom-firmware)) could add the capability to BHT / BTB entries via `rdmsr`, if anyone outside Intel could successfully add new microcode that would run to handle `rdmsr` of a certain Model-Specific-Register number. – Peter Cordes Oct 12 '22 at 02:40

1 Answers1

3

is it possible to view a process's BPT?

No: at least on Intel processors it's hidden inside the processor itself and not exposed to either userspace or kernel in any way. Nor is it even documented, and constitutes "secret sauce".

You can glean some details about branch predictor by conducting careful experiments and observing various performance counters, but you can't examine it directly.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362