All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: "Daniel P. Smith" <dpsmith@apertussolutions.com>,
	"Marek Marczykowski-Górecki" <marmarek@invisiblethingslab.com>,
	"Andrew Cooper" <andrew.cooper3@citrix.com>,
	xen-devel@lists.xenproject.org
Subject: Re: [PATCH v3 2/7] x86/time: move CMOS edge detection into read helper
Date: Wed, 4 Sep 2024 11:46:00 +0200	[thread overview]
Message-ID: <ZtgsWN0O8guwNSVd@macbook.local> (raw)
In-Reply-To: <5695338e-3543-4611-a6a4-0b42e0727e1d@suse.com>

On Tue, Sep 03, 2024 at 05:02:21PM +0200, Jan Beulich wrote:
> On 03.09.2024 15:02, Roger Pau Monne wrote:
> > Move the logic that ensures the CMOS RTC data is read just after it's been
> > updated into the __get_cmos_time() function that does the register reads.  This
> > requires returning a boolean from __get_cmos_time() to signal whether the read
> > has been successfully performed after an update.
> 
> Considering the limited use of both function, that's probably fine a change
> to make, despite me otherwise thinking that this is the slightly wrong move.
> I'd generally expect __get_cmos_time() to be usable without that checking,
> so long as the results are interpreted appropriately.

I've expanded the commit message a bit to reflect what you mention
here.

> > --- a/xen/arch/x86/time.c
> > +++ b/xen/arch/x86/time.c
> > @@ -1247,8 +1247,26 @@ struct rtc_time {
> >      unsigned int year, mon, day, hour, min, sec;
> >  };
> >  
> > -static void __get_cmos_time(struct rtc_time *rtc)
> > +static bool __get_cmos_time(struct rtc_time *rtc)
> >  {
> > +    s_time_t start, t1, t2;
> > +    unsigned long flags;
> > +
> > +    spin_lock_irqsave(&rtc_lock, flags);
> > +
> > +    /* read RTC exactly on falling edge of update flag */
> > +    start = NOW();
> > +    do { /* may take up to 1 second... */
> > +        t1 = NOW() - start;
> > +    } while ( !(CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP) &&
> > +              t1 <= SECONDS(1) );
> > +
> > +    start = NOW();
> > +    do { /* must try at least 2.228 ms */
> > +        t2 = NOW() - start;
> > +    } while ( (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP) &&
> > +              t2 < MILLISECS(3) );
> > +
> >      rtc->sec  = CMOS_READ(RTC_SECONDS);
> >      rtc->min  = CMOS_READ(RTC_MINUTES);
> >      rtc->hour = CMOS_READ(RTC_HOURS);
> > @@ -1268,11 +1286,15 @@ static void __get_cmos_time(struct rtc_time *rtc)
> >  
> >      if ( (rtc->year += 1900) < 1970 )
> >          rtc->year += 100;
> > +
> > +    spin_unlock_irqrestore(&rtc_lock, flags);
> 
> Imo this unlock wants placing at least ahead of the if() in context. The
> lock needs to protect only the port accesses, not any of the calculations.

I could even cache the value of CMOS_READ(RTC_CONTROL) ahead of the
check, so that the drop could be dropped earlier, but I'm not going to
do it here.

Thanks, Roger.


  reply	other threads:[~2024-09-04  9:46 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-03 13:02 [PATCH v3 0/7] x86/time: improvements to wallclock logic Roger Pau Monne
2024-09-03 13:02 ` [PATCH v3 1/7] x86/time: introduce helper to fetch Xen wallclock when running as a guest Roger Pau Monne
2024-09-03 14:48   ` Jan Beulich
2024-09-04  9:29     ` Roger Pau Monné
2024-09-03 13:02 ` [PATCH v3 2/7] x86/time: move CMOS edge detection into read helper Roger Pau Monne
2024-09-03 15:02   ` Jan Beulich
2024-09-04  9:46     ` Roger Pau Monné [this message]
2024-09-03 13:02 ` [PATCH v3 3/7] x86/time: split CMOS read and probe logic into function Roger Pau Monne
2024-09-03 15:16   ` Jan Beulich
2024-09-04 10:48     ` Roger Pau Monné
2024-09-03 13:03 ` [PATCH v3 4/7] x86/time: introduce probing logic for the wallclock Roger Pau Monne
2024-09-03 15:32   ` Jan Beulich
2024-09-04 10:58     ` Roger Pau Monné
2024-09-04 11:49       ` Jan Beulich
2024-09-04 12:30         ` Roger Pau Monné
2024-09-04 12:41           ` Jan Beulich
2024-09-03 13:03 ` [PATCH v3 5/7] x86/time: prefer CMOS over EFI_GET_TIME Roger Pau Monne
2024-09-03 13:03 ` [PATCH v3 6/7] x86/time: introduce command line option to select wallclock Roger Pau Monne
2024-09-03 15:37   ` Jan Beulich
2024-09-03 13:03 ` [PATCH v3 7/7] x86/time: probe the CMOS RTC by default Roger Pau Monne
2024-09-03 15:48   ` Jan Beulich
2024-09-04 12:45     ` Roger Pau Monné
2024-09-04 13:21       ` Jan Beulich
2024-09-03 15:38 ` [PATCH v3 0/7] x86/time: improvements to wallclock logic Jan Beulich

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=ZtgsWN0O8guwNSVd@macbook.local \
    --to=roger.pau@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=dpsmith@apertussolutions.com \
    --cc=jbeulich@suse.com \
    --cc=marmarek@invisiblethingslab.com \
    --cc=xen-devel@lists.xenproject.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.