2022-05-18 03:52:57

by Mateusz Jończyk

[permalink] [raw]
Subject: [PATCH v2 resend 0/2] x86/rtc: refactoring

Hello,

The first and main patch of this series removes duplicated code in
mach_get_cmos_time() in arch/x86/kernel/rtc.c . This function performed
the same thing as mc146818_get_time() - reading the time from the CMOS
RTC - but used a different algorithm. So modify it to use common
mc146818_get_time().

The second patch renames a function in arch/x86/kernel/rtc.c.

Tested originally (on top of 5.18-rc3) on 3 computers, and in i386 and
amd64 VMs.

Greetings,
Mateusz

v2:
- drop the previously first patch ("rtc-mc146818-lib: reduce RTC_UIP
polling period"). Its intent was to make behaviour of
mc146818_get_time() more similar to the existing version of
mach_get_cmos_time() by decreasing the polling period in
mc146818_get_time(). However, I determined that this does not matter
for users of mach_get_cmos_time().

- use pr_err instead of pr_err_ratelimited in the first remaining
patch,

- small patch description modifications.

Signed-off-by: Mateusz Jończyk <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: [email protected]
Cc: "H. Peter Anvin" <[email protected]>
Cc: Alessandro Zummo <[email protected]>
Cc: Alexandre Belloni <[email protected]>

Mateusz Jończyk (2):
x86/rtc: rewrite mach_get_cmos_time to delete duplicated code
x86/rtc: rename mach_set_rtc_mmss

arch/x86/include/asm/mc146818rtc.h | 2 +-
arch/x86/kernel/rtc.c | 63 +++++-------------------------
arch/x86/kernel/x86_init.c | 2 +-
3 files changed, 11 insertions(+), 56 deletions(-)


base-commit: 42226c989789d8da4af1de0c31070c96726d990c
--
2.25.1



2022-05-18 04:34:07

by Mateusz Jończyk

[permalink] [raw]
Subject: [PATCH v2 resend 2/2] x86/rtc: rename mach_set_rtc_mmss

Once upon a time, before
commit 3195ef59cb42 ("x86: Do full rtc synchronization with ntp")
in 2013, the function set only the minute and seconds registers
of the CMOS RTC. This is no longer true, so rename the function to
mach_set_cmos_time.

Signed-off-by: Mateusz Jończyk <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: [email protected]
Cc: "H. Peter Anvin" <[email protected]>
---
arch/x86/include/asm/mc146818rtc.h | 2 +-
arch/x86/kernel/rtc.c | 4 ++--
arch/x86/kernel/x86_init.c | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/include/asm/mc146818rtc.h b/arch/x86/include/asm/mc146818rtc.h
index 97198001e567..6115bb3d5795 100644
--- a/arch/x86/include/asm/mc146818rtc.h
+++ b/arch/x86/include/asm/mc146818rtc.h
@@ -95,7 +95,7 @@ static inline unsigned char current_lock_cmos_reg(void)
unsigned char rtc_cmos_read(unsigned char addr);
void rtc_cmos_write(unsigned char val, unsigned char addr);

-extern int mach_set_rtc_mmss(const struct timespec64 *now);
+extern int mach_set_cmos_time(const struct timespec64 *now);
extern void mach_get_cmos_time(struct timespec64 *now);

#define RTC_IRQ 8
diff --git a/arch/x86/kernel/rtc.c b/arch/x86/kernel/rtc.c
index 1cadc8a15267..349046434513 100644
--- a/arch/x86/kernel/rtc.c
+++ b/arch/x86/kernel/rtc.c
@@ -27,13 +27,13 @@ DEFINE_SPINLOCK(rtc_lock);
EXPORT_SYMBOL(rtc_lock);

/*
- * In order to set the CMOS clock precisely, set_rtc_mmss has to be
+ * In order to set the CMOS clock precisely, mach_set_cmos_time has to be
* called 500 ms after the second nowtime has started, because when
* nowtime is written into the registers of the CMOS clock, it will
* jump to the next second precisely 500 ms later. Check the Motorola
* MC146818A or Dallas DS12887 data sheet for details.
*/
-int mach_set_rtc_mmss(const struct timespec64 *now)
+int mach_set_cmos_time(const struct timespec64 *now)
{
unsigned long long nowtime = now->tv_sec;
struct rtc_time tm;
diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
index e84ee5cdbd8c..57353519bc11 100644
--- a/arch/x86/kernel/x86_init.c
+++ b/arch/x86/kernel/x86_init.c
@@ -138,7 +138,7 @@ struct x86_platform_ops x86_platform __ro_after_init = {
.calibrate_cpu = native_calibrate_cpu_early,
.calibrate_tsc = native_calibrate_tsc,
.get_wallclock = mach_get_cmos_time,
- .set_wallclock = mach_set_rtc_mmss,
+ .set_wallclock = mach_set_cmos_time,
.iommu_shutdown = iommu_shutdown_noop,
.is_untracked_pat_range = is_ISA_range,
.nmi_init = default_nmi_init,
--
2.25.1