From patchwork Thu May 30 13:58:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aniket Masule X-Patchwork-Id: 10968785 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 4BBC11398 for ; Thu, 30 May 2019 13:58:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E52A285C9 for ; Thu, 30 May 2019 13:58:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 326E1289F4; Thu, 30 May 2019 13:58:59 +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=ham 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 AB229285C9 for ; Thu, 30 May 2019 13:58:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726843AbfE3N66 (ORCPT ); Thu, 30 May 2019 09:58:58 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:46398 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726232AbfE3N66 (ORCPT ); Thu, 30 May 2019 09:58:58 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id CEBFC60A4E; Thu, 30 May 2019 13:58:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1559224736; bh=hGP7IswY6Ww3EU3THIoL2zY9SdpXplW17KpRi5mpIJk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fJ5GwcBu04mQtFTQ3ddhTQww2jDRf2ASzmNdCjXVPoZlQeesLRhfK72Nb0j8055q0 GMa8Joj5mAjCFRmtaIYXTTW/1nwdpW/PEB8bJD3OD4I42i1zmPhpUzqxd/fXhfhywx cFM4HIRH9wfToX0I8Gg5u7PU1Y9j9gpJdbAB/mqY= 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 0AD7060588; Thu, 30 May 2019 13:58:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1559224736; bh=hGP7IswY6Ww3EU3THIoL2zY9SdpXplW17KpRi5mpIJk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fJ5GwcBu04mQtFTQ3ddhTQww2jDRf2ASzmNdCjXVPoZlQeesLRhfK72Nb0j8055q0 GMa8Joj5mAjCFRmtaIYXTTW/1nwdpW/PEB8bJD3OD4I42i1zmPhpUzqxd/fXhfhywx cFM4HIRH9wfToX0I8Gg5u7PU1Y9j9gpJdbAB/mqY= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 0AD7060588 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 1/5] media: venus: Add codec data table Date: Thu, 30 May 2019 19:28:24 +0530 Message-Id: <1559224708-6039-2-git-send-email-amasule@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1559224708-6039-1-git-send-email-amasule@codeaurora.org> References: <1559224708-6039-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 for different types of codec It indicates the cycles required by video hardware to process each macroblock. Signed-off-by: Aniket Masule --- drivers/media/platform/qcom/venus/core.c | 13 +++++++++++++ drivers/media/platform/qcom/venus/core.h | 15 +++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/drivers/media/platform/qcom/venus/core.c b/drivers/media/platform/qcom/venus/core.c index 7393667..e7ebea1 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_data sdm845_codec_data[] = { + { V4L2_PIX_FMT_H264, VIDC_SESSION_TYPE_ENC, 125 }, + { V4L2_PIX_FMT_HEVC, VIDC_SESSION_TYPE_ENC, 125 }, + { V4L2_PIX_FMT_VP8, VIDC_SESSION_TYPE_ENC, 125 }, + { V4L2_PIX_FMT_MPEG2, VIDC_SESSION_TYPE_DEC, 50 }, + { V4L2_PIX_FMT_H264, VIDC_SESSION_TYPE_DEC, 50 }, + { V4L2_PIX_FMT_HEVC, VIDC_SESSION_TYPE_DEC, 50 }, + { V4L2_PIX_FMT_VP8, VIDC_SESSION_TYPE_DEC, 50 }, + { V4L2_PIX_FMT_VP9, VIDC_SESSION_TYPE_DEC, 50 }, +}; + static const struct venus_resources sdm845_res = { .freq_tbl = sdm845_freq_table, .freq_tbl_size = ARRAY_SIZE(sdm845_freq_table), + .codec_data = sdm845_codec_data, + .codec_data_size = ARRAY_SIZE(sdm845_codec_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..b1a9b43 100644 --- a/drivers/media/platform/qcom/venus/core.h +++ b/drivers/media/platform/qcom/venus/core.h @@ -35,12 +35,20 @@ struct reg_val { u32 value; }; +struct codec_data { +u32 pixfmt; +u32 session_type; +int vpp_cycles; +}; + 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_data *codec_data; + unsigned int codec_data_size; const char * const clks[VIDC_CLKS_NUM_MAX]; unsigned int clks_num; enum hfi_version hfi_version; @@ -216,6 +224,12 @@ struct venus_buffer { struct list_head ref_list; }; +struct clock_data { + u32 core_id; + unsigned long freq; + struct codec_data *codec_data; +}; + #define to_venus_buffer(ptr) container_of(ptr, struct venus_buffer, vb) /** @@ -275,6 +289,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; From patchwork Thu May 30 13:58:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aniket Masule X-Patchwork-Id: 10968791 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 27A0F1398 for ; Thu, 30 May 2019 13:59:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B5C328382 for ; Thu, 30 May 2019 13:59:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0FC95289A5; Thu, 30 May 2019 13:59:09 +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 678F028923 for ; Thu, 30 May 2019 13:59:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726988AbfE3N7E (ORCPT ); Thu, 30 May 2019 09:59:04 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:46496 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726232AbfE3N7E (ORCPT ); Thu, 30 May 2019 09:59:04 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 865CF60DAA; Thu, 30 May 2019 13:59:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1559224742; bh=s9op8rSOVHaZd3OBUe426rJmaSfw6DuRrLGlKD9kKGM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KpkwNMZ0xk4UCYnBmRgA6MvFHGBNYwJ/0qLa/kRoLr9dqU3DoIJ/KO/sT8GRnExhM vLq8UfDM5tsK1oFVKDNbkUSZ34amb0WjA3F+65KtSko+NNhlgHbls4MkAutXz6m7ep ruwO0CmGmpc2rD8wPHjiBsiOAVxv/NI0TiJR8dHg= 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 9F7726049C; Thu, 30 May 2019 13:58:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1559224741; bh=s9op8rSOVHaZd3OBUe426rJmaSfw6DuRrLGlKD9kKGM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RAEn5bY96eqqflEDZB+dcMquLGVFpTabXEz/Of0pLACvR9y/EZ+Zb3aS6lLTNSVY3 nM06xacb2izJGaGE2Bu9QXZZAen4mfXxtq2x/2e6OdcHIU0/Rw1cQJhfkGmL7vZDM8 6np+k4Z87iA+B69rFHZhEyC+SQ/BfGsRfqSLZgPQ= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 9F7726049C 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 2/5] media: venus: Initialize codec data Date: Thu, 30 May 2019 19:28:25 +0530 Message-Id: <1559224708-6039-3-git-send-email-amasule@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1559224708-6039-1-git-send-email-amasule@codeaurora.org> References: <1559224708-6039-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 Initialize the codec data with core resources. Signed-off-by: Aniket Masule --- 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 ++++ 4 files changed, 39 insertions(+) diff --git a/drivers/media/platform/qcom/venus/helpers.c b/drivers/media/platform/qcom/venus/helpers.c index 5cad601..f7f724b 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_data(struct venus_inst *inst) +{ + const struct codec_data *codec_data; + unsigned int i, codec_data_size; + u32 pixfmt; + int ret = 0; + + if (!IS_V4(inst->core)) + return 0; + + codec_data = inst->core->res->codec_data; + codec_data_size = inst->core->res->codec_data_size; + pixfmt = inst->session_type == VIDC_SESSION_TYPE_DEC ? + inst->fmt_out->pixfmt : inst->fmt_cap->pixfmt; + + for (i = 0; i < codec_data_size; i++) { + if (codec_data[i].pixfmt == pixfmt && + codec_data[i].session_type == inst->session_type) { + inst->clk_data.codec_data = &codec_data[i]; + break; + } + } + + if (!inst->clk_data.codec_data) + ret = -EINVAL; + + return ret; +} +EXPORT_SYMBOL_GPL(venus_helper_init_codec_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..f9360a8 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_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..51795fd 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_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..792cdce 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_data(inst); + if (ret) + goto deinit; + ret = venc_set_properties(inst); if (ret) goto deinit; From patchwork Thu May 30 13:58:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aniket Masule X-Patchwork-Id: 10968795 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 BEC861398 for ; Thu, 30 May 2019 13:59:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B1723285C9 for ; Thu, 30 May 2019 13:59:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A576A288F3; Thu, 30 May 2019 13:59:13 +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 257AB28995 for ; Thu, 30 May 2019 13:59:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726670AbfE3N7I (ORCPT ); Thu, 30 May 2019 09:59:08 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:46546 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726232AbfE3N7I (ORCPT ); Thu, 30 May 2019 09:59:08 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 6DC3A6087B; Thu, 30 May 2019 13:59:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1559224746; bh=kW/yCGwNEKbklqD5qFu0UiMJZe2xtWTKbyDGLSimCdg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zv+CAlCTnd51SXy0NqOXePRSFjphCZjaC4xn8RvymAFRPqzzHUbMzdOQlust93P0M jyprsQiY0O9Wcaq0anWsECjS2DhlP+Fu/3XVnjNyafwqj34GrfHF1fz3gEomdwyZLw QKRgTodk/iIB6GCoactioNJ9ZSTwsx0Vz4vUU3n4= 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 AE16760A33; Thu, 30 May 2019 13:59:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1559224745; bh=kW/yCGwNEKbklqD5qFu0UiMJZe2xtWTKbyDGLSimCdg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PQ8TEPgAOg/ATzjV5nSQ2gslzmbPafyAaJ7qCTWgWMhObwt4IbT7WbYloaWCaDKOZ w+fPIaYREfdio4+K75ggMuicB0wAXwIEKoirL6Qvjm4dQTcPzpfUcRkommaJS2P4RC eTNvO7XLWUPKf2yk6T/CrWVhlsHG6FMP3HC1cO+I= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org AE16760A33 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 3/5] media: venus: Update clock scaling Date: Thu, 30 May 2019 19:28:26 +0530 Message-Id: <1559224708-6039-4-git-send-email-amasule@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1559224708-6039-1-git-send-email-amasule@codeaurora.org> References: <1559224708-6039-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 f7f724b..f2470af 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_inst_freq(struct venus_inst *inst, + u32 filled_len) +{ + 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; + + return vpp_cycles; +} + +static int scale_clocks_vpu4(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; + u32 filled_len = 0; + unsigned long freq = 0, freq_core0 = 0, freq_core1 = 0; + int ret; + + freq = calculate_inst_freq(inst, filled_len); + + 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); + + 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_V3(inst->core) || IS_V1(inst->core)) + return scale_clocks(inst); + else + return scale_clocks_vpu4(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 Thu May 30 13:58:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aniket Masule X-Patchwork-Id: 10968797 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 029FF1398 for ; Thu, 30 May 2019 13:59:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E905128A00 for ; Thu, 30 May 2019 13:59:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD026289A5; Thu, 30 May 2019 13:59:17 +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=ham 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 7C071286D5 for ; Thu, 30 May 2019 13:59:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726973AbfE3N7R (ORCPT ); Thu, 30 May 2019 09:59:17 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:46720 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726232AbfE3N7Q (ORCPT ); Thu, 30 May 2019 09:59:16 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 49D97609EF; Thu, 30 May 2019 13:59:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1559224755; bh=Gw03O+/PtVO6JQStq1Nny3J68DvX5BsW7lmhCePed3U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OG+gfv4Ni2bzOX1nNoYSy4B6FSPbFPI5Wyq+JBNQu3sGwzbLSL1r7MQpDa9EVKOzX 98j1lDSNhY2Lm5O7vj3heoa5o6FAjY1lBP1G2bvbjNnEnasG3ImwlFLQwebed0vHqd V8Lq8zkx2fdKue0mX/JPvZynEWXMBzLUscZ9bAJY= 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 DC96460E5D; Thu, 30 May 2019 13:59:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1559224754; bh=Gw03O+/PtVO6JQStq1Nny3J68DvX5BsW7lmhCePed3U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EXH6js2pxZoeAE+q/qRjza3UdVT++DP1m2BMWeHoZwju/eVwUInpwt8DVTZQDYuLI Drw1Nw0iJ2oSYfeyL4bJb0anZxhu5p9hMWiXapAcSdjKHJM77Op9mLck/hwlqGZ/oi wrCVG/5VMoo596Or3Pv9r3FpWxVm59bJkWkTWHk8= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org DC96460E5D 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 4/5] media: venus: Add interface for load per core Date: Thu, 30 May 2019 19:28:27 +0530 Message-Id: <1559224708-6039-5-git-send-email-amasule@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1559224708-6039-1-git-send-email-amasule@codeaurora.org> References: <1559224708-6039-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 and interface to calculate load per core. Also, add an interface to get maximum cores available with video. This interface is preparation for updating core selection. Signed-off-by: Aniket Masule --- drivers/media/platform/qcom/venus/helpers.c | 18 ++++++++++++++++++ drivers/media/platform/qcom/venus/hfi_helper.h | 1 + drivers/media/platform/qcom/venus/hfi_parser.h | 5 +++++ 3 files changed, 24 insertions(+) diff --git a/drivers/media/platform/qcom/venus/helpers.c b/drivers/media/platform/qcom/venus/helpers.c index f2470af..692ba3b 100644 --- a/drivers/media/platform/qcom/venus/helpers.c +++ b/drivers/media/platform/qcom/venus/helpers.c @@ -331,6 +331,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_data->vpp_cycles; + } + mutex_unlock(&core->lock); + + return load; +} + static u32 load_per_type(struct venus_core *core, u32 session_type) { struct venus_inst *inst = NULL; diff --git a/drivers/media/platform/qcom/venus/hfi_helper.h b/drivers/media/platform/qcom/venus/hfi_helper.h index 34ea503..3677e2e 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 From patchwork Thu May 30 13:58:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aniket Masule X-Patchwork-Id: 10968801 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 C20A9912 for ; Thu, 30 May 2019 13:59:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B3A082863D for ; Thu, 30 May 2019 13:59:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A7E7428995; Thu, 30 May 2019 13:59:30 +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=ham 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 12DDB2880B for ; Thu, 30 May 2019 13:59:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727053AbfE3N73 (ORCPT ); Thu, 30 May 2019 09:59:29 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:46894 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726232AbfE3N73 (ORCPT ); Thu, 30 May 2019 09:59:29 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id D8B4A60588; Thu, 30 May 2019 13:59:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1559224768; bh=0nXJ2kRIt9+nus4XkTsFSv+sPOQK6UV39wlcPrXeboU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V/+r37DXYeUzfF7VzI7Mo6yRTa/MDYOXQfhKirKKFIblGlM7D/T7QNq0ifK9BNtM5 UioNrxSh4XB/NwtKtB+dRv5RMQNR8GoykUJ8WstRIWK+EGlheWUlqBs2J+WU1W8lS6 Q8dw3DKdq6sX5YGQY//4sVvv/zFZLDuNqSdkNroE= 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 D800460F3A; Thu, 30 May 2019 13:59:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1559224766; bh=0nXJ2kRIt9+nus4XkTsFSv+sPOQK6UV39wlcPrXeboU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FCk5nZKg9OS8kFCjMAqUsssovGoYipPgSJ/+W4BiJwz/kelbmGj6uJn1mGW0Ewi2K fAW6kW73Xa8TV3vT2Wiz9sJehqexWMXwoQxAppIgoKBcDGroonQMMU909zgnIqmT83 SkDmGcEv0t9rv9qLpEV4/1TL0nAzNyBdvPAcjqJA= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org D800460F3A 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 5/5] media: venus: Update core selection Date: Thu, 30 May 2019 19:28:28 +0530 Message-Id: <1559224708-6039-6-git-send-email-amasule@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1559224708-6039-1-git-send-email-amasule@codeaurora.org> References: <1559224708-6039-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 | 50 +++++++++++++++++++++++++---- drivers/media/platform/qcom/venus/helpers.h | 2 +- drivers/media/platform/qcom/venus/vdec.c | 5 +-- drivers/media/platform/qcom/venus/venc.c | 4 ++- 4 files changed, 51 insertions(+), 10 deletions(-) diff --git a/drivers/media/platform/qcom/venus/helpers.c b/drivers/media/platform/qcom/venus/helpers.c index 692ba3b..6ce202f 100644 --- a/drivers/media/platform/qcom/venus/helpers.c +++ b/drivers/media/platform/qcom/venus/helpers.c @@ -500,6 +500,16 @@ static int load_scale_clocks(struct venus_inst *inst) return scale_clocks_vpu4(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) { @@ -803,19 +813,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_decide_core(struct venus_inst *inst, u32 cores_max) { - 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, core0_load = 0, core1_load = 0; + unsigned long min_load, max_freq, cur_inst_load; + int ret; if (!IS_V4(inst->core)) return 0; - cu.video_core_enable_mask = usage; + core0_load = load_per_core(core, VIDC_CORE_ID_1); + core1_load = load_per_core(core, VIDC_CORE_ID_2); - return hfi_session_set_property(inst, ptype, &cu); + min_core_id = core0_load < core1_load ? VIDC_CORE_ID_1 : VIDC_CORE_ID_2; + min_load = min(core0_load, core1_load); + + if (cores_max < VIDC_CORE_ID_1) { + min_core_id = VIDC_CORE_ID_1; + min_load = core0_load; + } + + cur_inst_load = load_per_instance(inst) * + inst->clk_data.codec_data->vpp_cycles; + 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_decide_core); int venus_helper_init_codec_data(struct venus_inst *inst) { diff --git a/drivers/media/platform/qcom/venus/helpers.h b/drivers/media/platform/qcom/venus/helpers.h index f9360a8..c41ceb3 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_data(struct venus_inst *inst); -int venus_helper_set_core_usage(struct venus_inst *inst, u32 usage); +int venus_helper_decide_core(struct venus_inst *inst, u32 cores_max); 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/vdec.c b/drivers/media/platform/qcom/venus/vdec.c index 51795fd..9f988ba 100644 --- a/drivers/media/platform/qcom/venus/vdec.c +++ b/drivers/media/platform/qcom/venus/vdec.c @@ -544,14 +544,15 @@ static int vdec_output_conf(struct venus_inst *inst) u32 height = inst->out_height; u32 out_fmt, out2_fmt; bool ubwc = false; - u32 ptype; + u32 ptype, cores_max; int ret; ret = venus_helper_set_work_mode(inst, VIDC_WORK_MODE_2); if (ret) return ret; - ret = venus_helper_set_core_usage(inst, VIDC_CORE_ID_1); + cores_max = core_num_max(inst); + ret = venus_helper_decide_core(inst, cores_max); if (ret) return ret; diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c index 792cdce..ed39efd 100644 --- a/drivers/media/platform/qcom/venus/venc.c +++ b/drivers/media/platform/qcom/venus/venc.c @@ -654,13 +654,15 @@ static int venc_set_properties(struct venus_inst *inst) struct hfi_quantization quant; struct hfi_quantization_range quant_range; u32 ptype, rate_control, bitrate, profile = 0, level = 0; + u32 cores_max; int ret; ret = venus_helper_set_work_mode(inst, VIDC_WORK_MODE_2); if (ret) return ret; - ret = venus_helper_set_core_usage(inst, VIDC_CORE_ID_2); + cores_max = core_num_max(inst); + ret = venus_helper_decide_core(inst, cores_max); if (ret) return ret;