From patchwork Wed Feb 1 07:33:10 2023 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: 51208 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2388:b0:96:219d:e725 with SMTP id i8csp248907dyf; Tue, 31 Jan 2023 23:36:46 -0800 (PST) X-Google-Smtp-Source: AK7set/h51VIvm7R4VdJvR5Nzp1dNxWhGr7+vAxUzbxmKiO5yu/m7MaLp8V3Xj+HOsrtJux5ZRpQ X-Received: by 2002:a05:6402:254b:b0:4a0:aac4:1030 with SMTP id l11-20020a056402254b00b004a0aac41030mr1161225edb.28.1675237006171; Tue, 31 Jan 2023 23:36:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675237006; cv=none; d=google.com; s=arc-20160816; b=LT48aIZe0TCYblPm2F5/QCoFqjPigzeAZO3Cygy0tb/iQznH4bKnzF7l3Q6UUCxxlO LQCvOk9UKhcCMmvxujuO82VmQzvY6VtBiqzJTDDR97xeiwldrsfRoFHPOxZYhMGtwSNw hICEghxfAVpqSAWEoarkDZtzhT1ALCcAd4L5xc5qtP7MnCRFatrayYvDRAr0SUkNC+Zs GOSTYbcnhHavs0zmB0nL/tdaX15D/wkhoonYcoSo60hoi0y1o2XE40h0rPC0Z1MjUd8K qoqjNLfFXvDgkLg2IuyI7Z1X/LDWAsJWSs3+aFC1wgj+LORJB+21uBTUJLxSJrlHAWkK wYVw== 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=+wAF+3zLOgriKKOOYsRbB+eAkK6iaY9L7YqRIbK9lWQ=; b=WWhA6u5TO6jKQucDU68+5YB87hknMK5jLqwFeJuuV8dZrY86PP6QpBWSAGe1PX2119 NnmYtbiYG00LR5ff84+wGKL48juVYx7QgFtlvbzwNBfwH5DCjtq1MmvURPwWfwUs3uYI nvsn3GtT/MGyhFiPUnBbqNVw8/wapU5IOUzPcYfjCuKrfqK0DEyD7CKE6SU3b/B3gxZ0 HFJq8niV86N3MyPpVp7IyKu1sAfYhSutxPUX+P0P2kT4Zx9oBEDx8W5WQXc4Z6y2VdhI QGGYLnSKk+qWJtybuNA7snOtPJBGT9o9cLs3rRFeKpPHk5TXqpuQoqZb5lnU6bJDVIKJ 0Few== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=WpdGMWWO; 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 o18-20020a50c292000000b004a0e8d82badsi20424805edf.617.2023.01.31.23.36.21; Tue, 31 Jan 2023 23:36:46 -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=WpdGMWWO; 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 S231614AbjBAHdl (ORCPT + 99 others); Wed, 1 Feb 2023 02:33:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230414AbjBAHdf (ORCPT ); Wed, 1 Feb 2023 02:33:35 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 317473B0C9; Tue, 31 Jan 2023 23:33:26 -0800 (PST) X-UUID: b4479c92a20211ed945fc101203acc17-20230201 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=+wAF+3zLOgriKKOOYsRbB+eAkK6iaY9L7YqRIbK9lWQ=; b=WpdGMWWOSsvkHMyZPIfz6rrdFuGQ9V9CSOSAmyIztQbbGtYh15QyDhYYSrcJpRXnYz4VHMPWQT4a99C85vV14XiFOhw+eqXaGucJUJKCVEWnPvZhxQ41loKAtk7b98i51w4VjXS/7taKW3dpsgzPcqiP9BmDpq+3xvsqJf0xkms=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.18,REQID:1985644d-cb1c-4d53-bb83-65d5d8527508,IP:0,U RL:0,TC:0,Content:0,EDM:-30,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-30 X-CID-META: VersionHash:3ca2d6b,CLOUDID:08a51ef7-ff42-4fb0-b929-626456a83c14,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:2,IP:nil,UR L:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0 X-CID-BVR: 0 X-UUID: b4479c92a20211ed945fc101203acc17-20230201 Received: from mtkmbs11n2.mediatek.inc [(172.21.101.187)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1066864785; Wed, 01 Feb 2023 15:33:21 +0800 Received: from mtkmbs13n2.mediatek.inc (172.21.101.108) by mtkmbs13n2.mediatek.inc (172.21.101.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Wed, 1 Feb 2023 15:33:20 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs13n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Wed, 1 Feb 2023 15:33:18 +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 v4,1/7] media: mediatek: vcodec: add params to record lat and core lat_buf count Date: Wed, 1 Feb 2023 15:33:10 +0800 Message-ID: <20230201073316.27923-2-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230201073316.27923-1-yunfei.dong@mediatek.com> References: <20230201073316.27923-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?1756613319123857490?= X-GMAIL-MSGID: =?utf-8?q?1756613319123857490?= 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 Reviewed-by: AngeloGioacchino Del Regno --- .../platform/mediatek/vcodec/vdec_msg_queue.c | 23 ++++++++++++++++++- .../platform/mediatek/vcodec/vdec_msg_queue.h | 6 +++++ 2 files changed, 28 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..3f016c87d722 100644 --- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c +++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c @@ -52,6 +52,22 @@ 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) +{ + if (hardware_index == MTK_VDEC_CORE) + atomic_inc(&msg_queue->core_list_cnt); + else + atomic_inc(&msg_queue->lat_list_cnt); +} + +static void vdec_msg_queue_dec(struct vdec_msg_queue *msg_queue, int hardware_index) +{ + if (hardware_index == MTK_VDEC_CORE) + atomic_dec(&msg_queue->core_list_cnt); + else + atomic_dec(&msg_queue->lat_list_cnt); +} + int vdec_msg_queue_qbuf(struct vdec_msg_queue_ctx *msg_ctx, struct vdec_lat_buf *buf) { struct list_head *head; @@ -66,6 +82,7 @@ int vdec_msg_queue_qbuf(struct vdec_msg_queue_ctx *msg_ctx, struct vdec_lat_buf list_add_tail(head, &msg_ctx->ready_queue); msg_ctx->ready_num++; + vdec_msg_queue_inc(&buf->ctx->msg_queue, msg_ctx->hardware_index); if (msg_ctx->hardware_index != MTK_VDEC_CORE) wake_up_all(&msg_ctx->ready_to_use); else @@ -127,6 +144,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 +259,13 @@ 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); + 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..b1aa5572ba49 100644 --- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h +++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h @@ -72,6 +72,9 @@ 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 */ struct vdec_msg_queue { struct vdec_lat_buf lat_buf[NUM_BUFFER_COUNT]; @@ -82,6 +85,9 @@ 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; }; /** From patchwork Wed Feb 1 07:33:11 2023 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: 51203 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2388:b0:96:219d:e725 with SMTP id i8csp248334dyf; Tue, 31 Jan 2023 23:35:35 -0800 (PST) X-Google-Smtp-Source: AK7set9pFOICOx5oviyZYPh9rc0FQ8yRjIsKNpFDtZsCoJd5aWihHe7X1mpJor/YZ5C1G5l1SL7j X-Received: by 2002:a05:6402:5167:b0:4a2:2e33:35fd with SMTP id d7-20020a056402516700b004a22e3335fdmr1115832ede.15.1675236935636; Tue, 31 Jan 2023 23:35:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675236935; cv=none; d=google.com; s=arc-20160816; b=SZbm3RpE5EuzkJeQXQ6elGo+Gq4Lj8GQjvmT7aDIX0GA0rZlBUD7cUg6yD/Mcpm67P N2lVK2iEhvHh9MwlRh4u8SEjqwvI8tjG+1iGuGm35EyI9pmKwD5sp3UejLjlp/64PzWD KNQtHbOTlQ4g/kFGooeqrLaOAuLmFPz/9R4u3XNzd4o95m36dACkVNlomBVUF5H11/n6 4BPACCeW6NVls6VgHNAOdU/4HS80chGjz9hSpsBzAxs2aVlv3EOE7VgDYwhxjNUFWEZ4 14Tz0bvyuH+cMHonQLKEdTeYYQ0ZWUOuBKOQHC7epg0uVKIYxyr1LMdMXIze2MdsnHk1 JDaw== 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=gz7OdVfZErCQdXy+fRjQiUvbIcVWxDyhc2LsrCgb9is=; b=ptF9zEO3EKWzoOApBxubRw5MiXFDVk6HnMSYca5hYKExmlycXO2I2ynw7yziMKfh3h V7nWCkrnZ5fk6HEFTBJhe0Bl8kZtcMNAsKVZHmoa9ID72js0FNuUrqbHUvl9tRaYRpUi 1LnQk9xxC3fTJvzJbBcoaLvvcbXl9xtp+BkdMA7rIeNkxn9IxzTLD8T70YreOCvPINFk KBuqwqd2tMlMR6XmDdQM2wHU8IL8MbpZYhd62OylZObrjjojJcrV9/hYXUteKPLxXP3D n9yoQq8r7yX38+EtHcgfa6A3dDjRvA8gUK/YhY+Y2EoiDWrT/trXKWFcPqgSIWVJbFtq 6dSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=rTxonek8; 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 ui37-20020a170907c92500b008775d7fcb5dsi20030983ejc.46.2023.01.31.23.35.10; Tue, 31 Jan 2023 23:35:35 -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=rTxonek8; 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 S230372AbjBAHdf (ORCPT + 99 others); Wed, 1 Feb 2023 02:33:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229770AbjBAHde (ORCPT ); Wed, 1 Feb 2023 02:33:34 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 736F839280; Tue, 31 Jan 2023 23:33:26 -0800 (PST) X-UUID: b48bf9b4a20211ed945fc101203acc17-20230201 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=gz7OdVfZErCQdXy+fRjQiUvbIcVWxDyhc2LsrCgb9is=; b=rTxonek8ID5oMGsI+c48QCIVSehhumk1cnVy4C1kNU9ST4VlCOYbIMcJu60UyASOOI4hDpbkcmvOP9ksGGECC95aQzk+r8zYHRV2vaQ/D/txyyFkIlgzLsUpRObsdN7BKaWm+497Vtb3Ie7GG8fzAFpTAHJF84/Q3yEfA9DGbgk=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.18,REQID:913115e3-2d96-4d6a-bb1c-8b1928f21b2d,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.18,REQID:913115e3-2d96-4d6a-bb1c-8b1928f21b2d,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:3ca2d6b,CLOUDID:06a51ef7-ff42-4fb0-b929-626456a83c14,B ulkID:230201153323CDW8L4LK,BulkQuantity:0,Recheck:0,SF:38|29|28|17|19|48,T C:nil,Content:0,EDM:-3,IP:nil,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 ,OSI:0,OSA:0 X-CID-BVR: 0 X-UUID: b48bf9b4a20211ed945fc101203acc17-20230201 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 982533512; Wed, 01 Feb 2023 15:33:22 +0800 Received: from mtkmbs13n2.mediatek.inc (172.21.101.194) by mtkmbs11n2.mediatek.inc (172.21.101.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Wed, 1 Feb 2023 15:33:21 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs13n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Wed, 1 Feb 2023 15:33: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 v4,2/7] media: mediatek: vcodec: using each instance lat_buf count replace core ready list Date: Wed, 1 Feb 2023 15:33:11 +0800 Message-ID: <20230201073316.27923-3-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230201073316.27923-1-yunfei.dong@mediatek.com> References: <20230201073316.27923-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?1756613245042583063?= X-GMAIL-MSGID: =?utf-8?q?1756613245042583063?= 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 Reviewed-by: AngeloGioacchino Del Regno --- 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 3f016c87d722..ad5002ca953e 100644 --- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c +++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c @@ -239,7 +239,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 Wed Feb 1 07:33:12 2023 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: 51204 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2388:b0:96:219d:e725 with SMTP id i8csp248341dyf; Tue, 31 Jan 2023 23:35:36 -0800 (PST) X-Google-Smtp-Source: AK7set+xG2LWpCIeRJ0EXEQMc4sVNQAykZi75tFSX+kZjnvq8k3fKAvI8Cl9pQx7YmDuSAW4ppct X-Received: by 2002:aa7:c306:0:b0:49e:c16:2c0f with SMTP id l6-20020aa7c306000000b0049e0c162c0fmr741629edq.1.1675236936265; Tue, 31 Jan 2023 23:35:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675236936; cv=none; d=google.com; s=arc-20160816; b=nrIw9yZeh6GFaQZzy+IMyOUWSBIa91ZWYzyMZgX6AQPAt3wvJsuaLS5/gemdNWZ1l6 ZGWWfo9BJXEqnJKJ9UQ41u31CXcldnl9GuxogYBtgYdCWMPnAxYHM5BSrAgesZ13kFk/ Uzx8XmP7ZtpWiUb7RuTwwTBGkQjrrIuSbHrnPWEqRR5K56O8d2Lm3V+ndvp/jT46Hart L9+D8jzFJ9brnLuDIk6oZ4xGIvkIFyybiDVu/IwBJrto1j0hPzms4aMnFn/X7TcEx62f 4BZeVSc1MJ32qfgAEBUthFm95Ia8crx9yxuHYS13Bkbu6EArLXLwFX3YVsrGZyA/j3xa 87mQ== 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=88pRMCVl/UXV909ZRbmU0TQkYikt3A2ZWXIraNYULyw=; b=VeAx6Cf/Q6m+liwrw6s1YMienRk8ZUP1dyOePPeqjbL3hpxJ5CSYJ4aPwdjS+IyW5z bplL5MTzdXLLNsaNREPDdoOf7g4Ge1ZBMt6P/2u71SpjdnQnT0Ca48iQM1PgFts7KRMm X8HR1C/3YcIZqOqIg+dCg9GrjYFzNmW0y33hcj2LnZyeSo1NbL3RbdHZKvwjmLNqKI8O 8tEZ5f2RmbiVNxN3jXGWLuNqAcZqWysEpdz2P+hQcZR4ErBYhlNGKrq6gs1PN7lITClx 5DTIsvAI8613xx0gdjcO7f0N6ukH8eHZrnzhQQoGAdTzeHNrjA3qSj7uuAnFVYWEdKLT Si+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=N4Qb8eaU; 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 i13-20020a50c3cd000000b004a25ca16299si6341946edf.538.2023.01.31.23.35.12; Tue, 31 Jan 2023 23:35:36 -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=N4Qb8eaU; 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 S231918AbjBAHdo (ORCPT + 99 others); Wed, 1 Feb 2023 02:33:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229770AbjBAHdg (ORCPT ); Wed, 1 Feb 2023 02:33:36 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3543D11140; Tue, 31 Jan 2023 23:33:28 -0800 (PST) X-UUID: b5b3dc08a20211ed945fc101203acc17-20230201 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=88pRMCVl/UXV909ZRbmU0TQkYikt3A2ZWXIraNYULyw=; b=N4Qb8eaUdEXT7rXoAPalF8ezWO4inOdxSbemKlt8oI4tp6ki+fNMf8Zv7VAtHFzatpu4XqmMHy1dq6azy3f6ATFvuJt6wlufJRII06GQTJBjz8fFsAyfXBtklQVbgHULPCUbm6ysdXDAUz/numbI0SQB0VFdwulofAYPte/HOyw=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.18,REQID:7de75d24-44f1-46c9-bcc7-e74fd3776c5f,IP:0,U RL:0,TC:0,Content:0,EDM:25,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:25 X-CID-META: VersionHash:3ca2d6b,CLOUDID:7ca51ef7-ff42-4fb0-b929-626456a83c14,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:5,IP:nil,UR L:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0 X-CID-BVR: 0 X-UUID: b5b3dc08a20211ed945fc101203acc17-20230201 Received: from mtkmbs13n2.mediatek.inc [(172.21.101.108)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 612455149; Wed, 01 Feb 2023 15:33:24 +0800 Received: from mtkmbs13n2.mediatek.inc (172.21.101.194) by mtkmbs11n1.mediatek.inc (172.21.101.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Wed, 1 Feb 2023 15:33:22 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs13n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Wed, 1 Feb 2023 15:33: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 v4,3/7] media: mediatek: vcodec: move lat_buf to the top of core list Date: Wed, 1 Feb 2023 15:33:12 +0800 Message-ID: <20230201073316.27923-4-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230201073316.27923-1-yunfei.dong@mediatek.com> References: <20230201073316.27923-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?1756613245804926700?= X-GMAIL-MSGID: =?utf-8?q?1756613245804926700?= 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 | 21 ++++++++++++++++++- .../platform/mediatek/vcodec/vdec_msg_queue.h | 2 ++ 2 files changed, 22 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 ad5002ca953e..0da6e3e2ef0b 100644 --- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c +++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c @@ -174,8 +174,26 @@ 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 list_head *list_core[3]; + struct vdec_msg_queue_ctx *core_ctx; + int ret, i, in_core_count = 0; 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) { + list_core[in_core_count++] = &buf->core_list; + list_del(&buf->core_list); + } + } + + for (i = 0; i < in_core_count; i++) { + list_add(list_core[in_core_count - (1 + i)], &core_ctx->ready_queue); + queue_work(msg_queue->ctx->dev->core_workqueue, &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, @@ -257,6 +275,7 @@ int vdec_msg_queue_init(struct vdec_msg_queue *msg_queue, if (msg_queue->wdma_addr.size) return 0; + msg_queue->ctx = ctx; vdec_msg_queue_init_ctx(&msg_queue->lat_ctx, MTK_VDEC_LAT0); INIT_WORK(&msg_queue->core_work, vdec_msg_queue_core_work); diff --git a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h index b1aa5572ba49..56280d6682c5 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 @@ -85,6 +86,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 Wed Feb 1 07:33:13 2023 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: 51209 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2388:b0:96:219d:e725 with SMTP id i8csp249406dyf; Tue, 31 Jan 2023 23:37:58 -0800 (PST) X-Google-Smtp-Source: AK7set/hExbh90TL40xnGpNCsdH8tGJIo4UdQv9Bx3ygu6qeVDaylIRqDH/Nz38huGgxc+TNY86p X-Received: by 2002:a05:6402:248b:b0:4a2:dac:d2a4 with SMTP id q11-20020a056402248b00b004a20dacd2a4mr1113566eda.9.1675237078090; Tue, 31 Jan 2023 23:37:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675237078; cv=none; d=google.com; s=arc-20160816; b=EFUEBLSr4797drqSp9F1kcB/aNtjZ1N+TUAoBP+sPHQOr82TwQJQTv5RgfesAYsMto hdmAJHO/9op2VChnrWvoRVzOgrLlCrcDtwcMgrAh9gZpp+QSgEIV73Qoq/8TeATJ0RrD gvkmkyS9gKOr5/7/L9iqMQjKYDEG0fh3uLbsc+BBRhDhVlmE3NJwf/JhJut0uSPxG+xn GaTRcNrR0V80Fe+WJQjtJTRtmhymeUDKL+w2lUaaUEuVJMHBW4q88XqPey4kwMWspSbG 3u4PJ0/YLqqxN6jsGP9eU5+8n3dr3ECXSe4jUFNpovm493DJ3JHEkeEJYUy4ICE4MH4j HZNw== 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=yicZlhgHEByptDrJJcDgc4g/qNfy8/ddnqXBGAC7QFM=; b=NdHbA8HatMgRVKelP7oikZpKE3qRN4wfLXEzuofxMkky9+laKnNxzlxWlDFtnID6v1 kTQGY8C28RVDxLjeVDt7OanrdtQ8wUYsY2EOZ9GsuoK9V5Q7KdM8AVS16nvoNPF294HT iqFVuzdnr6SyEuBrffOG2twG8ZATFcH2VIibtVrrZ8XIgTRrNBs0eHY/9NADCefPVLKM 4e+x0MhqtK2BmZ1xBBPpXK/Lh/Ms2VgMY8W45VwYcYeLA5Yy2KSvuLS2mZh9B5pPMkFu o2k9svHos8WSgNRjWlDo/zuHyCNFf0ieu2qFcFcpb3XmRVUDnq6h0SPMyx0zITMq+kTy 7xaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b="E/6oPFiB"; 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 n11-20020a056402060b00b004a0ab10b040si19662862edv.448.2023.01.31.23.37.04; Tue, 31 Jan 2023 23:37:58 -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="E/6oPFiB"; 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 S231781AbjBAHd5 (ORCPT + 99 others); Wed, 1 Feb 2023 02:33:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231917AbjBAHdj (ORCPT ); Wed, 1 Feb 2023 02:33:39 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F258975E; Tue, 31 Jan 2023 23:33:29 -0800 (PST) X-UUID: b654cbf4a20211ed945fc101203acc17-20230201 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=yicZlhgHEByptDrJJcDgc4g/qNfy8/ddnqXBGAC7QFM=; b=E/6oPFiBePt3NDUN56vAXNUzDwnXEEZl+MivuEkCt4mnXCm0t4PbKDkw6BNGjUYX0Th2Wtap2Iog50VRBpnvgHqp5hhGdEdKTgj5/jZMdLGbRA8E06fmjlLrQ61LXhgzFTzM0tWa2+XsxHXKr4cqLGcy3dEx3UhcZksvX7VoTVk=; X-CID-P-RULE: Spam_GS6885AD X-CID-O-INFO: VERSION:1.1.18,REQID:ad230056-78e9-4399-b295-86c22c7c5892,IP:0,U RL:0,TC:0,Content:0,EDM:25,RT:0,SF:95,FILE:0,BULK:0,RULE:Spam_GS6885AD,ACT ION:quarantine,TS:120 X-CID-INFO: VERSION:1.1.18,REQID:ad230056-78e9-4399-b295-86c22c7c5892,IP:0,URL :0,TC:0,Content:0,EDM:25,RT:0,SF:95,FILE:0,BULK:0,RULE:Spam_GS981B3D,ACTIO N:quarantine,TS:120 X-CID-META: VersionHash:3ca2d6b,CLOUDID:7ba51ef7-ff42-4fb0-b929-626456a83c14,B ulkID:230201153326Y1WHBXPM,BulkQuantity:0,Recheck:0,SF:38|29|28|17|19|48,T C:nil,Content:0,EDM:5,IP:nil,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0, OSI:0,OSA:0 X-CID-BVR: 0 X-UUID: b654cbf4a20211ed945fc101203acc17-20230201 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 1781945916; Wed, 01 Feb 2023 15:33:25 +0800 Received: from mtkmbs13n2.mediatek.inc (172.21.101.108) by mtkmbs13n2.mediatek.inc (172.21.101.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Wed, 1 Feb 2023 15:33:23 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs13n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Wed, 1 Feb 2023 15:33: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 v4,4/7] media: mediatek: vcodec: add core decode done event Date: Wed, 1 Feb 2023 15:33:13 +0800 Message-ID: <20230201073316.27923-5-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230201073316.27923-1-yunfei.dong@mediatek.com> References: <20230201073316.27923-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?1756613394771220240?= X-GMAIL-MSGID: =?utf-8?q?1756613394771220240?= 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 Reviewed-by: AngeloGioacchino Del Regno --- 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 0da6e3e2ef0b..ce7c82e38103 100644 --- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c +++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c @@ -196,7 +196,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) { @@ -257,6 +257,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); @@ -281,6 +282,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); + 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 56280d6682c5..a75c04418f52 100644 --- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h +++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h @@ -76,6 +76,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 + * @core_dec_done: core work queue decode done event */ struct vdec_msg_queue { struct vdec_lat_buf lat_buf[NUM_BUFFER_COUNT]; @@ -90,6 +91,7 @@ struct vdec_msg_queue { atomic_t lat_list_cnt; atomic_t core_list_cnt; + wait_queue_head_t core_dec_done; }; /** From patchwork Wed Feb 1 07:33:14 2023 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: 51206 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2388:b0:96:219d:e725 with SMTP id i8csp248505dyf; Tue, 31 Jan 2023 23:35:56 -0800 (PST) X-Google-Smtp-Source: AK7set+S1Q4hxNngykWPzvBQV44DY0buGaCHIYAIDdOrnQMT98cBx82WF3vhomTmDoRpFZ06rjiS X-Received: by 2002:a17:907:a688:b0:887:d0e6:fa24 with SMTP id vv8-20020a170907a68800b00887d0e6fa24mr1277189ejc.76.1675236956339; Tue, 31 Jan 2023 23:35:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675236956; cv=none; d=google.com; s=arc-20160816; b=oDoM6GMDt1BZTEnRbHSTpzFYhe3tRwyRrOxofaEB1x5hQRuOQNed5W7zfKSk5vA5/M B0c5A/33f9KkWI+42jdSy+D01ZvccbqfNxNX/OHG/6QHMuCZ9gHZmAE8yypLklmEzHHG ZC7dXcCaQR3xiebwcG81NDcdrt86I0OpRGii9oXaY7E37xxf5n9M849Y4Rbtxf92pulT lO7NjBTvHgdOVcEIiLZVQJLzhXWO5xfv4StQq8abpcLjIi09sADjiehRwsg7UnAn56Dh Dscm6e4fzjv1qMsGub9T/hBX3CDh/E2QoVLimB7s7ag48+y99WRkPFHwXjyYqNZKxtfM HByw== 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=1iGDkFl5JqVQjjGy2SvcMkXm0cL0smb4pzYZQiFbmEg=; b=cELfG8tnCxMuNrQ/YDScedgUqcTp0PvYzlgMj6bXH8cTDB+a+gws80X/Mr+qZ9qd4y i6eGRwWriIOyD4E3LTUgnZEHZESGknt9vJ/+FjM8eR/HfAIWXxBOd32zyPLortVxwENQ 4nUPjZjnWIEFjW5PkTUO1j88cWblj751lrvw4C2XuI0DrkmguMjdgAXx89LOfBV4lxQD EVfBmpQP1LPr7g1QrpFrxNoux1tTjh5eAqZdllvjPGv7uOuNSsilRTeV9xbwPj64opd4 c21eeefPZRj9/UH76G6rzj0sjl07Er3yHvT7RAy2ZKrVEEmmYsKjgK/+hdC6AcpKITsq v3lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=iOJ06AUL; 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 eu7-20020a170907298700b00883258d9025si11883899ejc.821.2023.01.31.23.35.32; Tue, 31 Jan 2023 23:35:56 -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=iOJ06AUL; 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 S231963AbjBAHdv (ORCPT + 99 others); Wed, 1 Feb 2023 02:33:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231911AbjBAHdj (ORCPT ); Wed, 1 Feb 2023 02:33:39 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36615EB49; Tue, 31 Jan 2023 23:33:31 -0800 (PST) X-UUID: b658489ca20211ed945fc101203acc17-20230201 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=1iGDkFl5JqVQjjGy2SvcMkXm0cL0smb4pzYZQiFbmEg=; b=iOJ06AULMKTzoQunOZ18fOWboHJBw943zcWcsxBpeySpMAeM+KWQmfFf5nu2J+C9lAvv193582bsqKqkvIEcbRhgGu6bMeoLLQMiRmLjURuxkHxVfla3THi0/7M8IA8g6P1UMqDR7XrZc0y/peZIio+xFOuISR9Bo3aJDVnUkTE=; X-CID-P-RULE: Spam_GS6885AD X-CID-O-INFO: VERSION:1.1.18,REQID:cf85827f-3b28-43a5-9b15-2272a182dea5,IP:0,U RL:0,TC:0,Content:0,EDM:25,RT:0,SF:95,FILE:0,BULK:0,RULE:Spam_GS6885AD,ACT ION:quarantine,TS:120 X-CID-INFO: VERSION:1.1.18,REQID:cf85827f-3b28-43a5-9b15-2272a182dea5,IP:0,URL :0,TC:0,Content:0,EDM:25,RT:0,SF:95,FILE:0,BULK:0,RULE:Spam_GS981B3D,ACTIO N:quarantine,TS:120 X-CID-META: VersionHash:3ca2d6b,CLOUDID:18a58f8d-8530-4eff-9f77-222cf6e2895b,B ulkID:230201153326Y2UJ25ZD,BulkQuantity:0,Recheck:0,SF:38|29|28|17|19|48,T C:nil,Content:0,EDM:5,IP:nil,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0, OSI:0,OSA:0 X-CID-BVR: 0 X-UUID: b658489ca20211ed945fc101203acc17-20230201 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 1598251367; Wed, 01 Feb 2023 15:33:25 +0800 Received: from mtkmbs13n2.mediatek.inc (172.21.101.108) by mtkmbs13n2.mediatek.inc (172.21.101.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Wed, 1 Feb 2023 15:33:24 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs13n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Wed, 1 Feb 2023 15:33: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 v4,5/7] media: mediatek: vcodec: remove unused lat_buf Date: Wed, 1 Feb 2023 15:33:14 +0800 Message-ID: <20230201073316.27923-6-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230201073316.27923-1-yunfei.dong@mediatek.com> References: <20230201073316.27923-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?1756613266691614723?= X-GMAIL-MSGID: =?utf-8?q?1756613266691614723?= 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 Reviewed-by: AngeloGioacchino Del Regno --- .../platform/mediatek/vcodec/vdec_msg_queue.c | 18 +++++++++++++++--- 1 file changed, 15 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 ce7c82e38103..cdc539a46cb9 100644 --- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c +++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c @@ -177,7 +177,7 @@ bool vdec_msg_queue_wait_lat_buf_full(struct vdec_msg_queue *msg_queue) struct vdec_lat_buf *buf, *tmp; struct list_head *list_core[3]; struct vdec_msg_queue_ctx *core_ctx; - int ret, i, in_core_count = 0; + int ret, i, in_core_count = 0, count = 0; long timeout_jiff; core_ctx = &msg_queue->ctx->dev->msg_queue_core_ctx; @@ -204,8 +204,20 @@ 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++; + list_del(&buf->core_list); + } + } + 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; } From patchwork Wed Feb 1 07:33:15 2023 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: 51205 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2388:b0:96:219d:e725 with SMTP id i8csp248356dyf; Tue, 31 Jan 2023 23:35:38 -0800 (PST) X-Google-Smtp-Source: AK7set/Y1TuotdLLe+bkxy/UtyWOdc5iVElXhiBhe8Cd3ScZRHgoZHkUsZW+43QX3TmavlefXA9o X-Received: by 2002:a05:6402:1909:b0:497:43ec:9e1d with SMTP id e9-20020a056402190900b0049743ec9e1dmr1441701edz.0.1675236938570; Tue, 31 Jan 2023 23:35:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675236938; cv=none; d=google.com; s=arc-20160816; b=x+cPc05E3fOsYnXh537x/HhZXt05PR1xLCosxX9jvlsLLxAFwsHAMRP6DZlOFrL90+ W4oeAWpOkJ1DqvJWTxki0VHltnT+033dzwyX0OX3G+ZjF4N1qi49l9NNXzxrVtn/W1CF UDnOr5ZqqaQ5q1RqyvMYGdSbsw6RT++97Kpn5FepKlD92W/x4fJRgxiSbqXp48Ra2Aa7 lO+NZRR/BDvA0dsQDHorj4KtbBF20aOjXS5Q+IO4W4ywfMrRjPXNFlzsXn2UmYGAOgJ9 Pm8fJall7C5zWXJK6oeKUug82DjCROQ6SZo5zhm1GHS27Fxu2l0kSl2a5p5gDvkP44kj 4arA== 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=VGOhPn9WiWW6pB8TKxx2qIP4+8wsLCqYE4xeDwAEtJ4=; b=cqLV8IVXauNbaLyjWwOsfhuEFaa8yFyQbhFmUCWKLx4A5uSijDuVbi0gQYqE2wBOf/ mBgeMzs0Gm2H8C1H8f4FGOhC3PC88EdG3cWZX2exFDihHkzxIDbcGGepElq/GwVDRlvx QO5x1nwnHKFQgJ84BEQJqU1pAMgnXo6j/n44XYlTBW5IdQqHeYp/+9gjuHZSaxpIW5pR RkTHrH4Eob/MUHvADlNT+xjsemfp8Zdau2dezIBAhhiSsFmkmmrbw/Mb/nhXY9u0kGrB iX3fvnrdbVXBIeRIe1jbw8FXtNM5ZGHVlTCiLLOs7tSz1lN990XL2qlH6RTF3udfUppe o5NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=qT1993y0; 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 ss2-20020a170907c00200b0082517442ad3si22861277ejc.682.2023.01.31.23.35.15; Tue, 31 Jan 2023 23:35:38 -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=qT1993y0; 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 S231926AbjBAHdr (ORCPT + 99 others); Wed, 1 Feb 2023 02:33:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231841AbjBAHdh (ORCPT ); Wed, 1 Feb 2023 02:33:37 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29B3118B00; Tue, 31 Jan 2023 23:33:32 -0800 (PST) X-UUID: b7940dc2a20211eda06fc9ecc4dadd91-20230201 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=VGOhPn9WiWW6pB8TKxx2qIP4+8wsLCqYE4xeDwAEtJ4=; b=qT1993y0I3RvxMNc7KjeboxE9amQ0jYnRrshcmu3RYjCQHwbgcSredDWXppRfFl4eIfC1T0EKilEMU0/4pD7ETBdjX5pZ+mNpNKa3IeC7kfVCItWFt/fycrbvc5tiHppIGIJoYWlXu6u8ONxBtx9AIXLR6d1krBAwVi1r2oaHtM=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.18,REQID:e546e14d-a9e7-444b-8735-7d77946e8034,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:3ca2d6b,CLOUDID:6ba58f8d-8530-4eff-9f77-222cf6e2895b,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,OSI:0,OSA:0 X-CID-BVR: 0,NGT X-UUID: b7940dc2a20211eda06fc9ecc4dadd91-20230201 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 611283494; Wed, 01 Feb 2023 15:33:27 +0800 Received: from mtkmbs13n2.mediatek.inc (172.21.101.194) by mtkmbs11n1.mediatek.inc (172.21.101.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Wed, 1 Feb 2023 15:33:25 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs13n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Wed, 1 Feb 2023 15:33: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 v4,6/7] media: mediatek: vcodec: making sure queue_work successfully Date: Wed, 1 Feb 2023 15:33:15 +0800 Message-ID: <20230201073316.27923-7-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230201073316.27923-1-yunfei.dong@mediatek.com> References: <20230201073316.27923-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?1756613247951765672?= X-GMAIL-MSGID: =?utf-8?q?1756613247951765672?= Putting core work to work queue using queue_work maybe fail, call queue_work again when the count of core work in work queue is less than core_list_cnt, making sure all the buffer in core list can be scheduled. Fixes: 365e4ba01df4 ("media: mtk-vcodec: Add work queue for core hardware decode") Signed-off-by: Yunfei Dong --- .../platform/mediatek/vcodec/vdec_msg_queue.c | 31 ++++++++++++++----- .../platform/mediatek/vcodec/vdec_msg_queue.h | 2 ++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c index cdc539a46cb9..f3073d1e7f42 100644 --- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c +++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c @@ -71,6 +71,7 @@ static void vdec_msg_queue_dec(struct vdec_msg_queue *msg_queue, int hardware_in int vdec_msg_queue_qbuf(struct vdec_msg_queue_ctx *msg_ctx, struct vdec_lat_buf *buf) { struct list_head *head; + int status; head = vdec_get_buf_list(msg_ctx->hardware_index, buf); if (!head) { @@ -83,11 +84,17 @@ int vdec_msg_queue_qbuf(struct vdec_msg_queue_ctx *msg_ctx, struct vdec_lat_buf msg_ctx->ready_num++; vdec_msg_queue_inc(&buf->ctx->msg_queue, msg_ctx->hardware_index); - if (msg_ctx->hardware_index != MTK_VDEC_CORE) + if (msg_ctx->hardware_index != MTK_VDEC_CORE) { wake_up_all(&msg_ctx->ready_to_use); - else - queue_work(buf->ctx->dev->core_workqueue, - &buf->ctx->msg_queue.core_work); + } else { + if (buf->ctx->msg_queue.core_work_cnt < + atomic_read(&buf->ctx->msg_queue.core_list_cnt)) { + status = queue_work(buf->ctx->dev->core_workqueue, + &buf->ctx->msg_queue.core_work); + if (status) + buf->ctx->msg_queue.core_work_cnt++; + } + } mtk_v4l2_debug(3, "enqueue buf type: %d addr: 0x%p num: %d", msg_ctx->hardware_index, buf, msg_ctx->ready_num); @@ -254,6 +261,7 @@ static void vdec_msg_queue_core_work(struct work_struct *work) container_of(msg_queue, struct mtk_vcodec_ctx, msg_queue); struct mtk_vcodec_dev *dev = ctx->dev; struct vdec_lat_buf *lat_buf; + int status; lat_buf = vdec_msg_queue_dqbuf(&dev->msg_queue_core_ctx); if (!lat_buf) @@ -270,11 +278,17 @@ static void vdec_msg_queue_core_work(struct work_struct *work) 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); - queue_work(dev->core_workqueue, &msg_queue->core_work); + spin_lock(&dev->msg_queue_core_ctx.ready_lock); + lat_buf->ctx->msg_queue.core_work_cnt--; + + if (lat_buf->ctx->msg_queue.core_work_cnt < + atomic_read(&lat_buf->ctx->msg_queue.core_list_cnt)) { + status = queue_work(lat_buf->ctx->dev->core_workqueue, + &lat_buf->ctx->msg_queue.core_work); + if (status) + lat_buf->ctx->msg_queue.core_work_cnt++; } + spin_unlock(&dev->msg_queue_core_ctx.ready_lock); } int vdec_msg_queue_init(struct vdec_msg_queue *msg_queue, @@ -289,6 +303,7 @@ int vdec_msg_queue_init(struct vdec_msg_queue *msg_queue, return 0; msg_queue->ctx = ctx; + msg_queue->core_work_cnt = 0; vdec_msg_queue_init_ctx(&msg_queue->lat_ctx, MTK_VDEC_LAT0); INIT_WORK(&msg_queue->core_work, vdec_msg_queue_core_work); diff --git a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h index a75c04418f52..a5d44bc97c16 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 * @core_dec_done: core work queue decode done event + * @core_work_cnt: the number of core work in work queue */ struct vdec_msg_queue { struct vdec_lat_buf lat_buf[NUM_BUFFER_COUNT]; @@ -92,6 +93,7 @@ struct vdec_msg_queue { atomic_t lat_list_cnt; atomic_t core_list_cnt; wait_queue_head_t core_dec_done; + int core_work_cnt; }; /** From patchwork Wed Feb 1 07:33:16 2023 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: 51207 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2388:b0:96:219d:e725 with SMTP id i8csp248549dyf; Tue, 31 Jan 2023 23:35:59 -0800 (PST) X-Google-Smtp-Source: AK7set+IQDLfVO2D68AEdAPdaWkYpuQzN7nBz7BGfmSdCi0Tuv71R5WohVjXF3aauZLlKZadJb4z X-Received: by 2002:aa7:d919:0:b0:4a3:43c1:843f with SMTP id a25-20020aa7d919000000b004a343c1843fmr961665edr.19.1675236959440; Tue, 31 Jan 2023 23:35:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675236959; cv=none; d=google.com; s=arc-20160816; b=yCp6y8AOqdEFYUy5ACVrEGPw9ooAXVO6cVwJyiNxRycFt1lLfgz4sE7QLV2PqsPHW+ gLCYB7ZUqKcD07ULUECCb2B/n92Z8dDlm0G75aaOtGRCGrZDBPY4z3Czo93yb1okk++B eB1Splqklf7ILbd3kKhPxFC6iinozeHPRwnipzNScpJHN+vDA3zqRtKllpwP8SZ+0q8x bQJbXG+twQJ5PH3yDGk5hsBXXMkitPHdC83eeoRN4+yE+DOn5+hgn/wgMZQ/UgVADfdq CptqsrPLgN1T+cuD/p1VvlcLjspz3isOyc9Ixt0nLSB1IPMVXWntSA2rI4v43lFvRj9L ccWQ== 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=GdM+CxNswjU0Sm0RCB0Us5l9zdkJ+nj/JYBJ+VUqKrY=; b=x6/YftpaskGDOask9FxvFue2UR8t0tshjaZ2AeOrnd+H4uiKHzZc1p2LjUjLHVjmXF P/dn5Gu9XRSul8UdOkL13BH4g4IvPVZ6d6v4tZ2Af8PiK8v4JVXCki3m/853Vig0Lnm0 ReM3X9CmKNgW5bpFRUJKO0mrSqDOit6fcIAXwFYc7+RvPq0+ulhx8zOm/2x/1AJn9ZA5 S8p/KZnLwmjJG+lG2IPejHoxKUIjcr2T7asRh1xH//EAzC8ja8JxUpXOfffDbKAXMLMp NhCEHJx+0zK9kzOtpPLYbUyhMjt6Yrklj+0IYdfWdWHZn+uz0FtNUI+tDWRwegZucXhH 6o+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=Yd8XgR4V; 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 k6-20020aa7d8c6000000b004837719c1cfsi20389592eds.220.2023.01.31.23.35.35; Tue, 31 Jan 2023 23:35:59 -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=Yd8XgR4V; 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 S230523AbjBAHdx (ORCPT + 99 others); Wed, 1 Feb 2023 02:33:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231910AbjBAHdj (ORCPT ); Wed, 1 Feb 2023 02:33:39 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A5468A41; Tue, 31 Jan 2023 23:33:31 -0800 (PST) X-UUID: b82fd7a2a20211eda06fc9ecc4dadd91-20230201 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=GdM+CxNswjU0Sm0RCB0Us5l9zdkJ+nj/JYBJ+VUqKrY=; b=Yd8XgR4VMExwZyTPWSlxDeUiYxP1TPfv4YHoEKHPpJvZPGsqfu8pW08nN5DQevgwgvfyv86LGPdJYCn2AHcZmx0HL86bs9AjLeSTUekkPfGc5aIpZFGenTLDKGlCp9XN/CKRPMaReiowMrC3ce9Wcf70JwaMrymiTCynoHjblXc=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.18,REQID:84f7041a-0b6d-4bea-8c14-d11c498fa6ed,IP:0,U RL:0,TC:0,Content:-25,EDM:-30,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACT ION:release,TS:-55 X-CID-META: VersionHash:3ca2d6b,CLOUDID:cfa51ef7-ff42-4fb0-b929-626456a83c14,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:2,IP:nil,UR L:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0 X-CID-BVR: 0 X-UUID: b82fd7a2a20211eda06fc9ecc4dadd91-20230201 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1216760531; Wed, 01 Feb 2023 15:33:28 +0800 Received: from mtkmbs13n2.mediatek.inc (172.21.101.194) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Wed, 1 Feb 2023 15:33:26 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs13n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Wed, 1 Feb 2023 15:33:25 +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 v4,7/7] media: mediatek: vcodec: change lat thread decode error condition Date: Wed, 1 Feb 2023 15:33:16 +0800 Message-ID: <20230201073316.27923-8-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230201073316.27923-1-yunfei.dong@mediatek.com> References: <20230201073316.27923-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?1756613270213735681?= X-GMAIL-MSGID: =?utf-8?q?1756613270213735681?= If lat thread can't get lat buffer, it should be that current instance don't be schedulded, the driver can't free the src buffer directly. Fixes: 7b182b8d9c85 ("media: mediatek: vcodec: Refactor get and put capture buffer flow") Signed-off-by: Yunfei Dong Reviewed-by: AngeloGioacchino Del Regno --- .../platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c | 6 ++++-- .../platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c | 2 +- .../platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c index ffbcee04dc26..04beb3f08eea 100644 --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c +++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c @@ -258,8 +258,10 @@ static void mtk_vdec_worker(struct work_struct *work) if (src_buf_req) v4l2_ctrl_request_complete(src_buf_req, &ctx->ctrl_hdl); } else { - v4l2_m2m_src_buf_remove(ctx->m2m_ctx); - v4l2_m2m_buf_done(vb2_v4l2_src, state); + if (ret != -EAGAIN) { + v4l2_m2m_src_buf_remove(ctx->m2m_ctx); + v4l2_m2m_buf_done(vb2_v4l2_src, state); + } v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx); } } diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c index 8f262e86bb05..07774b6a3dbd 100644 --- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c +++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c @@ -574,7 +574,7 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs, lat_buf = vdec_msg_queue_dqbuf(&inst->ctx->msg_queue.lat_ctx); if (!lat_buf) { mtk_vcodec_err(inst, "failed to get lat buffer"); - return -EINVAL; + return -EAGAIN; } share_info = lat_buf->private_data; src_buf_info = container_of(bs, struct mtk_video_dec_buf, bs_buffer); diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c index cbb6728b8a40..cf16cf2807f0 100644 --- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c +++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c @@ -2070,7 +2070,7 @@ static int vdec_vp9_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs, lat_buf = vdec_msg_queue_dqbuf(&instance->ctx->msg_queue.lat_ctx); if (!lat_buf) { mtk_vcodec_err(instance, "Failed to get VP9 lat buf\n"); - return -EBUSY; + return -EAGAIN; } pfc = (struct vdec_vp9_slice_pfc *)lat_buf->private_data; if (!pfc) {