From patchwork Sat Dec 10 07:32:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?WXVuZmVpIERvbmcgKOiRo+S6kemjnik=?= X-Patchwork-Id: 31983 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1185853wrr; Fri, 9 Dec 2022 23:40:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf7ZhrmCogsqgYE2w57OoNS7fos2p7YdAb57GwM/8FBvFqjAduYX6gv+CHyZ2o8DU6O9XAbS X-Received: by 2002:a05:6a20:690c:b0:9d:efbe:a113 with SMTP id q12-20020a056a20690c00b0009defbea113mr13936101pzj.35.1670658013767; Fri, 09 Dec 2022 23:40:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670658013; cv=none; d=google.com; s=arc-20160816; b=R/mmNQDqMPhsfJt7lHxwQ/4tD4dsde30hap/1G97nzvcliNdnFZKAc1J/enXIMRNLm LJ+JMNAf8Q+0b4J40dx9Fyr2KmltNGZCLjGcB0agEWixYSUlWemkobhU+r/9CDkBztyY 3cy7MOhPKm2FNY8T0I/PQnBocKymufsSDRkWZhJpf65q8PzZceqUEaHIYh6E6EISTpgO vLKyq061btLaFZ68g1owENX8pK9ZUq1Xjr9S4iZrJafM7ZNwghglcKHVKpeIAxwovfVy m6qKRA2HnLAT6wetacGu/cBA1SSvVbI4ukMwbBIyMW+HdmPx9M9jzXl7rKgcup7TiQxC uRpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=v587XwApxR6glrcE+8uPlmJ2HRcCy46cr/DumtCsnYY=; b=TdKGQa1Bn6Q+EOpEsWHfSExnaMNWKX3a0NWLSb5DFkNeq3NMbY7Gr1ykvYtsa4bym+ 5L/wu/CCSkp5xiTMaafT1Z2l8RimQKV9nlnI97pazMGPjXSVV9zzFRHBvK/HTWS60WHz m4tRHVMgwvO9t+gKRPHHeuhpShQKanD5SPadY79zxPbxOCuPoQzj/TDX1t0vlSGj8vp6 6wp9OpWS0dMPiUlXCAU2l2LeaKgMOGrGWh3MKLyk6W6rT6ns1TZrGrVxd2GAKLxa+67m U4c2uBbNoc2fVAR9Xvhu/bS5zp1EDL2YFnox7ftAgVvIPUkyDFqBzhsItUD/JRM8LBl/ DU8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=B4kCdSG6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c125-20020a633583000000b00478496a1373si3858103pga.382.2022.12.09.23.39.53; Fri, 09 Dec 2022 23:40:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=B4kCdSG6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229845AbiLJHc7 (ORCPT + 99 others); Sat, 10 Dec 2022 02:32:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229756AbiLJHci (ORCPT ); Sat, 10 Dec 2022 02:32:38 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5B3BEC; Fri, 9 Dec 2022 23:32:34 -0800 (PST) X-UUID: db90b74f06ef418b8e03b72166c7869c-20221210 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=v587XwApxR6glrcE+8uPlmJ2HRcCy46cr/DumtCsnYY=; b=B4kCdSG6W2bcp5zm4A1XmdnGDPkeYUC+tvAvPHIDdHSMTNef6269+wzdxB+i9p9SCweXdrKiwNm374rHnnms2OYpFcoOEIkOm5qJYOkw87vDgJxhzJQIuOYG1cPCwDQeP/r/saNj1c9f6F+xyWHvLlDj3mets+oONYgfnwYjcLo=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.14,REQID:f40990b9-795e-4744-b14d-e33b1466438c,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:95 X-CID-INFO: VERSION:1.1.14,REQID:f40990b9-795e-4744-b14d-e33b1466438c,IP:0,URL :0,TC:0,Content:0,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Spam_GS981B3D,ACTION :quarantine,TS:95 X-CID-META: VersionHash:dcaaed0,CLOUDID:cce4dc24-4387-4253-a41d-4f6f2296b154,B ulkID:221210153226RJJR5LFY,BulkQuantity:0,Recheck:0,SF:38|28|17|19|48,TC:n il,Content:0,EDM:-3,IP:nil,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 X-UUID: db90b74f06ef418b8e03b72166c7869c-20221210 Received: from mtkmbs13n1.mediatek.inc [(172.21.101.193)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1767036929; Sat, 10 Dec 2022 15:32:23 +0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.3; Sat, 10 Dec 2022 15:32:21 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas11.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Sat, 10 Dec 2022 15:32:20 +0800 From: Yunfei Dong To: Yunfei Dong , Chen-Yu Tsai , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Tiffany Lin CC: Mauro Carvalho Chehab , Matthias Brugger , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , , , , , , Subject: [PATCH 1/5] media: mediatek: vcodec: add params to record lat and core lat_buf count Date: Sat, 10 Dec 2022 15:32:14 +0800 Message-ID: <20221210073218.17350-2-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221210073218.17350-1-yunfei.dong@mediatek.com> References: <20221210073218.17350-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-MTK: N X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,RDNS_NONE, SPF_HELO_PASS,SPF_PASS,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751811897894927685?= X-GMAIL-MSGID: =?utf-8?q?1751811897894927685?= Using lat_buf to share decoder information between lat and core work queue, adding params to record the buf count. Fixes: 365e4ba01df4 ("media: mtk-vcodec: Add work queue for core hardware decode") Signed-off-by: Yunfei Dong --- .../platform/mediatek/vcodec/vdec_msg_queue.c | 32 ++++++++++++++++++- .../platform/mediatek/vcodec/vdec_msg_queue.h | 9 ++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c index dc2004790a47..af7ddba1923a 100644 --- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c +++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c @@ -52,6 +52,30 @@ static struct list_head *vdec_get_buf_list(int hardware_index, struct vdec_lat_b } } +static void vdec_msg_queue_inc(struct vdec_msg_queue *msg_queue, int hardware_index) +{ + mutex_lock(&msg_queue->list_cnt_mutex); + + if (hardware_index == MTK_VDEC_CORE) + atomic_inc(&msg_queue->core_list_cnt); + else + atomic_inc(&msg_queue->lat_list_cnt); + + mutex_unlock(&msg_queue->list_cnt_mutex); +} + +static void vdec_msg_queue_dec(struct vdec_msg_queue *msg_queue, int hardware_index) +{ + mutex_lock(&msg_queue->list_cnt_mutex); + + if (hardware_index == MTK_VDEC_CORE) + atomic_dec(&msg_queue->core_list_cnt); + else + atomic_dec(&msg_queue->lat_list_cnt); + + mutex_unlock(&msg_queue->list_cnt_mutex); +} + int vdec_msg_queue_qbuf(struct vdec_msg_queue_ctx *msg_ctx, struct vdec_lat_buf *buf) { struct list_head *head; @@ -72,6 +96,7 @@ int vdec_msg_queue_qbuf(struct vdec_msg_queue_ctx *msg_ctx, struct vdec_lat_buf queue_work(buf->ctx->dev->core_workqueue, &buf->ctx->msg_queue.core_work); + vdec_msg_queue_inc(&buf->ctx->msg_queue, msg_ctx->hardware_index); mtk_v4l2_debug(3, "enqueue buf type: %d addr: 0x%p num: %d", msg_ctx->hardware_index, buf, msg_ctx->ready_num); spin_unlock(&msg_ctx->ready_lock); @@ -127,6 +152,7 @@ struct vdec_lat_buf *vdec_msg_queue_dqbuf(struct vdec_msg_queue_ctx *msg_ctx) return NULL; } list_del(head); + vdec_msg_queue_dec(&buf->ctx->msg_queue, msg_ctx->hardware_index); msg_ctx->ready_num--; mtk_v4l2_debug(3, "dqueue buf type:%d addr: 0x%p num: %d", @@ -241,10 +267,14 @@ int vdec_msg_queue_init(struct vdec_msg_queue *msg_queue, vdec_msg_queue_init_ctx(&msg_queue->lat_ctx, MTK_VDEC_LAT0); INIT_WORK(&msg_queue->core_work, vdec_msg_queue_core_work); + + atomic_set(&msg_queue->lat_list_cnt, 0); + atomic_set(&msg_queue->core_list_cnt, 0); + mutex_init(&msg_queue->list_cnt_mutex); + msg_queue->wdma_addr.size = vde_msg_queue_get_trans_size(ctx->picinfo.buf_w, ctx->picinfo.buf_h); - err = mtk_vcodec_mem_alloc(ctx, &msg_queue->wdma_addr); if (err) { mtk_v4l2_err("failed to allocate wdma_addr buf"); diff --git a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h index c43d427f5f54..94e01a618c5a 100644 --- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h +++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h @@ -72,6 +72,10 @@ struct vdec_lat_buf { * @wdma_wptr_addr: ube write point * @core_work: core hardware work * @lat_ctx: used to store lat buffer list + * + * @lat_list_cnt: used to record each instance lat list count + * @core_list_cnt: used to record each instance core list count + * @list_cnt_mutex: used to protect list count */ struct vdec_msg_queue { struct vdec_lat_buf lat_buf[NUM_BUFFER_COUNT]; @@ -82,6 +86,11 @@ struct vdec_msg_queue { struct work_struct core_work; struct vdec_msg_queue_ctx lat_ctx; + + atomic_t lat_list_cnt; + atomic_t core_list_cnt; + /* Protects access to lat and core list cnt */ + struct mutex list_cnt_mutex; }; /** From patchwork Sat Dec 10 07:32:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?WXVuZmVpIERvbmcgKOiRo+S6kemjnik=?= X-Patchwork-Id: 31978 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1184458wrr; Fri, 9 Dec 2022 23:34:43 -0800 (PST) X-Google-Smtp-Source: AA0mqf6dycRT2hGyfdm4lL2sxSthbgtbIz6H1Xb2ZJcU3TWg4+yUtH4zKx/sjaLvLcIeI2sFSKGP X-Received: by 2002:a05:6402:1f8e:b0:45c:835c:eab6 with SMTP id c14-20020a0564021f8e00b0045c835ceab6mr8377715edc.36.1670657683550; Fri, 09 Dec 2022 23:34:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670657683; cv=none; d=google.com; s=arc-20160816; b=hBLxP/mCLAR6nq9SRucbP0AVoh/+Z9yBuoO2MMxSoU6rPn8fMEirti+dKfaMjUC6aj 1axWZgTY+MqMMIPi80nkufflE4pNq0/kixv3Oj+0MeLniUHqQLwvpIUM8+TY957N4kam yD2yeYy2smUeUVZ02ICXMsR60T0bqhr0lJcKB8R3ro1h0wRAphTtNW2XpwBCbQWRUXPI Zl1nyDX/d+OfTYqax4yIS9Ds0HP8tooIWe/WsQf9OLtjfA8b0AIvJeUI+ICaS5nyaESR eW/OljypLFhhshpJZX1xxObIp3M9PGnhbWKZVYsj2bP1t2QLlFKavrI10AUjMgVFlS60 0jmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sAiL5PkBTmgJc7hwfS7p7RsdgPoufa31hrlJwDk2pyc=; b=uwwot/ZQTgcHpTjYqzg+lyZuOFbqK6KX2Ky6lfXXcSKh53iHGdljT53Rin4TuXfUVo RCJocLBDyIjzSjYvKBn83lWElhKUyoNN2INnvnwhuNjsPzEkJpof+0vRB445Z7r6jcBB griRriy1Ggxjf+PaaKyuPfvUdwdLzHYq7koGRuJzyrjNB86ZovaALgL6VIsBIg/uEIb3 wo+94Wo8/Brd3fRFM0Z/n9EGO/WsJrWdvxsuYQauCpmaqqJtQRuNU4vcwbXiUIiTh8QU iup4kDE1t909QT8z5NP1pvw/AAdD9116w3E6XexjCXlo2R9r1yFxa9tz2QhsOBSvgo93 nCtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=solOnwkw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y1-20020a50e601000000b004677d91cdeasi2969046edm.244.2022.12.09.23.34.20; Fri, 09 Dec 2022 23:34:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=solOnwkw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229734AbiLJHch (ORCPT + 99 others); Sat, 10 Dec 2022 02:32:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229721AbiLJHcf (ORCPT ); Sat, 10 Dec 2022 02:32:35 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0599925E87; Fri, 9 Dec 2022 23:32:29 -0800 (PST) X-UUID: 87ab1a13f3444c90a7284eeea5fb23ef-20221210 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=sAiL5PkBTmgJc7hwfS7p7RsdgPoufa31hrlJwDk2pyc=; b=solOnwkwjOuKOGh0w3+B7MaXJccBeV4p1C1Q88TCZAoA5f6ztVFIXBy4WPzzyK+KzryARfeKICB8s5pCTrOiJcws5KeDSyTLiJEZSE79kzRlL7GW9UothvE/0pOIfuzElIHRjgjU/WNsdRwTh+tAHWkvjbiJTNU+pcA3XVSW4oA=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.14,REQID:721d517f-bf02-474c-851e-e11a6bdfc3aa,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:dcaaed0,CLOUDID:cee4dc24-4387-4253-a41d-4f6f2296b154,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 X-UUID: 87ab1a13f3444c90a7284eeea5fb23ef-20221210 Received: from mtkexhb02.mediatek.inc [(172.21.101.103)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 2081499845; Sat, 10 Dec 2022 15:32:24 +0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs11n1.mediatek.inc (172.21.101.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.15; Sat, 10 Dec 2022 15:32:22 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas11.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Sat, 10 Dec 2022 15:32:21 +0800 From: Yunfei Dong To: Yunfei Dong , Chen-Yu Tsai , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Tiffany Lin CC: Mauro Carvalho Chehab , Matthias Brugger , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , , , , , , Subject: [PATCH 2/5] media: mediatek: vcodec: using each instance lat_buf count replace core ready list Date: Sat, 10 Dec 2022 15:32:15 +0800 Message-ID: <20221210073218.17350-3-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221210073218.17350-1-yunfei.dong@mediatek.com> References: <20221210073218.17350-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-MTK: N X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, T_SPF_TEMPERROR,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751811551551161470?= X-GMAIL-MSGID: =?utf-8?q?1751811551551161470?= Core Hardware decoder depends on each instance lat_buf count, calling queue_work decode again when the lat_buf count of each instance isn't zero. Fixes: 365e4ba01df4 ("media: mtk-vcodec: Add work queue for core hardware decode") Signed-off-by: Yunfei Dong --- drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c index af7ddba1923a..2b88065d4d2a 100644 --- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c +++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c @@ -247,7 +247,7 @@ static void vdec_msg_queue_core_work(struct work_struct *work) mtk_vcodec_dec_disable_hardware(ctx, MTK_VDEC_CORE); vdec_msg_queue_qbuf(&ctx->msg_queue.lat_ctx, lat_buf); - if (!list_empty(&dev->msg_queue_core_ctx.ready_queue)) { + if (atomic_read(&lat_buf->ctx->msg_queue.core_list_cnt)) { mtk_v4l2_debug(3, "re-schedule to decode for core: %d", dev->msg_queue_core_ctx.ready_num); queue_work(dev->core_workqueue, &msg_queue->core_work); From patchwork Sat Dec 10 07:32:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?WXVuZmVpIERvbmcgKOiRo+S6kemjnik=?= X-Patchwork-Id: 31981 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1185218wrr; Fri, 9 Dec 2022 23:37:34 -0800 (PST) X-Google-Smtp-Source: AA0mqf78ThXm7NrI87FAy1/yl9XjVaEAx+Rs5cjc2R6lpUcymvkMOzc5vmnxwaN2In/ZxQ7BjBC7 X-Received: by 2002:a17:906:55d5:b0:7c1:f64:61f1 with SMTP id z21-20020a17090655d500b007c10f6461f1mr6671981ejp.45.1670657853745; Fri, 09 Dec 2022 23:37:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670657853; cv=none; d=google.com; s=arc-20160816; b=YE76mbPr91eaOFDyOliOQY6JtXj7SCpWqOQX3Z9P53vFoqnoJRmm8V9m/qJzJz/ZmA vnxVeh5yrEEKbGYR9Chgx0r3g7+cRTvZQdwY2joxP4gGHAQi7nwy7NOxQ5uKNM5X4nHq 4h0VqLKxtx8sDstcK+Jd4wM9YfZIz9zQF8xIuZ2J+cX3381i8CTBjoooM8YSKqsGMQOX KtArwibmBX+cLfBtbW2GqRm1nB49Z5tRy0q4/rsmabfR+cXOhTH4P8J5UuY95GYGoOkV 8C2wMdqaAd2X57r3pVd6E/yVvpNaIQgRYJW4z43rfuZmqx1KP4GNCbbqT1tu6BwKT/yg A9Fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VOw6AP+dqwsKppLZIIsKU5kSHbhWeg9EUE99I+EJGB4=; b=MybSL+mJYPDzSKWyrkTEYCDxWVX2Y1bwAB/80IJWL36QLMAvAJoFdvZNF/HFeNAPgW SymxO4sxr8/dReDdrpBLGQSGTlWpc1rr5QYrQRGS7DF1+nUGzYC7l0swUwVDv5aE6bu1 gW6Vv7e+8W1BjhSa79sEO/rf+e0Eo+0W3sq10jx+ZIQDOm/XV6f9Egr4hqOlyaLtVaHO LMqjtLUd8DIUC1H2TRm5RsDBTm6VulmpPFTFHvfvimQ03QLGLKwspo9ziRawFv6yYWaG 5bA/p3oT/I0Fv4TgLA+EvujlfSv60maKW19acak9K46sEuVQD1qU7xFGgSrVTHpA5P+B eHvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=tu6jdsJt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sz24-20020a1709078b1800b0078dad659776si1577106ejc.320.2022.12.09.23.37.10; Fri, 09 Dec 2022 23:37:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=tu6jdsJt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229821AbiLJHcy (ORCPT + 99 others); Sat, 10 Dec 2022 02:32:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229749AbiLJHci (ORCPT ); Sat, 10 Dec 2022 02:32:38 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2BC513C; Fri, 9 Dec 2022 23:32:34 -0800 (PST) X-UUID: 861c897e684e41b8bdece7b7c905ac0a-20221210 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=VOw6AP+dqwsKppLZIIsKU5kSHbhWeg9EUE99I+EJGB4=; b=tu6jdsJtx4Uzc4GVlcvlC3GvXiGr81Ak3kDoLlfq9j7h0vbNGXcfQGFQ9A6rbPIhw+3+hnlVPZnPQ7s4obISTYt+kPDF4WqM1jbRx3tdpbd56urDstXpiPdwIV6rKUcd2Y0InFEa0TsZJwEU2Yb1AbbPz4e63xG6DbHoKrrWOD8=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.14,REQID:a6dfaacc-c8b5-43c8-9f8c-7e40ff014fc8,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:95 X-CID-INFO: VERSION:1.1.14,REQID:a6dfaacc-c8b5-43c8-9f8c-7e40ff014fc8,IP:0,URL :0,TC:0,Content:0,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Spam_GS981B3D,ACTION :quarantine,TS:95 X-CID-META: VersionHash:dcaaed0,CLOUDID:66e01717-b863-49f8-8228-cbdfeedd1fa4,B ulkID:221210153226DM0RCII6,BulkQuantity:0,Recheck:0,SF:38|28|17|19|48,TC:n il,Content:0,EDM:-3,IP:nil,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 X-UUID: 861c897e684e41b8bdece7b7c905ac0a-20221210 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1679060076; Sat, 10 Dec 2022 15:32:25 +0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs11n2.mediatek.inc (172.21.101.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.15; Sat, 10 Dec 2022 15:32:23 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas11.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Sat, 10 Dec 2022 15:32:22 +0800 From: Yunfei Dong To: Yunfei Dong , Chen-Yu Tsai , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Tiffany Lin CC: Mauro Carvalho Chehab , Matthias Brugger , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , , , , , , Subject: [PATCH 3/5] media: mediatek: vcodec: move lat_buf to the top of core list Date: Sat, 10 Dec 2022 15:32:16 +0800 Message-ID: <20221210073218.17350-4-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221210073218.17350-1-yunfei.dong@mediatek.com> References: <20221210073218.17350-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-MTK: N X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,RDNS_NONE, SPF_HELO_PASS,SPF_PASS,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751811729542841936?= X-GMAIL-MSGID: =?utf-8?q?1751811729542841936?= Current instance will decode done when begin to wait lat buf full, move the lat_buf of current instance to the top of core list to make sure current instance's lat_buf will be used firstly. Fixes: 365e4ba01df4 ("media: mtk-vcodec: Add work queue for core hardware decode") Signed-off-by: Yunfei Dong Reviewed-by: AngeloGioacchino Del Regno --- .../platform/mediatek/vcodec/vdec_msg_queue.c | 16 ++++++++++++++++ .../platform/mediatek/vcodec/vdec_msg_queue.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c index 2b88065d4d2a..6275536d5063 100644 --- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c +++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c @@ -182,9 +182,24 @@ void vdec_msg_queue_update_ube_wptr(struct vdec_msg_queue *msg_queue, uint64_t u bool vdec_msg_queue_wait_lat_buf_full(struct vdec_msg_queue *msg_queue) { + struct vdec_lat_buf *buf, *tmp; + struct vdec_msg_queue_ctx *core_ctx; long timeout_jiff; int ret; + core_ctx = &msg_queue->ctx->dev->msg_queue_core_ctx; + spin_lock(&core_ctx->ready_lock); + list_for_each_entry_safe(buf, tmp, &core_ctx->ready_queue, core_list) { + if (buf && buf->ctx == msg_queue->ctx) { + spin_lock(&msg_queue->lat_ctx.ready_lock); + list_move(&buf->core_list, &core_ctx->ready_queue); + spin_unlock(&msg_queue->lat_ctx.ready_lock); + queue_work(buf->ctx->dev->core_workqueue, + &buf->ctx->msg_queue.core_work); + } + } + spin_unlock(&core_ctx->ready_lock); + timeout_jiff = msecs_to_jiffies(1000 * (NUM_BUFFER_COUNT + 2)); ret = wait_event_timeout(msg_queue->lat_ctx.ready_to_use, msg_queue->lat_ctx.ready_num == NUM_BUFFER_COUNT, @@ -268,6 +283,7 @@ int vdec_msg_queue_init(struct vdec_msg_queue *msg_queue, vdec_msg_queue_init_ctx(&msg_queue->lat_ctx, MTK_VDEC_LAT0); INIT_WORK(&msg_queue->core_work, vdec_msg_queue_core_work); + msg_queue->ctx = ctx; atomic_set(&msg_queue->lat_list_cnt, 0); atomic_set(&msg_queue->core_list_cnt, 0); mutex_init(&msg_queue->list_cnt_mutex); diff --git a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h index 94e01a618c5a..53ad05396c8c 100644 --- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h +++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h @@ -72,6 +72,7 @@ struct vdec_lat_buf { * @wdma_wptr_addr: ube write point * @core_work: core hardware work * @lat_ctx: used to store lat buffer list + * @ctx: point to mtk_vcodec_ctx * * @lat_list_cnt: used to record each instance lat list count * @core_list_cnt: used to record each instance core list count @@ -86,6 +87,7 @@ struct vdec_msg_queue { struct work_struct core_work; struct vdec_msg_queue_ctx lat_ctx; + struct mtk_vcodec_ctx *ctx; atomic_t lat_list_cnt; atomic_t core_list_cnt; From patchwork Sat Dec 10 07:32:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?WXVuZmVpIERvbmcgKOiRo+S6kemjnik=?= X-Patchwork-Id: 31979 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1184623wrr; Fri, 9 Dec 2022 23:35:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Q+W8LXzQpUG8z4/son849qeUYRTTss38QbnzSYSssdrkGuoX6FDFW9k+NeFeJW00XWOLm X-Received: by 2002:a05:6402:5305:b0:462:6ace:34cb with SMTP id eo5-20020a056402530500b004626ace34cbmr7512627edb.0.1670657714555; Fri, 09 Dec 2022 23:35:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670657714; cv=none; d=google.com; s=arc-20160816; b=PYkAIi8vNnAbPzwVHpjlwTOz1jvoBoGq6jlgpwPkRQW2xTn4EBmdzhwbafJJZskQOa z0lMEnmero6BcZlaie5yFEDPH6JuUnvEH4xsBA5WGUh2V9E5/X/ZwuXTjdUIB6XLepkY yzB9Y656oUJE4/vZaozgxM3c6BuykdGZ8wqtm8UM+qWNfPQnZF2s9gP2bwYgqGfWuBuY 9HOksKpbd8lpos12K+OS5Nm4AT6NTDQgepek7YeYaVuWPxXeNAk0CTeSpu8Tc83fp7A6 S0DMDr/PFsG2zcla8oVF+9P9SPGXYLMn6SsK91Z48GglsKkxIWtxhCbpKm143ogbN/FA mVSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ecg1Ipv3buo16sdVZWJCgG3SlQX6vGOmvjh9A8JgIBs=; b=RB+wqTlteke8VXt7howqRflLwghUhhv/NX1LtfrBugIV5hUxttuo6dBR4VWTolSn5M 6VXlllK/DxVREQ6Cyhh6AZbRfFI15psxNnh7uXTI93+ZFC2ORTptgnm00uyXF9trpGj9 OQKkJcDa/SuVBX24CaN5U230k4qAxIyqPAjva8BShBnxE3DJEpN2Lo10e6BMeLu2U6Ps 2mA54z1NvxY/wy4pZ7x3M+U5Aj+jApoy1BWDL5UMUUUebP4ZdZ2XeZxsBENN6bBEQlkx h4gVzaTx7lbfmKIVIT+Gi3LpLRrN4YaPnmyXMg49US14tT2x4nIlYpp5qsPeQtjyXc4G 7Anw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=BYwVbyXB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z13-20020a05640240cd00b00468c952c935si3623629edb.146.2022.12.09.23.34.51; Fri, 09 Dec 2022 23:35:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=BYwVbyXB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229793AbiLJHcr (ORCPT + 99 others); Sat, 10 Dec 2022 02:32:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229750AbiLJHci (ORCPT ); Sat, 10 Dec 2022 02:32:38 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F384025E89; Fri, 9 Dec 2022 23:32:32 -0800 (PST) X-UUID: fd40ca88b7d7474f8f8532cd1a1bbf06-20221210 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=ecg1Ipv3buo16sdVZWJCgG3SlQX6vGOmvjh9A8JgIBs=; b=BYwVbyXB205wzsUBh2eyVzao3L0T6rcrIMidbF8HvDHiswxnvBfKtPh3h3wlk4iqgKllTJEZ2q74N90/KvzEghMl7UAvxe9L+JUIIJcn8N1bKmOTNqhjix2cdQSzBcQd2zBX8eNzAeTirjFwMdwFChQbiXrWqrizy/oGrP6tFPk=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.14,REQID:ceb39d6e-710a-4fa3-9787-40b81d301bd9,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:dcaaed0,CLOUDID:43a631d2-652d-43fd-a13a-a5dd3c69a43d,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 X-UUID: fd40ca88b7d7474f8f8532cd1a1bbf06-20221210 Received: from mtkexhb02.mediatek.inc [(172.21.101.103)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1022282198; Sat, 10 Dec 2022 15:32:26 +0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs13n2.mediatek.inc (172.21.101.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.15; Sat, 10 Dec 2022 15:32:24 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas11.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Sat, 10 Dec 2022 15:32:23 +0800 From: Yunfei Dong To: Yunfei Dong , Chen-Yu Tsai , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Tiffany Lin CC: Mauro Carvalho Chehab , Matthias Brugger , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , , , , , , Subject: [PATCH 4/5] media: mediatek: vcodec: add core decode done event Date: Sat, 10 Dec 2022 15:32:17 +0800 Message-ID: <20221210073218.17350-5-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221210073218.17350-1-yunfei.dong@mediatek.com> References: <20221210073218.17350-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-MTK: N X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751811583676776608?= X-GMAIL-MSGID: =?utf-8?q?1751811583676776608?= Need to make sure core decode done before current instance is free. Fixes: 365e4ba01df4 ("media: mtk-vcodec: Add work queue for core hardware decode") Signed-off-by: Yunfei Dong --- drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c | 4 +++- drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c index 6275536d5063..9bbbd3fa20eb 100644 --- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c +++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c @@ -201,7 +201,7 @@ bool vdec_msg_queue_wait_lat_buf_full(struct vdec_msg_queue *msg_queue) spin_unlock(&core_ctx->ready_lock); timeout_jiff = msecs_to_jiffies(1000 * (NUM_BUFFER_COUNT + 2)); - ret = wait_event_timeout(msg_queue->lat_ctx.ready_to_use, + ret = wait_event_timeout(msg_queue->ctx->msg_queue.core_dec_done, msg_queue->lat_ctx.ready_num == NUM_BUFFER_COUNT, timeout_jiff); if (ret) { @@ -262,6 +262,7 @@ static void vdec_msg_queue_core_work(struct work_struct *work) mtk_vcodec_dec_disable_hardware(ctx, MTK_VDEC_CORE); vdec_msg_queue_qbuf(&ctx->msg_queue.lat_ctx, lat_buf); + wake_up_all(&ctx->msg_queue.core_dec_done); if (atomic_read(&lat_buf->ctx->msg_queue.core_list_cnt)) { mtk_v4l2_debug(3, "re-schedule to decode for core: %d", dev->msg_queue_core_ctx.ready_num); @@ -287,6 +288,7 @@ int vdec_msg_queue_init(struct vdec_msg_queue *msg_queue, atomic_set(&msg_queue->lat_list_cnt, 0); atomic_set(&msg_queue->core_list_cnt, 0); mutex_init(&msg_queue->list_cnt_mutex); + init_waitqueue_head(&msg_queue->core_dec_done); msg_queue->wdma_addr.size = vde_msg_queue_get_trans_size(ctx->picinfo.buf_w, diff --git a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h index 53ad05396c8c..0944b6436fb6 100644 --- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h +++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h @@ -77,6 +77,7 @@ struct vdec_lat_buf { * @lat_list_cnt: used to record each instance lat list count * @core_list_cnt: used to record each instance core list count * @list_cnt_mutex: used to protect list count + * @core_dec_done: core work queue decode done event */ struct vdec_msg_queue { struct vdec_lat_buf lat_buf[NUM_BUFFER_COUNT]; @@ -93,6 +94,7 @@ struct vdec_msg_queue { atomic_t core_list_cnt; /* Protects access to lat and core list cnt */ struct mutex list_cnt_mutex; + wait_queue_head_t core_dec_done; }; /** From patchwork Sat Dec 10 07:32:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?WXVuZmVpIERvbmcgKOiRo+S6kemjnik=?= X-Patchwork-Id: 31980 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1184942wrr; Fri, 9 Dec 2022 23:36:33 -0800 (PST) X-Google-Smtp-Source: AA0mqf4W4x9/b7AomJSZpaiXRRdQkANThwmqAaPf2dLDmngndUBPIfrjgmayUk2gMfvfz4JUgSx0 X-Received: by 2002:a17:906:564d:b0:7c0:d609:6f9b with SMTP id v13-20020a170906564d00b007c0d6096f9bmr8037337ejr.27.1670657793027; Fri, 09 Dec 2022 23:36:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670657793; cv=none; d=google.com; s=arc-20160816; b=ypNBAUmkyDzYngUv7VmrhiX7OmXjWnwGifporH+UYC7mrV2j7TWM2iEwVwquBoUGO8 Os1Q/PnbJz6Oe5EGw4MJFj64y8SDW+wX7W/52tzO7+9Upr++ZHkAb35/hcUBPSlV205p MYLBcVw9/I3EAexwS0us4wAiuoztV/0Q1Jgyb3BQKCgd5v7HQzSngn/Roe4fNDGnDxSg L3qpR4i70SZJKq0+HL34/DvqfcYjk/PbcIaF7BeUE3qxQ5G7I83ntlVDO571j7NBSExi CCFqaLVXd5j3bITIs3wy3CGCpoyuEb+QMziOPwOXDGLzQh4vWswwUyzQWLr2UDhdkxHr rVbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YXm7IiRh/S8ttqiZj2NLiwg/hF3EgrsbC+UQ+b2o5bc=; b=afI9ZRMFN7IyFCE3LyjDCrL/WKEx0BFSdEuGyyKSReElO23GE5+5Q0uEUfgdCXmbEm x3SaIembMb3qQjmEDgY11xFC6GTMFh41M0wCW1E+R4x/UH6S9VLcuqUd3Di3y4yjuGJf hamIMwix1o8EwoKRN6S3MuFaPj762vzVwRJoqZf+uZSDy6eq9bXp7qN0Up6WR0Z18RnK qk2Kkfsas+1eolui6Xb0V86EIqyJibhTYy5foL6UKHPTtZ8NNhC0SemZKARI/3VkbXzI PVbAwr4GXZGI4aEeaJC7VmQLTCus3TMdbnvREj1DIdVpjIig9Eb/Ug2q+2UI8YkYVFZb s1yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b="h/Xe8SaM"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dt22-20020a170907729600b007ae1052555dsi1871404ejc.436.2022.12.09.23.36.08; Fri, 09 Dec 2022 23:36:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b="h/Xe8SaM"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229721AbiLJHcm (ORCPT + 99 others); Sat, 10 Dec 2022 02:32:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229738AbiLJHci (ORCPT ); Sat, 10 Dec 2022 02:32:38 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBEC4FD; Fri, 9 Dec 2022 23:32:34 -0800 (PST) X-UUID: 4252be373d7844958154b945cf10f50f-20221210 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=YXm7IiRh/S8ttqiZj2NLiwg/hF3EgrsbC+UQ+b2o5bc=; b=h/Xe8SaMT9uO/mnW5RafqFRwI4smljAanjqoGVQVlgW2zprK7WuW7gLYSRoIP9Z/GaefkGcY/Ckgh8Vtxiq8HOhqMFObRTp/fY0KKyHuQZpeEFi79jPhF08c3LFFrmc0qDtp3gZ9Z9u/AFoaMLoc21hrKOHC0PTlaORaWiDHpow=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.14,REQID:f5412007-d4b2-45de-9a02-64314a55ed12,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:dcaaed0,CLOUDID:f6e4dc24-4387-4253-a41d-4f6f2296b154,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 X-UUID: 4252be373d7844958154b945cf10f50f-20221210 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1047213448; Sat, 10 Dec 2022 15:32:27 +0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.15; Sat, 10 Dec 2022 15:32:25 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas11.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Sat, 10 Dec 2022 15:32:24 +0800 From: Yunfei Dong To: Yunfei Dong , Chen-Yu Tsai , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Tiffany Lin CC: Mauro Carvalho Chehab , Matthias Brugger , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , , , , , , Subject: [PATCH 5/5] media: mediatek: vcodec: remove unused lat_buf Date: Sat, 10 Dec 2022 15:32:18 +0800 Message-ID: <20221210073218.17350-6-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221210073218.17350-1-yunfei.dong@mediatek.com> References: <20221210073218.17350-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-MTK: N X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,RDNS_NONE, SPF_HELO_PASS,SPF_PASS,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751811665649228373?= X-GMAIL-MSGID: =?utf-8?q?1751811665649228373?= Remove unused lat_buf from core list, or leading to core list access NULL point. Fixes: 365e4ba01df4 ("media: mtk-vcodec: Add work queue for core hardware decode") Signed-off-by: Yunfei Dong --- .../platform/mediatek/vcodec/vdec_msg_queue.c | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c index 9bbbd3fa20eb..3f18eca7dbdd 100644 --- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c +++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c @@ -185,7 +185,7 @@ bool vdec_msg_queue_wait_lat_buf_full(struct vdec_msg_queue *msg_queue) struct vdec_lat_buf *buf, *tmp; struct vdec_msg_queue_ctx *core_ctx; long timeout_jiff; - int ret; + int ret, count = 0; core_ctx = &msg_queue->ctx->dev->msg_queue_core_ctx; spin_lock(&core_ctx->ready_lock); @@ -209,8 +209,22 @@ bool vdec_msg_queue_wait_lat_buf_full(struct vdec_msg_queue *msg_queue) msg_queue->lat_ctx.ready_num); return true; } - mtk_v4l2_err("failed with lat buf isn't full: %d", - msg_queue->lat_ctx.ready_num); + + spin_lock(&core_ctx->ready_lock); + list_for_each_entry_safe(buf, tmp, &core_ctx->ready_queue, core_list) { + if (buf && buf->ctx == msg_queue->ctx) { + count++; + spin_lock(&msg_queue->lat_ctx.ready_lock); + list_del(&buf->core_list); + spin_unlock(&msg_queue->lat_ctx.ready_lock); + } + } + spin_unlock(&core_ctx->ready_lock); + + mtk_v4l2_err("failed with lat buf isn't full: list(%d %d) count:%d", + atomic_read(&msg_queue->lat_list_cnt), + atomic_read(&msg_queue->core_list_cnt), count); + return false; }