Mateusz Jończyk fc04b2ccf0 x86/rtc: Rewrite & simplify mach_get_cmos_time() by deleting duplicated functionality
There are functions in drivers/rtc/rtc-mc146818-lib.c that handle
reading from / writing to the CMOS RTC clock. mach_get_cmos_time() in
arch/x86/kernel/rtc.c did not use them and was mostly a duplicate of
mc146818_get_time(). Modify mach_get_cmos_time() to use
mc146818_get_time() and remove the duplicated functionality.

mach_get_cmos_time() used a different algorithm than
mc146818_get_time(), but these functions are equivalent. The major
differences are:

- mc146818_get_time() is better refined and handles various edge
  conditions,

- when the UIP ("Update in progress") bit of the RTC is set,
  mach_get_cmos_time() was busy waiting with cpu_relax() while
  mc146818_get_time() is using mdelay(1) in every loop iteration.
  (However, there is my commit merged for Linux 5.20 / 6.0 to decrease
  this period to 100us:
    commit d2a632a8a117 ("rtc: mc146818-lib: reduce RTC_UIP polling period")
  ),

- mach_get_cmos_time() assumed that the RTC year is >= 2000, which
  may not be true on some old boxes with a dead battery,

- mach_get_cmos_time() was holding the rtc_lock for a long time
  and could hang if the RTC is broken or not present.

The RTC writing counterpart, mach_set_rtc_mmss() is already using
mc146818_get_time() from drivers/rtc. This was done in
        commit 3195ef59cb42 ("x86: Do full rtc synchronization with ntp")
It appears that mach_get_cmos_time() was simply forgotten.

mach_get_cmos_time() is really used only in read_persistent_clock64(),
which is called only in a few places in kernel/time/timekeeping.c .

[ mingo: These changes are not supposed to change behavior, but they are
         not identity transformations either, as mc146818_get_time() is a
	 better but different implementation of the same logic - so
	 regressions are possible in principle. ]

Signed-off-by: Mateusz Jończyk <mat.jonczyk@o2.pl>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20220813131034.768527-1-mat.jonczyk@o2.pl
2022-08-14 11:24:08 +02:00
..
2022-03-15 10:32:40 +01:00
2021-11-02 22:22:13 -07:00
2022-02-25 09:36:05 +01:00
2022-04-19 17:14:09 -07:00
2022-08-05 09:41:12 -07:00
2022-07-01 11:11:34 +02:00
2022-06-27 10:34:00 +02:00
2022-04-07 08:27:51 -07:00
2022-08-02 15:21:18 -07:00
2021-03-18 15:31:53 +01:00
2022-06-20 06:22:04 -04:00
2022-03-15 10:32:36 +01:00
2021-12-01 00:06:43 +01:00
2022-04-14 14:09:43 +02:00
2021-03-18 15:31:53 +01:00
2022-05-19 19:30:31 +02:00
2022-04-14 14:09:43 +02:00
2022-02-25 09:36:05 +01:00
2021-10-25 23:02:36 -04:00
2022-04-14 14:09:43 +02:00