linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH v5 3/6] drm/mediatek: Detect CMDQ execution timeout
       [not found] ` <20211027021857.20816-4-jason-jh.lin@mediatek.com>
@ 2021-10-27  9:31   ` Fei Shao
  2021-10-27 23:47     ` Chun-Kuang Hu
  0 siblings, 1 reply; 6+ messages in thread
From: Fei Shao @ 2021-10-27  9:31 UTC (permalink / raw)
  To: jason-jh.lin
  Cc: Chun-Kuang Hu, Philipp Zabel, Matthias Brugger, Jassi Brar,
	Yongqiang Niu, David Airlie, Daniel Vetter, dri-devel,
	linux-mediatek, linux-arm-kernel, linux-kernel, hsinyi,
	nancy.lin, singo.chang

Hi Jason,

On Wed, Oct 27, 2021 at 10:19 AM jason-jh.lin <jason-jh.lin@mediatek.com> wrote:
>
> From: Chun-Kuang Hu <chunkuang.hu@kernel.org>
>
> CMDQ is used to update display register in vblank period, so
> it should be execute in next 2 vblank. One vblank interrupt
> before send message (occasionally) and one vblank interrupt
> after cmdq done. If it fail to execute in next 3 vblank,
> tiemout happen.
>
> Signed-off-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>
> Signed-off-by: jason-jh.lin <jason-jh.lin@mediatek.com>
> Reviewed-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>
> ---
>  drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 20 ++++++++++++++++++--
>  1 file changed, 18 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> index e23e3224ac67..dad1f85ee315 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> @@ -54,6 +54,7 @@ struct mtk_drm_crtc {
>  #if IS_REACHABLE(CONFIG_MTK_CMDQ)
>         struct cmdq_client              cmdq_client;
>         u32                             cmdq_event;
> +       u32                             cmdq_vblank_cnt;
>  #endif
>
>         struct device                   *mmsys_dev;
> @@ -227,7 +228,10 @@ struct mtk_ddp_comp *mtk_drm_ddp_comp_for_plane(struct drm_crtc *crtc,
>  static void ddp_cmdq_cb(struct mbox_client *cl, void *mssg)
>  {
>         struct cmdq_cb_data *data = mssg;
> +       struct cmdq_client *cmdq_cl = container_of(cl, struct cmdq_client, client);
> +       struct mtk_drm_crtc *mtk_crtc = container_of(cmdq_cl, struct mtk_drm_crtc, cmdq_client);
>
> +       mtk_crtc->cmdq_vblank_cnt = 0;
>         cmdq_pkt_destroy(data->pkt);
>  }
>  #endif
> @@ -483,6 +487,15 @@ static void mtk_drm_crtc_update_config(struct mtk_drm_crtc *mtk_crtc,
>                                            cmdq_handle->pa_base,
>                                            cmdq_handle->cmd_buf_size,
>                                            DMA_TO_DEVICE);
> +               /*
> +                * CMDQ command should execute in next 3 vblank.
> +                * One vblank interrupt before send message (occasionally)
> +                * and one vblank interrupt after cmdq done,
> +                * so it's timeout after 3 vblank interrupt.
> +                * If it fail to execute in next 3 vblank, timeout happen.
> +                */
> +               mtk_crtc->cmdq_vblank_cnt = 3;
> +
>                 mbox_send_message(mtk_crtc->cmdq_client.chan, cmdq_handle);
>                 mbox_client_txdone(mtk_crtc->cmdq_client.chan, 0);
>         }
> @@ -499,11 +512,14 @@ static void mtk_crtc_ddp_irq(void *data)
>
>  #if IS_REACHABLE(CONFIG_MTK_CMDQ)
>         if (!priv->data->shadow_register && !mtk_crtc->cmdq_client.chan)
> +               mtk_crtc_ddp_config(crtc, NULL);
> +       else if (mtk_crtc->cmdq_vblank_cnt > 0 && --mtk_crtc->cmdq_vblank_cnt == 0)
I think atomic_dec_and_test() does what you want to do here.




> +               DRM_ERROR("mtk_crtc %d CMDQ execute command timeout!\n",
> +                         drm_crtc_index(&mtk_crtc->base));
>  #else
>         if (!priv->data->shadow_register)
> -#endif
>                 mtk_crtc_ddp_config(crtc, NULL);
> -
> +#endif
>         mtk_drm_finish_page_flip(mtk_crtc);
>  }
>
> --
> 2.18.0
>

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

* Re: [PATCH v5 5/6] drm/mediatek: Add mbox_free_channel in mtk_drm_crtc_destroy
       [not found] ` <20211027021857.20816-6-jason-jh.lin@mediatek.com>
