From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Mario Kleiner <mario.kleiner.de@gmail.com>
Cc: Dave Airlie <airlied@redhat.com>,
intel-gfx@lists.freedesktop.org,
"dri-devel@lists.freedesktop.org"
<dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH 01/19] drm/core: Add drm_accurate_vblank_count, v4.
Date: Mon, 25 Apr 2016 15:26:02 +0300 [thread overview]
Message-ID: <20160425122602.GX4329@intel.com> (raw)
In-Reply-To: <571D9EA4.9050606@gmail.com>
On Mon, Apr 25, 2016 at 06:35:48AM +0200, Mario Kleiner wrote:
> Sorry for the late review, but see below...
>
> On 04/19/2016 09:52 AM, Maarten Lankhorst wrote:
> > This function is useful for gen2 intel devices which have no frame
> > counter, but need a way to determine the current vblank count without
> > racing with the vblank interrupt handler.
> >
> > intel_pipe_update_start checks if no vblank interrupt will occur
> > during vblank evasion, but cannot check whether the vblank handler has
> > run to completion. This function uses the timestamps to determine
> > when the last vblank has happened, and interpolates from there.
> >
> > Changes since v1:
> > - Take vblank_time_lock and don't use drm_vblank_count_and_time.
> > Changes since v2:
> > - Don't return time of last vblank.
> > Changes since v3:
> > - Change pipe to unsigned int. (Ville)
> > - Remove unused documentation for tv_ret. (kbuild)
> >
> > Cc: Mario Kleiner <mario.kleiner.de@gmail.com>
> > Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> > Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > Acked-by: David Airlie <airlied@linux.ie> #irc
> > ---
> > drivers/gpu/drm/drm_irq.c | 26 ++++++++++++++++++++++++++
> > include/drm/drmP.h | 1 +
> > 2 files changed, 27 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
> > index 3c1a6f18e71c..f1bda13562da 100644
> > --- a/drivers/gpu/drm/drm_irq.c
> > +++ b/drivers/gpu/drm/drm_irq.c
> > @@ -303,6 +303,32 @@ static void drm_update_vblank_count(struct drm_device *dev, unsigned int pipe,
> > store_vblank(dev, pipe, diff, &t_vblank, cur_vblank);
> > }
> >
> > +/**
> > + * drm_accurate_vblank_count - retrieve the master vblank counter
> > + * @crtc: which counter to retrieve
> > + *
> > + * This function is similar to @drm_crtc_vblank_count but this
> > + * function interpolates to handle a race with vblank irq's.
> > + */
> > +
> > +u32 drm_accurate_vblank_count(struct drm_crtc *crtc)
> > +{
> > + struct drm_device *dev = crtc->dev;
> > + unsigned int pipe = drm_crtc_index(crtc);
> > + u32 vblank;
> > + unsigned long flags;
> > +
>
> This function is rather dangerous to use on any driver that doesn't have
> precise vblank timestamping, or doesn't have the guarantee that hw
> vblank counters (if there are any) and timestamps update exactly at
> leading edge of vblank, so i think we need some WARN() here and maybe
> much less encouraging docs to avoid this being called from incapable kms
> drivers or in general code.
>
> - If the driver doesn't have precise scanoutpos based timestamping each
> call into drm_update_vblank_count from non-irq context will reset the
> vblank timestamps to zero, so clients will only receive invalid
> timestamps if this is frequently used. Also bogus vblank counts
>
> Atm. only i915 Intel, AMD, NVidia desktop for >= NV-50, maybe nouveau
> driven Tegra parts, and some modern Adrenos (msm/mdp-5 - i assume from
> the code?) support this reliably.
>
> - If the drivers scanoutpos timestamps and/or vblank counter don't
> increment at leading edge we will get funny off-by-one problems with
> vblank counters. That's why we normally only call
> drm_update_vblank_count() from vblank irq on such parts - the only safe
> place to avoid off-by-one problems, and limit vblank disable/enable to
> only at most once every 5 seconds to reduce the problems caused by
> off-by-one errors.
>
> Which restricts the list to only the above parts, maybe minus Adreno
> where i don't know if it obeys the "leading edge" rule or not.
>
> So on most SoC's one must not use this function.
>
> WARN_ON(!dev->vblank_disable_immediate, "This function is unsafe on this
> driver.");
>
> would probably prevent the worst abuse, unless drivers lie about
> vblank_disable_immediate. Not sure how much this was checked for msm /
> Adreno? At least drm_vblank_init() only allows vblank_disable_immediate
> if the driver at least implements proper timestamping.
>
> Not sure how much general use this function will have outside Intel
> gen-2 with the restrictions on safe use?
This (or something like it) needs to be used also in generic vblank
wait functions. Currently those are racy.
>
> > + spin_lock_irqsave(&dev->vblank_time_lock, flags);
> > +
> > + drm_update_vblank_count(dev, pipe, 0);
> > + vblank = dev->vblank[pipe].count;
>
> Could do vblank = drm_vblank_count(dev, pipe); instead, given that we
> avoid open coding this in most places.
>
> -mario
>
> > +
> > + spin_unlock_irqrestore(&dev->vblank_time_lock, flags);
> > +
> > + return vblank;
> > +}
> > +EXPORT_SYMBOL(drm_accurate_vblank_count);
> > +
> > /*
> > * Disable vblank irq's on crtc, make sure that last vblank count
> > * of hardware and corresponding consistent software vblank counter
> > diff --git a/include/drm/drmP.h b/include/drm/drmP.h
> > index 005202ea5900..90527c41cd5a 100644
> > --- a/include/drm/drmP.h
> > +++ b/include/drm/drmP.h
> > @@ -995,6 +995,7 @@ extern void drm_crtc_vblank_off(struct drm_crtc *crtc);
> > extern void drm_crtc_vblank_reset(struct drm_crtc *crtc);
> > extern void drm_crtc_vblank_on(struct drm_crtc *crtc);
> > extern void drm_vblank_cleanup(struct drm_device *dev);
> > +extern u32 drm_accurate_vblank_count(struct drm_crtc *crtc);
> > extern u32 drm_vblank_no_hw_counter(struct drm_device *dev, unsigned int pipe);
> >
> > extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
> >
--
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2016-04-25 12:26 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-19 7:52 [PATCH 00/19] Rework page flip, remove cs flips, async unpin and unified pageflip Maarten Lankhorst
2016-04-19 7:52 ` [PATCH 01/19] drm/core: Add drm_accurate_vblank_count, v4 Maarten Lankhorst
2016-04-25 4:35 ` Mario Kleiner
2016-04-25 6:32 ` [PATCH 01/19] drm/core: Add drm_accurate_vblank_count, v5 Maarten Lankhorst
2016-04-25 7:49 ` Mario Kleiner
2016-04-27 23:02 ` Mario Kleiner
2016-04-25 12:26 ` Ville Syrjälä [this message]
2016-04-19 7:52 ` [PATCH 02/19] drm/i915: Remove stallcheck special handling, v2 Maarten Lankhorst
2016-04-27 13:24 ` Patrik Jakobsson
2016-04-28 8:48 ` Maarten Lankhorst
2016-04-28 9:54 ` Patrik Jakobsson
2016-04-28 10:20 ` Maarten Lankhorst
2016-05-03 13:48 ` Patrik Jakobsson
2016-05-03 14:15 ` Maarten Lankhorst
2016-04-19 7:52 ` [PATCH 03/19] drm/i915: Remove intel_prepare_page_flip, v2 Maarten Lankhorst
2016-04-25 23:14 ` Patrik Jakobsson
2016-04-28 9:24 ` Maarten Lankhorst
2016-04-19 7:52 ` [PATCH 04/19] drm/i915: Add support for detecting vblanks when hw frame counter is unavailable Maarten Lankhorst
2016-04-27 14:06 ` Patrik Jakobsson
2016-04-27 14:23 ` Ville Syrjälä
2016-05-10 12:30 ` Patrik Jakobsson
2016-04-19 7:52 ` [PATCH 05/19] drm/i915: Unify unpin_work and mmio_work into flip_work Maarten Lankhorst
2016-04-29 12:47 ` Patrik Jakobsson
2016-04-19 7:52 ` [PATCH 06/19] Revert "drm/i915: Avoid stalling on pending flips for legacy cursor updates" Maarten Lankhorst
2016-05-10 12:31 ` Patrik Jakobsson
2016-04-19 7:52 ` [PATCH 07/19] drm/i915: Allow mmio updates on all platforms, v2 Maarten Lankhorst
2016-04-19 12:48 ` Ville Syrjälä
2016-04-19 13:37 ` Maarten Lankhorst
2016-05-12 11:49 ` [RFC PATCH " Maarten Lankhorst
2016-04-19 7:52 ` [PATCH 08/19] drm/i915: Convert flip_work to a list Maarten Lankhorst
2016-05-02 9:22 ` Patrik Jakobsson
2016-05-02 11:07 ` Maarten Lankhorst
2016-04-19 7:52 ` [PATCH 09/19] drm/i915: Add the exclusive fence to plane_state Maarten Lankhorst
2016-05-03 12:47 ` Patrik Jakobsson
2016-04-19 7:52 ` [PATCH 10/19] drm/i915: Rework intel_crtc_page_flip to be almost atomic, v3 Maarten Lankhorst
2016-04-19 7:52 ` [PATCH 11/19] drm/i915: Remove cs based page flip support Maarten Lankhorst
2016-04-19 7:52 ` [PATCH 12/19] drm/i915: Remove use_mmio_flip kernel parameter Maarten Lankhorst
2016-05-11 8:48 ` Patrik Jakobsson
2016-04-19 7:52 ` [PATCH 13/19] drm/i915: Remove queue_flip pointer Maarten Lankhorst
2016-05-11 8:49 ` Patrik Jakobsson
2016-04-19 7:52 ` [PATCH 14/19] drm/i915: Pass atomic states to fbc update functions Maarten Lankhorst
2016-05-11 9:13 ` Patrik Jakobsson
2016-04-19 7:52 ` [PATCH 15/19] drm/i915: Prepare MST connector removal for async unpin Maarten Lankhorst
2016-05-11 9:26 ` Patrik Jakobsson
2016-04-19 7:52 ` [PATCH 16/19] drm/i915: Make unpin async Maarten Lankhorst
2016-04-25 16:26 ` Lionel Landwerlin
2016-04-25 16:26 ` Lionel Landwerlin
2016-04-26 7:14 ` Maarten Lankhorst
2016-04-19 7:52 ` [PATCH 17/19] Reapply "drm/i915: Avoid stalling on pending flips for legacy cursor updates" Maarten Lankhorst
2016-04-19 7:52 ` [PATCH 18/19] drm/i915: Check for unpin correctness Maarten Lankhorst
2016-04-19 7:52 ` [PATCH 19/19] drm/i915: Allow async update of pageflips Maarten Lankhorst
2016-04-19 8:19 ` Chris Wilson
2016-04-19 12:26 ` Maarten Lankhorst
2016-04-20 13:24 ` Daniel Vetter
2016-04-20 13:45 ` Chris Wilson
2016-04-20 7:39 ` Maarten Lankhorst
2016-04-19 8:27 ` ✗ Fi.CI.BAT: failure for Rework page flip, remove cs flips, async unpin and unified pageflip 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=20160425122602.GX4329@intel.com \
--to=ville.syrjala@linux.intel.com \
--cc=airlied@redhat.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=mario.kleiner.de@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.