Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6917083ybi; Mon, 22 Jul 2019 04:00:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqx1ERKlCA/SswJ1mn9CRSQS78h+2opHBAGf0E/83kfSI2bsVwzmNXMFueJGWTaqgOpX9mPB X-Received: by 2002:a63:8dc9:: with SMTP id z192mr16919649pgd.151.1563793215206; Mon, 22 Jul 2019 04:00:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563793215; cv=none; d=google.com; s=arc-20160816; b=ilv4mS6Dg4T5g6q5Aja8xlyfosKGNQ6HIgOmbH+iTf4g7z5lP5BbJgYA2tEybFcuQM nSgzw/XJRNjo4K7v4ap/1hJWOzY+s0sxCpVcOGUnQlx248jssE5uOO1vM6KcG9CG2zT6 pCoiEu533oaHSg6p9q5RUx8hkf3dJH3W4RBv1FsczK3Imp4Ky7kM/H8JLkFM4ss4nVqY RlyObhEKE2Hs7MgKWT3rLMH2EkpfHI/KXxyQo/kus7aIc7+w24NbrWUcwX2SgdGYwqEZ dcfjfRkgLcP/Vl5gzXhAaV+YHIvausAP/v4+zk+7P1rRcN7YhJQ31mLs+0RPvNditozh etGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature:dkim-signature; bh=Io5QcvLB1mi1uBUADtWqU+RNJ/u1U6U2e5NgqJXf118=; b=RDTPUFp4ueI9La8OkIBVI3ew+7sR8c8CSWkQWhhvrH5B3zUnUaIYQm0s+/eWG/VPbH OfOQnTjtX7nFYZQX8UXsvluhTn2ARyPNgDgvtUvGsHnDpmBTq/cHaY4wWolRDYBXjHf1 0SCAFIw0pgYL14492cFYez4XyOaQ6kuMHwnwi+ZB7t5k/6gFimuKAc1ZNBPDXE1GMryM 7lxjU5OXN2L27Tusc/x3cln6KMbETAodyUNu3J0dtAbKMbAjs4cUkSHuSwykIao37EWm q3NvZlHMr5U3vILVyhK0GW2IFz4Pf6iynnuBL0vfNjRDpimx8xw/73ZoehG2T9P2wPo+ gIHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=knipq++s; dkim=pass header.i=@codeaurora.org header.s=default header.b=JYi7SBQM; 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 h3si11649805pld.32.2019.07.22.03.59.58; Mon, 22 Jul 2019 04:00:15 -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=knipq++s; dkim=pass header.i=@codeaurora.org header.s=default header.b=JYi7SBQM; 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 S1728739AbfGVJHz (ORCPT + 99 others); Mon, 22 Jul 2019 05:07:55 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:39664 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728722AbfGVJHy (ORCPT ); Mon, 22 Jul 2019 05:07:54 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 8A9DE6179C; Mon, 22 Jul 2019 09:07:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1563786473; bh=UeDyAtIWpA7gei3U6JuRRJQg255isa7UX8RScXF9Kpw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=knipq++ssmpp4LKg/tcKSCR0AKpR6wehnCmvyCnD+BPUWvzsaGzRpNOeHtgOtb5W1 eD8FPHWkfpuL3NB2azx/zZ9p96lZYE8OqTnwqlxJ+Og1f93Z5PUrfaUicO3C+KkeX3 Fd4EfASTmyEYoOW0Q7UHwRelnpKTThgK0MjQwvng= 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,SPF_NONE autolearn=no autolearn_force=no version=3.4.0 Received: from amasule-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: amasule@codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 904BA6119F; Mon, 22 Jul 2019 09:07:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1563786472; bh=UeDyAtIWpA7gei3U6JuRRJQg255isa7UX8RScXF9Kpw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JYi7SBQM8wkDBvY/+evuQojlTJ/36TKPr4+9MJt1OgaOWeRS9tsk1Ygth66vjw/xS VXaqQ0I+4P0Ilq3o4ES7Nq6DcT9hn/TguhI+nqhqqHbzu3ng93DntdaHfUpR5a7nFX NbzzmH/GyzBPkW6eladUMtNkJ2IfH+1N8ZIQoXcI= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 904BA6119F Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=amasule@codeaurora.org From: Aniket Masule To: linux-media@vger.kernel.org, stanimir.varbanov@linaro.org Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, vgarodia@codeaurora.org, Aniket Masule Subject: [PATCH v6 2/4] media: venus: Update clock scaling Date: Mon, 22 Jul 2019 14:37:30 +0530 Message-Id: <1563786452-22188-2-git-send-email-amasule@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1563786452-22188-1-git-send-email-amasule@codeaurora.org> References: <1563786452-22188-1-git-send-email-amasule@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 91 +++++++++++++++++++++++++++-- 1 file changed, 87 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/qcom/venus/helpers.c b/drivers/media/platform/qcom/venus/helpers.c index 7492373..2c976e4 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,89 @@ static int load_scale_clocks(struct venus_core *core) return ret; } +static unsigned long calculate_vpp_freq(struct venus_inst *inst) +{ + unsigned long vpp_freq = 0; + 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; + + return vpp_freq; +} + +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 clk *clk = core->clks[0]; + struct device *dev = core->dev; + unsigned int i; + unsigned long freq = 0, freq_core1 = 0, freq_core2 = 0; + int ret; + + freq = calculate_vpp_freq(inst); + + if (freq > table[0].freq) + dev_warn(dev, "HW is overloaded, needed: %lu max: %lu\n", + freq, table[0].freq); + + 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_core1 += inst->clk_data.freq; + } else if (inst->clk_data.core_id == VIDC_CORE_ID_2) { + freq_core2 += inst->clk_data.freq; + } else if (inst->clk_data.core_id == VIDC_CORE_ID_3) { + freq_core1 += inst->clk_data.freq; + freq_core2 += inst->clk_data.freq; + } + } + mutex_unlock(&core->lock); + + freq = max(freq_core1, freq_core2); + + ret = clk_set_rate(clk, freq); + if (ret) + goto err; + + ret = clk_set_rate(core->core0_clk, freq); + if (ret) + goto err; + + ret = clk_set_rate(core->core1_clk, freq); + 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_V4(inst->core)) + return scale_clocks_v4(inst); + + if (inst->state == INST_START) + return 0; + + return scale_clocks(inst); +} + static void fill_buffer_desc(const struct venus_buffer *buf, struct hfi_buffer_desc *bd, bool response) { @@ -1053,7 +1137,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 +1154,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 +1164,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) -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project