@ 2021-10-27 23:30   ` Chun-Kuang Hu
  0 siblings, 0 replies; 6+ messages in thread
From: Chun-Kuang Hu @ 2021-10-27 23:30 UTC (permalink / raw)
  To: jason-jh.lin
  Cc: Chun-Kuang Hu, Philipp Zabel, Matthias Brugger, Jassi Brar,
	Yongqiang Niu, David Airlie, Daniel Vetter, DRI Development,
	moderated list:ARM/Mediatek SoC support, Linux ARM, linux-kernel,
	Hsin-Yi Wang, fshao, Nancy Lin, singo.chang

Hi, Jason:

jason-jh.lin <jason-jh.lin@mediatek.com> 於 2021年10月27日 週三 上午10:19寫道:
>
> Add mbox_free_channel in mtk_drm_crtc_destroy.
>
> Signed-off-by: jason-jh.lin <jason-jh.lin@mediatek.com>
> ---
>  drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> index ffa54b416ca7..31f05efc1bc0 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> @@ -156,6 +156,10 @@ static void mtk_drm_crtc_destroy(struct drm_crtc *crtc)
>         mtk_mutex_put(mtk_crtc->mutex);
>  #if IS_REACHABLE(CONFIG_MTK_CMDQ)
>         mtk_drm_cmdq_pkt_destroy(&mtk_crtc->cmdq_handle);
> +
> +       if (mtk_crtc->cmdq_client.chan)
> +               mbox_free_channel(mtk_crtc->cmdq_client.chan);
> +                                 mtk_crtc->cmdq_client.chan = NULL;

Except the indent,

Reviewed-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>

>  #endif
>         drm_crtc_cleanup(crtc);
>  }
> --
> 2.18.0
>

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

* Re: [PATCH v5 4/6] drm/mediatek: Add cmdq_handle in mtk_crtc
       [not found] ` <20211027021857.20816-5-jason-jh.lin@mediatek.com>
