From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B389EC433DB for ; Thu, 18 Feb 2021 16:10:27 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CDB9464E76 for ; Thu, 18 Feb 2021 16:10:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CDB9464E76 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0F6D86EA41; Thu, 18 Feb 2021 16:10:22 +0000 (UTC) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by gabe.freedesktop.org (Postfix) with ESMTPS id CA4C76EA3A; Thu, 18 Feb 2021 16:10:19 +0000 (UTC) IronPort-SDR: bXdwMT6cf4++Hm+KgOJobO7Ve3Bt6qC3Y4sBM/OmZzFLu14OUXkUDBOXfANGZdEgq5Lc6MYP0z /RvlVhtlEXdA== X-IronPort-AV: E=McAfee;i="6000,8403,9898"; a="268396553" X-IronPort-AV: E=Sophos;i="5.81,187,1610438400"; d="scan'208";a="268396553" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Feb 2021 08:10:18 -0800 IronPort-SDR: IxeQOOqDAPE94dTukHPpEnzyyv0XNFLLRW4Ds1OiT/5YHHp7d6xwNrVWhHb+G73dqKrTVNkWNI IQwZ+/w+d4wA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,187,1610438400"; d="scan'208";a="439863945" Received: from stinkbox.fi.intel.com (HELO stinkbox) ([10.237.72.171]) by orsmga001.jf.intel.com with SMTP; 18 Feb 2021 08:10:15 -0800 Received: by stinkbox (sSMTP sendmail emulation); Thu, 18 Feb 2021 18:10:15 +0200 Date: Thu, 18 Feb 2021 18:10:15 +0200 From: Ville =?iso-8859-1?Q?Syrj=E4l=E4?= To: dri-devel@lists.freedesktop.org Message-ID: References: <20210204020400.29628-1-ville.syrjala@linux.intel.com> <20210218160305.16711-1-ville.syrjala@linux.intel.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210218160305.16711-1-ville.syrjala@linux.intel.com> X-Patchwork-Hint: comment Subject: Re: [Intel-gfx] [PATCH v2] drm/vblank: Do not store a new vblank timestamp in drm_vblank_restore() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Vetter , intel-gfx@lists.freedesktop.org, Dhinakaran Pandiyan Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" On Thu, Feb 18, 2021 at 06:03:05PM +0200, Ville Syrjala wrote: > From: Ville Syrj=E4l=E4 > = > drm_vblank_restore() exists because certain power saving states > can clobber the hardware frame counter. The way it does this is > by guesstimating how many frames were missed purely based on > the difference between the last stored timestamp vs. a newly > sampled timestamp. > = > If we should call this function before a full frame has > elapsed since we sampled the last timestamp we would end up > with a possibly slightly different timestamp value for the > same frame. Currently we will happily overwrite the already > stored timestamp for the frame with the new value. This > could cause userspace to observe two different timestamps > for the same frame (and the timestamp could even go > backwards depending on how much error we introduce when > correcting the timestamp based on the scanout position). > = > To avoid that let's not update the stored timestamp at all, > and instead we just fix up the last recorded hw vblank counter > value such that the already stored timestamp/seq number will > match. Thus the next time a vblank irq happens it will calculate > the correct diff between the current and stored hw vblank counter > values. > = > Sidenote: Another possible idea that came to mind would be to > do this correction only if the power really was removed since > the last time we sampled the hw frame counter. But to do that > we would need a robust way to detect when it has occurred. Some > possibilities could involve some kind of hardare power well > transition counter, or potentially we could store a magic value > in a scratch register that lives in the same power well. But > I'm not sure either of those exist, so would need an actual > investigation to find out. All of that is very hardware specific > of course, so would have to be done in the driver code. Forgot to mention that I wasn't able to test this with PSR since HSW+PSR1 is bork, but I did test it a bit w/o PSR by artificially adding arbitrary offsets to the reported hw frame counter value. The behaviour seemed sane enough at least. > = > Cc: Dhinakaran Pandiyan > Cc: Rodrigo Vivi > Cc: Daniel Vetter > Signed-off-by: Ville Syrj=E4l=E4 > --- > drivers/gpu/drm/drm_vblank.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > = > diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c > index 2bd989688eae..3417e1ac7918 100644 > --- a/drivers/gpu/drm/drm_vblank.c > +++ b/drivers/gpu/drm/drm_vblank.c > @@ -1478,6 +1478,7 @@ static void drm_vblank_restore(struct drm_device *d= ev, unsigned int pipe) > u64 diff_ns; > u32 cur_vblank, diff =3D 1; > int count =3D DRM_TIMESTAMP_MAXRETRIES; > + u32 max_vblank_count =3D drm_max_vblank_count(dev, pipe); > = > if (drm_WARN_ON(dev, pipe >=3D dev->num_crtcs)) > return; > @@ -1504,7 +1505,7 @@ static void drm_vblank_restore(struct drm_device *d= ev, unsigned int pipe) > drm_dbg_vbl(dev, > "missed %d vblanks in %lld ns, frame duration=3D%d ns, hw_diff=3D%= d\n", > diff, diff_ns, framedur_ns, cur_vblank - vblank->last); > - store_vblank(dev, pipe, diff, t_vblank, cur_vblank); > + vblank->last =3D (cur_vblank - diff) & max_vblank_count; > } > = > /** > -- = > 2.26.2 -- = Ville Syrj=E4l=E4 Intel _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx