Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3346270ybi; Mon, 29 Jul 2019 05:07:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqwdcb5Qz/v7X8lC9Fusota9riEsmR5Wx1MguXhb8ULXW/RQoFt6mugTib25PtOsAELuOTVJ X-Received: by 2002:a62:cdc3:: with SMTP id o186mr36627929pfg.168.1564402034508; Mon, 29 Jul 2019 05:07:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564402034; cv=none; d=google.com; s=arc-20160816; b=JuLrQM8duBv5vCFrz7IWOlhPKKkaQm2exWwKQAwXUzO/deW9CibzEWig5CuENJWo37 XIcSZ9r/fzcEKfcMyeJNNuzUz8ShTXiUhV/Z3gN4jDf5UHw1ogs1aUp82s/K+27bAmRQ eggqYicgNUWUAncBAL7jq2CU9t9SIwRu16lVAUXRSzwV3tB23+UsLWjH4TWtbi+yKmJT 0TwuTd2WXVECGhT2F7PtXI1g3hJ048z/YRdGWaki+aBJnZkHEh8TnPb8IFTlrqt5WZfH 6d6oW66IsCrduyEhZAvjUSB5hDB1QsOQvp69aKHGBZc0r1vTUY+mVJQPshh737zMkubL nDLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=8547tTieJTlVcp1ebRnVxi/sn+gdsxGXf1dlpzxnCUw=; b=QgAITsPKyXgGkvQr9PNIzkF9lFsjmdaYWnbYeoRv4fzzyafUN2C5U3UoZrfv5FjT/y gKG10LcLRd+7hLZEw6FgW0ayDUH5Is4p+grap+SHzNHUJpVIHa6aeRjuj2yBC1s9N2RW w5gTK/XdlLeUN1mibyDp8RpM3z9+HRH4E+C+OGCxUMD2+QTLnu8a/V7DwepVuJMyNzl/ gO8IvrBO2SW9deRxnMg/xNMe+P77Qnfw52BLqJVjahQyXu+zI510oH7JWZdJF7CdqHpj cdEo3C/b6AMEEPIlBTQw9eceFb9sr2ViE1o+yLiK/SBwaFJbmEQoRiPYHGrmYMtkk312 QYCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=L8sOkg7A; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id h8si26963391pgc.402.2019.07.29.05.06.56; Mon, 29 Jul 2019 05:07:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=L8sOkg7A; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727171AbfG2Hyf (ORCPT + 99 others); Mon, 29 Jul 2019 03:54:35 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:32865 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726717AbfG2Hyf (ORCPT ); Mon, 29 Jul 2019 03:54:35 -0400 Received: by mail-lj1-f194.google.com with SMTP id h10so57634857ljg.0 for ; Mon, 29 Jul 2019 00:54:33 -0700 (PDT) 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=8547tTieJTlVcp1ebRnVxi/sn+gdsxGXf1dlpzxnCUw=; b=L8sOkg7Ax87vy+96EbbXXe/57YWfMfL5VN12MJf0jWV2nZrspx9wgCZekwqwSafd+U ZRyGHhnULDy68f7hnWZPmk7IKc+tNUGqcMJRpeyjY78EgutxWvTEr4fq/8sfr87zj/vH GZAvXJswddC6YrbIKnEbsOHxrwqAF0t8pW7jyTBFPuxMiiQCoEIdEWWQNWzt2Vy+ruNF EeXQiBZGrIN/lw84IuwycszDODdxj5/tTnNzSKWgQzwc4m/8tA5/JitSBkOp3WPyFW+l D9cUX7ZgMX+vsw7kKdMQaE78AQyO+sTBk6vnQ25VQKkj+pWK3VGjFkA8POTzzxpygod0 7FgA== 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=8547tTieJTlVcp1ebRnVxi/sn+gdsxGXf1dlpzxnCUw=; b=rZ0ZEQYOvajtk4LkzpS5gmtzKCzmB6cCuoIpMRw2xrr+A8YwcQi388nU1K95rqurUI Uj3dmrY3Hw+BvXhdKKldAjff3q43dK3LpuyS7NFjSml+znWw1Vk4KEoRMazCu5VB/WS8 7eY0AE7R84YxZg04uNDoJWY8TXQaX0e9zcBuDSyU9+N3sSIOB/Txb1b++d5fSBaiyttH FdQBX+T1OCuMP9PmP1ULp0lw8DGlo81TordethP4MYA9bUl3f/uA1H8ziY2+7fBR9rjc XKnUEMbw81Tfs+UNgoOiDRLWBgejTfUyVFZv+H/icbhvKS8u6OfRNPzVhjKtCjZChTje cTBg== X-Gm-Message-State: APjAAAVK6TufbHbzzfGIIgB5U3WXEeLTvv8RnpO1YoGvPwQ92QM55Gtw vxwqy59/W3n7nNbQUDfETMz0dw== X-Received: by 2002:a2e:b0e6:: with SMTP id h6mr5315235ljl.18.1564386872598; Mon, 29 Jul 2019 00:54:32 -0700 (PDT) Received: from [192.168.28.50] ([37.157.136.206]) by smtp.googlemail.com with ESMTPSA id t1sm12678137lji.52.2019.07.29.00.54.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Jul 2019 00:54:31 -0700 (PDT) Subject: Re: [PATCH v6 3/4] media: venus: Update to bitrate based clock scaling To: Aniket Masule , linux-media@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, vgarodia@codeaurora.org References: <1563786452-22188-1-git-send-email-amasule@codeaurora.org> <1563786452-22188-3-git-send-email-amasule@codeaurora.org> From: Stanimir Varbanov Message-ID: Date: Mon, 29 Jul 2019 10:54:28 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <1563786452-22188-3-git-send-email-amasule@codeaurora.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/22/19 12:07 PM, Aniket Masule wrote: > Introduced clock scaling using bitrate, preavious > calculations consider only the cycles per mb. > Also, clock scaling is now triggered before every > buffer being queued to the device. This helps in > deciding precise clock cycles required. > > Signed-off-by: Aniket Masule > --- > drivers/media/platform/qcom/venus/helpers.c | 33 +++++++++++++++++++++++++---- > 1 file changed, 29 insertions(+), 4 deletions(-) > > diff --git a/drivers/media/platform/qcom/venus/helpers.c b/drivers/media/platform/qcom/venus/helpers.c > index 2c976e4..edf403d 100644 > --- a/drivers/media/platform/qcom/venus/helpers.c > +++ b/drivers/media/platform/qcom/venus/helpers.c > @@ -399,17 +399,26 @@ static int scale_clocks(struct venus_inst *inst) > return ret; > } > > -static unsigned long calculate_vpp_freq(struct venus_inst *inst) > +static unsigned long calculate_inst_freq(struct venus_inst *inst, > + unsigned long filled_len) > { > - unsigned long vpp_freq = 0; > + unsigned long vpp_freq = 0, vsp_freq = 0; > + u64 fps = inst->fps; > u32 mbs_per_sec; > > mbs_per_sec = load_per_instance(inst); > vpp_freq = mbs_per_sec * inst->clk_data.codec_freq_data->vpp_freq; > /* 21 / 20 is overhead factor */ > vpp_freq += vpp_freq / 20; > + vsp_freq = mbs_per_sec * inst->clk_data.codec_freq_data->vsp_freq; > > - return vpp_freq; > + /* 10 / 7 is overhead factor */ > + if (inst->session_type == VIDC_SESSION_TYPE_ENC) > + vsp_freq += (inst->controls.enc.bitrate * 10) / 7; > + else > + vsp_freq += ((fps * filled_len * 8) * 10) / 7; > + > + return max(vpp_freq, vsp_freq); > } > > static int scale_clocks_v4(struct venus_inst *inst) > @@ -417,13 +426,27 @@ static int scale_clocks_v4(struct venus_inst *inst) > struct venus_core *core = inst->core; > const struct freq_tbl *table = core->res->freq_tbl; > unsigned int num_rows = core->res->freq_tbl_size; > + struct v4l2_m2m_ctx *m2m_ctx = inst->m2m_ctx; > struct clk *clk = core->clks[0]; > struct device *dev = core->dev; > unsigned int i; > unsigned long freq = 0, freq_core1 = 0, freq_core2 = 0; > + unsigned long filled_len = 0; > + struct venus_buffer *buf, *n; > + struct vb2_buffer *vb; > int ret; > > - freq = calculate_vpp_freq(inst); > + mutex_lock(&inst->lock); the lock is not needed and having it will produce a deadlock. > + v4l2_m2m_for_each_src_buf_safe(m2m_ctx, buf, n) { > + vb = &buf->vb.vb2_buf; > + filled_len = max(filled_len, vb2_get_plane_payload(vb, 0)); > + } > + mutex_unlock(&inst->lock); > + > + if (inst->session_type == VIDC_SESSION_TYPE_DEC && !filled_len) > + return 0; > + > + freq = calculate_inst_freq(inst, filled_len); > > if (freq > table[0].freq) > dev_warn(dev, "HW is overloaded, needed: %lu max: %lu\n", > @@ -1093,6 +1116,8 @@ void venus_helper_vb2_buf_queue(struct vb2_buffer *vb) > if (ret) > goto unlock; > > + load_scale_clocks(inst); > + > ret = session_process_buf(inst, vbuf); > if (ret) > return_buf_error(inst, vbuf); > -- regards, Stan