@ 2021-10-27 23:32   ` Chun-Kuang Hu
  0 siblings, 0 replies; 6+ messages in thread
From: Chun-Kuang Hu @ 2021-10-27 23:32 UTC (permalink / raw)
  To: jason-jh.lin
  Cc: Chun-Kuang Hu, Philipp Zabel, Matthias Brugger, Jassi Brar,
	Yongqiang Niu, David Airlie, Daniel Vetter, DRI Development,
	moderated list:ARM/Mediatek SoC support, Linux ARM, linux-kernel,
	Hsin-Yi Wang, fshao, Nancy Lin, singo.chang

Hi, Jason:

jason-jh.lin <jason-jh.lin@mediatek.com> 於 2021年10月27日 週三 上午10:19寫道:
>
> From: Chun-Kuang Hu <chunkuang.hu@kernel.org>
>
> One mtk_crtc need just one cmdq_handle, so add one cmdq_handle
> in mtk_crtc to prevent frequently allocation and free of
> cmdq_handle.

Reviewed-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>

>
> Signed-off-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>
> Signed-off-by: jason-jh.lin <jason-jh.lin@mediatek.com>
> ---
>  drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 62 +++++++++++++++++++++++--
>  1 file changed, 57 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> index dad1f85ee315..ffa54b416ca7 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> @@ -53,6 +53,7 @@ struct mtk_drm_crtc {
>
>  #if IS_REACHABLE(CONFIG_MTK_CMDQ)
>         struct cmdq_client              cmdq_client;
> +       struct cmdq_pkt                 cmdq_handle;
>         u32                             cmdq_event;
>         u32                             cmdq_vblank_cnt;
>  #endif
> @@ -107,12 +108,55 @@ static void mtk_drm_finish_page_flip(struct mtk_drm_crtc *mtk_crtc)
>         }
>  }
>
> +#if IS_REACHABLE(CONFIG_MTK_CMDQ)
> +static int mtk_drm_cmdq_pkt_create(struct cmdq_client *client, struct cmdq_pkt *pkt,
> +                                  size_t size)
> +{
> +       struct device *dev;
> +       dma_addr_t dma_addr;
> +
> +       pkt->va_base = kzalloc(size, GFP_KERNEL);
> +       if (!pkt->va_base) {
> +               kfree(pkt);
> +               return -ENOMEM;
> +       }
> +       pkt->buf_size = size;
> +       pkt->cl = (void *)client;
> +
> +       dev = client->chan->mbox->dev;
> +       dma_addr = dma_map_single(dev, pkt->va_base, pkt->buf_size,
> +                                 DMA_TO_DEVICE);
> +       if (dma_mapping_error(dev, dma_addr)) {
> +               dev_err(dev, "dma map failed, size=%u\n", (u32)(u64)size);
> +               kfree(pkt->va_base);
> +               kfree(pkt);
> +               return -ENOMEM;
> +       }
> +
> +       pkt->pa_base = dma_addr;
> +
> +       return 0;
> +}
> +
> +static void mtk_drm_cmdq_pkt_destroy(struct cmdq_pkt *pkt)
> +{
> +       struct cmdq_client *client = (struct cmdq_client *)pkt->cl;
> +
> +       dma_unmap_single(client->chan->mbox->dev, pkt->pa_base, pkt->buf_size,
> +                        DMA_TO_DEVICE);
> +       kfree(pkt->va_base);
> +       kfree(pkt);
> +}
> +#endif
> +
>  static void mtk_drm_crtc_destroy(struct drm_crtc *crtc)
>  {
>         struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
>
>         mtk_mutex_put(mtk_crtc->mutex);
> -
> +#if IS_REACHABLE(CONFIG_MTK_CMDQ)
> +       mtk_drm_cmdq_pkt_destroy(&mtk_crtc->cmdq_handle);
> +#endif
>         drm_crtc_cleanup(crtc);
>  }
>
> @@ -227,12 +271,10 @@ struct mtk_ddp_comp *mtk_drm_ddp_comp_for_plane(struct drm_crtc *crtc,
>  #if IS_REACHABLE(CONFIG_MTK_CMDQ)
>  static void ddp_cmdq_cb(struct mbox_client *cl, void *mssg)
>  {
> -       struct cmdq_cb_data *data = mssg;
>         struct cmdq_client *cmdq_cl = container_of(cl, struct cmdq_client, client);
>         struct mtk_drm_crtc *mtk_crtc = container_of(cmdq_cl, struct mtk_drm_crtc, cmdq_client);
>
>         mtk_crtc->cmdq_vblank_cnt = 0;
> -       cmdq_pkt_destroy(data->pkt);
>  }
>  #endif
>
> @@ -438,7 +480,7 @@ static void mtk_drm_crtc_update_config(struct mtk_drm_crtc *mtk_crtc,
>                                        bool needs_vblank)
>  {
>  #if IS_REACHABLE(CONFIG_MTK_CMDQ)
> -       struct cmdq_pkt *cmdq_handle;
> +       struct cmdq_pkt *cmdq_handle = &mtk_crtc->cmdq_handle;
>  #endif
>         struct drm_crtc *crtc = &mtk_crtc->base;
>         struct mtk_drm_private *priv = crtc->dev->dev_private;
> @@ -478,7 +520,7 @@ static void mtk_drm_crtc_update_config(struct mtk_drm_crtc *mtk_crtc,
>  #if IS_REACHABLE(CONFIG_MTK_CMDQ)
>         if (mtk_crtc->cmdq_client.chan) {
>                 mbox_flush(mtk_crtc->cmdq_client.chan, 2000);
> -               cmdq_handle = cmdq_pkt_create(&mtk_crtc->cmdq_client, PAGE_SIZE);
> +               cmdq_handle->cmd_buf_size = 0;
>                 cmdq_pkt_clear_event(cmdq_handle, mtk_crtc->cmdq_event);
>                 cmdq_pkt_wfe(cmdq_handle, mtk_crtc->cmdq_event, false);
>                 mtk_crtc_ddp_config(crtc, cmdq_handle);
> @@ -877,6 +919,16 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
>                                 drm_crtc_index(&mtk_crtc->base));
>                         mbox_free_channel(mtk_crtc->cmdq_client.chan);
>                         mtk_crtc->cmdq_client.chan = NULL;
> +               } else {
> +                       ret = mtk_drm_cmdq_pkt_create(&mtk_crtc->cmdq_client,
> +                                                     &mtk_crtc->cmdq_handle,
> +                                                     PAGE_SIZE);
> +                       if (ret) {
> +                               dev_dbg(dev, "mtk_crtc %d failed to create cmdq packet\n",
> +                                       drm_crtc_index(&mtk_crtc->base));
> +                               mbox_free_channel(mtk_crtc->cmdq_client.chan);
> +                               mtk_crtc->cmdq_client.chan = NULL;
> +                       }
>                 }
>         }
>  #endif
> --
> 2.18.0
>

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

* Re: [PATCH v5 3/6] drm/mediatek: Detect CMDQ execution timeout
  2021-10-27  9:31   ` [PATCH v5 3/6] drm/mediatek: Detect CMDQ execution timeout Fei Shao
@ 2021-10-27 23:47     ` Chun-Kuang Hu
  2021-10-28  3:19       ` Fei Shao
  0 siblings, 1 reply; 6+ messages in thread
From: Chun-Kuang Hu @ 2021-10-27 23:47 UTC (permalink / raw)
  To: Fei Shao
  Cc: jason-jh.lin, Chun-Kuang Hu, Philipp Zabel, Matthias Brugger,
	Jassi Brar, Yongqiang Niu, David Airlie, Daniel Vetter,
	DRI Development, moderated list:ARM/Mediatek SoC support,
	Linux ARM, linux-kernel, Hsin-Yi Wang, Nancy Lin, singo.chang

Hi, Fei:

Fei Shao <fshao@chromium.org> 於 2021年10月27日 週三 下午5:32寫道:
>
> Hi Jason,
>
> On Wed, Oct 27, 2021 at 10:19 AM jason-jh.lin <jason-jh.lin@mediatek.com> wrote:
> >
> > From: Chun-Kuang Hu <chunkuang.hu@kernel.org>
> >
> > CMDQ is used to update display register in vblank period, so
> > it should be execute in next 2 vblank. One vblank interrupt
> > before send message (occasionally) and one vblank interrupt
> > after cmdq done. If it fail to execute in next 3 vblank,
> > tiemout happen.
> >
> > Signed-off-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>
> > Signed-off-by: jason-jh.lin <jason-jh.lin@mediatek.com>
> > Reviewed-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>
> > ---
> >  drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 20 ++++++++++++++++++--
> >  1 file changed, 18 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> > index e23e3224ac67..dad1f85ee315 100644
> > --- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> > +++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> > @@ -54,6 +54,7 @@ struct mtk_drm_crtc {
> >  #if IS_REACHABLE(CONFIG_MTK_CMDQ)
> >         struct cmdq_client              cmdq_client;
> >         u32                             cmdq_event;
> > +       u32                             cmdq_vblank_cnt;
> >  #endif
> >
> >         struct device                   *mmsys_dev;
> > @@ -227,7 +228,10 @@ struct mtk_ddp_comp *mtk_drm_ddp_comp_for_plane(struct drm_crtc *crtc,
> >  static void ddp_cmdq_cb(struct mbox_client *cl, void *mssg)
> >  {
> >         struct cmdq_cb_data *data = mssg;
> > +       struct cmdq_client *cmdq_cl = container_of(cl, struct cmdq_client, client);
> > +       struct mtk_drm_crtc *mtk_crtc = container_of(cmdq_cl, struct mtk_drm_crtc, cmdq_client);
> >
> > +       mtk_crtc->cmdq_vblank_cnt = 0;
> >         cmdq_pkt_destroy(data->pkt);
> >  }
> >  #endif
> > @@ -483,6 +487,15 @@ static void mtk_drm_crtc_update_config(struct mtk_drm_crtc *mtk_crtc,
> >                                            cmdq_handle->pa_base,
> >                                            cmdq_handle->cmd_buf_size,
> >                                            DMA_TO_DEVICE);
> > +               /*
> > +                * CMDQ command should execute in next 3 vblank.
> > +                * One vblank interrupt before send message (occasionally)
> > +                * and one vblank interrupt after cmdq done,
> > +                * so it's timeout after 3 vblank interrupt.
> > +                * If it fail to execute in next 3 vblank, timeout happen.
> > +                */
> > +               mtk_crtc->cmdq_vblank_cnt = 3;
> > +
> >                 mbox_send_message(mtk_crtc->cmdq_client.chan, cmdq_handle);
> >                 mbox_client_txdone(mtk_crtc->cmdq_client.chan, 0);
> >         }
> > @@ -499,11 +512,14 @@ static void mtk_crtc_ddp_irq(void *data)
> >
> >  #if IS_REACHABLE(CONFIG_MTK_CMDQ)
> >         if (!priv->data->shadow_register && !mtk_crtc->cmdq_client.chan)
> > +               mtk_crtc_ddp_config(crtc, NULL);
> > +       else if (mtk_crtc->cmdq_vblank_cnt > 0 && --mtk_crtc->cmdq_vblank_cnt == 0)
> I think atomic_dec_and_test() does what you want to do here.

I think this operation is not necessary to be atomic operation, and
this statement could be reduced to

else if (--mtk_crtc->cmdq_vblank_cnt == 0)

>
>
>
>
> > +               DRM_ERROR("mtk_crtc %d CMDQ execute command timeout!\n",
> > +                         drm_crtc_index(&mtk_crtc->base));
> >  #else
> >         if (!priv->data->shadow_register)
> > -#endif
> >                 mtk_crtc_ddp_config(crtc, NULL);
> > -
> > +#endif
> >         mtk_drm_finish_page_flip(mtk_crtc);
> >  }
> >
> > --
> > 2.18.0
> >

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

