zephyr/lib/posix
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
..
clock.c posix: Fix calculation of clock base in clock_settime 2019-05-21 08:24:59 -04:00
CMakeLists.txt
fs.c
Kconfig lib/posix: correct the meaning of CONFIG_MAX_PTHREAD_COUNT 2019-05-11 08:24:36 -04:00
mqueue.c
pthread_barrier.c
pthread_common.c
pthread_cond.c
pthread_key.c
pthread_mutex.c
pthread_rwlock.c
pthread_sched.c
pthread.c lib/posix: correct the meaning of CONFIG_MAX_PTHREAD_COUNT 2019-05-11 08:24:36 -04:00
semaphore.c
sleep.c
timer.c