Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2279746ybi; Mon, 17 Jun 2019 01:59:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqzGDza9xAUHYdNInAnLrR1l/9xGg3JWSgCZsFcOSHl2HI2oweTsoXuju3Nvj2e/mX6dp3Ei X-Received: by 2002:a62:6:: with SMTP id 6mr48330340pfa.159.1560761947636; Mon, 17 Jun 2019 01:59:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560761947; cv=none; d=google.com; s=arc-20160816; b=aerSyRTlbKEv2bVupnRBj0usgmDwdYaO/30wsAHrvczbD+TgDfd/Y12q/NO1piFyns UQPvxbvzEmoaZcpK3VRvCtI7M3QWli5EhPsNlX31Wduw361GFpd2mjOsrth0/RYZLR6o FJan2TnqJKYPWmvP0uEb/c+weCl+uVNJuev9heKySEZw0LHsOSKp36205WGNGJVFwQ4U ibx7wX2SMrgSgZpDqG6AdJlZaN0+ocFT3UUZW5j6rKGMGZVGq6QJ3FiF2vmHZOfk+1LH 5UIeEcL/MJ/9JeuCLHFn7lC+yleOMYkDfZX5bQJ1Axz+91L3hwrY9HevVvlJHhDGYgNY pIkQ== 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=/kfB3EQM4cTIQNVbeoHSHizf5Tj4LK22gsgty3+LXc4=; b=DJXzCEt8rnHY2gUEgcAAMYrWpj5lH1NiforY6qga7g6K4mHlNmf5AbzWKprA/t5ULc M6MRNtdrlKv/gmJ1oO4gN1xEd+t1ye4v5v7c7A45Cm3CbL4lrWcY6n9IRbc+U4Lz+TFp VjDFmu8IBqStUQe+FB5JjSdON7xJyBo9MNTawba2WjzAkUL9w8fvNX4XE4R7A839JR+0 92ZCOUGHgzH4Ygvg0ymz07EtdudnZ4OI6OAmJmMBeVkrZ6S03rE51QugQzPGBdt1kMmN bV9thXatOXVD4Q2u2fnCoDa2g2TujCmsLnRtoGdger0ioNrj993qWggI9rPcgYf9wetj XZzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pP2hnCpm; 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 q24si5620155pff.62.2019.06.17.01.58.52; Mon, 17 Jun 2019 01:59:07 -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=pP2hnCpm; 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 S1726674AbfFQI6X (ORCPT + 99 others); Mon, 17 Jun 2019 04:58:23 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:44233 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726292AbfFQI6W (ORCPT ); Mon, 17 Jun 2019 04:58:22 -0400 Received: by mail-lf1-f65.google.com with SMTP id r15so5891951lfm.11 for ; Mon, 17 Jun 2019 01:58:20 -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=/kfB3EQM4cTIQNVbeoHSHizf5Tj4LK22gsgty3+LXc4=; b=pP2hnCpmuzmpUuxLP4KXKlNOeVTx1TBwhIPclOpxEGCjl9Sn4/ckg1hPVnKleZ2xox F3w4hqV+atBA6b7c0syRJzgWA2wAf+jrfHPro3azRbvZPT9i0onlmBkMqkMfXZH6Ul4A gX61NkB3VHxK2rBK7ZAq/0M8bPEUknYdnwZbtnFbQfJ16mVsk+QTEJ0VZBEoZMU+WGH0 SXzzbfIA2vwxdZQyGMiKFGGwDl+1Q281FEQx8ppVf84X3tDfPYjGw5jYMKmKkmbBW/AL 4he0CbiRp8s+Vk3F6A5nQ4FeqPJ1SJvhMQPM7BU+BLVpTQv17D4ovGeyMVln5ZzmuZX6 zTSg== 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=/kfB3EQM4cTIQNVbeoHSHizf5Tj4LK22gsgty3+LXc4=; b=n413liKxdgSpd+pZ+kuJXWglKDgwMxfaPLN0qUzvQT9EEOCfXngbOBghTNxyAGO1Ql De/Kyo8YSd7SefdfBPbYAgYNItOmUn+FcK/92eK09ldVwepSTo8wdIGZZyK8VTHdm8tE NcFqxBt4qZPLgfVyGfdzOPVaoDiLzJT/n3UOebaIOLr0nrNe1+HZzPBxMlPRxayvLWJZ JFJng4heFDsE6aZ8viZqm35mjT7FnBLUei0+UkVMAdXNC53Xu1MZT/PmCN14nHNi7/5z LRMFEdZlC0YiKV+UFkmQSXu2WbOK/bmkN7isCzYwYLRC4/jmn/7UHIttWAo3HexEtD+V o3Sw== X-Gm-Message-State: APjAAAXkNEjB12aLNJ1JPPJzKNCzWRCJ8jNBQ82FKwFaWIRsLn2PBcvA CpVzzSdM5N2yURsWJP6wyFL5Sw== X-Received: by 2002:ac2:52ac:: with SMTP id r12mr34554695lfm.126.1560761899947; Mon, 17 Jun 2019 01:58:19 -0700 (PDT) Received: from [192.168.27.209] ([37.157.136.206]) by smtp.googlemail.com with ESMTPSA id y2sm1667139lfc.35.2019.06.17.01.58.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Jun 2019 01:58:18 -0700 (PDT) Subject: Re: [PATCH 3/5] media: venus: Update clock scaling To: Aniket Masule , linux-media@vger.kernel.org, stanimir.varbanov@linaro.org Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, vgarodia@codeaurora.org References: <1560233130-27264-1-git-send-email-amasule@codeaurora.org> <1560233130-27264-4-git-send-email-amasule@codeaurora.org> From: Stanimir Varbanov Message-ID: Date: Mon, 17 Jun 2019 11:58:17 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <1560233130-27264-4-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/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? > + > + 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? > +} > + > +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. > +{ > + 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? > + > + ret = clk_set_rate(clk, freq); > + if (ret) > + goto err; > + > + ret = clk_set_rate(core->core0_clk, freq); IMO this should set freq_core0 > + if (ret) > + goto err; > + > + ret = clk_set_rate(core->core1_clk, freq); set freq_core1 > + 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); > +} > + > 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) > -- regards, Stan