From ebf874c351cff29a61ec59ec01f2e5f2c4726b40 Mon Sep 17 00:00:00 2001 From: Peter Daifuku Date: Fri, 7 Dec 2018 11:04:07 -0800 Subject: [PATCH] nvgpu: pmu: cleanup init thread on destroy In nvgpu_kill_task_pg_init(), call nvgpu_thread_join() if the init thread is no longer running in order to reclaim thread resources. Bug 2452799 JIRA ESRM-437 Change-Id: Id9c67f689027f00039ac2df226ee9c28ad89dd1d Signed-off-by: Peter Daifuku Reviewed-on: https://git-master.nvidia.com/r/1967983 Reviewed-by: svc-mobile-coverity Reviewed-by: svc-misra-checker GVS: Gerrit_Virtual_Submit Reviewed-by: Alex Waterman Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/pmu/pmu.c | 2 ++ drivers/gpu/nvgpu/include/nvgpu/thread.h | 9 +++++++++ drivers/gpu/nvgpu/os/linux/thread.c | 10 +++++++++- drivers/gpu/nvgpu/os/posix/thread.c | 5 +++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/nvgpu/common/pmu/pmu.c b/drivers/gpu/nvgpu/common/pmu/pmu.c index 593d52b36..cc2e8efa1 100644 --- a/drivers/gpu/nvgpu/common/pmu/pmu.c +++ b/drivers/gpu/nvgpu/common/pmu/pmu.c @@ -172,6 +172,8 @@ void nvgpu_kill_task_pg_init(struct gk20a *g) nvgpu_udelay(2); } while (nvgpu_timeout_expired_msg(&timeout, "timeout - waiting PMU state machine thread stop") == 0); + } else { + nvgpu_thread_join(&pmu->pg_init.state_task); } } diff --git a/drivers/gpu/nvgpu/include/nvgpu/thread.h b/drivers/gpu/nvgpu/include/nvgpu/thread.h index b113f9720..eac06ef17 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/thread.h +++ b/drivers/gpu/nvgpu/include/nvgpu/thread.h @@ -80,4 +80,13 @@ bool nvgpu_thread_should_stop(struct nvgpu_thread *thread); */ bool nvgpu_thread_is_running(struct nvgpu_thread *thread); +/** + * nvgpu_thread_join - join a thread to reclaim resources + * after it has exited + * + * @thread - thread to join + * + */ +void nvgpu_thread_join(struct nvgpu_thread *thread); + #endif /* NVGPU_THREAD_H */ diff --git a/drivers/gpu/nvgpu/os/linux/thread.c b/drivers/gpu/nvgpu/os/linux/thread.c index 92c556f21..3da61eed4 100644 --- a/drivers/gpu/nvgpu/os/linux/thread.c +++ b/drivers/gpu/nvgpu/os/linux/thread.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -17,6 +17,7 @@ #include #include +#include int nvgpu_thread_proxy(void *threaddata) { @@ -61,3 +62,10 @@ bool nvgpu_thread_is_running(struct nvgpu_thread *thread) { return ACCESS_ONCE(thread->running); }; + +void nvgpu_thread_join(struct nvgpu_thread *thread) +{ + while (ACCESS_ONCE(thread->running)) { + nvgpu_msleep(10); + } +}; diff --git a/drivers/gpu/nvgpu/os/posix/thread.c b/drivers/gpu/nvgpu/os/posix/thread.c index e72f95800..d2e6d98d2 100644 --- a/drivers/gpu/nvgpu/os/posix/thread.c +++ b/drivers/gpu/nvgpu/os/posix/thread.c @@ -95,3 +95,8 @@ bool nvgpu_thread_is_running(struct nvgpu_thread *thread) { return thread->running; } + +void nvgpu_thread_join(struct nvgpu_thread *thread) +{ + (void) pthread_join(thread->thread, NULL); +}