Timekeeping: Fix dead lock in update_wall_time by correct shift convertion.
PATCH 1/1 Timekeeping: Fix dead lock in update_wall_time by correct shift convertion.
update_wall_time() runs into dead lock after kernel traps into kgdb and exits per user's request some seconds layer. This is root caused to be wrong calculation of maxshift in update_wall_time().
The shift in update_wall_time() and logarithmic_accumulation() is clock shift. In order to generate ntp_error and maxshift correctly, shift convertion between clock and ntp should be done properly.
Signed-off-by Sonic Zhang <[email protected]>
--- kernel/time/timekeeping.c | 20 ++++++++++++++------ 1 files changed, 14 insertions(+), 6 deletions(-)
kernel/time/timekeeping.c +0 -0
@@ -770,10 +770,14 @@ static cycle_t logarithmic_accumulation(cycle_t
offset, int shift)
raw_time.tv_sec++;
}- /* Accumulate error between NTP and clock interval */ - timekeeper.ntp_error += tick_length << shift; - timekeeper.ntp_error -= timekeeper.xtime_interval << - (timekeeper.ntp_error_shift + shift); + /* + * Accumulate error between NTP and clock interval. + * Paramter shift is clock shift. It should minus shift + * conversion between clock and ntp to generate ntp shift. + */
+ timekeeper.ntp_error += tick_length <<
+ (shift - timekeeper.ntp_error_shift);
+ timekeeper.ntp_error -= timekeeper.xtime_interval << shift;
return offset;
}
@@ -813,8 +817,12 @@ void update_wall_time(void)
*/
shift = ilog2(offset) - ilog2(timekeeper.cycle_interval);
shift = max(0, shift);
- /* Bound shift to one less then what overflows tick_length */
- maxshift = (8*sizeof(tick_length) - (ilog2(tick_length)+1)) - 1;
+ /*
+ * Bound shift to one less then what overflows tick_length.
+ * Should plus shift conversion between clock and ntp.
+ */
+ maxshift = (8*sizeof(tick_length) - (ilog2(tick_length)+1)) - 1
+ + timekeeper.ntp_error_shift;
shift = min(shift, maxshift);
while (offset >= timekeeper.cycle_interval) {
offset = logarithmic_accumulation(offset, shift);Signature · 1 line
1.6.0