Skip to content

Commit 297160d

Browse files
yunfei-mtkmchehab
authored andcommitted
media: mediatek: vcodec: move core context from device to each instance
There are so many lat buffer in core context list, some instances maybe be scheduled for a very long time. Moving the core context to each instance, it only be used to control lat buffer of each instance. And the core work queue of each instance is scheduled by system. Fixes: 2cfca6c ("media: mediatek: vcodec: move lat_buf to the top of core list") Signed-off-by: Yunfei Dong <[email protected]> Reviewed-by: AngeloGioacchino Del Regno <[email protected]> Signed-off-by: Hans Verkuil <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent 2864e30 commit 297160d

File tree

7 files changed

+26
-46
lines changed

7 files changed

+26
-46
lines changed

drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
310310
}
311311

312312
if (IS_VDEC_LAT_ARCH(dev->vdec_pdata->hw_arch)) {
313-
vdec_msg_queue_init_ctx(&dev->msg_queue_core_ctx, MTK_VDEC_CORE);
314313
dev->core_workqueue =
315314
alloc_ordered_workqueue("core-decoder",
316315
WQ_MEM_RECLAIM | WQ_FREEZABLE);

drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,6 @@ struct mtk_vcodec_enc_pdata {
462462
* @enc_capability: used to identify encode capability
463463
*
464464
* @core_workqueue: queue used for core hardware decode
465-
* @msg_queue_core_ctx: msg queue context used for core workqueue
466465
*
467466
* @subdev_dev: subdev hardware device
468467
* @subdev_prob_done: check whether all used hw device is prob done
@@ -511,7 +510,6 @@ struct mtk_vcodec_dev {
511510
unsigned int enc_capability;
512511

513512
struct workqueue_struct *core_workqueue;
514-
struct vdec_msg_queue_ctx msg_queue_core_ctx;
515513

516514
void *subdev_dev[MTK_VDEC_HW_MAX];
517515
int (*subdev_prob_done)(struct mtk_vcodec_dev *vdec_dev);

drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
672672
if (IS_VDEC_INNER_RACING(inst->ctx->dev->dec_capability)) {
673673
memcpy(&share_info->h264_slice_params, &inst->vsi->h264_slice_params,
674674
sizeof(share_info->h264_slice_params));
675-
vdec_msg_queue_qbuf(&inst->ctx->dev->msg_queue_core_ctx, lat_buf);
675+
vdec_msg_queue_qbuf(&inst->ctx->msg_queue.core_ctx, lat_buf);
676676
}
677677

678678
/* wait decoder done interrupt */
@@ -698,7 +698,7 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
698698
if (!IS_VDEC_INNER_RACING(inst->ctx->dev->dec_capability)) {
699699
memcpy(&share_info->h264_slice_params, &inst->vsi->h264_slice_params,
700700
sizeof(share_info->h264_slice_params));
701-
vdec_msg_queue_qbuf(&inst->ctx->dev->msg_queue_core_ctx, lat_buf);
701+
vdec_msg_queue_qbuf(&inst->ctx->msg_queue.core_ctx, lat_buf);
702702
}
703703
mtk_vcodec_debug(inst, "dec num: %d lat crc: 0x%x 0x%x 0x%x", inst->slice_dec_num,
704704
inst->vsi->dec.crc[0], inst->vsi->dec.crc[1], inst->vsi->dec.crc[2]);

drivers/media/platform/mediatek/vcodec/vdec/vdec_hevc_req_multi_if.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ static int vdec_hevc_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
10171017
if (IS_VDEC_INNER_RACING(inst->ctx->dev->dec_capability)) {
10181018
memcpy(&share_info->hevc_slice_params, &inst->vsi->hevc_slice_params,
10191019
sizeof(share_info->hevc_slice_params));
1020-
vdec_msg_queue_qbuf(&inst->ctx->dev->msg_queue_core_ctx, lat_buf);
1020+
vdec_msg_queue_qbuf(&inst->ctx->msg_queue.core_ctx, lat_buf);
10211021
}
10221022

10231023
/* wait decoder done interrupt */
@@ -1043,7 +1043,7 @@ static int vdec_hevc_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
10431043
if (!IS_VDEC_INNER_RACING(inst->ctx->dev->dec_capability)) {
10441044
memcpy(&share_info->hevc_slice_params, &inst->vsi->hevc_slice_params,
10451045
sizeof(share_info->hevc_slice_params));
1046-
vdec_msg_queue_qbuf(&inst->ctx->dev->msg_queue_core_ctx, lat_buf);
1046+
vdec_msg_queue_qbuf(&inst->ctx->msg_queue.core_ctx, lat_buf);
10471047
}
10481048
mtk_vcodec_debug(inst, "dec num: %d lat crc: 0x%x 0x%x 0x%x", inst->slice_dec_num,
10491049
inst->vsi->dec.crc[0], inst->vsi->dec.crc[1], inst->vsi->dec.crc[2]);

drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2119,7 +2119,7 @@ static int vdec_vp9_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
21192119
vdec_msg_queue_update_ube_wptr(&ctx->msg_queue,
21202120
vsi->trans.dma_addr_end +
21212121
ctx->msg_queue.wdma_addr.dma_addr);
2122-
vdec_msg_queue_qbuf(&ctx->dev->msg_queue_core_ctx, lat_buf);
2122+
vdec_msg_queue_qbuf(&ctx->msg_queue.core_ctx, lat_buf);
21232123

21242124
return 0;
21252125
err_free_fb_out:

drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -177,29 +177,20 @@ void vdec_msg_queue_update_ube_wptr(struct vdec_msg_queue *msg_queue, uint64_t u
177177

178178
bool vdec_msg_queue_wait_lat_buf_full(struct vdec_msg_queue *msg_queue)
179179
{
180-
struct vdec_lat_buf *buf, *tmp;
181-
struct list_head *list_core[3];
182-
struct vdec_msg_queue_ctx *core_ctx;
183-
int ret, i, in_core_count = 0, count = 0;
180+
int ret;
184181
long timeout_jiff;
185182

186-
core_ctx = &msg_queue->ctx->dev->msg_queue_core_ctx;
187-
spin_lock(&core_ctx->ready_lock);
188-
list_for_each_entry_safe(buf, tmp, &core_ctx->ready_queue, core_list) {
189-
if (buf && buf->ctx == msg_queue->ctx) {
190-
list_core[in_core_count++] = &buf->core_list;
191-
list_del(&buf->core_list);
192-
}
193-
}
194-
195-
for (i = 0; i < in_core_count; i++) {
196-
list_add(list_core[in_core_count - (1 + i)], &core_ctx->ready_queue);
197-
queue_work(msg_queue->ctx->dev->core_workqueue, &msg_queue->core_work);
183+
if (atomic_read(&msg_queue->lat_list_cnt) == NUM_BUFFER_COUNT) {
184+
mtk_v4l2_debug(3, "wait buf full: list(%d %d) ready_num:%d status:%d",
185+
atomic_read(&msg_queue->lat_list_cnt),
186+
atomic_read(&msg_queue->core_list_cnt),
187+
msg_queue->lat_ctx.ready_num,
188+
msg_queue->status);
189+
return true;
198190
}
199-
spin_unlock(&core_ctx->ready_lock);
200191

201192
timeout_jiff = msecs_to_jiffies(1000 * (NUM_BUFFER_COUNT + 2));
202-
ret = wait_event_timeout(msg_queue->ctx->msg_queue.core_dec_done,
193+
ret = wait_event_timeout(msg_queue->core_dec_done,
203194
msg_queue->lat_ctx.ready_num == NUM_BUFFER_COUNT,
204195
timeout_jiff);
205196
if (ret) {
@@ -208,18 +199,9 @@ bool vdec_msg_queue_wait_lat_buf_full(struct vdec_msg_queue *msg_queue)
208199
return true;
209200
}
210201

211-
spin_lock(&core_ctx->ready_lock);
212-
list_for_each_entry_safe(buf, tmp, &core_ctx->ready_queue, core_list) {
213-
if (buf && buf->ctx == msg_queue->ctx) {
214-
count++;
215-
list_del(&buf->core_list);
216-
}
217-
}
218-
spin_unlock(&core_ctx->ready_lock);
219-
220-
mtk_v4l2_err("failed with lat buf isn't full: list(%d %d) count:%d",
202+
mtk_v4l2_err("failed with lat buf isn't full: list(%d %d)",
221203
atomic_read(&msg_queue->lat_list_cnt),
222-
atomic_read(&msg_queue->core_list_cnt), count);
204+
atomic_read(&msg_queue->core_list_cnt));
223205

224206
return false;
225207
}
@@ -247,6 +229,8 @@ void vdec_msg_queue_deinit(struct vdec_msg_queue *msg_queue,
247229

248230
kfree(lat_buf->private_data);
249231
}
232+
233+
cancel_work_sync(&msg_queue->core_work);
250234
}
251235

252236
static void vdec_msg_queue_core_work(struct work_struct *work)
@@ -258,11 +242,11 @@ static void vdec_msg_queue_core_work(struct work_struct *work)
258242
struct mtk_vcodec_dev *dev = ctx->dev;
259243
struct vdec_lat_buf *lat_buf;
260244

261-
spin_lock(&ctx->dev->msg_queue_core_ctx.ready_lock);
245+
spin_lock(&msg_queue->core_ctx.ready_lock);
262246
ctx->msg_queue.status &= ~CONTEXT_LIST_QUEUED;
263-
spin_unlock(&ctx->dev->msg_queue_core_ctx.ready_lock);
247+
spin_unlock(&msg_queue->core_ctx.ready_lock);
264248

265-
lat_buf = vdec_msg_queue_dqbuf(&dev->msg_queue_core_ctx);
249+
lat_buf = vdec_msg_queue_dqbuf(&msg_queue->core_ctx);
266250
if (!lat_buf)
267251
return;
268252

@@ -276,12 +260,11 @@ static void vdec_msg_queue_core_work(struct work_struct *work)
276260
mtk_vcodec_dec_disable_hardware(ctx, MTK_VDEC_CORE);
277261
vdec_msg_queue_qbuf(&ctx->msg_queue.lat_ctx, lat_buf);
278262

279-
wake_up_all(&ctx->msg_queue.core_dec_done);
280263
if (!(ctx->msg_queue.status & CONTEXT_LIST_QUEUED) &&
281264
atomic_read(&msg_queue->core_list_cnt)) {
282-
spin_lock(&ctx->dev->msg_queue_core_ctx.ready_lock);
265+
spin_lock(&msg_queue->core_ctx.ready_lock);
283266
ctx->msg_queue.status |= CONTEXT_LIST_QUEUED;
284-
spin_unlock(&ctx->dev->msg_queue_core_ctx.ready_lock);
267+
spin_unlock(&msg_queue->core_ctx.ready_lock);
285268
queue_work(ctx->dev->core_workqueue, &msg_queue->core_work);
286269
}
287270
}
@@ -297,8 +280,8 @@ int vdec_msg_queue_init(struct vdec_msg_queue *msg_queue,
297280
if (msg_queue->wdma_addr.size)
298281
return 0;
299282

300-
msg_queue->ctx = ctx;
301283
vdec_msg_queue_init_ctx(&msg_queue->lat_ctx, MTK_VDEC_LAT0);
284+
vdec_msg_queue_init_ctx(&msg_queue->core_ctx, MTK_VDEC_CORE);
302285
INIT_WORK(&msg_queue->core_work, vdec_msg_queue_core_work);
303286

304287
atomic_set(&msg_queue->lat_list_cnt, 0);

drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ struct vdec_lat_buf {
8484
* @wdma_wptr_addr: ube write point
8585
* @core_work: core hardware work
8686
* @lat_ctx: used to store lat buffer list
87-
* @ctx: point to mtk_vcodec_ctx
87+
* @core_ctx: used to store core buffer list
8888
*
8989
* @lat_list_cnt: used to record each instance lat list count
9090
* @core_list_cnt: used to record each instance core list count
@@ -100,7 +100,7 @@ struct vdec_msg_queue {
100100

101101
struct work_struct core_work;
102102
struct vdec_msg_queue_ctx lat_ctx;
103-
struct mtk_vcodec_ctx *ctx;
103+
struct vdec_msg_queue_ctx core_ctx;
104104

105105
atomic_t lat_list_cnt;
106106
atomic_t core_list_cnt;

0 commit comments

Comments
 (0)