On Tue, Nov 10, 2020 at 7:51 PM RUI Zhengxin <ru...@126.com> wrote: > > This issue is very critial, it can make the select abnormally return timeout > after long run time. > If the timeout is set to 5ms, when the system run after 70000s(19.4h), > the select function will wait 10ms timeout, which is two times of setting > value. > > > This issue is created by calculating timeout watchdog expire tick using the > absolute time since libbsd5 version. > > 在 2020-11-03 10:26:39,"RUI Zhengxin" <ru...@126.com> 写道: > > Hello everyone, > > > We meet an issue of select function timeout drift in rtems-libbsd5.1. > > The select timeout can drift 1ms every 14000 seconds. > > > Kernel put the select thread to sleep queue in sleepq_set_timeout_sbt, > > the expire value is calculated by this > > expire = (sbt - SBT_1S + sbt_per_tick - 1) / sbt_per_tick; > > > sbt is the absolute time, > > Precision is a constant value, no time drift. > > but the sbt_per_tick is not an accurate value, > > It can make the expire vaule bigger and bigger while sbt is increasing. > > > in rtems_bsd_initialize function, > > rtems_bsd_sbt_per_watchdog_tick = SBT_1S / tps; > > in our system the tick rate is set to 1000Hz, > > The real value of rtems_bsd_sbt_per_watchdog_tick is 1<<32/1000=4294967.296 > > but in integer type the value is 4294967. > > The error is 0.296/4294967 = 0.069ppm, > > and it can increase the expire value 1ms every 14000 seconds. >
I don't think this bug can be fixed simply by arithmetic. Mixing power-of-2 timeouts with power-of-10 ticks means the arithmetic will always be subject to roundoff error. The choices are to use a power-of-2 hertz, or to determine the drift amount and reset your clock when you hit a round number. In your case, the error is 0.296 per tick, so after 1000 ticks you should adjust by 296. Or, if you can use HZ=1024 (if that is supported by your clock source) then you will get 1<<32/1024 = 1<<22 precisely. > Zhengxin > Best regards. > > > > > _______________________________________________ > users mailing list > users@rtems.org > http://lists.rtems.org/mailman/listinfo/users _______________________________________________ users mailing list users@rtems.org http://lists.rtems.org/mailman/listinfo/users