From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B92BF35DA77 for ; Fri, 24 Apr 2026 09:17:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777022274; cv=none; b=ltvI/Mfs7pvcLUyhmtkiuv7Kar89+zk2hd7jsBSrxXPaj9BnQw8BFz8gWMgegisD/q2a6onA6UQeaVDiEKppnNjlESo6MBc9bGOjoUtItEKun60gspLcX0QASQJ4mdlMHOTW0mnmc4q+c5ERPI301cf+EfCBFJLaWcqJVdEhNb0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777022274; c=relaxed/simple; bh=ZqD9SCbSH5/aik2kX9oPA2bNhJzOsnyxshXjNaCGGS4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=uVzK0acfPQ3gNjEKcVZBKe93th+oPLJ7CW72AiGnAnz7D1ChR/NJOhyYn14/9w1FKkpaFsSepv3YsBVJhR3ddVYkV1+tBL4qPGSdkYwYY0/V/PIU9R1oTbnp9lWNegRaPCoTHeHFC6/X3NL/d9bantSrmrFXcdmX68LZ2bKbUeY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=ler9R/RQ; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=dhwtm89n; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="ler9R/RQ"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="dhwtm89n" Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 63O3LrXe756631 for ; Fri, 24 Apr 2026 09:17:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= ZqD9SCbSH5/aik2kX9oPA2bNhJzOsnyxshXjNaCGGS4=; b=ler9R/RQwVPLaFBw QTto4e4FT8hhSvQBmGbiMupbl8C6Z0NoDBHOVyrzFz3LGhuW1hsKQUVizLozF/da 1W9E1QAkOZHe/W2VgpglzjkR2zFt61FLDgGyBvbT5ztpPRHIElEje875bNKq5fjt uwAaBBEg0/80XZsEsmWOOsVLLd8d+8Ill2uXnIfXdLa92ei4sUiftNYihWKVbiVV VpkY+H4s+qSJODhaQDJuBRwEjkuoMKHdcXByp33MOv4o8iGjX4kdUw/8kk7FOi+1 c6faHB3MoYuVosMYxUbk8c49bd0K2UO3AQoFgncOfGV1K3IyvK45QreBZFOQpHf8 IyWKHA== Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4dqr4bk93f-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 24 Apr 2026 09:17:51 +0000 (GMT) Received: by mail-pf1-f197.google.com with SMTP id d2e1a72fcca58-82fa2165c3eso4473009b3a.0 for ; Fri, 24 Apr 2026 02:17:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1777022270; x=1777627070; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=ZqD9SCbSH5/aik2kX9oPA2bNhJzOsnyxshXjNaCGGS4=; b=dhwtm89nMsLCDiYN9FteF+PNcKkylUaDtn2uxjqL4/t+I/89AYP4OLwwbmveEh6Y0O wkfjl6tg85Y5fvrgyJUoNYUij45zh5SOeJLbWpQve4Et3hueheYJi4H58UUttic9IG2i 3veyzj3RZo/h/I8NNyaUFpLIwD/ADremeb/RO5NjIHhQT8ZDdMbCL/A2FIiqn2t+7rdM 72xUMd/y9OO4K3M3oXHfGiv/afQd3/yz/e7IOBzN88ncJH4QmxPFCF0a8FS6EQf4TIup JbZ8zd1DMYsuBJOEyMhIS8m/wZAPcsbia+a/53j/7vAkaIRsxdTr67CEqYtN8ucpoixQ Vgsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777022270; x=1777627070; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ZqD9SCbSH5/aik2kX9oPA2bNhJzOsnyxshXjNaCGGS4=; b=ka23uypSlgXbvSEPIMtt5piCjUteNMiNFjdXVpwaKb1Wd5ef0zLprS/CsGhTirUyJK bWaPozXjY+aSy8CNXMBBaAzwWHx94Q4uaI87z3ChfIbA0QfsfIH7IGMz7m2QdNeJhAl5 Txcly2x0JKDSpFrTvo/TJkTQsnqLpsnMZt3ZPfOPsREYXjD4jbCpE3BN94BYjO21BJnw hTC30PDTOosk/0RD/OxPWjKOL+HXLsDjjulTEeekwcMaYYyFUCqty7UfI5bTVeC/qX71 1lwtTmO/oIT4CfeUeni1BhpMS71x0dpT3KeCPQ/OwrIPU0u9HAdGLOyO3026DyP8cMoe acHQ== X-Forwarded-Encrypted: i=1; AFNElJ9HbhQ+huPR7vK8OZQOWJP5jMeJBFDqTbJyzC+n6hoZx9dHLKDtRkM/rVSqjedZGFE60pnyOyKw4mhWEnc=@vger.kernel.org X-Gm-Message-State: AOJu0YxCE2cTMHuGr862wPO+2+5SHvHWniUI0xRdsfN4ryCCf3YdmBsj /qYZf/eR/5ftWnpoQty9TZ3koCQDAezsEoCg7/0HmcwJudy/ckE0LSaONrQU/Oo6+HAdl/olKkI Ph05WoyGAvqwQv2XzorYrTa95WkUrBf1+QwZhohBXC1hb9qmmtNFhBHbaS4gEt039dT8= X-Gm-Gg: AeBDieur7GpJOIjyBmllFsZRoDrch432Zs2i2LLyLHSSGRxZe7o2f25m18CF+xm++Rc L8By6g14gYX2DXtVBwXacAOCrYs6WK6lsE0CyfieKqmdtF8xRC+OhjlVnqLLFL9+h65aRsIcWVE DYQtzYRFwQXCTuqrjRSwjLdzxqCvpHp3OCQtno2p8zYxX2xuS2AtwRDhYWx9HE82CmNUSiN9pOp jQh4V+PWwoeDE8vt7ARWsXwZDiX8w7rfSNRxyAC1muL7+ZLnbiS5Ah2k+dJ0kFO939NcDMB7klU PalP/iUA1FOk8mrDOyDNOGNzRpN6k7yAtu1K3xOnZsZPfonA9v5p9tvReJ/9FaUMwBvMSca/0pY 07j+yNYd0QLqcY38bDLq1wV7oa+Yr0k3yH71+hSDjuMsiRsgG3bwfaO/hUGTbvKAYBw== X-Received: by 2002:a05:6a00:2da2:b0:82c:9c47:fef9 with SMTP id d2e1a72fcca58-82f8c87e249mr34286769b3a.2.1777022270458; Fri, 24 Apr 2026 02:17:50 -0700 (PDT) X-Received: by 2002:a05:6a00:2da2:b0:82c:9c47:fef9 with SMTP id d2e1a72fcca58-82f8c87e249mr34286725b3a.2.1777022269873; Fri, 24 Apr 2026 02:17:49 -0700 (PDT) Received: from [192.168.29.100] ([49.43.194.239]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82f8ebe40dasm22540997b3a.40.2026.04.24.02.17.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Apr 2026 02:17:49 -0700 (PDT) Message-ID: Date: Fri, 24 Apr 2026 14:47:44 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCH] media: iris: optimize COMV buffer allocation for VPU3x and VPU4x Content-Language: en-US To: Vikash Garodia , Bryan O'Donoghue , Dikshita Agarwal , Abhinav Kumar , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org References: <20260421-optimize_comv_buffer-v1-1-7c9a24da3ad3@oss.qualcomm.com> <899e0575-6de3-4ab7-b817-7a51c6b45787@oss.qualcomm.com> From: Vishnu Reddy In-Reply-To: <899e0575-6de3-4ab7-b817-7a51c6b45787@oss.qualcomm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDI0MDA4NiBTYWx0ZWRfXx8d7xBetXwgP 57RwlgFBGAzdj1x2Gh3xG6NgMIpx4ZtbKnfb5Juw+KZnfXvc2a5DPRo1sWsfceVKKwxXDCz1BBJ Ul9uqoS337+XEvZcxwpQRvwyyNomWEF9DLlgd8c8MiuXqXQs3oplqW6jcN8a6Vm8Jae5vRat2st Lk8ECUNVcq+Bo/9Ub9Gcb/cmAp4yXdg0O88y9zXA70udPCYnEX6cngglOMtNDUE0AcG34mxMFyt t/MWiDmVtBIKABw87ND8o3qrAe6tPv3wQf3mJ9v5PYObVz9RuesQGmew3dRzLeeoxbvl8oYZN0o 3pFjWxJ0ED6OMbcu0PHTtbtfA5CIaFa0ZICuoBIICqRxUkXC95DTbehEDY88oqSXhVKv+ZxUziz epuTgIJDON/16KyHZDkhO5PfoY0dG/rQq4yU2OsdmbdiOA+nXFurEEX7+947drTiYZLN+DpfztP WQzsoIejSpju/KG5QEw== X-Authority-Analysis: v=2.4 cv=TtnWQjXh c=1 sm=1 tr=0 ts=69eb353f cx=c_pps a=rEQLjTOiSrHUhVqRoksmgQ==:117 a=gkiTcqCCC2T/77GpOVv7Jg==:17 a=IkcTkHD0fZMA:10 a=A5OVakUREuEA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=3WHJM1ZQz_JShphwDgj5:22 a=P-IC7800AAAA:8 a=EUspDBNiAAAA:8 a=LgKhh46ExfKBiJyGOCMA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=2VI0MkxyNR6bbpdq8BZq:22 a=d3PnA9EDa4IxuAV0gXij:22 X-Proofpoint-ORIG-GUID: iuj0Dr_pDo_zbxIj4P3x2d5oOVbcZOTi X-Proofpoint-GUID: iuj0Dr_pDo_zbxIj4P3x2d5oOVbcZOTi X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-23_03,2026-04-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 malwarescore=0 clxscore=1015 adultscore=0 spamscore=0 bulkscore=0 suspectscore=0 phishscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2604240086 On 4/22/2026 1:12 PM, Vikash Garodia wrote: > > > On 4/21/2026 2:31 PM, Bryan O'Donoghue wrote: >> On 21/04/2026 07:41, Vishnu Reddy wrote: >>> The existing iris_vpu_dec_comv_size() used VIDEO_MAX_FRAME (32) as >>> num_comv count unconditionally when calculating the COMV buffer size. >>> This resulted in an oversized COMV buffer allocation throughout decode >>> session, wasting memory regardless of actual number of buffers required. >> >> You should define what a COMV buffer is before talking about how you are >> changing it, i.e. define the term Co-located Motion Vector (CMOV) and then >> use the abbreviation CMOV liberally as you wish. >> >>> For VPU3x and VPU4x platforms, introduce iris_vpu3x_4x_dec_comv_size() to >>> replace iris_vpu_dec_comv_size(). It derives num_comv dynamically, it >> >> "These derive num_cmove dynamically" >> >>> uses inst->fw_min_count once the firmware has reported its minimum buffer >>> requirements, and fallback to inst->buffers[BUF_OUTPUT].min_count during >>> initialization before firmware has communicated its requirements. This >>> aligns the COMV buffer size to the actual count needed rather than always >>> allocating with fixed VIDEO_MAX_FRAME value. >>> >>> Additionally, during iris_vdec_inst_init(), fw_min_count was initialized >>> to MIN_BUFFERS instead of 0. This masked the fallback logic and caused the >>> COMV size calculation to use MIN_BUFFERS even before firmware had reported >>> its actual requirements. Fix this by initializing fw_min_count to 0. >>> >>> During testing of 1080p AVC, it reduces the COMV buffer size from 32.89MB >>> to 6.16MB per decode session, significantly reducing memory consumption. >> >> Cool nice fix. >> > > Indeed, a good saving. > >>> >>> Signed-off-by: Vishnu Reddy >>> --- >>>   drivers/media/platform/qcom/iris/iris_vdec.c       |  2 +- >>>   drivers/media/platform/qcom/iris/iris_vpu_buffer.c | 24 ++++++++++++ >>> +++++++--- >>>   drivers/media/platform/qcom/iris/iris_vpu_buffer.h |  1 + >>>   3 files changed, 23 insertions(+), 4 deletions(-) >>> >>> diff --git a/drivers/media/platform/qcom/iris/iris_vdec.c b/drivers/ >>> media/platform/qcom/iris/iris_vdec.c >>> index 719217399a30..f433065e08b2 100644 >>> --- a/drivers/media/platform/qcom/iris/iris_vdec.c >>> +++ b/drivers/media/platform/qcom/iris/iris_vdec.c >>> @@ -24,7 +24,7 @@ int iris_vdec_inst_init(struct iris_inst *inst) >>>       inst->fmt_src = kzalloc_obj(*inst->fmt_src); >>>       inst->fmt_dst = kzalloc_obj(*inst->fmt_dst); >>> >>> -    inst->fw_min_count = MIN_BUFFERS; >>> +    inst->fw_min_count = 0; >>> >>>       f = inst->fmt_src; >>>       f->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; >>> diff --git a/drivers/media/platform/qcom/iris/iris_vpu_buffer.c b/ >>> drivers/media/platform/qcom/iris/iris_vpu_buffer.c >>> index 9270422c1601..57237543b229 100644 >>> --- a/drivers/media/platform/qcom/iris/iris_vpu_buffer.c >>> +++ b/drivers/media/platform/qcom/iris/iris_vpu_buffer.c >>> @@ -731,6 +731,23 @@ static u32 iris_vpu_dec_comv_size(struct iris_inst *inst) >>>       u32 height = f->fmt.pix_mp.height; >>>       u32 width = f->fmt.pix_mp.width; >>> >>> +    if (inst->codec == V4L2_PIX_FMT_H264) >>> +        return hfi_buffer_comv_h264d(width, height, num_comv); >>> +    else if (inst->codec == V4L2_PIX_FMT_HEVC) >>> +        return hfi_buffer_comv_h265d(width, height, num_comv); >>> + >>> +    return 0; >>> +} >>> + >>> +static u32 iris_vpu3x_4x_dec_comv_size(struct iris_inst *inst) >>> +{ >>> +    struct v4l2_format *f = inst->fmt_src; >>> +    u32 height = f->fmt.pix_mp.height; >>> +    u32 width = f->fmt.pix_mp.width; >>> +    u32 num_comv; >>> + >>> +    num_comv = inst->fw_min_count ? inst->fw_min_count : inst- >>> >buffers[BUF_OUTPUT].min_count; >> >> Please just if/else this though its far easier to read/understand that way. >> >>> + >>>       if (inst->codec == V4L2_PIX_FMT_H264) >>>           return hfi_buffer_comv_h264d(width, height, num_comv); >>>       else if (inst->codec == V4L2_PIX_FMT_HEVC) >>> @@ -739,7 +756,8 @@ static u32 iris_vpu_dec_comv_size(struct iris_inst *inst) >>>           if (inst->fw_caps[DRAP].value) >>>               return 0; >>>           else >>> -            return hfi_buffer_comv_av1d(width, height, num_comv); >>> +            return hfi_buffer_comv_av1d(width, height, >>> +                            num_comv + AV1D_COMV_BUFFER_OVERHEAD); >>>       } >>> >>>       return 0; >>> @@ -2025,7 +2043,7 @@ u32 iris_vpu_buf_size(struct iris_inst *inst, enum >>> iris_buffer_type buffer_type) >>> >>>       static const struct iris_vpu_buf_type_handle >>> dec_internal_buf_type_handle[] = { >>>           {BUF_BIN,         iris_vpu_dec_bin_size             }, >>> -        {BUF_COMV,        iris_vpu_dec_comv_size            }, >>> +        {BUF_COMV,        iris_vpu3x_4x_dec_comv_size       }, >>>           {BUF_NON_COMV,    iris_vpu_dec_non_comv_size        }, >>>           {BUF_LINE,        iris_vpu_dec_line_size            }, >>>           {BUF_PERSIST,     iris_vpu_dec_persist_size         }, >>> @@ -2098,7 +2116,7 @@ u32 iris_vpu4x_buf_size(struct iris_inst *inst, enum >>> iris_buffer_type buffer_typ >>> >>>       static const struct iris_vpu_buf_type_handle >>> dec_internal_buf_type_handle[] = { >>>           {BUF_BIN,         iris_vpu_dec_bin_size         }, >>> -        {BUF_COMV,        iris_vpu_dec_comv_size        }, >>> +        {BUF_COMV,        iris_vpu3x_4x_dec_comv_size   }, >>>           {BUF_NON_COMV,    iris_vpu_dec_non_comv_size    }, >>>           {BUF_LINE,        iris_vpu4x_dec_line_size      }, >>>           {BUF_PERSIST,     iris_vpu4x_dec_persist_size   }, >>> diff --git a/drivers/media/platform/qcom/iris/iris_vpu_buffer.h b/ >>> drivers/media/platform/qcom/iris/iris_vpu_buffer.h >>> index 12640eb5ed8c..7a9cc1c92da3 100644 >>> --- a/drivers/media/platform/qcom/iris/iris_vpu_buffer.h >>> +++ b/drivers/media/platform/qcom/iris/iris_vpu_buffer.h >>> @@ -110,6 +110,7 @@ struct iris_inst; >>>   #define MAX_PE_NBR_DATA_LCU16_LINE_BUFFER_SIZE 96 >>>   #define AV1D_NUM_HW_PIC_BUF    16 >>>   #define AV1D_NUM_FRAME_HEADERS 16 >>> +#define AV1D_COMV_BUFFER_OVERHEAD 7 >> >> Whats this ? Why is there a new seven byte overhead ? Does it represent a >> header, an alignment ? > > Vishnu, pls check if we need to add this as initial count was 18 [1] ? What if > initial count was 11 [2], and post DRC, fw_min_count would be 11 too for AV1d, > so the overhead can be avoided. > > [1] > https://elixir.bootlin.com/linux/v7.0-rc7/source/drivers/media/platform/qcom/iris/iris_hfi_gen2_command.c#L1220 > > [2] > https://elixir.bootlin.com/linux/v7.0-rc7/source/drivers/media/platform/qcom/iris/iris_vpu_buffer.c#L2157 > Thanks for the information, will check and update in next revision. > Regards, > Vikash >> >> An overhead can mean anything. >> >>>   #define SIZE_AV1D_SEQUENCE_HEADER 768 >>>   #define SIZE_AV1D_METADATA        512 >>>   #define SIZE_AV1D_FRAME_HEADER    1280 >>> >>> --- >>> base-commit: 4fbeef21f5387234111b5d52924e77757626faa5 >>> change-id: 20260421-optimize_comv_buffer-ae7107673609 >>> >>> Best regards, >>> --  >>> Vishnu Reddy >>> >> >> >