From 845253af3a59494bb070cd7af999dd4c3f4738fc Mon Sep 17 00:00:00 2001 From: Christian Helmuth Date: Wed, 30 Jan 2019 14:05:09 +0100 Subject: [PATCH] dde_linux: prevent truncation in update_jiffies() Before, jiffies wrapped after 2**32 microseconds (71.5 minutes) to 0. --- repos/dde_linux/src/lib/lxip/timer_handler.cc | 8 ++++++-- repos/dde_linux/src/lx_kit/timer.cc | 11 +++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/repos/dde_linux/src/lib/lxip/timer_handler.cc b/repos/dde_linux/src/lib/lxip/timer_handler.cc index fc7b21c4f..2aacb15d5 100644 --- a/repos/dde_linux/src/lib/lxip/timer_handler.cc +++ b/repos/dde_linux/src/lib/lxip/timer_handler.cc @@ -188,7 +188,7 @@ class Lx::Timer _tick(tick) { _timer_conn.sigh(_handler); - jiffies = 0; + update_jiffies(); } /** @@ -271,7 +271,11 @@ class Lx::Timer */ void update_jiffies() { - jiffies = msecs_to_jiffies(_timer_conn.elapsed_ms()); + /* + * Do not use lx_emul usecs_to_jiffies(unsigned int) because + * of implicit truncation! + */ + jiffies = _timer_conn.curr_time().trunc_to_plain_ms().value / JIFFIES_TICK_MS; } /** diff --git a/repos/dde_linux/src/lx_kit/timer.cc b/repos/dde_linux/src/lx_kit/timer.cc index a27e92b80..70be31fe2 100644 --- a/repos/dde_linux/src/lx_kit/timer.cc +++ b/repos/dde_linux/src/lx_kit/timer.cc @@ -169,6 +169,7 @@ class Lx_kit::Timer : public Lx::Timer _timer_alloc(&alloc) { _timer_conn.sigh(_dispatcher); + update_jiffies(); } Context* first() { return _list.first(); } @@ -277,8 +278,14 @@ class Lx_kit::Timer : public Lx::Timer return false; } - void update_jiffies() { - _jiffies = usecs_to_jiffies(_timer_conn_modern.curr_time().trunc_to_plain_us().value); } + void update_jiffies() + { + /* + * Do not use lx_emul usecs_to_jiffies(unsigned int) because + * of implicit truncation! + */ + _jiffies = _timer_conn_modern.curr_time().trunc_to_plain_ms().value / JIFFIES_TICK_MS; + } void usleep(unsigned us) { _timer_conn.usleep(us); }