[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <bf9d84ad6973d55f40bafdb9a70dc49178d4af10.camel@ndufresne.ca>
Date: Tue, 16 Dec 2025 16:27:05 -0500
From: Nicolas Dufresne <nicolas@...fresne.ca>
To: Kyrie Wu <kyrie.wu@...iatek.com>, Hans Verkuil
<hverkuil-cisco@...all.nl>, Mauro Carvalho Chehab <mchehab@...nel.org>,
Rob Herring <robh@...nel.org>, Krzysztof Kozlowski <krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>, Matthias Brugger
<matthias.bgg@...il.com>, AngeloGioacchino Del Regno
<angelogioacchino.delregno@...labora.com>, linux-media@...r.kernel.org,
devicetree@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org, linux-mediatek@...ts.infradead.org
Subject: Re: [PATCH v11 04/12] media: mediatek: jpeg: fix stop streaming
flow for multi-core
Le mardi 02 décembre 2025 à 17:47 +0800, Kyrie Wu a écrit :
> For jpeg multi-core architecture, if all hardware run at the
> same time, some input and output buffers are occupied.
> If one hardware is completed firstly, while other hardwares are
is compelted -> completes
harwares -> core, matches mtk_jpeg_core.c file name
> still running. The decoding completion signal calls
decoding -> decode.
> mtk_jpeg_dec_stop_streaming, and the function of v4l2_m2m_buf_done
> is called in mtk_jpeg_dec_stop_streaming to complete all
> input/output buffers. However, some buffers are occupied by other
> hardwares, resulting in errors. It needs to add a counter to
> calculate the used decoding buffer counts, it will increase 1 when
> the buffer set to hardware and decrease to 0 until the all buffers
> decoded and the function could continue to be executed.
More things to fix, also same for other of your commits, please reflow between
70 and 75 as suggested in the guide. It should look even.
>
> Fixes: 0fa49df4222f ("media: mtk-jpegdec: support jpegdec multi-hardware")
> Fixes: dedc21500334 ("media: mtk-jpegdec: add jpeg decode worker interface")
> Fixes: 934e8bccac95 ("mtk-jpegenc: support jpegenc multi-hardware")
> Fixes: 5fb1c2361e56 ("mtk-jpegenc: add jpeg encode worker interface")
>
> Signed-off-by: Kyrie Wu <kyrie.wu@...iatek.com>
> ---
> .../media/platform/mediatek/jpeg/mtk_jpeg_core.c | 16 ++++++++++++++++
> .../media/platform/mediatek/jpeg/mtk_jpeg_core.h | 2 ++
> .../platform/mediatek/jpeg/mtk_jpeg_dec_hw.c | 9 +++++++++
> .../platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 9 +++++++++
> 4 files changed, 36 insertions(+)
>
> diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> index bd0afc93d491..59fd79c89f88 100644
> --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> @@ -857,8 +857,12 @@ static struct vb2_v4l2_buffer *mtk_jpeg_buf_remove(struct mtk_jpeg_ctx *ctx,
> static void mtk_jpeg_enc_stop_streaming(struct vb2_queue *q)
> {
> struct mtk_jpeg_ctx *ctx = vb2_get_drv_priv(q);
> + struct mtk_jpeg_dev *jpeg = ctx->jpeg;
> struct vb2_v4l2_buffer *vb;
>
> + if (jpeg->variant->multi_core)
> + wait_event(jpeg->hw_wq, (atomic_read(&ctx->buf_list_cnt) == 0));
> +
Can't it simply be solved with vb2_wait_for_all_buffers() ?
Nicolas
> while ((vb = mtk_jpeg_buf_remove(ctx, q->type)))
> v4l2_m2m_buf_done(vb, VB2_BUF_STATE_ERROR);
> }
> @@ -866,6 +870,7 @@ static void mtk_jpeg_enc_stop_streaming(struct vb2_queue *q)
> static void mtk_jpeg_dec_stop_streaming(struct vb2_queue *q)
> {
> struct mtk_jpeg_ctx *ctx = vb2_get_drv_priv(q);
> + struct mtk_jpeg_dev *jpeg = ctx->jpeg;
> struct vb2_v4l2_buffer *vb;
>
> /*
> @@ -873,6 +878,9 @@ static void mtk_jpeg_dec_stop_streaming(struct vb2_queue *q)
> * Before STREAMOFF, we still have to return the old resolution and
> * subsampling. Update capture queue when the stream is off.
> */
> + if (jpeg->variant->multi_core)
> + wait_event(jpeg->hw_wq, (atomic_read(&ctx->buf_list_cnt) == 0));
> +
> if (ctx->state == MTK_JPEG_SOURCE_CHANGE &&
> V4L2_TYPE_IS_CAPTURE(q->type)) {
> struct mtk_jpeg_src_buf *src_buf;
> @@ -1181,6 +1189,7 @@ static int mtk_jpeg_open(struct file *file)
> spin_lock_init(&ctx->done_queue_lock);
> v4l2_fh_init(&ctx->fh, vfd);
> v4l2_fh_add(&ctx->fh, file);
> + atomic_set(&ctx->buf_list_cnt, 0);
>
> ctx->jpeg = jpeg;
> ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(jpeg->m2m_dev, ctx,
> @@ -1563,6 +1572,11 @@ static int mtk_jpegdec_set_hw_param(struct mtk_jpeg_ctx *ctx,
> return 0;
> }
>
> +static void jpeg_buf_queue_inc(struct mtk_jpeg_ctx *ctx)
> +{
> + atomic_inc(&ctx->buf_list_cnt);
> +}
> +
> static irqreturn_t mtk_jpeg_enc_done(struct mtk_jpeg_dev *jpeg)
> {
> struct mtk_jpeg_ctx *ctx;
> @@ -1671,6 +1685,7 @@ static void mtk_jpegenc_worker(struct work_struct *work)
> &src_buf->vb2_buf);
> mtk_jpeg_set_enc_params(ctx, comp_jpeg[hw_id]->reg_base);
> mtk_jpeg_enc_start(comp_jpeg[hw_id]->reg_base);
> + jpeg_buf_queue_inc(ctx);
> v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
> spin_unlock_irqrestore(&comp_jpeg[hw_id]->hw_lock, flags);
>
> @@ -1786,6 +1801,7 @@ static void mtk_jpegdec_worker(struct work_struct *work)
> &bs,
> &fb);
> mtk_jpeg_dec_start(comp_jpeg[hw_id]->reg_base);
> + jpeg_buf_queue_inc(ctx);
> v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
> spin_unlock_irqrestore(&comp_jpeg[hw_id]->hw_lock, flags);
>
> diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
> index 148fd41759b7..33f7fbc4ca5e 100644
> --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
> +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
> @@ -288,6 +288,7 @@ struct mtk_jpeg_q_data {
> * @dst_done_queue: encoded frame buffer queue
> * @done_queue_lock: encoded frame operation spinlock
> * @last_done_frame_num: the last encoded frame number
> + * @buf_list_cnt: the frame buffer count own by jpeg driver
> */
> struct mtk_jpeg_ctx {
> struct mtk_jpeg_dev *jpeg;
> @@ -306,6 +307,7 @@ struct mtk_jpeg_ctx {
> /* spinlock protecting the encode done buffer */
> spinlock_t done_queue_lock;
> u32 last_done_frame_num;
> + atomic_t buf_list_cnt;
> };
>
> #endif /* _MTK_JPEG_CORE_H */
> diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
> index a1e54715cb7e..84d12eea35f7 100644
> --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
> +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
> @@ -519,6 +519,11 @@ static void mtk_jpegdec_put_buf(struct mtk_jpegdec_comp_dev *jpeg)
> spin_unlock_irqrestore(&ctx->done_queue_lock, flags);
> }
>
> +static void jpeg_buf_queue_dec(struct mtk_jpeg_ctx *ctx)
> +{
> + atomic_dec(&ctx->buf_list_cnt);
> +}
> +
> static void mtk_jpegdec_timeout_work(struct work_struct *work)
> {
> enum vb2_buffer_state buf_state = VB2_BUF_STATE_ERROR;
> @@ -527,9 +532,11 @@ static void mtk_jpegdec_timeout_work(struct work_struct *work)
> job_timeout_work.work);
> struct mtk_jpeg_dev *master_jpeg = cjpeg->master_dev;
> struct vb2_v4l2_buffer *src_buf, *dst_buf;
> + struct mtk_jpeg_ctx *ctx;
>
> src_buf = cjpeg->hw_param.src_buffer;
> dst_buf = cjpeg->hw_param.dst_buffer;
> + ctx = cjpeg->hw_param.curr_ctx;
> v4l2_m2m_buf_copy_metadata(src_buf, dst_buf, true);
>
> mtk_jpeg_dec_reset(cjpeg->reg_base);
> @@ -540,6 +547,7 @@ static void mtk_jpegdec_timeout_work(struct work_struct *work)
> wake_up(&master_jpeg->hw_wq);
> v4l2_m2m_buf_done(src_buf, buf_state);
> mtk_jpegdec_put_buf(cjpeg);
> + jpeg_buf_queue_dec(ctx);
> }
>
> static irqreturn_t mtk_jpegdec_hw_irq_handler(int irq, void *priv)
> @@ -580,6 +588,7 @@ static irqreturn_t mtk_jpegdec_hw_irq_handler(int irq, void *priv)
> buf_state = VB2_BUF_STATE_DONE;
> v4l2_m2m_buf_done(src_buf, buf_state);
> mtk_jpegdec_put_buf(jpeg);
> + jpeg_buf_queue_dec(ctx);
> pm_runtime_put(ctx->jpeg->dev);
> clk_disable_unprepare(jpeg->jdec_clk.clks->clk);
>
> diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
> index 28d05909c96f..1862444f35f5 100644
> --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
> +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
> @@ -248,6 +248,11 @@ static void mtk_jpegenc_put_buf(struct mtk_jpegenc_comp_dev *jpeg)
> spin_unlock_irqrestore(&ctx->done_queue_lock, flags);
> }
>
> +static void jpeg_buf_queue_enc(struct mtk_jpeg_ctx *ctx)
> +{
> + atomic_dec(&ctx->buf_list_cnt);
> +}
> +
> static void mtk_jpegenc_timeout_work(struct work_struct *work)
> {
> struct delayed_work *dly_work = to_delayed_work(work);
> @@ -258,9 +263,11 @@ static void mtk_jpegenc_timeout_work(struct work_struct *work)
> struct mtk_jpeg_dev *master_jpeg = cjpeg->master_dev;
> enum vb2_buffer_state buf_state = VB2_BUF_STATE_ERROR;
> struct vb2_v4l2_buffer *src_buf, *dst_buf;
> + struct mtk_jpeg_ctx *ctx;
>
> src_buf = cjpeg->hw_param.src_buffer;
> dst_buf = cjpeg->hw_param.dst_buffer;
> + ctx = cjpeg->hw_param.curr_ctx;
> v4l2_m2m_buf_copy_metadata(src_buf, dst_buf, true);
>
> mtk_jpeg_enc_reset(cjpeg->reg_base);
> @@ -271,6 +278,7 @@ static void mtk_jpegenc_timeout_work(struct work_struct *work)
> wake_up(&master_jpeg->hw_wq);
> v4l2_m2m_buf_done(src_buf, buf_state);
> mtk_jpegenc_put_buf(cjpeg);
> + jpeg_buf_queue_enc(ctx);
> }
>
> static irqreturn_t mtk_jpegenc_hw_irq_handler(int irq, void *priv)
> @@ -304,6 +312,7 @@ static irqreturn_t mtk_jpegenc_hw_irq_handler(int irq, void *priv)
> buf_state = VB2_BUF_STATE_DONE;
> v4l2_m2m_buf_done(src_buf, buf_state);
> mtk_jpegenc_put_buf(jpeg);
> + jpeg_buf_queue_enc(ctx);
> pm_runtime_put(ctx->jpeg->dev);
> clk_disable_unprepare(jpeg->venc_clk.clks->clk);
>
Download attachment "signature.asc" of type "application/pgp-signature" (229 bytes)
Powered by blists - more mailing lists