From: Alexandre Belloni <alexandre.belloni@free-electrons.com>
To: Huang Adrian <adrianhuang0701@gmail.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>,
rtc-linux@googlegroups.com, Brecht Machiels <brecht@mos6581.org>,
Thomas Gleixner <tglx@linutronix.de>,
John Stultz <john.stultz@linaro.org>,
Rabin Vincent <rabin.vincent@stericsson.com>,
Borislav Petkov <bp@suse.de>,
Nagananda Chumbalkar <nchumbalkar@lenovo.com>,
Adrian Huang <ahuang12@lenovo.com>
Subject: [rtc-linux] Re: [RFC PATCH 2/2] rtc: Restore the RTC alarm time to the configured alarm time in BIOS Setup
Date: Fri, 22 May 2015 12:04:33 +0200 [thread overview]
Message-ID: <20150522100433.GK3244@piout.net> (raw)
In-Reply-To: <CAHKZfL2+PKCzYcmL-XHC-33aXQ0hjZqOYLbbgN8O0sTvOFTj0A@mail.gmail.com>
Hi,
On 20/05/2015 at 12:30:27 +0800, Huang Adrian wrote :
> >
> > Actually, I'm not sure that solves your issue. From what I
> > understand, what is happening in step 4 is the bug you want to work
> > around and it happens because AF gets set even if AIE is not set.
> >
>
> Yes.
>
> > So, your rtc_alarm_restore() basically calls cmos_set_alarm() which
> > calls cmos_irq_disable() finally this one calls cmos_checkintr() which
> > does read register C and so clears AF.
> >
>
> The call path is correct. cmos_checkintr() did clear interrupt flags. But,
> the problem is that AF is set in the next one second.
>
> Assume 'n' is the current time.
>
> 1) The call path is finished at 'n' (current time). It clears the
> interrupt flags.
> 2) At n + 1, AF is set because the HW alarm time is programmed at n +1.
>
> This leads to the problem.
>
> > What I'm not sure is why cmos_do_shutdown() isn't clearing AF properly.
> > Is it correctly called at shutdown?
> >
>
> The function cmos_pnp_shutdown() simply returns because
> cmos_poweroff() always returns 0 (CONFIG_PM and CONFIG_PNP are
> set). The cmos_do_shutdown() is not invoked at shutdown. We did not
> get a chance to clear interrupt flag. Here is the callpath:
>
> kernel_restart_prepare() -> device_shutdown() -> cmos_pnp_shutdown()
>
> [Experiment 1 - SLES11 SP3 with upstream kernel (without my patch)]
> The revised code in cmos_pnp_shutdown() is shown as follows. It
> ensures that cmos_do_shutdown() is invoked, which gets the last chance
> to clear the interrupt flag before powering off the machine.
>
> #if 0
> if (system_state == SYSTEM_POWER_OFF && !cmos_poweroff(dev))
> return;
> #endif
> cmos_poweroff(dev);
>
>
> The issue can be still reproduced. This implies that the time cost
> between hwclock and cmos_do_shutdown() is within one second.
> So, AF is not set yet.
>
> [Experiment 2 - SLES11 SP3 with upstream kernel (without my patch)]
> Still apply the code snippet in Experiment 1. The system stayed
> power off when I intentionally added 'sleep 3' command in the end of
> the 'stop' service of /etc/init.d/boot.clock (This script uses the
> hwclock utility to set hardware clock
> to the current system time). This proves that cmos_do_shutdown()
> clears AF generated by RTC HW.
>
> The system always stayed power off with 10-time shutdown tests.
>
> [Experiment 3 - SLES11 SP3 with upstream kernel (without my patch)]
> Do not apply the code snippet in Experiment 1. Also added 'sleep 3'
> command in the end of the 'stop' service of /etc/init.d/boot.clock.
> The issue can be reproduced. This proves that cmos_pnp_shutdown()
> simply returns without invoking cmos_do_shutdown(). So, AF is not
> cleared.
>
> Experiments 1-3 show that the issue happens if the time cost
> between hwclock and cmos_do_shutdown() is within one second.
> If we want to clear the interrupt flag for every shutdown, we need
> to re-write the cmos_pnp_shutdown() to ensure the
> cmos_do_shutdown() is invoke for every shutdown.
>
> Although my patch can work around the issue, kindly let me know
> if you want to re-work cmos_pnp_shutdown(). We can come out a
> better way to invoke cmos_do_shutdown() for every shutdown. But,
> be remember, the issue still happens even though we make sure
> cmos_do_shutdown() is invoked for every shutdown. The problem
> is the one second interval.
>
That's what I understood. How I see it is the following: your patch is
reading and setting the alarm then clearing AF at a later point in the
shutdown. This may as well be before that one second has elapsed so I
don't feel this is a proper fix. Also, other RTCs don't suffer from that
issue and this may actually break some of them.
What I would do is ensure that AF gets cleared in cmos_do_shutdown()
after setting the alarm to now or now - 1 when it is not used for
wakeup/restart.
Regards,
--
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
--
--
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
next prev parent reply other threads:[~2015-05-22 10:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-08 9:35 [rtc-linux] [RFC PATCH 2/2] rtc: Restore the RTC alarm time to the configured alarm time in BIOS Setup Adrian Huang
2015-05-18 22:05 ` [rtc-linux] " Alexandre Belloni
2015-05-20 4:30 ` Huang Adrian
2015-05-22 10:04 ` Alexandre Belloni [this message]
2015-05-28 11:16 ` Huang Adrian
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=20150522100433.GK3244@piout.net \
--to=alexandre.belloni@free-electrons.com \
--cc=a.zummo@towertech.it \
--cc=adrianhuang0701@gmail.com \
--cc=ahuang12@lenovo.com \
--cc=bp@suse.de \
--cc=brecht@mos6581.org \
--cc=john.stultz@linaro.org \
--cc=nchumbalkar@lenovo.com \
--cc=rabin.vincent@stericsson.com \
--cc=rtc-linux@googlegroups.com \
--cc=tglx@linutronix.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox