mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drm/mediatek: Add no pending_planes flag checking for mtk_crtc_finish_page_flip()
@ 2024-11-18  3:36 Jason-JH.Lin
  2024-11-18  8:20 ` CK Hu (胡俊光)
  0 siblings, 1 reply; 3+ messages in thread
From: Jason-JH.Lin @ 2024-11-18  3:36 UTC (permalink / raw)
  To: Chun-Kuang Hu
  Cc: AngeloGioacchino Del Regno, Shawn Sung, dri-devel,
	linux-mediatek, linux-kernel, linux-arm-kernel, Jason-JH . Lin,
	Singo Chang, Nancy Lin, Project_Global_Chrome_Upstream_Group,
	Fei Shao

mtk_crtc_finish_page_flip() is used to notify the page flip that has
been completed to the userspace, so userspace can free the frame buffer
of the last frame and commit the next frame.

However, mtk_crtc_finish_page_flip() cannot guarantee the GCE has
configured all the display hardware settings of the last frame.
This may cause the display hardware to still access the last frame
buffer released by the userspace.

So add the checking condition of no pending_plens flags to make sure
GCE has executed all the pending planes configuration.

Fixes: 7f82d9c43879 ("drm/mediatek: Clear pending flag when cmdq packet is done")
Signed-off-by: Jason-JH.Lin <jason-jh.lin@mediatek.com>
---
 drivers/gpu/drm/mediatek/mtk_crtc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/mediatek/mtk_crtc.c b/drivers/gpu/drm/mediatek/mtk_crtc.c
index eb0e1233ad04..b03b9102ff90 100644
--- a/drivers/gpu/drm/mediatek/mtk_crtc.c
+++ b/drivers/gpu/drm/mediatek/mtk_crtc.c
@@ -113,7 +113,8 @@ static void mtk_drm_finish_page_flip(struct mtk_crtc *mtk_crtc)
 	drm_crtc_handle_vblank(&mtk_crtc->base);
 
 	spin_lock_irqsave(&mtk_crtc->config_lock, flags);
-	if (!mtk_crtc->config_updating && mtk_crtc->pending_needs_vblank) {
+	if (!mtk_crtc->config_updating && mtk_crtc->pending_needs_vblank &&
+	    !mtk_crtc->pending_planes) {
 		mtk_crtc_finish_page_flip(mtk_crtc);
 		mtk_crtc->pending_needs_vblank = false;
 	}
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/mediatek: Add no pending_planes flag checking for mtk_crtc_finish_page_flip()
  2024-11-18  3:36 [PATCH] drm/mediatek: Add no pending_planes flag checking for mtk_crtc_finish_page_flip() Jason-JH.Lin
@ 2024-11-18  8:20 ` CK Hu (胡俊光)
  2024-11-19  6:33   ` Jason-JH Lin (林睿祥)
  0 siblings, 1 reply; 3+ messages in thread
From: CK Hu (胡俊光) @ 2024-11-18  8:20 UTC (permalink / raw)
  To: Jason-JH Lin (林睿祥), chunkuang.hu
  Cc: linux-mediatek, Singo Chang (張興國),
	linux-kernel, Shawn Sung (宋孝謙),
	Nancy Lin (林欣螢),
	dri-devel, Project_Global_Chrome_Upstream_Group,
	linux-arm-kernel, fshao, AngeloGioacchino Del Regno

Hi, Jason:

On Mon, 2024-11-18 at 11:36 +0800, Jason-JH.Lin wrote:
> mtk_crtc_finish_page_flip() is used to notify the page flip that has
> been completed to the userspace, so userspace can free the frame buffer
> of the last frame and commit the next frame.
> 
> However, mtk_crtc_finish_page_flip() cannot guarantee the GCE has
> configured all the display hardware settings of the last frame.
> This may cause the display hardware to still access the last frame
> buffer released by the userspace.
> 
> So add the checking condition of no pending_plens flags to make sure
> GCE has executed all the pending planes configuration.

What's the probability?
If it's low probability, we could drop calling mtk_crtc_finish_page_flip().
If it's not low probability, I think drop calling mtk_crtc_finish_page_flip() would reduce the fps and we should find another way.

Regards,
CK

> 
> Fixes: 7f82d9c43879 ("drm/mediatek: Clear pending flag when cmdq packet is done")
> Signed-off-by: Jason-JH.Lin <jason-jh.lin@mediatek.com>
> ---
>  drivers/gpu/drm/mediatek/mtk_crtc.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/mediatek/mtk_crtc.c b/drivers/gpu/drm/mediatek/mtk_crtc.c
> index eb0e1233ad04..b03b9102ff90 100644
> --- a/drivers/gpu/drm/mediatek/mtk_crtc.c
> +++ b/drivers/gpu/drm/mediatek/mtk_crtc.c
> @@ -113,7 +113,8 @@ static void mtk_drm_finish_page_flip(struct mtk_crtc *mtk_crtc)
>  	drm_crtc_handle_vblank(&mtk_crtc->base);
>  
>  	spin_lock_irqsave(&mtk_crtc->config_lock, flags);
> -	if (!mtk_crtc->config_updating && mtk_crtc->pending_needs_vblank) {
> +	if (!mtk_crtc->config_updating && mtk_crtc->pending_needs_vblank &&
> +	    !mtk_crtc->pending_planes) {
>  		mtk_crtc_finish_page_flip(mtk_crtc);
>  		mtk_crtc->pending_needs_vblank = false;
>  	}

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/mediatek: Add no pending_planes flag checking for mtk_crtc_finish_page_flip()
  2024-11-18  8:20 ` CK Hu (胡俊光)
@ 2024-11-19  6:33   ` Jason-JH Lin (林睿祥)
  0 siblings, 0 replies; 3+ messages in thread
From: Jason-JH Lin (林睿祥) @ 2024-11-19  6:33 UTC (permalink / raw)
  To: CK Hu (胡俊光), chunkuang.hu
  Cc: linux-kernel, linux-mediatek,
	Singo Chang (張興國),
	Shawn Sung (宋孝謙),
	Nancy Lin (林欣螢),
	dri-devel, Project_Global_Chrome_Upstream_Group,
	linux-arm-kernel, fshao, AngeloGioacchino Del Regno

On Mon, 2024-11-18 at 08:20 +0000, CK Hu (胡俊光) wrote:
> Hi, Jason:
> 
> On Mon, 2024-11-18 at 11:36 +0800, Jason-JH.Lin wrote:
> > mtk_crtc_finish_page_flip() is used to notify the page flip that
> > has
> > been completed to the userspace, so userspace can free the frame
> > buffer
> > of the last frame and commit the next frame.
> > 
> > However, mtk_crtc_finish_page_flip() cannot guarantee the GCE has
> > configured all the display hardware settings of the last frame.
> > This may cause the display hardware to still access the last frame
> > buffer released by the userspace.
> > 
> > So add the checking condition of no pending_plens flags to make
> > sure
> > GCE has executed all the pending planes configuration.
> 
> What's the probability?
> If it's low probability, we could drop calling
> mtk_crtc_finish_page_flip().
> If it's not low probability, I think drop calling
> mtk_crtc_finish_page_flip() would reduce the fps and we should find
> another way.

It won't happen in display normal flow, which uses the
mbox_send_message() in IRQ context.
But it's easy to reproduce in display SVP flow, which uses the
mbox_send_message() to queue a work to the workqueue out of the IRQ
context for communicating with TEE world.

In mediaTek hardware design of configuring display hardware by GCE, I
think we should use mtk_crtc_finish_page_flip() to notify 
`DRM_EVENT_FLIP_COMPLETED` to userspace when GCE finished configuring
all display hardware settings for each atomic_commit().

Although it's still no problem in display normal flow without this
modification.
But I believe we can increase the accuracy of the timing to notify
`DRM_EVENT_FLIP_COMPLETED` to userspace, if we called
mtk_crtc_finished_page_flip() when the all the display hardware
settings is configured.

Maybe this patch is not quite straightforward to express the meaning of
calling mtk_crtc_finish_page_flip() after GCE completing all the
display configuration.
So after I verifying it in my local environment with SVP flow, I'll
move mtk_crtc_finish_page_flip() to the ddp_cmdq_cb() directly and send
the v2.

Regards,
Jason-JH.Lin

> 
> Regards,
> CK
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-11-19  6:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-18  3:36 [PATCH] drm/mediatek: Add no pending_planes flag checking for mtk_crtc_finish_page_flip() Jason-JH.Lin
2024-11-18  8:20 ` CK Hu (胡俊光)
2024-11-19  6:33   ` Jason-JH Lin (林睿祥)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®