* Re: [PATCH v5 3/6] drm/mediatek: Detect CMDQ execution timeout
  2021-10-27 23:47     ` Chun-Kuang Hu
@ 2021-10-28  3:19       ` Fei Shao
  2021-11-17 23:51         ` Chun-Kuang Hu
  0 siblings, 1 reply; 6+ messages in thread
From: Fei Shao @ 2021-10-28  3:19 UTC (permalink / raw)
  To: Chun-Kuang Hu
  Cc: jason-jh.lin, Philipp Zabel, Matthias Brugger, Jassi Brar,
	Yongqiang Niu, David Airlie, Daniel Vetter, DRI Development,
	moderated list:ARM/Mediatek SoC support, Linux ARM, linux-kernel,
	Hsin-Yi Wang, Nancy Lin, singo.chang

Hi Chun-Kuang,

On Thu, Oct 28, 2021 at 7:47 AM Chun-Kuang Hu <chunkuang.hu@kernel.org> wrote:
>
> Hi, Fei:
>
> Fei Shao <fshao@chromium.org> 於 2021年10月27日 週三 下午5:32寫道:
> >
> > Hi Jason,
> >
> > On Wed, Oct 27, 2021 at 10:19 AM jason-jh.lin <jason-jh.lin@mediatek.com> wrote:
> > >
> > > From: Chun-Kuang Hu <chunkuang.hu@kernel.org>
> > >
> > > CMDQ is used to update display register in vblank period, so
> > > it should be execute in next 2 vblank. One vblank interrupt
> > > before send message (occasionally) and one vblank interrupt
> > > after cmdq done. If it fail to execute in next 3 vblank,
> > > tiemout happen.
> > >
> > > Signed-off-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>
> > > Signed-off-by: jason-jh.lin <jason-jh.lin@mediatek.com>
> > > Reviewed-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>
> > > ---
> > >  drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 20 ++++++++++++++++++--
> > >  1 file changed, 18 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> > > index e23e3224ac67..dad1f85ee315 100644
> > > --- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> > > +++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> > > @@ -54,6 +54,7 @@ struct mtk_drm_crtc {
> > >  #if IS_REACHABLE(CONFIG_MTK_CMDQ)
> > >         struct cmdq_client              cmdq_client;
> > >         u32                             cmdq_event;
> > > +       u32                             cmdq_vblank_cnt;
> > >  #endif
> > >
> > >         struct device                   *mmsys_dev;
> > > @@ -227,7 +228,10 @@ struct mtk_ddp_comp *mtk_drm_ddp_comp_for_plane(struct drm_crtc *crtc,
> > >  static void ddp_cmdq_cb(struct mbox_client *cl, void *mssg)
> > >  {
> > >         struct cmdq_cb_data *data = mssg;
> > > +       struct cmdq_client *cmdq_cl = container_of(cl, struct cmdq_client, client);
> > > +       struct mtk_drm_crtc *mtk_crtc = container_of(cmdq_cl, struct mtk_drm_crtc, cmdq_client);
> > >
> > > +       mtk_crtc->cmdq_vblank_cnt = 0;
> > >         cmdq_pkt_destroy(data->pkt);
> > >  }
> > >  #endif
> > > @@ -483,6 +487,15 @@ static void mtk_drm_crtc_update_config(struct mtk_drm_crtc *mtk_crtc,
> > >                                            cmdq_handle->pa_base,
> > >                                            cmdq_handle->cmd_buf_size,
> > >                                            DMA_TO_DEVICE);
> > > +               /*
> > > +                * CMDQ command should execute in next 3 vblank.
> > > +                * One vblank interrupt before send message (occasionally)
> > > +                * and one vblank interrupt after cmdq done,
> > > +                * so it's timeout after 3 vblank interrupt.
> > > +                * If it fail to execute in next 3 vblank, timeout happen.
> > > +                */
> > > +               mtk_crtc->cmdq_vblank_cnt = 3;
> > > +
> > >                 mbox_send_message(mtk_crtc->cmdq_client.chan, cmdq_handle);
> > >                 mbox_client_txdone(mtk_crtc->cmdq_client.chan, 0);
> > >         }
> > > @@ -499,11 +512,14 @@ static void mtk_crtc_ddp_irq(void *data)
> > >
> > >  #if IS_REACHABLE(CONFIG_MTK_CMDQ)
> > >         if (!priv->data->shadow_register && !mtk_crtc->cmdq_client.chan)
> > > +               mtk_crtc_ddp_config(crtc, NULL);
> > > +       else if (mtk_crtc->cmdq_vblank_cnt > 0 && --mtk_crtc->cmdq_vblank_cnt == 0)
> > I think atomic_dec_and_test() does what you want to do here.
>
> I think this operation is not necessary to be atomic operation, and
> this statement could be reduced to
>
> else if (--mtk_crtc->cmdq_vblank_cnt == 0)

I was thinking about using existing helpers to wrap up the counter
operations, but I agree that it's not necessary.
Just dropping the redundant check would be good enough.


>
> >
> > > +               DRM_ERROR("mtk_crtc %d CMDQ execute command timeout!\n",
> > > +                         drm_crtc_index(&mtk_crtc->base));
> > >  #else
> > >         if (!priv->data->shadow_register)
> > > -#endif
> > >                 mtk_crtc_ddp_config(crtc, NULL);
> > > -
> > > +#endif
> > >         mtk_drm_finish_page_flip(mtk_crtc);
> > >  }
> > >
> > > --
> > > 2.18.0
> > >

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

* Re: [PATCH v5 3/6] drm/mediatek: Detect CMDQ execution timeout
  2021-10-28  3:19       ` Fei Shao
