[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAPBb6MUnXmtSKy9NwikYXjafgB+WM9TKEFjkYK16T2V7KRx=JQ@mail.gmail.com>
Date: Wed, 25 Nov 2020 12:46:11 +0900
From: Alexandre Courbot <acourbot@...omium.org>
To: Stanimir Varbanov <stanimir.varbanov@...aro.org>
Cc: linux-media@...r.kernel.org, linux-arm-msm@...r.kernel.org,
linux-kernel@...r.kernel.org,
Vikash Garodia <vgarodia@...eaurora.org>,
Mansur Alisha Shaik <mansur@...eaurora.org>,
Dikshita Agarwal <dikshita@...eaurora.org>
Subject: Re: [PATCH 2/3] venus: Limit HFI sessions to the maximum supported
On Fri, Nov 20, 2020 at 9:12 AM Stanimir Varbanov
<stanimir.varbanov@...aro.org> wrote:
>
> Currently we rely on firmware to return error when we reach the maximum
> supported number of sessions. But this errors are happened at reqbuf
> time which is a bit later. The more reasonable way looks like is to
> return the error on driver open.
>
> To achieve that modify hfi_session_create to return error when we reach
> maximum count of sessions and thus refuse open.
>
> Signed-off-by: Stanimir Varbanov <stanimir.varbanov@...aro.org>
> ---
> drivers/media/platform/qcom/venus/core.h | 1 +
> drivers/media/platform/qcom/venus/hfi.c | 19 +++++++++++++++----
> .../media/platform/qcom/venus/hfi_parser.c | 3 +++
> 3 files changed, 19 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h
> index db0e6738281e..3a477fcdd3a8 100644
> --- a/drivers/media/platform/qcom/venus/core.h
> +++ b/drivers/media/platform/qcom/venus/core.h
> @@ -96,6 +96,7 @@ struct venus_format {
> #define MAX_CAP_ENTRIES 32
> #define MAX_ALLOC_MODE_ENTRIES 16
> #define MAX_CODEC_NUM 32
> +#define MAX_SESSIONS 16
>
> struct raw_formats {
> u32 buftype;
> diff --git a/drivers/media/platform/qcom/venus/hfi.c b/drivers/media/platform/qcom/venus/hfi.c
> index 638ed5cfe05e..8420be6d3991 100644
> --- a/drivers/media/platform/qcom/venus/hfi.c
> +++ b/drivers/media/platform/qcom/venus/hfi.c
> @@ -175,6 +175,7 @@ static int wait_session_msg(struct venus_inst *inst)
> int hfi_session_create(struct venus_inst *inst, const struct hfi_inst_ops *ops)
> {
> struct venus_core *core = inst->core;
> + int ret;
>
> if (!ops)
> return -EINVAL;
> @@ -183,12 +184,22 @@ int hfi_session_create(struct venus_inst *inst, const struct hfi_inst_ops *ops)
> init_completion(&inst->done);
> inst->ops = ops;
>
> - mutex_lock(&core->lock);
> - list_add_tail(&inst->list, &core->instances);
> - atomic_inc(&core->insts_count);
> + ret = mutex_lock_interruptible(&core->lock);
> + if (ret)
> + return ret;
Why do we change to mutex_lock_interruptible() here? This makes this
function return an error even though we could obtain the lock just by
trying a bit harder.
> +
> + ret = atomic_read(&core->insts_count);
> + if (ret + 1 > core->max_sessions_supported) {
> + ret = -EAGAIN;
> + } else {
> + atomic_inc(&core->insts_count);
> + list_add_tail(&inst->list, &core->instances);
> + ret = 0;
> + }
> +
> mutex_unlock(&core->lock);
>
> - return 0;
> + return ret;
> }
> EXPORT_SYMBOL_GPL(hfi_session_create);
>
> diff --git a/drivers/media/platform/qcom/venus/hfi_parser.c b/drivers/media/platform/qcom/venus/hfi_parser.c
> index 363ee2a65453..52898633a8e6 100644
> --- a/drivers/media/platform/qcom/venus/hfi_parser.c
> +++ b/drivers/media/platform/qcom/venus/hfi_parser.c
> @@ -276,6 +276,9 @@ u32 hfi_parser(struct venus_core *core, struct venus_inst *inst, void *buf,
> words_count--;
> }
>
> + if (!core->max_sessions_supported)
> + core->max_sessions_supported = MAX_SESSIONS;
> +
> parser_fini(inst, codecs, domain);
>
> return HFI_ERR_NONE;
> --
> 2.17.1
>
Powered by blists - more mailing lists