renode / renode

Renode - Antmicro's open source simulation and virtual development framework for complex embedded systems
https://renode.io
Other
1.55k stars 273 forks source link

Time measurements isn't accurate #445

Open frejohg opened 1 year ago

frejohg commented 1 year ago

HiT

I'm trying to measure the time or clock cycles it takes to run a function. I'm comparing hardware and Renode. For my arduino nano 33 sense ble I can use the built in cycle counter and output this on serial as following:

DWT->CYCCNT = 0; start = DWT->CYCCNT; myFunction(); stop = DWT->CYCCNT; elapsed = stop-start; Serial.println(elapsed);

I get around 8000 cycles, which with 64 MHz should be around 126 uS.

If I use the binary in Renode

machine LoadPlatformDescription @/home/fred/appimages/renode_1.13.2_portable/platforms/boards/arduino_nano_33_ble.repl sysbus LoadELF @/home/fred/Arduino/hello_world_cyccnt2/build/arduino.mbed_nano.nano33ble/hello_world_cyccnt2.ino.elf machine StartGdbServer 3333 true sysbus.cpu EnableProfiler CollapsedStack @/home/fred/trace1 machine EnableProfiler @/home/fred/profiler1

The way I used to measure the time of the function in Renode was to put a digitalWrite before and after the function and see with the profiler what the time between the GPIO access is. And that is around 50 uS.

Is there any way to overcome this inaccuracy?

Enviroment: arch x86_64 xfce Renode, version 1.13.2.18007 (9ab53ff7-202210031000) arduino-ide_2.0.4_Linux_64bit

PiotrZierhoffer commented 1 year ago

Renode is a functional simulator, and while there are ways to make it more accurate in terms of time measurement, it's not aiming to be 1:1 with hardware.

You have two things you can check:

Please verify it with the docs and let us know if you find better settings for you

frejohg commented 1 year ago

Hi

Ok I tried the PerformanceInMips and found that it is not linear, meaning that it does not scale accurately, I could find a setting that produced the same results as tests on a physical device, but this setting did not produce accurate results between renode and another calculation on the same device.

Could you specify which of the settings in the nRF52840.repl file that are the clock cycles? That would be helpful thank you.

PiotrZierhoffer commented 1 year ago

@frejohg I assume the most reasonable option for you would be to add a line here: https://github.com/renode/renode/blob/master/platforms/cpus/nrf52840.repl#L2

nvic: IRQControllers.NVIC @ sysbus 0xE000E000
    systickFrequency: 10000000 // your frequency here
    -> cpu@0

It would be interesting to learn what's the proper value from the perspective of your use case