Dear Firesim Folks,
I am trying to set up and enable hardware performance counters so that I can read microarchitectural events (e.g. cache hits/misses, branch mispredictions)
What I have done is to put the following code sequence in /home/zma/firesim/target-design/chipyard/generators/testchipip/src/main/resources/testchipip/bootrom/bootrom.S. I tried putting the code at the end of the file (right before mret) and at the very beginning (right after .start):
li t3, -1
csrw mcounteren, t3
csrw scounteren, t3
li t3, 0x100
csrw mhpmevent3, t3 // exception
li t3, 0x201
csrw mhpmevent4, t3 // branch mispredition
li t3, 0x401
csrw mhpmevent5, t3 // control-flow target mispredition
li t3, 0x801
csrw mhpmevent6, t3 // flush
li t3, 0x102
csrw mhpmevent7, t3 // I$ miss
li t3, 0x202
csrw mhpmevent8, t3 // D$ miss
li t3, 0x402
csrw mhpmevent9, t3 // D$ release
li t3, 0x802
csrw mhpmevent10, t3 // ITLB miss
li t3, 0x1002
csrw mhpmevent11, t3 // DTLB miss
li t3, 0x2002
csrw mhpmevent12, t3 // L2 TLB miss
I did `make` in the bootrom folder and rebuilt the bitstream to make sure the code I added to the bootrom is effective.
To test if it is indeed effective, I added `jr zero` at the end of the code gadget above, for the purpose of crashing the booting process. But it never worked (i.e. I was still able to boost linux). My firesim version is 1.17.1
I was wondering if this is the right way of enabling hardware performance counters? If not, where should I put these code and how do I turn on the performance counter tracking?
Thanks so much in advance!
Sincerely,
Zechen Ma