All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: "Mateusz Jończyk" <mat.jonczyk@o2.pl>
Cc: linux-kernel@vger.kernel.org, linux-rtc@vger.kernel.org,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	Alessandro Zummo <a.zummo@towertech.it>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>
Subject: Re: [PATCH v4 1/2] x86/rtc: rewrite mach_get_cmos_time to delete duplicated code
Date: Sun, 14 Aug 2022 11:25:14 +0200	[thread overview]
Message-ID: <Yvi/eq7/IPsUAGVc@gmail.com> (raw)
In-Reply-To: <20220813131034.768527-1-mat.jonczyk@o2.pl>


* Mateusz Jończyk <mat.jonczyk@o2.pl> wrote:

> 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 code.
> 
> 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 .

LGTM, I've added the following background to the commit description:

   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.

Queued up both patches in tip:x86/timers and will push it out after 
testing.

Thanks!

	Ingo

  parent reply	other threads:[~2022-08-14  9:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-13 13:10 [PATCH v4 1/2] x86/rtc: rewrite mach_get_cmos_time to delete duplicated code Mateusz Jończyk
2022-08-13 13:10 ` [PATCH v4 2/2] x86/rtc: rename mach_set_rtc_mmss Mateusz Jończyk
2022-08-15  8:49   ` [tip: x86/timers] x86/rtc: Rename mach_set_rtc_mmss() to mach_set_cmos_time() tip-bot2 for Mateusz Jończyk
2022-08-14  9:25 ` Ingo Molnar [this message]
2022-08-15  8:49 ` [tip: x86/timers] x86/rtc: Rewrite & simplify mach_get_cmos_time() by deleting duplicated functionality tip-bot2 for Mateusz Jończyk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Yvi/eq7/IPsUAGVc@gmail.com \
    --to=mingo@kernel.org \
    --cc=a.zummo@towertech.it \
    --cc=alexandre.belloni@bootlin.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=mat.jonczyk@o2.pl \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.