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 2054A3491D0 for ; Wed, 22 Apr 2026 07:42:37 +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=1776843759; cv=none; b=LOIU1LlKbedWZ5kvB61H7TE+V8F0aO5YGQwOXt/nlQFE6cVhCok13svJb+Vg53SsI7k2eyUBVW9VGvKQhR65uq+ZdWbjkw60vgA26+Cai5Q6Q48YVZsQX9r7RI9cANbKUc6jJ+/1ewl9kbNgl3hjf6VadiwtsFrEHD4IkitDEcQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776843759; c=relaxed/simple; bh=Uzvz/FmS9kN7VxQy+5FxQU8H0DpWsgvzzvLgjxDQKMk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=MKUDZFKSfJs4IBjGB5XlnMurZJeMBR4oCSKz/u9/QC95zs4QmUIpX0+YeoYJG5BCxEHxvwjWtLoI/o4PYO7CcSuICt2GRm7IEqRCMQUD0LfNiiBvhq9vm3P2p+Yveoa8jp3KCiX/qKEAN8SAOe3gcgDOE4OXSsq+3WU7nB8jIzY= 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=cliodgs8; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=NZhvYuNP; 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="cliodgs8"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="NZhvYuNP" Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 63M5Mk3X2209084 for ; Wed, 22 Apr 2026 07:42:36 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= ryfcJEToa6giZGDLLJr7ejuqA33i73uojsM9FLivb04=; b=cliodgs8+Hp0tYud buQQ4tEHZG2NTCVLhsqYI4XB5TVIypC6w9bwEGWHheLq7QTgc0UXaaPVu0aqvNCv IcfVEU/I4pqI70QXguMekzxvCBYd1JMYEGs6KPdJbNJV0cjgG1/7ZSkOK37AIvJZ POTul+uVjeUvrNHMX/8SLeEc1MxgSfsBXloFDCslyQujW6EYzLuGgpYUPwpnf2JO /ZZIKOCH/OdbbC1ZciWZJf1TT7UCp2QTg+4g0z5cVxG6Vanxo9bfy5EVoMhNnBXQ RLlWtClleSRl/6T1Q+NlhRqmu5Lq3WDOF31fnHD1qxLfMbGGrguLF/UgRCLbwi+Z GA5Y4Q== Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4dpengaa5v-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 22 Apr 2026 07:42:36 +0000 (GMT) Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-35d99c2908cso5010520a91.0 for ; Wed, 22 Apr 2026 00:42:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1776843755; x=1777448555; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=ryfcJEToa6giZGDLLJr7ejuqA33i73uojsM9FLivb04=; b=NZhvYuNPl43V+kwEE3150HtQvjGTgkHvPVIehD0oct4MrktvUZSBaed+gamoNF3n6P bVem4MOn7jpZKhiCXX0h49pKJfo/7J/T91c9TH+y1JxIyBnTIXWkG8VydS8MK4EHg1RD kPAlBrNdOI6UFaT4bMAefBplpeD4KPBV1C47W+EiQ2a0Oki0qBOsJtGbKh0W7j6CTrFi OCkNu5qcKOwFxS/7ZKSKHg0k7KAqTHLs5gh8prFO0xv1Xbr1/rH6ncuHUV05VsFAjZDb IZzxq7ajpjXe/skdlYBJAiQxoyJqstfhvatSx48NvK3w5TNX9Mcmh85kvOkWHUbRfIhG NINw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776843755; x=1777448555; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to: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=ryfcJEToa6giZGDLLJr7ejuqA33i73uojsM9FLivb04=; b=Xfzic+NeLBXydMdLIqj40yWk2txCgQZ0aTafNttG70THHt+Py9rfcXF7o6zvFHKYaP XXw2eDh/bRSoLIma690zIRS70Q+5EOlQW9WfxDkPCd0t+w+nKW2tHLntFuwB9el2b7EG 8fBYJvO9j/Jgqm+UYxjhJygcQQQXY1gwMPgbS+1IZwbsCofs2Kj2LNhJNm18eJO4h3mT Q/46LFD8JcDbFeknBJXwnD0rcnvp4b6LdvYM6iSLeLpKkdFATpkdtQ//kNCR/Q+SS2Ao 6hejpmvCj/9kNaPOO/xfWe3VMsCoV8mnxxjwXDgAshLff9fN+yhO4Cv+DxUKvyt/tiLb Ongw== X-Forwarded-Encrypted: i=1; AFNElJ8ycebDihqUJby8837RWzspYtq5L3OnWOptJuommDHMrHu9nPGSuEGHxVVZzWHbrdmapnzyrhaFXYSv2sU=@vger.kernel.org X-Gm-Message-State: AOJu0YwqEiSvYQxA0aLk6tHZJ1/jrKI++IuOXvhPCnLKPkVgNtDkLvL2 Jd4iMQVmiuIxQ2doJOnZOmqTM0eXY9FHtCT2O4u/OhA0ejlfaL/HFTWVnk/0J/AkuEC3HuZYaOY sX//zRXCni37DXQ3V8X0fKd8njNnqnA/PvXRs6bcFsSEVXDekN8uGtxhHV70Fwv0FOPI= X-Gm-Gg: AeBDiesppMlYnZobCjD+7TXsajrk13a2LGM1dp6FmDORap+CjVb79jwZL8Yjez42HD1 F1zWAz1giPZ9ra8ITT8lFPM3beGyyB3M+hn+HFb6pRw6OfoG+grGL8Dk7hkFxTqslMan2jkmYXS J+GfzldhmEWHN8KdXQxJQVKw5OVwOkNRXUa39Zt5WGYQ6DqSpBTsvgiHPdSU6e4CsX329zecb8Y 4L6e2avwLJ+JHYYNsxdRIYdvl1cnec32sRmX3o2NmFh4+XJdgEdWWK18V0pzfmfSKcg2IqA/R+A F4S9tYkLmvSSx18cxaEoc/ajmNJIgTB4Gb4QtfYYCbEGgyBREqO6QVsUDZ/rXaY3zcukslecHw6 9IwE8Jt1/v9hSLj+kgMQkNbhtdFW/6YyrnYp2qYLit22LrWu4iG9n36cgTa03/H2y X-Received: by 2002:a17:90b:1dc6:b0:35b:e51b:1935 with SMTP id 98e67ed59e1d1-36140462ab5mr19671280a91.17.1776843754914; Wed, 22 Apr 2026 00:42:34 -0700 (PDT) X-Received: by 2002:a17:90b:1dc6:b0:35b:e51b:1935 with SMTP id 98e67ed59e1d1-36140462ab5mr19671263a91.17.1776843754421; Wed, 22 Apr 2026 00:42:34 -0700 (PDT) Received: from [10.206.101.19] ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-361410b998fsm16131288a91.13.2026.04.22.00.42.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Apr 2026 00:42:33 -0700 (PDT) Message-ID: <899e0575-6de3-4ab7-b817-7a51c6b45787@oss.qualcomm.com> Date: Wed, 22 Apr 2026 13:12:17 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] media: iris: optimize COMV buffer allocation for VPU3x and VPU4x To: Bryan O'Donoghue , Vishnu Reddy , 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> Content-Language: en-US From: Vikash Garodia In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIyMDA3MiBTYWx0ZWRfXxvEu4i9UbMB+ K5/J6gj37M5f4A7BMUqmdGtpQykxuAFSa0g5D+RjjTyqWNEjcEZgi86dOfqV7QM1Uhx0saP43Pt QveTaPKRLLcmZpCLLAAPVDYcGk2R+2o41b/vcKHNODo7K+RcsAtFm0eVRG7U29/VYExLKUxyD71 YPhurqi2HXT25lh/cMm53JHLAwpa8Yk7yvbqDYUxrapCkbZH1Riw9bk30RB1MV36duWAC/8ZHQl x9ef5QeEjl7v7srGAy62gViVjocW1s3FRahrI9Nu9tJvInPXff3yyVuVF3mluZ9cW76gasLi07j bE6H5ThUkV73QzwKW+VmFgN312WKy48HsjtMP5iy5/U6KNkol0CucWDs5mrlj/A+mXD52ilVUI3 pjdg0+791tKv9OFbKJYVrWXndCgnQL9JG89Qp2VCxBpIj+7TuKNzN/mYvo5N6fUn3hiqn7c/VgZ js+updMEcy0DkIMo3mw== X-Proofpoint-ORIG-GUID: -8WoXnZL2A8BMaVzYjAZgPrhkQl3Jhs2 X-Authority-Analysis: v=2.4 cv=RYygzVtv c=1 sm=1 tr=0 ts=69e87bec cx=c_pps a=UNFcQwm+pnOIJct1K4W+Mw==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17 a=IkcTkHD0fZMA:10 a=A5OVakUREuEA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=rJkE3RaqiGZ5pbrm-msn:22 a=P-IC7800AAAA:8 a=EUspDBNiAAAA:8 a=sxecAc6Fdml7H7xBZ-gA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=uKXjsCUrEbL0IQVhDsJ9:22 a=d3PnA9EDa4IxuAV0gXij:22 X-Proofpoint-GUID: -8WoXnZL2A8BMaVzYjAZgPrhkQl3Jhs2 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-21_03,2026-04-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 lowpriorityscore=0 adultscore=0 phishscore=0 malwarescore=0 suspectscore=0 bulkscore=0 clxscore=1015 priorityscore=1501 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2604220072 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 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 >> > >