zephyr/lib
Alexander Mihajlovic f19787bb84 posix: Fix calculation of clock base in clock_settime
Previous version calculated rt_clock_base incorrectly by subtracting
clock_gettime from the specified time. Effectively the following
formula was used.

    rt_clock_base := new_time - clock_gettime()

This is clearly incorrect when we consider what should happen if we
call clock_settime with the result of clock_gettime. It ought to be
approximately a no-op, but instead we end up zeroing the clock.

    rt_clock_base := clock_gettime() - clock_gettime() = 0

This patch fixes clock_settime by instead using k_uptime_get to
calculate rt_clock_base, like so:

    rt_clock_base := new_time - k_uptime_get()

Trying the earlier thought experiment we get:

    rt_clock_base := clock_gettime() - k_uptime_get()

Using the definition of clock_gettime this expands to:

    rt_clock_base := (rt_clock_base + k_uptime_get()) - k_uptime_get()

The two k_uptime_get() terms cancel out, leaving:

    rt_clock_base := rt_clock_base

I.e. the no-op that we expect when calling clock_settime with
the result of clock_gettime.

Note: The bug is only observable when rt_clock_base is non-zero.
So when clock_settime is called for the first time, it will appear
to work correctly since rt_clock_base is initialized to 0.

Signed-off-by: Alexander Mihajlovic <alexander.mihajlovic@endian.se>
2019-05-21 08:24:59 -04:00
..
cmsis_rtos_v1 lib: cmsis_v1: set stack size larger if coverage 2019-05-02 15:42:33 -04:00
cmsis_rtos_v2 lib: cmsis_v2: increase stack sizes if coverage 2019-05-02 15:42:33 -04:00
gui license: cleanup: add SPDX Apache-2.0 license identifier 2019-04-07 08:45:22 -04:00
libc Build: Build with newlib-nano c library 2019-05-15 10:46:44 -05:00
os license: cleanup: add SPDX Apache-2.0 license identifier 2019-04-07 08:45:22 -04:00
posix posix: Fix calculation of clock base in clock_settime 2019-05-21 08:24:59 -04:00
CMakeLists.txt license: cleanup: add SPDX Apache-2.0 license identifier 2019-04-07 08:45:22 -04:00
Kconfig lib: flatten all loose components into one lib 2019-01-22 07:45:22 -05:00