emulation cycle number implementation
Hello, List!
I'm running MIPS assembler programs on QEMU. I need to log some events that happen through emulation (writes to some registers, for example). When an event happens, I need to print not only the event-related information, but an "emulation cycle number" also. This number should be an integer increasing value that is similar to real hardware clock.
How to implement this in QEMU? May QEMU timers be helpful in solving such a problem?
Thanks in advance.
Signature · 2 lines
Sincerely yours, Sergey Smolov
Quoted 8 lines · Sergey Smolov
I'm running MIPS assembler programs on QEMU. I need to log some events that happen through emulation (writes to some registers, for example). When an event happens, I need to print not only the event-related information, but an "emulation cycle number" also. This number should be an integer increasing value that is similar to real hardware clock.
How to implement this in QEMU? May QEMU timers be helpful in solving such a problem?
You can use cpu_get_ticks(), though if we're not in icount mode you may find it doesn't behave quite as helpfully as you might like (in that case it roughly tracks host hardware cycles.)
thanks
-- PMM
Quoted 7 lines · Peter Maydell
Quoted 6 lines · Sergey Smolov
I'm running MIPS assembler programs on QEMU. I need to log some events that happen through emulation (writes to some registers, for example). When an event happens, I need to print not only the event-related information, but an "emulation cycle number" also. This number should be an integer increasing value that is similar to real hardware clock.
Quoted 8 lines
Quoted 2 lines
How to implement this in QEMU? May QEMU timers be helpful in solving such a problem?
You can use
cpu_get_ticks(), though if we're not in icount mode you may find it doesn't behave quite as helpfully as you might like (in that case it roughly tracks host hardware cycles.)thanks
-- PMM
Thank you, Peter!
But what if I like to track guest hardware cycles? I run the same program on QEMU and RTL model of MIPS microprocessor, and I want to compare simulation traces. I expect, that emulation will start from 0 tick in both cases, at least.
Signature · 2 lines
Sincerely yours, Sergey Smolov
Quoted 4 lines · Sergey Smolov
But what if I like to track guest hardware cycles? I run the same program on QEMU and RTL model of MIPS microprocessor, and I want to compare simulation traces. I expect, that emulation will start from 0 tick in both cases, at least.
Broadly, you can't, because QEMU is not a cycle accurate emulator. (For 21st century CPUs, cycle accurate emulation that isn't just "run the RTL" is pretty near to impossible for practical purposes anyway.) If you're using QEMU's icount mode then cpu_get_ticks() will I think get you number of instructions executed; that's as good as you're going to get, I'm afraid.
Last time I wanted to do comparison of simulation traces I just compared the sequence of instructions executed, without worrying about trying to compare against the other simulation's notional clock cycle count as well.
thanks
-- PMM