I've started to use gem5 to figure out what's going on from the perspective of cache hit miss or dram access.
I found that there exist m5_checkpoint, m5_reset_...
So, to print out "stat" of interest area, how I can use these APIs over a below example??
int main(void) {
init() // I don't care what happens here
run() // This function is what I want to analyze
return 0;
}
Closely related question: How to count the number of CPU clock cycles between the start and end of a benchmark in gem5?
By reading the source of the m5
tool, you can see that it just comes down to using magic (normally unassigned) instructions, or doing memory accesses to magic (normally unmapped) memory addresses.
Therefore, for the instructions for example, you can just insert those instructions with .inst
and inline assembly, usually in order:
resetsats
before region of interestdumpstats
afterwardsThe cleanest way to do this is to actually include the m5ops.h
header from gem5 source code that m5
CLI tool uses, but I find it easier to just handcode it myself at times.
For aarch64 for example they would look like:
/* resetstats */
__asm__ __volatile__ ("mov x0, #0; mov x1, #0; .inst 0XFF000110 | (0x40 << 16);" : : : "x0", "x1")
/* dumpstats */
__asm__ __volatile__ ("mov x0, #0; mov x1, #0; .inst 0xFF000110 | (0x41 << 16);" : : : "x0", "x1")
Here are: