Linux Power Management development
 help / color / mirror / Atom feed
From: "Arnd Bergmann" <arnd@arndb.de>
To: "Geert Uytterhoeven" <geert+renesas@glider.be>,
	"Stephen Boyd" <sboyd@kernel.org>,
	"Tomasz Figa" <tomasz.figa@gmail.com>,
	"Sylwester Nawrocki" <s.nawrocki@samsung.com>,
	"Will Deacon" <will@kernel.org>,
	"Wolfram Sang" <wsa+renesas@sang-engineering.com>,
	"Dejin Zheng" <zhengdejin5@gmail.com>,
	"Kai-Heng Feng" <kai.heng.feng@canonical.com>,
	"Nicholas Piggin" <npiggin@gmail.com>,
	"Heiko Carstens" <hca@linux.ibm.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Russell King" <linux@armlinux.org.uk>,
	"John Stultz" <jstultz@google.com>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Tony Lindgren" <tony@atomide.com>,
	"Krzysztof Kozlowski" <krzk@kernel.org>,
	"Tero Kristo" <tero.kristo@linux.intel.com>,
	"Ulf Hansson" <ulf.hansson@linaro.org>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	"Vincent Guittot" <vincent.guittot@linaro.org>
Cc: linux-arm-kernel@lists.infradead.org,
	Linux-Renesas <linux-renesas-soc@vger.kernel.org>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] iopoll: Do not use timekeeping in read_poll_timeout_atomic()
Date: Wed, 10 May 2023 15:35:32 +0200	[thread overview]
Message-ID: <02ce0541-08cf-4e14-a9b1-c53efea85178@app.fastmail.com> (raw)
In-Reply-To: <8db63020d18fc22e137e4a8f0aa15e6b9949a6f6.1683722688.git.geert+renesas@glider.be>

On Wed, May 10, 2023, at 15:23, Geert Uytterhoeven wrote:
> read_poll_timeout_atomic() uses ktime_get() to implement the timeout
> feature, just like its non-atomic counterpart.  However, there are
> several issues with this, due to its use in atomic contexts:
>
>   1. When called in the s2ram path (as typically done by clock or PM
>      domain drivers), timekeeping may be suspended, triggering the
>      WARN_ON(timekeeping_suspended) in ktime_get():
>
> 	WARNING: CPU: 0 PID: 654 at kernel/time/timekeeping.c:843 ktime_get+0x28/0x78
>
>      Calling ktime_get_mono_fast_ns() instead of ktime_get() would get
>      rid of that warning.  However, that would break timeout handling,
>      as (at least on systems with an ARM architectured timer), the time
>      returned by ktime_get_mono_fast_ns() does not advance while
>      timekeeping is suspended.
>      Interestingly, (on the same ARM systems) the time returned by
>      ktime_get() does advance while timekeeping is suspended, despite
>      the warning.
>
>   2. Depending on the actual clock source, and especially before a
>      high-resolution clocksource (e.g. the ARM architectured timer)
>      becomes available, time may not advance in atomic contexts, thus
>      breaking timeout handling.
>
> Fix this by abandoning the idea that one can rely on timekeeping to
> implement timeout handling in all atomic contexts, and switch from a
> global time-based to a locally-estimated timeout handling.  In most
> (all?) cases the timeout condition is exceptional and an error
> condition, hence any additional delays due to underestimating wall clock
> time are irrelevant.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

This looks reasonable to me,

Acked-by: Arnd Bergmann <arnd@arndb.de>

I assume you sent this because you ran into the bug on a
particular driver. It might help to be more specific about
how this can be reproduced.

> ---
> Alternatively, one could use a mixed approach (use both
> ktime_get_mono_fast_ns() and a local (under)estimate, and timeout on the
> earliest occasion), but I think that would complicate things without
> much gain.

Agreed.

     Arnd

  reply	other threads:[~2023-05-10 13:36 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-10 13:23 [PATCH v2 0/2] iopoll: Busy loop and timeout improvements Geert Uytterhoeven
2023-05-10 13:23 ` [PATCH v2 1/2] iopoll: Call cpu_relax() in busy loops Geert Uytterhoeven
2023-05-11  6:48   ` Tony Lindgren
2023-05-11 10:48     ` David Laight
2023-05-23  7:29       ` Geert Uytterhoeven
2023-05-23  8:55         ` David Laight
2023-05-11  9:48   ` Ulf Hansson
2023-05-10 13:23 ` [PATCH v2 2/2] iopoll: Do not use timekeeping in read_poll_timeout_atomic() Geert Uytterhoeven
2023-05-10 13:35   ` Arnd Bergmann [this message]
2023-05-10 13:46     ` Geert Uytterhoeven
2023-05-10 13:56       ` Arnd Bergmann
2023-05-11  6:48   ` Tony Lindgren
2023-05-11 10:26   ` Ulf Hansson
2023-05-11 12:44     ` Geert Uytterhoeven
2023-05-12  7:53       ` Ulf Hansson
2023-05-12  8:03         ` Geert Uytterhoeven
2023-05-15  9:26           ` Ulf Hansson

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=02ce0541-08cf-4e14-a9b1-c53efea85178@app.fastmail.com \
    --to=arnd@arndb.de \
    --cc=geert+renesas@glider.be \
    --cc=hca@linux.ibm.com \
    --cc=jstultz@google.com \
    --cc=kai.heng.feng@canonical.com \
    --cc=krzk@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=npiggin@gmail.com \
    --cc=peterz@infradead.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=s.nawrocki@samsung.com \
    --cc=sboyd@kernel.org \
    --cc=tero.kristo@linux.intel.com \
    --cc=tglx@linutronix.de \
    --cc=tomasz.figa@gmail.com \
    --cc=tony@atomide.com \
    --cc=ulf.hansson@linaro.org \
    --cc=vincent.guittot@linaro.org \
    --cc=will@kernel.org \
    --cc=wsa+renesas@sang-engineering.com \
    --cc=zhengdejin5@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