diff options
author | Chris MacGregor | 2014-02-27 19:40:59 +0100 |
---|---|---|
committer | Karel Zak | 2014-03-05 12:42:00 +0100 |
commit | 4a44a54b3caf77923f0e3f1d5bdf5eda6ef07f62 (patch) | |
tree | 993033408cc8e3b7e45bece638444b66c935227d /tools | |
parent | libmount: define BTRFS_TEST_MAGIC if missing (diff) | |
download | kernel-qcow2-util-linux-4a44a54b3caf77923f0e3f1d5bdf5eda6ef07f62.tar.gz kernel-qcow2-util-linux-4a44a54b3caf77923f0e3f1d5bdf5eda6ef07f62.tar.xz kernel-qcow2-util-linux-4a44a54b3caf77923f0e3f1d5bdf5eda6ef07f62.zip |
hwclock: fix possible hang and other set_hardware_clock_exact() issues
In sys-utils/hwclock.c, set_hardware_clock_exact() has some problems when the
process gets pre-empted (for more than 100ms) before reaching the time for
which it waits:
1. The "continue" statement causes execution to skip the final tdiff
assignment at the end of the do...while loop, leading to the while condition
using the wrong value of tdiff, and thus always exiting the loop once
newhwtime != sethwtime (e.g., after 1 second). This masks bug # 2, below.
2. The previously-existing bug is that because it starts over waiting for the
desired time whenever two successive calls to gettimeofday() return values >
100ms apart, the loop will never terminate unless the process holds the CPU
(without losing it for more than 100ms) for at least 500ms. This can happen
on a heavily loaded machine or on a virtual machine (or on a heavily loaded
virtual machine). This has been observed to occur, preventing a machine from
completing the shutdown or reboot process due to a "hwclock --systohc" call in
a shutdown script.
The new implementation presented in this patch takes a somewhat different
approach, intended to accomplish the same goals:
It computes the desired target system time (at which the requested hardware
clock time will be applied to the hardware clock), and waits for that time to
arrive. If it misses the time (such as due to being pre-empted for too long),
it recalculates the target time, and increases the tolerance (how late it can
be relative to the target time, and still be "close enough". Thus, if all is
well, the time will be set *very* precisely. On a machine where the hwclock
process is repeatedly pre-empted, it will set the time as precisely as is
possible under the conditions present on that particular machine. In any
case, it will always terminate eventually (and pretty quickly); it will never
hang forever.
[kzak@redhat.com: - tiny coding style changes]
Signed-off-by: Chris MacGregor <chrismacgregor@google.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'tools')
0 files changed, 0 insertions, 0 deletions