[En-Nut-Discussion] systime limit reduces valid uptime to 49 days
Bernard Fouché
bernard.fouche at kuantic.com
Tue Nov 6 19:43:39 CET 2007
Another possibility beside moving the tick counter to 64 bits:
periodically 'reduce' tick counters to never overflow.
For instance every day (or every 49 days!) the 32 bits tick count is set
back to zero, an other variable incremented and when one needs the time
in ms, a system function will recalculate a 64 bits value to return
including the current tick count plus this 'other variable'. So
NutGetTickCount() would return a 64 bits value, but work mostly in 32
bits in the interrupt code, so Ethernuts running with ATMEGAs won't be
impacted too much. (having these to count in 64 bits would be a big
penalty since the MCU core is mostly 8 bits)
But sure this 49 days limit is a trap for long time running devices,
some function may never timeout and stuck the whole thing. Currently I
have apps that need 1ms precision (or about) to be able to trigger I2C
operations, so moving to a tick every 62ms would be bad, but these apps
usually don't run 49 days in a row (and I use comparisons that handle
the 32 bits overflow since I have no feature that require a 49 days timer)
Yet another dirty trick: when the application considers to be idle, have
it reboot if the tick counter is over a particular value...
Bernard
Michael Müller wrote:
> Hi,
>
> I was quite shocked when looking at the code parts calculating the
> system time. If I did not calculate complete rubbish it seems as if
> there is a time overflow after 49 days! At least using Ethernut 1.3 with
> 32bit long variables. The comment at the head of NutGetMillis(void)
> function tells about a maximum systime of 8 years. It seems to refer to
> the old systick of 62ms instead of the current default value of 1ms.
>
> timer.c
> =======
>
> u_long NutGetTickCount(void);
>
> ...
>
> u_long NutGetSeconds(void)
> {
> return NutGetTickCount() / NutGetTickClock();
> }
>
> ostimer.c
> =========
> u_long NutGetTickClock(void)
> {
> return NUT_TICK_FREQ; /* = 1024 */
> }
>
> This reduces the maximum count of seconds to
>
> 2^32 / 1000 [s] = 49days!
>
> Are there any suggestions how to handle this?
> - Change the systick to 62ms again (was the reason just more precision
> for the "user application" or was it useful / necessary for the OS, too?) ?
> - Increase the tick variable of NutOS to a 64bit type
> (unsigned long long)?
>
>
> Best regards
> Michael
>
>
> _______________________________________________
> http://lists.egnite.de/mailman/listinfo/en-nut-discussion
>
>
More information about the En-Nut-Discussion
mailing list