Skip to content

kernel: reimplement k_uptime_get_32() #18744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2019

Conversation

pabigot
Copy link
Collaborator

@pabigot pabigot commented Aug 28, 2019

The current implementation does not return the low 32 bits of
k_uptime_get() as suggested by it's documentation; it returns the number
of milliseconds represented by the low 32-bits of the underlying system
clock. The truncation before translation results in discontinuities at
every point where the system clock increments bit 33.

Reimplement it using the full-precision value, and update the
documentation to note that this variant has little value for
long-running applications.

Closes #18739.

Signed-off-by: Peter Bigot [email protected]

@pabigot
Copy link
Collaborator Author

pabigot commented Aug 28, 2019

This is an alternative solution; contrast with #18742.

@pfalcon
Copy link
Collaborator

pfalcon commented Aug 28, 2019

This is an alternative solution; contrast with #18742.

Easy:

Files changed 2

vs

Files changed 47

Instant win.

@ioannisg ioannisg added the block: HW Test Testing on hardware required before merging label Sep 3, 2019
@galak
Copy link
Collaborator

galak commented Sep 3, 2019

We should think if we do want to deprecate this API as well.

include/kernel.h Outdated
* This routine returns the lower 32-bits of the elapsed time since the system
* booted, in milliseconds.
* This routine returns a value obtained by converting the lower
* 32-bits of the system clock into milliseconds.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks like it got left in by mistake. In fact the effect of this patch is to make the old text true (where it wasn't before). The new text reflects the old behavior.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait, no, the old text wasn't right either. Suggest "This routine returns the lower 32 bits of the system uptime in milliseconts". It's not the result of converting only the lower 32 bits anymore.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced with suggested text.

Copy link
Collaborator

@andyross andyross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc nitpicking. Code looks fine.

include/kernel.h Outdated
* This routine returns the lower 32-bits of the elapsed time since the system
* booted, in milliseconds.
* This routine returns a value obtained by converting the lower
* 32-bits of the system clock into milliseconds.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait, no, the old text wasn't right either. Suggest "This routine returns the lower 32 bits of the system uptime in milliseconts". It's not the result of converting only the lower 32 bits anymore.

The current implementation does not return the low 32 bits of
k_uptime_get() as suggested by it's documentation; it returns the number
of milliseconds represented by the low 32-bits of the underlying system
clock.  The truncation before translation results in discontinuities at
every point where the system clock increments bit 33.

Reimplement it using the full-precision value, and update the
documentation to note that this variant has little value for
long-running applications.

Closes zephyrproject-rtos#18739.

Signed-off-by: Peter Bigot <[email protected]>
@pabigot
Copy link
Collaborator Author

pabigot commented Sep 3, 2019

We should think if we do want to deprecate this API as well.

Can't without changing all uses of the deprecated API (that was what #18742 did). It should probably be deprecated in 2.1 around the time #17155 gets merged.

@pfalcon
Copy link
Collaborator

pfalcon commented Sep 3, 2019

We should think if we do want to deprecate this API as well.

Why would we want to deprecate it. Between k_uptime_get_32() and k_uptime_get_64, the latter is "more superfluous". It's perfectly possible to write a lot of useful software with 32-bit version (and thus remove 64-bit version, and implement optimized 32-bit).

I'd like to contrast that with a case in zephyrproject-rtos/sdk-ng#101 . There, there's official standard for 64-bit support, people rely on it, and Zephyr misses it. And the comments solicited? we did not need that the last 5 years, why change now?

So, we didn't need need to force 64-bit timestamps for 5 years, indeed, even "deprecation" patch #18742 just casts 64-bit value to 32-bit. So why would we deprecate 32-bit timestamps now, if they were part of the API all along? (Oh yeah, I didn't look into #17155 and don't have an idea what it may bring...).

@ioannisg
Copy link
Member

ioannisg commented Sep 3, 2019

@pabigot @andyross i am adding back-port label. If not required, please, comment here, so we kill the 1.14.1 back-port PR

@ioannisg ioannisg merged commit a6067a3 into zephyrproject-rtos:master Sep 3, 2019
@pabigot pabigot deleted the nordic/20190828b branch September 6, 2019 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: API Changes to public APIs area: Kernel block: HW Test Testing on hardware required before merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

k_uptime_get_32() does not behave as documented
6 participants