@ 2021-11-17 23:51         ` Chun-Kuang Hu
  0 siblings, 0 replies; 6+ messages in thread
From: Chun-Kuang Hu @ 2021-11-17 23:51 UTC (permalink / raw)
  To: Fei Shao
  Cc: Chun-Kuang Hu, jason-jh.lin, Philipp Zabel, Matthias Brugger,
	Jassi Brar, Yongqiang Niu, David Airlie, Daniel Vetter,
	DRI Development, moderated list:ARM/Mediatek SoC support,
	Linux ARM, linux-kernel, Hsin-Yi Wang, Nancy Lin, singo.chang

Hi, Fei:

Fei Shao <fshao@chromium.org> 於 2021年10月28日 週四 上午11:19寫道:
>
> Hi Chun-Kuang,
>
> On Thu, Oct 28, 2021 at 7:47 AM Chun-Kuang Hu <chunkuang.hu@kernel.org> wrote:
> >
> > Hi, Fei:
> >
> > Fei Shao <fshao@chromium.org> 於 2021年10月27日 週三 下午5:32寫道:
> > >
> > > Hi Jason,
> > >
> > > On Wed, Oct 27, 2021 at 10:19 AM jason-jh.lin <jason-jh.lin@mediatek.com> wrote:
> > > >
> > > > From: Chun-Kuang Hu <chunkuang.hu@kernel.org>
> > > >
> > > > CMDQ is used to update display register in vblank period, so
> > > > it should be execute in next 2 vblank. One vblank interrupt
> > > > before send message (occasionally) and one vblank interrupt
> > > > after cmdq done. If it fail to execute in next 3 vblank,
> > > > tiemout happen.
> > > >
> > > > Signed-off-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>
> > > > Signed-off-by: jason-jh.lin <jason-jh.lin@mediatek.com>
> > > > Reviewed-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>
> > > > ---
> > > >  drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 20 ++++++++++++++++++--
> > > >  1 file changed, 18 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> > > > index e23e3224ac67..dad1f85ee315 100644
> > > > --- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> > > > +++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> > > > @@ -54,6 +54,7 @@ struct mtk_drm_crtc {
> > > >  #if IS_REACHABLE(CONFIG_MTK_CMDQ)
> > > >         struct cmdq_client              cmdq_client;
> > > >         u32                             cmdq_event;
> > > > +       u32                             cmdq_vblank_cnt;
> > > >  #endif
> > > >
> > > >         struct device                   *mmsys_dev;
> > > > @@ -227,7 +228,10 @@ struct mtk_ddp_comp *mtk_drm_ddp_comp_for_plane(struct drm_crtc *crtc,
> > > >  static void ddp_cmdq_cb(struct mbox_client *cl, void *mssg)
> > > >  {
> > > >         struct cmdq_cb_data *data = mssg;
> > > > +       struct cmdq_client *cmdq_cl = container_of(cl, struct cmdq_client, client);
> > > > +       struct mtk_drm_crtc *mtk_crtc = container_of(cmdq_cl, struct mtk_drm_crtc, cmdq_client);
> > > >
> > > > +       mtk_crtc->cmdq_vblank_cnt = 0;
> > > >         cmdq_pkt_destroy(data->pkt);
> > > >  }
> > > >  #endif
> > > > @@ -483,6 +487,15 @@ static void mtk_drm_crtc_update_config(struct mtk_drm_crtc *mtk_crtc,
> > > >                                            cmdq_handle->pa_base,
> > > >                                            cmdq_handle->cmd_buf_size,
> > > >                                            DMA_TO_DEVICE);
> > > > +               /*
> > > > +                * CMDQ command should execute in next 3 vblank.
> > > > +                * One vblank interrupt before send message (occasionally)
> > > > +                * and one vblank interrupt after cmdq done,
> > > > +                * so it's timeout after 3 vblank interrupt.
> > > > +                * If it fail to execute in next 3 vblank, timeout happen.
> > > > +                */
> > > > +               mtk_crtc->cmdq_vblank_cnt = 3;
> > > > +
> > > >                 mbox_send_message(mtk_crtc->cmdq_client.chan, cmdq_handle);
> > > >                 mbox_client_txdone(mtk_crtc->cmdq_client.chan, 0);
> > > >         }
> > > > @@ -499,11 +512,14 @@ static void mtk_crtc_ddp_irq(void *data)
> > > >
> > > >  #if IS_REACHABLE(CONFIG_MTK_CMDQ)
> > > >         if (!priv->data->shadow_register && !mtk_crtc->cmdq_client.chan)
> > > > +               mtk_crtc_ddp_config(crtc, NULL);
> > > > +       else if (mtk_crtc->cmdq_vblank_cnt > 0 && --mtk_crtc->cmdq_vblank_cnt == 0)
> > > I think atomic_dec_and_test() does what you want to do here.
> >
> > I think this operation is not necessary to be atomic operation, and
> > this statement could be reduced to
> >
> > else if (--mtk_crtc->cmdq_vblank_cnt == 0)
>
> I was thinking about using existing helpers to wrap up the counter
> operations, but I agree that it's not necessary.
> Just dropping the redundant check would be good enough.

I find one thing so that I would like this version. If we do not check
mtk_crtc->cmdq_vblank_cnt > 0, mtk_crtc->cmdq_vblank_cnt would
decrease to minus. And one day it would round to positive. So I would
pick this version instead of v6.

Regards,
Chun-Kuang.

>
>
> >
> > >
> > > > +               DRM_ERROR("mtk_crtc %d CMDQ execute command timeout!\n",
> > > > +                         drm_crtc_index(&mtk_crtc->base));
> > > >  #else
> > > >         if (!priv->data->shadow_register)
> > > > -#endif
> > > >                 mtk_crtc_ddp_config(crtc, NULL);
> > > > -
> > > > +#endif
> > > >         mtk_drm_finish_page_flip(mtk_crtc);
> > > >  }
> > > >
> > > > --
> > > > 2.18.0
> > > >

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

end of thread, other threads:[~2021-11-17 23:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20211027021857.20816-1-jason-jh.lin@mediatek.com>
     [not found] ` <20211027021857.20816-4-jason-jh.lin@mediatek.com>
2021-10-27  9:31   ` [PATCH v5 3/6] drm/mediatek: Detect CMDQ execution timeout Fei Shao
2021-10-27 23:47     ` Chun-Kuang Hu
2021-10-28  3:19       ` Fei Shao
2021-11-17 23:51         ` Chun-Kuang Hu
     [not found] ` <20211027021857.20816-6-jason-jh.lin@mediatek.com>
2021-10-27 23:30   ` [PATCH v5 5/6] drm/mediatek: Add mbox_free_channel in mtk_drm_crtc_destroy Chun-Kuang Hu
     [not found] ` <20211027021857.20816-5-jason-jh.lin@mediatek.com>
2021-10-27 23:32   ` [PATCH v5 4/6] drm/mediatek: Add cmdq_handle in mtk_crtc Chun-Kuang Hu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).