Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2294062ybi; Mon, 1 Jul 2019 09:30:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqxwL5ZowdaluFXS5AhDFlX8+IIx3QNr7AJ7M5Jq/znI/NvUAOjRSrsdU5WgSOpck9JlLXB1 X-Received: by 2002:a63:e24c:: with SMTP id y12mr23350945pgj.81.1561998611403; Mon, 01 Jul 2019 09:30:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561998611; cv=none; d=google.com; s=arc-20160816; b=wmau93SK4u6mtYCIYw/D3r9Y+i16FNiMkS5PY8Refz4bj540oAVW3b6SfdqnJCiP9X 6iWK2o6OH2uZTHzFav+Bt/s6Vb7L7ngjqMGaJcIrJk+5NFQZp1We9Kau+zErDCkXygrD byTGFUIrgIIdyTVrPiu9JqqukQI47iOb5+mZgiQJMIrOOSn8jDgbHPuCkQtJAJ7ixprw Ks7C9BCb4xbJEdZ+BvE+98zwWhfYm91RlCV1X2vmFbRcVNlT4wFLwcgErkyq1ZxWigj1 4Jd/zWh8/Vv/mjENbHMUzcWii6YY8MhNmuSYqKEIwpuzsslm4yM3UiGOz0VP/81IF2en Rsfw== 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=ImGPcfrTaxEgEgkx65mt0ofrgVu0PRsPNy18Ds0mkaY=; b=wh1lKtvh0nbB7tid3SuNqlMIK153RhPKowsq+NUNUXdoPRe45FUCld13OF1Stc1jox AhjwGE0LzESQSHoFa/bJ1XypvLEmzo9UmeLKXch080E302PDOBTxGZM3y+qv4KyZ3xx5 xUwwc0/P+tRh9w8xLjsQgIJl82xp+/2XZrqBPBBK7LqGSPIyZb0RkpOZKjcT/higd5wn CceLsxbASrJkItXb+37lcVh9J6tRcWtT/4o+SfaySSbbM4h1LySQeX+OvTjVvkxjILDC eKQjoEE1XMrr1Md9tqoiW/FujQ98aWVoGI+4i5n/R8FyQvQ0fRyCMKZaRrbZK7O3SHfY DDAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DJ3zwEyE; 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 94si6256872plb.224.2019.07.01.09.29.55; Mon, 01 Jul 2019 09:30:11 -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=DJ3zwEyE; 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 S1729818AbfGAPpY (ORCPT + 99 others); Mon, 1 Jul 2019 11:45:24 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:41222 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727373AbfGAPpX (ORCPT ); Mon, 1 Jul 2019 11:45:23 -0400 Received: by mail-lf1-f67.google.com with SMTP id 136so9117106lfa.8 for ; Mon, 01 Jul 2019 08:45:22 -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=ImGPcfrTaxEgEgkx65mt0ofrgVu0PRsPNy18Ds0mkaY=; b=DJ3zwEyEiuc0ibdOqvlPD77n0POZywfOmkhuiKrjmpUkv/CUdB7OAvyi8F3WIrr9c7 1XJXiToXr0WVG76FIprtNBZJQ7Oosvjrx2NseXQUdzeXBJZB27n9fHUyYdCjMQeZEwhI 3pNdNprHm0a4E/6PNk0Jq2BUeph/Qyy4zcT4sF15duqYle1Vm8DzD6FtfD+P4cMRVRG8 VhTyZCy5xt1rJu5kcV/bE0bZrDYsRMnCEZpNp2sl5GhB3MkqcCQvZ8jL2wL/xKsp/bFx volPESdFR5/agT5n5MRrBlXQxL1FFXCaqiVUhUgeBokXm2SqtZwROS/LfBtUavelQ+SO c+FQ== 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=ImGPcfrTaxEgEgkx65mt0ofrgVu0PRsPNy18Ds0mkaY=; b=CTKIFWVXZoxWd7JnKHrIka/EZCchkuimne9d1kcjsYLrkFqn1P3kbyj/+E18z/kvZJ /DpMnIuUs8lmsw/qw5PyKZd+ynmm4s3PsiIL+Lym8QNXdj39JId9gDHxeGVVw58gGH5c rZglGgQc9+KPIya4apgmMMFlbQRl0GYJhw7GU21gH71fQtGzJatWt75WW9mYTZB+IMu8 hKCwlw7bwpQLjy9g9aUwhp1B9uUljpGrij3nzPu0L9gyBBFJsPbKbdC8VnFc5afLRhyZ wDd16l3nAKzPjcTtOT46VfNPgROMOjZIEbjzuWrw8lkPdzypIvt0Vlk5ZufXwZpceUCC L2yw== X-Gm-Message-State: APjAAAVe9MMkXgqgdqM3v7XQAU7JRDoMuKbkKrxshcoCcuovOcEiGbrS q51SV200ypZ6I/SCn7q4L/r+lA== X-Received: by 2002:ac2:4a6e:: with SMTP id q14mr12179312lfp.154.1561995921133; Mon, 01 Jul 2019 08:45:21 -0700 (PDT) Received: from [192.168.27.209] ([37.157.136.206]) by smtp.googlemail.com with ESMTPSA id d4sm2609795lfi.91.2019.07.01.08.45.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Jul 2019 08:45:20 -0700 (PDT) Subject: Re: [PATCH] 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: <1561537416-2067-1-git-send-email-amasule@codeaurora.org> <1561537416-2067-2-git-send-email-amasule@codeaurora.org> From: Stanimir Varbanov Message-ID: <00818fe7-95e6-b43f-fca8-c4669ffad947@linaro.org> Date: Mon, 1 Jul 2019 18:45:19 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.1 MIME-Version: 1.0 In-Reply-To: <1561537416-2067-2-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 Hi Aniket, On 6/26/19 11:23 AM, Aniket Masule wrote: > Introduced clock scaling using bitrate, current > 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/core.c | 16 +++++------ > drivers/media/platform/qcom/venus/core.h | 1 + > drivers/media/platform/qcom/venus/helpers.c | 43 +++++++++++++++++++++++++---- > 3 files changed, 47 insertions(+), 13 deletions(-) > > diff --git a/drivers/media/platform/qcom/venus/core.c b/drivers/media/platform/qcom/venus/core.c > index f1597d6..ad6bb74 100644 > --- a/drivers/media/platform/qcom/venus/core.c > +++ b/drivers/media/platform/qcom/venus/core.c > @@ -474,14 +474,14 @@ static __maybe_unused int venus_runtime_resume(struct device *dev) > }; > > static struct codec_freq_data sdm845_codec_freq_data[] = { > - { V4L2_PIX_FMT_H264, VIDC_SESSION_TYPE_ENC, 675 }, > - { V4L2_PIX_FMT_HEVC, VIDC_SESSION_TYPE_ENC, 675 }, > - { V4L2_PIX_FMT_VP8, VIDC_SESSION_TYPE_ENC, 675 }, > - { V4L2_PIX_FMT_MPEG2, VIDC_SESSION_TYPE_DEC, 200 }, > - { V4L2_PIX_FMT_H264, VIDC_SESSION_TYPE_DEC, 200 }, > - { V4L2_PIX_FMT_HEVC, VIDC_SESSION_TYPE_DEC, 200 }, > - { V4L2_PIX_FMT_VP8, VIDC_SESSION_TYPE_DEC, 200 }, > - { V4L2_PIX_FMT_VP9, VIDC_SESSION_TYPE_DEC, 200 }, > + { V4L2_PIX_FMT_H264, VIDC_SESSION_TYPE_ENC, 675, 10 }, > + { V4L2_PIX_FMT_HEVC, VIDC_SESSION_TYPE_ENC, 675, 10 }, > + { V4L2_PIX_FMT_VP8, VIDC_SESSION_TYPE_ENC, 675, 10 }, > + { V4L2_PIX_FMT_MPEG2, VIDC_SESSION_TYPE_DEC, 200, 10 }, > + { V4L2_PIX_FMT_H264, VIDC_SESSION_TYPE_DEC, 200, 10 }, > + { V4L2_PIX_FMT_HEVC, VIDC_SESSION_TYPE_DEC, 200, 10 }, > + { V4L2_PIX_FMT_VP8, VIDC_SESSION_TYPE_DEC, 200, 10 }, > + { V4L2_PIX_FMT_VP9, VIDC_SESSION_TYPE_DEC, 200, 10 }, > }; > > static const struct venus_resources sdm845_res = { > diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h > index 2ed6496..b964b7c 100644 > --- a/drivers/media/platform/qcom/venus/core.h > +++ b/drivers/media/platform/qcom/venus/core.h > @@ -39,6 +39,7 @@ struct codec_freq_data { > u32 pixfmt; > u32 session_type; > unsigned int vpp_freq; > + unsigned int vsp_freq; unsigned long? > }; > > struct venus_resources { > diff --git a/drivers/media/platform/qcom/venus/helpers.c b/drivers/media/platform/qcom/venus/helpers.c > index ef35fd8..634778a 100644 > --- a/drivers/media/platform/qcom/venus/helpers.c > +++ b/drivers/media/platform/qcom/venus/helpers.c > @@ -379,6 +379,9 @@ static int scale_clocks(struct venus_inst *inst) > unsigned int i; > int ret; > > + if (inst->state == INST_START) > + return 0; This condition is related (probably) to the change in venus_helper_vb2_buf_queue() but shouldn't it be copied in scale_clocks_v4 too? > + > mbs_per_sec = load_per_type(core, VIDC_SESSION_TYPE_ENC) + > load_per_type(core, VIDC_SESSION_TYPE_DEC); > > @@ -418,17 +421,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; this calculation is not used below. Is that intentional? > + > + /* 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 vpp_freq; > + return max(vpp_freq, vsp_freq); > } > > static int scale_clocks_v4(struct venus_inst *inst) > @@ -436,14 +448,30 @@ 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; > + drop this addition of blank line. > unsigned int i; > unsigned long freq = 0, freq_core0 = 0, freq_core1 = 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); > + 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) { > + dev_dbg(dev, "%s: No input to the session\n", __func__); please drop this debug message, if the user pushes empty buffers something will blow up earlier. > + return 0; > + } > + > + freq = calculate_inst_freq(inst, filled_len); > > if (freq > table[0].freq) > goto err; > @@ -471,6 +499,9 @@ static int scale_clocks_v4(struct venus_inst *inst) > > freq = max(freq_core0, freq_core1); > > + if (clk_get_rate(clk) == freq) > + return 0; > + above check is included in clk_set_rate(), you don't need it. > ret = clk_set_rate(clk, freq); > if (ret) > goto err; > @@ -1150,6 +1181,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