Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1663196ybi; Thu, 20 Jun 2019 01:29:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqwtuWdRqyK1pAv/YKLIgIdJspkO3eTWeQZsvCHT8nDvHT5uCJ4A5gWqoxZzC8u6sqgQ9Pcg X-Received: by 2002:a65:6541:: with SMTP id a1mr11697863pgw.409.1561019357973; Thu, 20 Jun 2019 01:29:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561019357; cv=none; d=google.com; s=arc-20160816; b=FHHLZ3GmWhzF0CyfLh5YUJUf0/dBiacbFVJukeE+xjIpAQAIxd0JRTnFU8rcoECL2p ot9aTGS4NjzaI1Ad5kH1jfQt5UzRG7WGnGGaFZ4i955gQky23WieqvbcPB4v7iyY3P13 HldYx33kCFaoT1oOa8TBXj2La1XsHUQ/nsDH7SdGsLHvz7Ccw5F8Tjgvdlm9nbgBqdil WN34OxF7dnCP2wHAIgS/ADZB4SA8zOuazZ0iRNqDn7KOhphjeFE9BoQDyUtddEWau2U0 D166wA+9LchCHGIS/whyY9EqTNSwHUQv/MeVI2VuKrRD7/9OBBqpRQs2vbTGDVmqINTn Gt8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:references :in-reply-to:subject:cc:to:from:date:content-transfer-encoding :mime-version:dkim-signature:dkim-signature; bh=07JGua3qlk3Yilh5fUEPgiS+apo+VcajK7yDVBHTNmM=; b=R895Hs/Lug+0Xj0iErLAaNzn7TjHzAap/y9JGN2wA8lZ+0aqbfJqmg4JathlalTUNg gpfmbfIVbsQq06e6YY8681QxMk6UoGjevMFNmFwK2DiGSKgkQyvk+JslMAiiDYABrwrM 8sC18CxQuKCDkzz+DYLwcgg0DPkSEen7aQEWDATXRjEmbaB8/HpCdIdejAgNAh/owF8G DT9dnW8GaNRpSyZDY26y8AQrxHj98aY0TPhZRAJNT5HKUMZwsoqYpwWjQut/JHAFhFse JO1JsyIDomwRkN+kVeb7MyVwXrgod1YVF8xTc5z1cDBky43xZOwIC89rzjVtDzA40Cpk IOBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=ocALnvCY; dkim=pass header.i=@codeaurora.org header.s=default header.b=hnuGTBxG; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j18si18593220pfe.235.2019.06.20.01.29.02; Thu, 20 Jun 2019 01:29:17 -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=@codeaurora.org header.s=default header.b=ocALnvCY; dkim=pass header.i=@codeaurora.org header.s=default header.b=hnuGTBxG; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730196AbfFTI2f (ORCPT + 99 others); Thu, 20 Jun 2019 04:28:35 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:54770 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725875AbfFTI2f (ORCPT ); Thu, 20 Jun 2019 04:28:35 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 55CEE60867; Thu, 20 Jun 2019 08:28:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1561019313; bh=UiZTqO2d/B91wZV2iRJUamihFX7vX8r/m9aAuZdvl0U=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ocALnvCYwC9QRJQUPsRcwvqANyJqa53SfaCIEmT0QswcBf+nmnNr7SnUhXh+X6cCW zmhXv405mWBfAyVbjG2dIKqTINyyN0XKOnfsocXETawt03GEEE2lGZecuH8IU5m6pV zExV2PTHNMe00CBhcZgFvSXcVqvr3oMcGWt11n8A= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_INVALID,DKIM_SIGNED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id 62894606FC; Thu, 20 Jun 2019 08:28:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1561019312; bh=UiZTqO2d/B91wZV2iRJUamihFX7vX8r/m9aAuZdvl0U=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=hnuGTBxGmMYkKvVgDNbeJaWwM1/2XzNz/fv1YwdrsesW+PX8UvHsu7wuSvco1OyP3 5fZ2u0qrcDNa1UsCqP72vH4hiURwfsBx0+0sxPvrxTkQvBlK1nwZsrPedS8hForSP+ xAmi05PCri21LPPcrvDLZY3RRp7dhUoJRVXVefxo= MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 20 Jun 2019 13:58:32 +0530 From: amasule@codeaurora.org To: Stanimir Varbanov Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, vgarodia@codeaurora.org Subject: Re: [PATCH 3/5] media: venus: Update clock scaling In-Reply-To: References: <1560233130-27264-1-git-send-email-amasule@codeaurora.org> <1560233130-27264-4-git-send-email-amasule@codeaurora.org> Message-ID: <0a0b2dd455f21d3ea7013c4595fb0fc7@codeaurora.org> X-Sender: amasule@codeaurora.org User-Agent: Roundcube Webmail/1.2.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Stan, On 2019-06-17 14:28, Stanimir Varbanov wrote: > Hi Aniket, > > On 6/11/19 9:05 AM, Aniket Masule wrote: >> Current clock scaling calculations are same for vpu4 and >> previous versions. For vpu4, Clock scaling calculations >> are updated with cycles/mb. This helps in getting precise >> clock required. >> >> Signed-off-by: Aniket Masule >> --- >> drivers/media/platform/qcom/venus/helpers.c | 88 >> +++++++++++++++++++++++++++-- >> 1 file changed, 84 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/media/platform/qcom/venus/helpers.c >> b/drivers/media/platform/qcom/venus/helpers.c >> index f7f724b..7bcc1e6 100644 >> --- a/drivers/media/platform/qcom/venus/helpers.c >> +++ b/drivers/media/platform/qcom/venus/helpers.c >> @@ -348,8 +348,9 @@ static u32 load_per_type(struct venus_core *core, >> u32 session_type) >> return mbs_per_sec; >> } >> >> -static int load_scale_clocks(struct venus_core *core) >> +static int scale_clocks(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; >> unsigned long freq = table[0].freq; >> @@ -398,6 +399,86 @@ static int load_scale_clocks(struct venus_core >> *core) >> return ret; >> } >> >> +static unsigned long calculate_inst_freq(struct venus_inst *inst) >> +{ >> + unsigned long vpp_cycles = 0; >> + u32 mbs_per_sec; >> + >> + mbs_per_sec = load_per_instance(inst); >> + vpp_cycles = mbs_per_sec * inst->clk_data.codec_data->vpp_cycles; >> + /* 21 / 20 is overhead factor */ >> + vpp_cycles += vpp_cycles / 20; > > shouldn't you multiply by 21? > Expansion of given expression results to the same. >> + >> + return vpp_cycles; > > It is not clear to me is that vpp_cycles or frequency (rate)? I just > lost in dimensions used here. > > If you return vpp_cycles could you rename the function name? > Initial calculations included frequency (for bitrate based scaling), which I removed. I will rename it calculate_inst_vpp_cycles for this patch. >> +} >> + >> +static int scale_clocks_vpu4(struct venus_inst *inst) > > does vpu4 equivalent to HFI_VERSION_4XX? If so could you rename > function > to scale_clocks_v4. > Sure Stan, I will rename it to scale_clocks_v4. >> +{ >> + 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 clk *clk = core->clks[0]; >> + struct device *dev = core->dev; >> + unsigned int i; >> + unsigned long freq = 0, freq_core0 = 0, freq_core1 = 0; >> + int ret; >> + >> + freq = calculate_inst_freq(inst); >> + >> + if (freq > table[0].freq) >> + goto err; >> + >> + for (i = 0; i < num_rows; i++) { >> + if (freq > table[i].freq) >> + break; >> + freq = table[i].freq; >> + } >> + >> + inst->clk_data.freq = freq; >> + >> + mutex_lock(&core->lock); >> + list_for_each_entry(inst, &core->instances, list) { >> + if (inst->clk_data.core_id == VIDC_CORE_ID_1) { >> + freq_core0 += inst->clk_data.freq; >> + } else if (inst->clk_data.core_id == VIDC_CORE_ID_2) { >> + freq_core1 += inst->clk_data.freq; >> + } else if (inst->clk_data.core_id == VIDC_CORE_ID_3) { >> + freq_core0 += inst->clk_data.freq; >> + freq_core1 += inst->clk_data.freq; >> + } >> + } >> + mutex_unlock(&core->lock); >> + >> + freq = max(freq_core0, freq_core1); > > hmm, this doesn't look right. core0 and core1 frequencies can be > different why you get the bigger and set it on both? > We can't set separate clocks to core0 and core1. As per the design, we can set clocks to the branch only not the individual cores. >> + >> + ret = clk_set_rate(clk, freq); >> + if (ret) >> + goto err; >> + >> + ret = clk_set_rate(core->core0_clk, freq); > > IMO this should set freq_core0 We need set max required frequency, due to the reason mentioned above. > >> + if (ret) >> + goto err; >> + >> + ret = clk_set_rate(core->core1_clk, freq); > > set freq_core1 > We need set max required frequency, due to the reason mentioned above. >> + if (ret) >> + goto err; >> + >> + return 0; >> + >> +err: >> + dev_err(dev, "failed to set clock rate %lu (%d)\n", freq, ret); >> + return ret; >> +} >> + >> +static int load_scale_clocks(struct venus_inst *inst) >> +{ >> + if (IS_V3(inst->core) || IS_V1(inst->core)) >> + return scale_clocks(inst); >> + else >> + return scale_clocks_vpu4(inst); > > could you reorder this to: > > if (IS_V4()) > return scale_clocks_v4(inst); > > return scale_clocks(inst); > Yes Stan. >> +} >> + >> static void fill_buffer_desc(const struct venus_buffer *buf, >> struct hfi_buffer_desc *bd, bool response) >> { >> @@ -1053,7 +1134,7 @@ void venus_helper_vb2_stop_streaming(struct >> vb2_queue *q) >> >> venus_helper_free_dpb_bufs(inst); >> >> - load_scale_clocks(core); >> + load_scale_clocks(inst); >> INIT_LIST_HEAD(&inst->registeredbufs); >> } >> >> @@ -1070,7 +1151,6 @@ void venus_helper_vb2_stop_streaming(struct >> vb2_queue *q) >> >> int venus_helper_vb2_start_streaming(struct venus_inst *inst) >> { >> - struct venus_core *core = inst->core; >> int ret; >> >> ret = intbufs_alloc(inst); >> @@ -1081,7 +1161,7 @@ int venus_helper_vb2_start_streaming(struct >> venus_inst *inst) >> if (ret) >> goto err_bufs_free; >> >> - load_scale_clocks(core); >> + load_scale_clocks(inst); >> >> ret = hfi_session_load_res(inst); >> if (ret) >>