Skip to content

posix: clock: current method of capturing elapsed time leads to loss in seconds #52975

@cfriedt

Description

@cfriedt

Describe the bug
Although it is a boundary, before the 64-bit tick counter rolls-over, the value of the monotonic clock (seconds field) should equal UINT64_MAX / CONFIG_SYS_CLOCK_TICKS_PER_SEC (integer division).

Currently, it seems to be off by an order of magnitude (test case provided in PR).

Please also mention any information which could help others to understand
the problem you're facing
:

  • What target platform are you using? all
  • What have you tried to diagnose or workaround this issue? written a test case
  • Is this a regression? If yes, have you been able to "git bisect" it to a
    specific commit?
    No

To Reproduce
Steps to reproduce the behavior:

  1. apply changes in referenced PR
  2. un-apply changes to lib/posix/clock.c
  3. west build -p auto -b qemu_x86_64 -t run tests/posix/common
  4. See error

Expected behavior

*** Booting Zephyr OS build zephyr-v3.2.0-2459-gdffb02fd134e ***
Running TESTSUITE posix_apis
===================================================================
START - test_clock_gettime_rollover
CONFIG_SYS_CLOCK_TICKS_PER_SEC: 100
rollover_s: 184467440737095516
t-1: {184467440737095516, 140000000}
t+0: {184467440737095516, 150000000}
t+1: {0, 0}
 PASS - test_clock_gettime_rollover in 0.063 seconds
 ===================================================================

Impact
That really depends on the application. It can be an annoyance for some but a showstopper for others.

Logs and console output

*** Booting Zephyr OS build zephyr-v3.2.0-2459-gdffb02fd134e ***
Running TESTSUITE posix_apis
===================================================================
START - test_clock_gettime_rollover
CONFIG_SYS_CLOCK_TICKS_PER_SEC: 100
rollover_s: 184467440737095516
t-1: {18446744073709551, 596000000}

    Assertion failed at WEST_TOPDIR/zephyr/tests/posix/common/src/clock.c:169: posix_apis_test_clock_gettime_rollover: rollover_s not equal to ts[0].tv_sec

 FAIL - test_clock_gettime_rollover in 0.025 seconds
 ===================================================================

Environment (please complete the following information):

  • OS: (e.g. Linux, MacOS, Windows): any
  • Toolchain (e.g Zephyr SDK, ...): Zephyr SDK 0.15.2
  • Commit SHA or Version used: bba9fc9

Additional context
This issue was encountered while writing tests to verify the fixes in

Metadata

Metadata

Assignees

Labels

area: POSIXPOSIX API LibrarybugThe issue is a bug, or the PR is fixing a bugpriority: mediumMedium impact/importance bug

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions