Hello
I was wondering why the .time value is so big in Linuxcnc. Probably this is documented somewhere but this value is not in ns but in arbitrary clocks returned by rtapi_get_clocks().
According to the documentation, rtapi_get_time() is really slow sometimes. So I created a component to test this:
https://github.com/hdiethelm/linuxcnc-fork/tree/timetest_component
It is not that slow according to my tests and the issues having with rtapi_get_clocks() returning random time units outweigh the 16ns rtapi_get_time() takes more in my opinion.
It might have been slow long time ago, the code is like 20 years old: ed4089d It is still an bit an issue on RTAI and it might still be an issue on certain systems. More tests would be good.
Results so far, Debian Trixie:
- VM, PREEMT_RT
- Clock to time ratio: 4.3
- rtapi_get_clocks(): 20ns
- rtapi_get_time(): 46ns
- CNC PC, PREEMT_RT
- Clock to time ratio: 3.2
- rtapi_get_clocks(): 8ns
- rtapi_get_time(): 20ns
- CNC PC, RTAI
- Clock to time ratio: 3.2
- rtapi_get_clocks(): 11ns
- rtapi_get_time(): 112ns
- CNC PC, Xenomai3
- Clock to time ratio: 3.2
- rtapi_get_clocks(): 8ns
- rtapi_get_time(): 24ns
- CNC PC, Xenomai4
- Clock to time ratio: 3.2
- rtapi_get_clocks(): 8ns
- rtapi_get_time(): 22ns
Started using:
scripts/halrun -I -f timetest.hal
timetest.txt
I created a prototype removing this function all together: https://github.com/hdiethelm/linuxcnc-fork/tree/rtapi_get_clocks_removal
While doing so, I even discovered issues where the time to clock conversion is wrong. For example here:
https://github.com/LinuxCNC/linuxcnc/blob/master/src/hal/drivers/hal_gpio.c#L367
This assumes one clock is 1 ns. However, on my PC, one clock is 0.24 ns
Due to RTAI is still used and somewhat slow (+100ns), a hybrid solution might be needed like rtapi_get_clocks_ns() which returns rtapi_get_time() for uspace and something like 1000.0*rtapi_get_clocks()/cpu_khz for RTAI.
Any feedback on this?
Hello
I was wondering why the .time value is so big in Linuxcnc. Probably this is documented somewhere but this value is not in ns but in arbitrary clocks returned by rtapi_get_clocks().
According to the documentation, rtapi_get_time() is really slow sometimes. So I created a component to test this:
https://github.com/hdiethelm/linuxcnc-fork/tree/timetest_component
It is not that slow according to my tests and the issues having with rtapi_get_clocks() returning random time units outweigh the 16ns rtapi_get_time() takes more in my opinion.
It might have been slow long time ago, the code is like 20 years old: ed4089d It is still an bit an issue on RTAI and it might still be an issue on certain systems. More tests would be good.
Results so far, Debian Trixie:
Started using:
scripts/halrun -I -f timetest.haltimetest.txt
I created a prototype removing this function all together: https://github.com/hdiethelm/linuxcnc-fork/tree/rtapi_get_clocks_removal
While doing so, I even discovered issues where the time to clock conversion is wrong. For example here:
https://github.com/LinuxCNC/linuxcnc/blob/master/src/hal/drivers/hal_gpio.c#L367
This assumes one clock is 1 ns. However, on my PC, one clock is 0.24 ns
Due to RTAI is still used and somewhat slow (+100ns), a hybrid solution might be needed like rtapi_get_clocks_ns() which returns rtapi_get_time() for uspace and something like 1000.0*rtapi_get_clocks()/cpu_khz for RTAI.
Any feedback on this?