From patchwork Tue Jul 16 05:09:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aniket Masule X-Patchwork-Id: 11045249 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D95F717E0 for ; Tue, 16 Jul 2019 05:09:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB9B128538 for ; Tue, 16 Jul 2019 05:09:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C025C28587; Tue, 16 Jul 2019 05:09:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 29EDA2856F for ; Tue, 16 Jul 2019 05:09:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729307AbfGPFJe (ORCPT ); Tue, 16 Jul 2019 01:09:34 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:58328 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726487AbfGPFJe (ORCPT ); Tue, 16 Jul 2019 01:09:34 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id B9C9A618DD; Tue, 16 Jul 2019 05:09:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1563253773; bh=w+/eBIzrpt3OyUu4hVcL4bF6SRMbjgzEylM6+Ge1s2E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KZjZ5zZNc+iMaklaVKwE+KDChwk7NiGTLT+0pVZYzag5Vvdvfa4vKgF7NiBdG6JXc qwmV2r91ooll8MPQR3aMh40yo3Ljz2wwwaQ2317jQNcxoiNtvBlrbe8ytIhfKHczI4 YoC4e5BAQy4yqauasy0STevgv8dQ2oH5MyMLm0vk= 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 CFD1361836; Tue, 16 Jul 2019 05:09:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1563253772; bh=w+/eBIzrpt3OyUu4hVcL4bF6SRMbjgzEylM6+Ge1s2E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BdzfZBFFyKk1GsYRfXoWSkTq2w0yl0PelNhNY7EFHQczx0VD0cSF7rIx5Q/hlu3S7 2dPW9b1h6TnJ4JcwiZAVeqWR1fL8xXC15VX/LDYCldqhJK3ay90/5R5CMJYSEtykmu Ji68nlKWaJlI/hoNTdLGLBf29JztoYWXG0zIh9fA= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org CFD1361836 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 v5 1/4] media: venus: Add codec data table Date: Tue, 16 Jul 2019 10:39:11 +0530 Message-Id: <1563253754-12003-2-git-send-email-amasule@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1563253754-12003-1-git-send-email-amasule@codeaurora.org> References: <1563253754-12003-1-git-send-email-amasule@codeaurora.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add vpp cycles for different types of codec. It indicates the cycles required by video hardware to process each macroblock. Add vsp cycles, cycles required by stream processor. Initialize the codec data with core resources. Signed-off-by: Aniket Masule --- drivers/media/platform/qcom/venus/core.c | 13 +++++++++++++ drivers/media/platform/qcom/venus/core.h | 16 +++++++++++++++ drivers/media/platform/qcom/venus/helpers.c | 30 +++++++++++++++++++++++++++++ drivers/media/platform/qcom/venus/helpers.h | 1 + drivers/media/platform/qcom/venus/vdec.c | 4 ++++ drivers/media/platform/qcom/venus/venc.c | 4 ++++ 6 files changed, 68 insertions(+) diff --git a/drivers/media/platform/qcom/venus/core.c b/drivers/media/platform/qcom/venus/core.c index 7393667..ad6bb74 100644 --- a/drivers/media/platform/qcom/venus/core.c +++ b/drivers/media/platform/qcom/venus/core.c @@ -473,9 +473,22 @@ static __maybe_unused int venus_runtime_resume(struct device *dev) { 244800, 100000000 }, /* 1920x1080@30 */ }; +static struct codec_freq_data sdm845_codec_freq_data[] = { + { 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 = { .freq_tbl = sdm845_freq_table, .freq_tbl_size = ARRAY_SIZE(sdm845_freq_table), + .codec_freq_data = sdm845_codec_freq_data, + .codec_freq_data_size = ARRAY_SIZE(sdm845_codec_freq_data), .clks = {"core", "iface", "bus" }, .clks_num = 3, .max_load = 2563200, diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h index 7a3feb5..b8aef19 100644 --- a/drivers/media/platform/qcom/venus/core.h +++ b/drivers/media/platform/qcom/venus/core.h @@ -35,12 +35,21 @@ struct reg_val { u32 value; }; +struct codec_freq_data { + u32 pixfmt; + u32 session_type; + unsigned long vpp_freq; + unsigned long vsp_freq; +}; + struct venus_resources { u64 dma_mask; const struct freq_tbl *freq_tbl; unsigned int freq_tbl_size; const struct reg_val *reg_tbl; unsigned int reg_tbl_size; + const struct codec_freq_data *codec_freq_data; + unsigned int codec_freq_data_size; const char * const clks[VIDC_CLKS_NUM_MAX]; unsigned int clks_num; enum hfi_version hfi_version; @@ -216,6 +225,12 @@ struct venus_buffer { struct list_head ref_list; }; +struct clock_data { + u32 core_id; + unsigned long freq; + const struct codec_freq_data *codec_freq_data; +}; + #define to_venus_buffer(ptr) container_of(ptr, struct venus_buffer, vb) /** @@ -275,6 +290,7 @@ struct venus_inst { struct list_head list; struct mutex lock; struct venus_core *core; + struct clock_data clk_data; struct list_head dpbbufs; struct list_head internalbufs; struct list_head registeredbufs; diff --git a/drivers/media/platform/qcom/venus/helpers.c b/drivers/media/platform/qcom/venus/helpers.c index 5cad601..7492373 100644 --- a/drivers/media/platform/qcom/venus/helpers.c +++ b/drivers/media/platform/qcom/venus/helpers.c @@ -715,6 +715,36 @@ int venus_helper_set_core_usage(struct venus_inst *inst, u32 usage) } EXPORT_SYMBOL_GPL(venus_helper_set_core_usage); +int venus_helper_init_codec_freq_data(struct venus_inst *inst) +{ + const struct codec_freq_data *data; + unsigned int i, data_size; + u32 pixfmt; + int ret = 0; + + if (!IS_V4(inst->core)) + return 0; + + data = inst->core->res->codec_freq_data; + data_size = inst->core->res->codec_freq_data_size; + pixfmt = inst->session_type == VIDC_SESSION_TYPE_DEC ? + inst->fmt_out->pixfmt : inst->fmt_cap->pixfmt; + + for (i = 0; i < data_size; i++) { + if (data[i].pixfmt == pixfmt && + data[i].session_type == inst->session_type) { + inst->clk_data.codec_freq_data = &data[i]; + break; + } + } + + if (!inst->clk_data.codec_freq_data) + ret = -EINVAL; + + return ret; +} +EXPORT_SYMBOL_GPL(venus_helper_init_codec_freq_data); + int venus_helper_set_num_bufs(struct venus_inst *inst, unsigned int input_bufs, unsigned int output_bufs, unsigned int output2_bufs) diff --git a/drivers/media/platform/qcom/venus/helpers.h b/drivers/media/platform/qcom/venus/helpers.h index 2475f284..2c13245 100644 --- a/drivers/media/platform/qcom/venus/helpers.h +++ b/drivers/media/platform/qcom/venus/helpers.h @@ -41,6 +41,7 @@ int venus_helper_set_output_resolution(struct venus_inst *inst, unsigned int width, unsigned int height, u32 buftype); int venus_helper_set_work_mode(struct venus_inst *inst, u32 mode); +int venus_helper_init_codec_freq_data(struct venus_inst *inst); int venus_helper_set_core_usage(struct venus_inst *inst, u32 usage); int venus_helper_set_num_bufs(struct venus_inst *inst, unsigned int input_bufs, unsigned int output_bufs, diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/venus/vdec.c index 282de21..d037f80 100644 --- a/drivers/media/platform/qcom/venus/vdec.c +++ b/drivers/media/platform/qcom/venus/vdec.c @@ -660,6 +660,10 @@ static int vdec_init_session(struct venus_inst *inst) if (ret) goto deinit; + ret = venus_helper_init_codec_freq_data(inst); + if (ret) + goto deinit; + return 0; deinit: hfi_session_deinit(inst); diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c index 32cff29..cdddc82 100644 --- a/drivers/media/platform/qcom/venus/venc.c +++ b/drivers/media/platform/qcom/venus/venc.c @@ -847,6 +847,10 @@ static int venc_init_session(struct venus_inst *inst) if (ret) goto deinit; + ret = venus_helper_init_codec_freq_data(inst); + if (ret) + goto deinit; + ret = venc_set_properties(inst); if (ret) goto deinit; From patchwork Tue Jul 16 05:09:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aniket Masule X-Patchwork-Id: 11045261 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BAD8717E0 for ; Tue, 16 Jul 2019 05:09:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC1FE28538 for ; Tue, 16 Jul 2019 05:09:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A08A328587; Tue, 16 Jul 2019 05:09:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D6162856F for ; Tue, 16 Jul 2019 05:09:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733110AbfGPFJj (ORCPT ); Tue, 16 Jul 2019 01:09:39 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:58402 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726487AbfGPFJi (ORCPT ); Tue, 16 Jul 2019 01:09:38 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 3847F61836; Tue, 16 Jul 2019 05:09:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1563253777; bh=UeDyAtIWpA7gei3U6JuRRJQg255isa7UX8RScXF9Kpw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mj+7DZz135Hz0iu2nWvPPIv9hlBPm+rzSvoLMPG1xZwMSgcwENDKLGnziZSaNh+5S arx3AMyrge264YHE67mhEcR4kVxybFivmC1guuGWzVovKjXTuWwUHwY2+7YAaXn6sE n/wKfICS5q7541Yq4v8/FSdG1iI7JC5tA9vxLH4Y= 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 CA279618CB; Tue, 16 Jul 2019 05:09:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1563253776; bh=UeDyAtIWpA7gei3U6JuRRJQg255isa7UX8RScXF9Kpw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YT+k64LKL9HgMzLUBtb73SGJC4iIA6343l+nRUZPiKyxNKF56oNWQh3f2VXe/BPRF s4OXHnGgAXvgEbuYLPW3+hJoxEteOoWu+/fNkmdCdkxk6r27W0+rWBlheewBi8Ws/N JhgFHmkx69O+XC/r3cbnns72LirMHSzHxGxmxQmE= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org CA279618CB 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 v5 2/4] media: venus: Update clock scaling Date: Tue, 16 Jul 2019 10:39:12 +0530 Message-Id: <1563253754-12003-3-git-send-email-amasule@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1563253754-12003-1-git-send-email-amasule@codeaurora.org> References: <1563253754-12003-1-git-send-email-amasule@codeaurora.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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) From patchwork Tue Jul 16 05:09:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aniket Masule X-Patchwork-Id: 11045253 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 27DE913B1 for ; Tue, 16 Jul 2019 05:09:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1869C28538 for ; Tue, 16 Jul 2019 05:09:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C41C28587; Tue, 16 Jul 2019 05:09:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 99BEA2856F for ; Tue, 16 Jul 2019 05:09:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733192AbfGPFJm (ORCPT ); Tue, 16 Jul 2019 01:09:42 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:58526 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726487AbfGPFJm (ORCPT ); Tue, 16 Jul 2019 01:09:42 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id DDF1E618EF; Tue, 16 Jul 2019 05:09:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1563253780; bh=pPd3WTwY7870EasNoe5YLiqpf057/4E2YiY+ke5Oj8A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZiSMhxwt1EX16Rp4WmsYJr5mtyyz1HmXyP3uRuvIn70JLdvCDm5vL4oCJDtXRwgz4 wZk2SkD2MiaJjO1pqJqkvQQWNZ02RjxvsoQ5jwTrxR/onc572LJpnnbU3s3s8tJJrc SQjjjc18SaZK9nn3h0bi4nhbEwMV17H5nATeHRwU= 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 8D048618DA; Tue, 16 Jul 2019 05:09:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1563253780; bh=pPd3WTwY7870EasNoe5YLiqpf057/4E2YiY+ke5Oj8A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZiSMhxwt1EX16Rp4WmsYJr5mtyyz1HmXyP3uRuvIn70JLdvCDm5vL4oCJDtXRwgz4 wZk2SkD2MiaJjO1pqJqkvQQWNZ02RjxvsoQ5jwTrxR/onc572LJpnnbU3s3s8tJJrc SQjjjc18SaZK9nn3h0bi4nhbEwMV17H5nATeHRwU= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 8D048618DA 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 v5 3/4] media: venus: Update to bitrate based clock scaling Date: Tue, 16 Jul 2019 10:39:13 +0530 Message-Id: <1563253754-12003-4-git-send-email-amasule@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1563253754-12003-1-git-send-email-amasule@codeaurora.org> References: <1563253754-12003-1-git-send-email-amasule@codeaurora.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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); + 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); From patchwork Tue Jul 16 05:09:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aniket Masule X-Patchwork-Id: 11045257 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 14AC813B1 for ; Tue, 16 Jul 2019 05:09:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0599728538 for ; Tue, 16 Jul 2019 05:09:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE5B328587; Tue, 16 Jul 2019 05:09:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68EE62856F for ; Tue, 16 Jul 2019 05:09:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733236AbfGPFJq (ORCPT ); Tue, 16 Jul 2019 01:09:46 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:58636 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726487AbfGPFJp (ORCPT ); Tue, 16 Jul 2019 01:09:45 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id D306A618E1; Tue, 16 Jul 2019 05:09:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1563253784; bh=vCDfLBQi0vOEE29uCHWzBtitQ7FOpbXrCftD/mU+WEY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gzfof5Pi4FdmI4VHWsn9WOZU6tmkNq9FJuRbs3NqaepTdVOl90LAAoGzDkQKVPVpS lBCHWO+NAN36hZa5dgvgrnPBfhYCyfQKekHK93VTA6TiuwM2Lz27kDVFCAdRT6Burx V3Uejek6bITyoUSUFVsQI2ssAd9BvpqtmTR6TB1U= 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 58306618DA; Tue, 16 Jul 2019 05:09:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1563253784; bh=vCDfLBQi0vOEE29uCHWzBtitQ7FOpbXrCftD/mU+WEY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gzfof5Pi4FdmI4VHWsn9WOZU6tmkNq9FJuRbs3NqaepTdVOl90LAAoGzDkQKVPVpS lBCHWO+NAN36hZa5dgvgrnPBfhYCyfQKekHK93VTA6TiuwM2Lz27kDVFCAdRT6Burx V3Uejek6bITyoUSUFVsQI2ssAd9BvpqtmTR6TB1U= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 58306618DA 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 v5 4/4] media: venus: Update core selection Date: Tue, 16 Jul 2019 10:39:14 +0530 Message-Id: <1563253754-12003-5-git-send-email-amasule@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1563253754-12003-1-git-send-email-amasule@codeaurora.org> References: <1563253754-12003-1-git-send-email-amasule@codeaurora.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Present core assignment is static. Introduced load balancing across the cores. Load on earch core is calculated and core with minimum load is assigned to given instance. Signed-off-by: Aniket Masule --- drivers/media/platform/qcom/venus/helpers.c | 69 +++++++++++++++++++++++--- drivers/media/platform/qcom/venus/helpers.h | 2 +- drivers/media/platform/qcom/venus/hfi_helper.h | 1 + drivers/media/platform/qcom/venus/hfi_parser.h | 5 ++ drivers/media/platform/qcom/venus/vdec.c | 2 +- drivers/media/platform/qcom/venus/venc.c | 2 +- 6 files changed, 72 insertions(+), 9 deletions(-) diff --git a/drivers/media/platform/qcom/venus/helpers.c b/drivers/media/platform/qcom/venus/helpers.c index edf403d..d479793 100644 --- a/drivers/media/platform/qcom/venus/helpers.c +++ b/drivers/media/platform/qcom/venus/helpers.c @@ -26,6 +26,7 @@ #include "helpers.h" #include "hfi_helper.h" #include "hfi_venus_io.h" +#include "hfi_parser.h" struct intbuf { struct list_head list; @@ -331,6 +332,24 @@ static u32 load_per_instance(struct venus_inst *inst) return mbs * inst->fps; } +static u32 load_per_core(struct venus_core *core, u32 core_id) +{ + struct venus_inst *inst = NULL; + u32 mbs_per_sec = 0, load = 0; + + mutex_lock(&core->lock); + list_for_each_entry(inst, &core->instances, list) { + if (inst->clk_data.core_id != core_id) + continue; + + mbs_per_sec = load_per_instance(inst); + load = mbs_per_sec * inst->clk_data.codec_freq_data->vpp_freq; + } + mutex_unlock(&core->lock); + + return load; +} + static u32 load_per_type(struct venus_core *core, u32 session_type) { struct venus_inst *inst = NULL; @@ -505,6 +524,16 @@ static int load_scale_clocks(struct venus_inst *inst) return scale_clocks(inst); } +int set_core_usage(struct venus_inst *inst, u32 usage) +{ + const u32 ptype = HFI_PROPERTY_CONFIG_VIDEOCORES_USAGE; + struct hfi_videocores_usage_type cu; + + cu.video_core_enable_mask = usage; + + return hfi_session_set_property(inst, ptype, &cu); +} + static void fill_buffer_desc(const struct venus_buffer *buf, struct hfi_buffer_desc *bd, bool response) { @@ -808,19 +837,47 @@ int venus_helper_set_work_mode(struct venus_inst *inst, u32 mode) } EXPORT_SYMBOL_GPL(venus_helper_set_work_mode); -int venus_helper_set_core_usage(struct venus_inst *inst, u32 usage) +int venus_helper_set_core(struct venus_inst *inst) { - const u32 ptype = HFI_PROPERTY_CONFIG_VIDEOCORES_USAGE; - struct hfi_videocores_usage_type cu; + struct venus_core *core = inst->core; + u32 min_core_id = 0, core1_load = 0, core2_load = 0; + unsigned long min_load, max_freq, cur_inst_load; + u32 cores_max; + int ret; if (!IS_V4(inst->core)) return 0; - cu.video_core_enable_mask = usage; + core1_load = load_per_core(core, VIDC_CORE_ID_1); + core2_load = load_per_core(core, VIDC_CORE_ID_2); + min_core_id = core1_load < core2_load ? VIDC_CORE_ID_1 : VIDC_CORE_ID_2; + min_load = min(core1_load, core2_load); + cores_max = core_num_max(inst); - return hfi_session_set_property(inst, ptype, &cu); + if (cores_max < VIDC_CORE_ID_2) { + min_core_id = VIDC_CORE_ID_1; + min_load = core1_load; + } + + cur_inst_load = load_per_instance(inst) * + inst->clk_data.codec_freq_data->vpp_freq; + max_freq = core->res->freq_tbl[0].freq; + + if ((cur_inst_load + min_load) > max_freq) { + dev_warn(core->dev, "HW is overloaded, needed: %lu max: %lu\n", + cur_inst_load, max_freq); + return -EINVAL; + } + + ret = set_core_usage(inst, min_core_id); + if (ret) + return ret; + + inst->clk_data.core_id = min_core_id; + + return 0; } -EXPORT_SYMBOL_GPL(venus_helper_set_core_usage); +EXPORT_SYMBOL_GPL(venus_helper_set_core); int venus_helper_init_codec_freq_data(struct venus_inst *inst) { diff --git a/drivers/media/platform/qcom/venus/helpers.h b/drivers/media/platform/qcom/venus/helpers.h index 2c13245..1034111 100644 --- a/drivers/media/platform/qcom/venus/helpers.h +++ b/drivers/media/platform/qcom/venus/helpers.h @@ -42,7 +42,7 @@ int venus_helper_set_output_resolution(struct venus_inst *inst, u32 buftype); int venus_helper_set_work_mode(struct venus_inst *inst, u32 mode); int venus_helper_init_codec_freq_data(struct venus_inst *inst); -int venus_helper_set_core_usage(struct venus_inst *inst, u32 usage); +int venus_helper_set_core(struct venus_inst *inst); int venus_helper_set_num_bufs(struct venus_inst *inst, unsigned int input_bufs, unsigned int output_bufs, unsigned int output2_bufs); diff --git a/drivers/media/platform/qcom/venus/hfi_helper.h b/drivers/media/platform/qcom/venus/hfi_helper.h index 34ea503..f3d1018 100644 --- a/drivers/media/platform/qcom/venus/hfi_helper.h +++ b/drivers/media/platform/qcom/venus/hfi_helper.h @@ -559,6 +559,7 @@ struct hfi_bitrate { #define HFI_CAPABILITY_LCU_SIZE 0x14 #define HFI_CAPABILITY_HIER_P_HYBRID_NUM_ENH_LAYERS 0x15 #define HFI_CAPABILITY_MBS_PER_SECOND_POWERSAVE 0x16 +#define HFI_CAPABILITY_MAX_VIDEOCORES 0x2B struct hfi_capability { u32 capability_type; diff --git a/drivers/media/platform/qcom/venus/hfi_parser.h b/drivers/media/platform/qcom/venus/hfi_parser.h index 3e931c7..264e6dd 100644 --- a/drivers/media/platform/qcom/venus/hfi_parser.h +++ b/drivers/media/platform/qcom/venus/hfi_parser.h @@ -107,4 +107,9 @@ static inline u32 frate_step(struct venus_inst *inst) return cap_step(inst, HFI_CAPABILITY_FRAMERATE); } +static inline u32 core_num_max(struct venus_inst *inst) +{ + return cap_max(inst, HFI_CAPABILITY_MAX_VIDEOCORES); +} + #endif diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/venus/vdec.c index d037f80..620e060 100644 --- a/drivers/media/platform/qcom/venus/vdec.c +++ b/drivers/media/platform/qcom/venus/vdec.c @@ -551,7 +551,7 @@ static int vdec_output_conf(struct venus_inst *inst) if (ret) return ret; - ret = venus_helper_set_core_usage(inst, VIDC_CORE_ID_1); + ret = venus_helper_set_core(inst); if (ret) return ret; diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c index cdddc82..28e76cc 100644 --- a/drivers/media/platform/qcom/venus/venc.c +++ b/drivers/media/platform/qcom/venus/venc.c @@ -660,7 +660,7 @@ static int venc_set_properties(struct venus_inst *inst) if (ret) return ret; - ret = venus_helper_set_core_usage(inst, VIDC_CORE_ID_2); + ret = venus_helper_set_core(inst); if (ret) return ret;