Skip to content

k_uptime_get_32() does not behave as documented #18739

@pabigot

Description

@pabigot

It was recently pointed out on slack that k_uptime_get_32() does not return The lower 32-bits of the elapsed time since the system booted, in milliseconds.

It returns instead the number of milliseconds corresponding to the low 32 bits of the tick counter.

u32_t z_impl_k_uptime_get_32(void)
{
        return __ticks_to_ms(z_tick_get_32());
}

The values are significantly different when you look at a 32-bit rollover of the tick clock:

At 10000 Hz ticks and 2^32 +/- 50:
t0 = 0x0000ffffffce = 4294967246 ticks => t0m = 429496724 ms
t1 = 0x000100000032 = 4294967346 ticks => t1m = 429496734 ms
t1-t0 = 100 ticks = 10 ms
and t1m-t0m = 10 ms
tt0 = 0x0000ffffffce = 4294967246 ticks => tt0m = 429496724 ms
tt1 = 0x000000000032 = 50 ticks => tt1m = 5 ms
tt1-tt0 = 100 ticks = 10 ms
but tt1m-tt1m = 3865470577 ms

This explains #17155 (comment) which had claimed that the current implementation followed an algorithm that I noted was incorrect. Apparently it does.

Metadata

Metadata

Labels

bugThe issue is a bug, or the PR is fixing a bugpriority: highHigh impact/importance bug

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions