Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1158965pxu; Fri, 27 Nov 2020 00:47:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJxsH1RxMAFYyqFTze72YozEl4QVKVJmTgItfn2v8dN4zd8j3q/wICeFYzqksY29VoKq311X X-Received: by 2002:a17:906:1e93:: with SMTP id e19mr6737215ejj.440.1606466844756; Fri, 27 Nov 2020 00:47:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606466844; cv=none; d=google.com; s=arc-20160816; b=kiaL04Y9U2TdpNJWyiZl2FspFmrj9IpYTcx3QkhpqHpl4cvNxTq54OYrThiL5JuKnu XPtB9t8/BqtzFCNVf8OAHm85GCXSK+50Z7zm/Y2MgwL/FmfeCe/XE8ow3RJ5SbyyWFh1 088rwCeGeFCey0p4/udTL1Gr4CuS7gKO7xHfjaGBKZDYhXsSYyjgWsMcDkpLxmWkuKhW S8fyQB0H9Ru/U11pWTMD9pdzen7QNkNynb99WL12FeG6rAU1mUOfi2sEQ5BYZP5R0Tam LNFPr6JIO3bpILLe97IKcke4vtih2VQo2QfdU5M6n0iQ5kAXq+Q7SrSP/wtG+6eJyTFg ju+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=V5KYSx6aCS9NMZ6LBkhsZnID6zJfBDD/ql119aALBaU=; b=a80pmyQrnXL41wt6qOAJ/dgMj/lOjaGOPCZ99TBUsWF+4tJD1Gq4DBOsWL8rPAzrMB Wsz4W7fLB+S3SdIG8dt1obEplF2uCLBIwijL5qRuCnbPaBS/4j+8aS0Bs3Bs+2AOK54O uQ0Qbp851o7hjJZ5dDbKKjLH5VUGbE3Sp/3XXfnNl+zxeKh433aVYETtDV7itTj0WBNn Hn3CFoAZZ3NVQVZSZONKMCu6JVIV5wAuk1vOa7Yjn3B6nytXpgkrdNXbLryULTscddDp 1Xo6cr9KhXHHlDQxOpeiTpLEfZbYHGHEIWv3qjfvvmiFGWD3lQQ0MxafVwT3oTtAcCuU 2YdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BvFjIsHV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g20si4650218edh.74.2020.11.27.00.47.02; Fri, 27 Nov 2020 00:47:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BvFjIsHV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732132AbgKZXvC (ORCPT + 99 others); Thu, 26 Nov 2020 18:51:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726287AbgKZXvC (ORCPT ); Thu, 26 Nov 2020 18:51:02 -0500 Received: from mail-ed1-x541.google.com (mail-ed1-x541.google.com [IPv6:2a00:1450:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 048A2C0617A7 for ; Thu, 26 Nov 2020 15:51:01 -0800 (PST) Received: by mail-ed1-x541.google.com with SMTP id k4so3964641edl.0 for ; Thu, 26 Nov 2020 15:51:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=V5KYSx6aCS9NMZ6LBkhsZnID6zJfBDD/ql119aALBaU=; b=BvFjIsHVznSKm0SCyX7mIYruIwzynFNq6nNjPldATYnR/9Kn4OLnH1J6oZe8DndYR8 qaZNte+m8uCJZSY0nFOFdcshKL6nsXVP71dxpFJKptdOGZ6saM+ujUu9dRLLJdmhclUL mMAIYoZXdVTod+NpaYIQd0N82DsifDhARArDWSSxexpzD4K0UO6xINti8XffHGlJMagI Di7/DyNAj0WIS5A+kqL1QExtFA4lhuYlGdouuIDmcTbhSQO9iE2xlvDJnt5qWOt9X9YA JAp0VeyqBvB+SP2QGYuZhyfXztlAIzkhA/AonRyq86JTdvL/unX2h0Z3ff3cvDBGXFZ6 09kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=V5KYSx6aCS9NMZ6LBkhsZnID6zJfBDD/ql119aALBaU=; b=hPpXbi/wkoZN1mJfhRv7M9QRi4IwnDlY88wsn9yz+7d28Vez6sBWujwF7L7LO1c3/u yltCX13yJvILvMaTA+bq5iL9Xl2VHGUuBFv7FY/CfCF5EbHGPKyVtOPhhh/MCBsDsjpm /QRIOUJpLvZC/ly9ATdC4g6xoPIrV//l/SZSQyI7hWFvyO+kaAwM/leIvvL7hwojvSFA 3baCH/1L8HaGmhsaE52xJPUX+HxW7v0WWd/YoaaWcx/F/xfBsbIHi/so3ul/hXlYqsm5 M5BFUs6YZWvvxPOy1tw+UAZgLtKoOBJbn/ps9Q/6I6cjpBh1riuTo3zLJCkCjj+5A6Xt 6pFg== X-Gm-Message-State: AOAM532DP6QEdupJ3+Y51r9pEfDrTQLguAuDxCDE2suLQ+tFkhQamunI jDLDpGoEc+tyFND8n4SoF33j5mMUg4dznsKX X-Received: by 2002:a50:d784:: with SMTP id w4mr4718044edi.201.1606434660535; Thu, 26 Nov 2020 15:51:00 -0800 (PST) Received: from [192.168.0.3] (hst-221-3.medicom.bg. [84.238.221.3]) by smtp.googlemail.com with ESMTPSA id 91sm1638444edy.45.2020.11.26.15.50.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 26 Nov 2020 15:50:59 -0800 (PST) Subject: Re: [PATCH 1/3] venus: venc: Init the session only once in queue_setup To: Alexandre Courbot Cc: linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Vikash Garodia , Mansur Alisha Shaik , Dikshita Agarwal References: <20201120001037.10032-1-stanimir.varbanov@linaro.org> <20201120001037.10032-2-stanimir.varbanov@linaro.org> From: Stanimir Varbanov Message-ID: Date: Fri, 27 Nov 2020 01:50:58 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/25/20 5:13 AM, Alexandre Courbot wrote: > Hi Stan, > > On Fri, Nov 20, 2020 at 9:12 AM Stanimir Varbanov > wrote: >> >> Init the hfi session only once in queue_setup and also cover that >> with inst->lock. >> >> Signed-off-by: Stanimir Varbanov >> --- >> drivers/media/platform/qcom/venus/venc.c | 98 ++++++++++++++++++------ >> 1 file changed, 73 insertions(+), 25 deletions(-) >> >> diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c >> index 4ecf78e30b59..3a2e449663d8 100644 >> --- a/drivers/media/platform/qcom/venus/venc.c >> +++ b/drivers/media/platform/qcom/venus/venc.c >> @@ -725,8 +725,10 @@ static int venc_init_session(struct venus_inst *inst) >> int ret; >> >> ret = hfi_session_init(inst, inst->fmt_cap->pixfmt); >> - if (ret) >> - return ret; >> + if (ret == -EINVAL) >> + return 0; > > Why is it safe to ignore EINVAL here? The confusion comes from hfi_session_init() return values. Presently hfi_session_init will return EINVAL when the session is already init. Maybe EINVAL is not fitting well with the expected behavior of the function. I thought about EALREADY, EBUSY but it doesn't fit well to me too. > >> + else if (ret) >> + goto deinit; >> >> ret = venus_helper_set_input_resolution(inst, inst->width, >> inst->height); >> @@ -762,17 +764,13 @@ static int venc_out_num_buffers(struct venus_inst *inst, unsigned int *num) >> struct hfi_buffer_requirements bufreq; >> int ret; >> >> - ret = venc_init_session(inst); >> + ret = venus_helper_get_bufreq(inst, HFI_BUFFER_INPUT, &bufreq); >> if (ret) >> return ret; >> >> - ret = venus_helper_get_bufreq(inst, HFI_BUFFER_INPUT, &bufreq); >> - >> *num = bufreq.count_actual; >> >> - hfi_session_deinit(inst); >> - >> - return ret; >> + return 0; >> } >> >> static int venc_queue_setup(struct vb2_queue *q, >> @@ -781,7 +779,7 @@ static int venc_queue_setup(struct vb2_queue *q, >> { >> struct venus_inst *inst = vb2_get_drv_priv(q); >> unsigned int num, min = 4; >> - int ret = 0; >> + int ret; >> >> if (*num_planes) { >> if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE && >> @@ -803,6 +801,17 @@ static int venc_queue_setup(struct vb2_queue *q, >> return 0; >> } >> >> + ret = mutex_lock_interruptible(&inst->lock); I'll keep original mutex_lock here in next version. >> + if (ret) >> + return ret; >> + >> + ret = venc_init_session(inst); >> + >> + mutex_unlock(&inst->lock); >> + >> + if (ret) >> + return ret; >> + >> switch (q->type) { >> case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: >> *num_planes = inst->fmt_out->num_planes; >> @@ -838,6 +847,54 @@ static int venc_queue_setup(struct vb2_queue *q, >> return ret; >> } >> >> +static int venc_buf_init(struct vb2_buffer *vb) >> +{ >> + struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue); >> + >> + inst->buf_count++; >> + >> + return venus_helper_vb2_buf_init(vb); >> +} >> + >> +static void venc_release_session(struct venus_inst *inst) >> +{ >> + int ret, abort = 0; >> + >> + mutex_lock(&inst->lock); >> + >> + ret = hfi_session_deinit(inst); >> + abort = (ret && ret != -EINVAL) ? 1 : 0; > > Here as well, I think a comment is warranted to explain why we can > ignore EINVAL. OK, will update that. > >> + >> + if (inst->session_error) >> + abort = 1; >> + >> + if (abort) >> + hfi_session_abort(inst); >> + >> + mutex_unlock(&inst->lock); >> + >> + venus_pm_load_scale(inst); >> + INIT_LIST_HEAD(&inst->registeredbufs); >> + venus_pm_release_core(inst); >> +} >> + >> +static void venc_buf_cleanup(struct vb2_buffer *vb) >> +{ >> + struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue); >> + struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); >> + struct venus_buffer *buf = to_venus_buffer(vbuf); >> + >> + mutex_lock(&inst->lock); >> + if (vb->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) >> + if (!list_empty(&inst->registeredbufs)) >> + list_del_init(&buf->reg_list); >> + mutex_unlock(&inst->lock); >> + >> + inst->buf_count--; >> + if (!inst->buf_count) >> + venc_release_session(inst); > > We are calling venc_init_session() during the queue setup but > venc_release_session() when the last buffer is cleaned up. For > symmetry, wouldn't it make sense to call venc_init_session() when the > first buffer is initialized by venc_buf_init()? Otherwise we can No, the session must be initialized in queue_setup in order to return the number and sizes of source/destination buffers. I raised several times the need of symmetrical operation to queue_setup to cover reqbuf(0) but there is no progress on that. Latest suggestion was to use .vidioc_reqbufs ioctl op but I fall with some other issues and at the end I came to this counting buf_init|cleanup solution. > potentially have a scenario where the queue is set up, but no buffer > is ever created, leading to the session never being released. dmabuf import case? -- regards, Stan