From f33770d313664e311e09c253318a574ac7a9f9e5 Mon Sep 17 00:00:00 2001 From: Asha Talambedu Date: Tue, 16 Nov 2021 16:42:51 +0530 Subject: [PATCH] tegra: nvadsp: Timeout added on wait for app start In cold boot stress test, it is observed that adsp OS hung intermittently(1/276). Due to which 1) app init of adspff is not able to complete as it does not receive start ack from adsp 2) wdt handler is triggered as adsp is hung for more than 10 seconds. When poweroff is issued in such case, the alsactl save/restore job which is part of shutdown sequence is hung as its unable to acquire lock held by host adsp audio driver fn that initiated nvadsp_os_start. Therefore, timeout is added while waiting for app init. If app init fails to happen within timeout duration, error status is received by nvadsp_os_start which inturn is received by host side adsp audio driver. This ensures that lock is released in case of adsff_init failure in nvadsp_os_start function so that shutdown can proceed without issue. Bug 3391964 Change-Id: Ieca54fe9dd21bf9de70d781cfaceb5ffe83809ef Signed-off-by: Asha Talambedu Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2626892 Tested-by: mobile promotions Reviewed-by: svc_kernel_abi Reviewed-by: svcacv Reviewed-by: Dara Ramesh Reviewed-by: Sharad Gupta Reviewed-by: mobile promotions GVS: Gerrit_Virtual_Submit --- drivers/platform/tegra/nvadsp/app.c | 12 +++++++++--- drivers/platform/tegra/nvadsp/os.c | 13 ++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/drivers/platform/tegra/nvadsp/app.c b/drivers/platform/tegra/nvadsp/app.c index 6fafdb80..12634b76 100644 --- a/drivers/platform/tegra/nvadsp/app.c +++ b/drivers/platform/tegra/nvadsp/app.c @@ -3,7 +3,7 @@ * * ADSP OS App management * - * Copyright (C) 2014-2018, NVIDIA Corporation. All rights reserved. + * Copyright (C) 2014-2021, NVIDIA Corporation. All rights reserved. * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and @@ -32,6 +32,7 @@ #include "adsp_shared_struct.h" #define DYN_APP_EXTN ".elf" +#define ADSP_APP_INIT_TIMEOUT 2000 /* in ms */ /* * structure to hold the list of app binaries loaded and @@ -616,7 +617,7 @@ nvadsp_app_info_t __must_check *nvadsp_app_init(nvadsp_app_handle_t handle, nvadsp_app_info_t *app; msgq_t *msgq_send; int *state; - unsigned long flags; + unsigned long flags, ret = 0; if (IS_ERR_OR_NULL(priv.pdev)) { pr_err("ADSP Driver is not initialized\n"); @@ -661,7 +662,12 @@ nvadsp_app_info_t __must_check *nvadsp_app_init(nvadsp_app_handle_t handle, nvadsp_mbox_send(&priv.mbox, 0, NVADSP_MBOX_SMSG, false, 0); - wait_for_completion(&app->wait_for_app_start); + ret = wait_for_completion_timeout(&app->wait_for_app_start, + msecs_to_jiffies(ADSP_APP_INIT_TIMEOUT)); + if (!ret) { + delete_app_instance(app); + return NULL; + } init_completion(&app->wait_for_app_start); return app; err: diff --git a/drivers/platform/tegra/nvadsp/os.c b/drivers/platform/tegra/nvadsp/os.c index 913a0b3d..ab465b8d 100644 --- a/drivers/platform/tegra/nvadsp/os.c +++ b/drivers/platform/tegra/nvadsp/os.c @@ -1805,7 +1805,18 @@ int nvadsp_os_start(void) #if defined(CONFIG_TEGRA_ADSP_FILEIO) if (!drv_data->adspff_init) { ret = adspff_init(priv.pdev); - if (!ret) + if (ret) { + priv.os_running = drv_data->adsp_os_running = false; + dev_err(dev, + "adsp boot failed at adspff init with ret = %d", + ret); + dump_adsp_sys(); + free_interrupts(&priv); +#ifdef CONFIG_PM + pm_runtime_put_sync(&priv.pdev->dev); +#endif + goto unlock; + } else drv_data->adspff_init = true; } #endif