devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Daniel Kurtz <djkurtz@chromium.org>
Cc: "linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"open list:OPEN FIRMWARE AND..." <devicetree@vger.kernel.org>,
	Kevin Hilman <khilman@kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	linux-mediatek@lists.infradead.org,
	Sasha Hauer <kernel@pengutronix.de>,
	Matthias Brugger <matthias.bgg@gmail.com>
Subject: Re: [PATCH 1/5] soc: mediatek: Add infracfg misc driver support
Date: Tue, 19 May 2015 09:45:35 +0200	[thread overview]
Message-ID: <20150519074535.GY6325@pengutronix.de> (raw)
In-Reply-To: <CAGS+omD-0bPeQqau9mm4pTqOhtPW=ecR5ibB8==pifRMgSKrjg@mail.gmail.com>

On Tue, May 19, 2015 at 02:54:41PM +0800, Daniel Kurtz wrote:
> >> > +       while (1) {
> >> > +               ret = regmap_read(infracfg, INFRA_TOPAXI_PROTECTSTA1, &val);
> >> > +               if (ret)
> >> > +                       return ret;
> >> > +
> >> > +               if ((val & mask) == mask)
> >> > +                       break;
> >> > +
> >> > +               cpu_relax();
> >> > +               if (time_after(jiffies, expired))
> >> > +                       return -EIO;
> >>
> >> I think we should check for timeout first, and then cpu_relax() if
> >> there is still time left (here and in
> >> mtk_infracfg_clear_bus_protection()).  Otherwise we end up doing one
> >> final cpu_relax() without rechecking the register we are polling
> >> (again, I have the same comment for the timeout loops in mtk-scpsys).
> >
> > I think cpu_relax() delays execution in the order of microseconds (I
> > don't actually know, just a guess), so if the timeout is a second the
> > order doesn't really matter. What can happen though is an interrupt
> > after the (val & mask) test but before the timeout check. So to be
> > truly correct we have to repeat the (val & mask) test after the
> > time_after() check. Is that what you want?
> 
> I'm not following, why would you need to repeat (val & mask) test
> after time_after?
> What does an interrupt have to do with it?
> Can you show a code snippet with what exactly you are proposing?

Consider you have this timeout loop:

	while (1) {
		if (success())
			break;

		if (time_after(jiffies, expired))
			return -ETIMEDOUT;
	}

Now when an interupt comes in between success() and time_after() then it
can happen that the delay caused by the interrupt makes the code timeout
even though success() might have become true in the meantime. So to be
correct you have to:

	while (1) {
		if (success())
			break;

		if (time_after(jiffies, expired)) {
			if (success())
				break;
			return -ETIMEDOUT;
	}

Or, if you don't want to repeat the termination condition:

	bool timeout = false;

	while (1) {
		if (success())
			break;

		if (timeout)
			return -ETIMEDOUT;

		if (time_after(jiffies, expired))
			timeout = true;
	}

Anyway, with the timeout of one second used here this is all academic.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

  reply	other threads:[~2015-05-19  7:45 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-11 19:23 [PATCH v2] Mediatek SCPSYS power domain support Sascha Hauer
     [not found] ` <1431372206-1237-1-git-send-email-s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2015-05-11 19:23   ` [PATCH 1/5] soc: mediatek: Add infracfg misc driver support Sascha Hauer
2015-05-12  7:12     ` Sascha Hauer
     [not found]     ` <1431372206-1237-2-git-send-email-s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2015-05-12  9:24       ` Paul Bolle
2015-05-12 13:26         ` Sascha Hauer
2015-05-15 14:17     ` Daniel Kurtz
     [not found]       ` <CAGS+omADXpnBnLvuH+xNmatL+89kLBELz6KqMFid7SOx=veiAg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-05-18  8:16         ` Sascha Hauer
2015-05-19  6:54           ` Daniel Kurtz
2015-05-19  7:45             ` Sascha Hauer [this message]
     [not found]               ` <20150519074535.GY6325-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2015-05-19 10:39                 ` Daniel Kurtz
2015-05-26 23:12     ` Kevin Hilman
     [not found]       ` <7hfv6jorw9.fsf-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>
2015-05-27  7:33         ` Sascha Hauer
2015-05-11 19:23   ` [PATCH 2/5] dt-bindings: soc: Add documentation for the MediaTek SCPSYS unit Sascha Hauer
2015-05-11 19:23 ` [PATCH 3/5] soc: Mediatek: Add SCPSYS power domain driver Sascha Hauer
2015-05-12 11:52   ` Matthias Brugger
2015-05-12 13:47     ` Sascha Hauer
2015-05-15 14:17   ` Daniel Kurtz
     [not found]     ` <CAGS+omDJ-7+L_46vwMyewHMkMNj69odhp=JY5i6Xj3-Loe6UNA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-05-19 10:30       ` Sascha Hauer
2015-05-19 11:06         ` Matthias Brugger
2015-05-20 14:03           ` Sascha Hauer
2015-05-20 16:06             ` Matthias Brugger
2015-05-11 19:23 ` [PATCH 4/5] ARM64: MediaTek: Add generic pm domain support Sascha Hauer
2015-05-11 19:23 ` [PATCH 5/5] ARM64: MediaTek MT8173: Add SCPSYS device node Sascha Hauer
  -- strict thread matches above, loose matches on Subject: below --
2015-05-20 14:18 [PATCH v3] Mediatek SCPSYS power domain support Sascha Hauer
     [not found] ` <1432131540-2523-1-git-send-email-s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2015-05-20 14:18   ` [PATCH 1/5] soc: mediatek: Add infracfg misc driver support Sascha Hauer
     [not found]     ` <1432131540-2523-2-git-send-email-s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2015-05-21  8:09       ` Paul Bolle
2015-06-09  8:46 [PATCH v4] Mediatek SCPSYS power domain support Sascha Hauer
     [not found] ` <1433839623-10804-1-git-send-email-s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2015-06-09  8:46   ` [PATCH 1/5] soc: mediatek: Add infracfg misc driver support Sascha Hauer

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=20150519074535.GY6325@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=devicetree@vger.kernel.org \
    --cc=djkurtz@chromium.org \
    --cc=kernel@pengutronix.de \
    --cc=khilman@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).