From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Jani Nikula <jani.nikula@intel.com>
Cc: intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
Imre Deak <imre.deak@intel.com>,
Geert Uytterhoeven <geert+renesas@glider.be>,
Matt Wagantall <mattw@codeaurora.org>,
Dejin Zheng <zhengdejin5@gmail.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 18/18] drm/i915/ddi: prefer read_poll_timeout() over readx_poll_timeout()
Date: Fri, 27 Jun 2025 20:32:28 +0300 [thread overview]
Message-ID: <aF7VrBSZQVlaSN6-@intel.com> (raw)
In-Reply-To: <1b5d73351eda2d86437a597673bd892baf90fafa@intel.com>
On Fri, Jun 27, 2025 at 07:26:22PM +0300, Jani Nikula wrote:
> On Fri, 27 Jun 2025, Ville Syrjälä <ville.syrjala@linux.intel.com> wrote:
> > On Fri, Jun 27, 2025 at 04:34:23PM +0300, Jani Nikula wrote:
> >> Internally the macro has:
> >>
> >> #define read_poll_timeout(op, val, cond, sleep_us, timeout_us, \
> >> sleep_before_read, args...) \
> >>
> >> ...
> >>
> >> (val) = op(args); \
> >>
> >> So you do need to provide an lvalue val, and you need to be able to add
> >> () after op. I think GCC allows not passing varargs. IOW you'd need to
> >> implement another macro (which could be used to implement the existing
> >> one, but not the other way round).
> >
> > Just get rid of the 'args' and 'val' and it'll work just fine.
> > Then it'll be almost identical to wait_for() (basically just missing the
> > increasing backoff stuff).
> >
> > AFAICS this thing was originally added just for reading a single
> > register and checking some bit/etc, so the name made some sense.
> > But now we're abusing it for all kinds of random things, so even
> > the name no longer makes that much sense.
>
> Yeah, evolution not intelligent design.
>
> > So I think just something like this would work fine for us:
>
> LGTM, with the _atomic version for completeness.
The other differences between wait_for() and read_poll_timeout()
I see are:
- read_poll_timeout() always evaluates 'cond' at least twice.
For some things I think it would make sense to omit 'op'
entirely so we don't have to introduce pointless variables
in the caller (eg. poll_timeout(, pipe_scanline_is_moving(...), ...))
but the double evaluation of 'cond' there is not desirable.
Should be an easy change to make read_poll_timeout() more
like wait_for() and stash the return value into a variable.
- ktime_get() vs. ktime_get_raw(). I suppose it doesn't really
matter too much which is used?
- 'op' and 'cond' are evaluated twice during the same iteration of
the loop for the timeout case in read_poll_timeout(). wait_for()
is a bit more optimal here by sampling the timeout first, then
doing the 'op'+'cond', and finally checking whether the timeout
happened.
I suppose optimizing the timeout case isn't very critical. Though
the code would be a bit less repetitive, with the caveat that we
need an extra variable for the timeout result.
- wait_for() has an explicit compiler barrier to make sure 'cond'
and the timeout evaluation aren't reordered. Though I think it's
in the wrong spot for the cases where 'op' is the one that samples
the thing that 'cond' checks.
However I *think* ktime_get() being a function call should be enough
to prevent that reordering from happening?
I guess I'll see what I can cook up to make this stuff
more agreeable...
--
Ville Syrjälä
Intel
next prev parent reply other threads:[~2025-06-27 17:32 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-27 11:36 [PATCH 00/18] drm/i915/display: convert to generic read_poll_timeout() Jani Nikula
2025-06-27 11:36 ` [PATCH 01/18] drm/i915/hdmi: use generic read_poll_timeout() instead of __wait_for() Jani Nikula
2025-06-27 11:36 ` [PATCH 02/18] drm/i915/hdcp: " Jani Nikula
2025-06-29 13:39 ` Kandpal, Suraj
2025-06-27 11:36 ` [PATCH 03/18] drm/i915/dsi: use generic read_poll_timeout() instead of wait_for_us() Jani Nikula
2025-06-27 11:36 ` [PATCH 04/18] drm/i915/dsi-pll: use generic read_poll_timeout() instead of wait_for() Jani Nikula
2025-06-27 11:36 ` [PATCH 05/18] drm/i915/gmbus: use generic read_poll_timeout*() instead of wait_for*() Jani Nikula
2025-06-27 11:36 ` [PATCH 06/18] drm/i915/wm: use generic read_poll_timeout() instead of wait_for() Jani Nikula
2025-06-27 11:36 ` [PATCH 07/18] drm/i915/cdclk: " Jani Nikula
2025-06-27 11:36 ` [PATCH 08/18] drm/i915/power: " Jani Nikula
2025-06-27 11:36 ` [PATCH 09/18] drm/i915/power-well: use generic read_poll_timeout() instead of wait_for() for DKL PHY Jani Nikula
2025-06-27 11:36 ` [PATCH 10/18] drm/i915/power-well: use generic read_poll_timeout() instead of wait_for() for VLV/CHV Jani Nikula
2025-06-27 11:36 ` [PATCH 11/18] drm/i915/dp: use generic read_poll_timeout() instead of wait_for() Jani Nikula
2025-06-27 11:36 ` [PATCH 12/18] drm/i915/dp: use generic read_poll_timeout() instead of wait_for() in link training Jani Nikula
2025-06-27 11:36 ` [PATCH 13/18] drm/i915/vblank: use generic read_poll_timeout() instead of wait_for() Jani Nikula
2025-06-27 11:36 ` [PATCH 14/18] drm/i915/tc: " Jani Nikula
2025-06-27 11:36 ` [PATCH 15/18] drm/i915/dsb: " Jani Nikula
2025-06-27 11:36 ` [PATCH 16/18] drm/i915/lspcon: " Jani Nikula
2025-06-27 11:36 ` [PATCH 17/18] drm/i915/opregion: " Jani Nikula
2025-06-27 11:36 ` [PATCH 18/18] drm/i915/ddi: prefer read_poll_timeout() over readx_poll_timeout() Jani Nikula
2025-06-27 12:00 ` Imre Deak
2025-06-27 12:43 ` Jani Nikula
2025-06-27 12:53 ` Ville Syrjälä
2025-06-27 13:34 ` Jani Nikula
2025-06-27 15:40 ` Ville Syrjälä
2025-06-27 16:26 ` Jani Nikula
2025-06-27 17:32 ` Ville Syrjälä [this message]
2025-06-30 20:52 ` David Laight
2025-06-27 14:15 ` [PATCH v2] " Jani Nikula
2025-06-30 14:41 ` ✓ i915.CI.BAT: success for drm/i915/display: convert to generic read_poll_timeout() (rev2) Patchwork
2025-06-30 15:35 ` ✗ CI.checkpatch: warning " Patchwork
2025-06-30 15:36 ` ✓ CI.KUnit: success " Patchwork
2025-06-30 15:50 ` ✗ CI.checksparse: warning " Patchwork
2025-06-30 16:17 ` ✓ Xe.CI.BAT: success " Patchwork
2025-07-01 5:54 ` ✓ i915.CI.Full: " Patchwork
2025-07-01 17:57 ` ✗ Xe.CI.Full: failure " Patchwork
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=aF7VrBSZQVlaSN6-@intel.com \
--to=ville.syrjala@linux.intel.com \
--cc=geert+renesas@glider.be \
--cc=imre.deak@intel.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=jani.nikula@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mattw@codeaurora.org \
--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 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.