From 23f6da4fe5bdd232cbd1da6c3a0e2d09b4711b43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konsta=20H=C3=B6ltt=C3=A4?= Date: Thu, 2 Dec 2021 18:23:59 +0200 Subject: [PATCH] gpu: nvgpu: add should stop condition to workers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As the docs of nvgpu_thread say, each thread (which the worker loop is) should wake up and check also nvgpu_thread_should_stop() to manage graceful and quick exit as requested. The loop does have that check already, but the workqueue condition does not, so the cond wait might end up waiting until its timeout hits. It's not robust to trust the worker users to have a swift timeout for exiting the thread, so read the should-stop flag in the wakeup condition too. Simplify the clk arb worker ops now that calling nvgpu_worker_should_stop from there is no longer necessary. (Other worker users did not have those, so they were technically buggy.) Change-Id: I5409b8037564d4b6445a15cdbd4f1f3d616c4083 Signed-off-by: Konsta Hölttä Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2635808 Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-misra Reviewed-by: svc-mobile-cert Reviewed-by: svcacv Reviewed-by: Alex Waterman Reviewed-by: mobile promotions Tested-by: mobile promotions GVS: Gerrit_Virtual_Submit --- drivers/gpu/nvgpu/common/clk_arb/clk_arb.c | 5 ----- drivers/gpu/nvgpu/common/utils/worker.c | 5 +++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/nvgpu/common/clk_arb/clk_arb.c b/drivers/gpu/nvgpu/common/clk_arb/clk_arb.c index 2effe0795..9ae96a289 100644 --- a/drivers/gpu/nvgpu/common/clk_arb/clk_arb.c +++ b/drivers/gpu/nvgpu/common/clk_arb/clk_arb.c @@ -404,13 +404,8 @@ static void nvgpu_clk_arb_worker_poll_init(struct nvgpu_worker *worker) const struct nvgpu_worker_ops clk_arb_worker_ops = { .pre_process = nvgpu_clk_arb_worker_poll_init, - .wakeup_early_exit = nvgpu_worker_should_stop, - .wakeup_post_process = NULL, .wakeup_process_item = nvgpu_clk_arb_worker_poll_wakeup_process_item, - .wakeup_condition = - nvgpu_worker_should_stop, - .wakeup_timeout = NULL, }; /** diff --git a/drivers/gpu/nvgpu/common/utils/worker.c b/drivers/gpu/nvgpu/common/utils/worker.c index df3eef734..d5498cc78 100644 --- a/drivers/gpu/nvgpu/common/utils/worker.c +++ b/drivers/gpu/nvgpu/common/utils/worker.c @@ -153,13 +153,14 @@ static int nvgpu_worker_poll_work(void *arg) nvgpu_worker_pre_process(worker); - while (!nvgpu_thread_should_stop(&worker->poll_task)) { + while (!nvgpu_worker_should_stop(worker)) { int ret; ret = NVGPU_COND_WAIT_INTERRUPTIBLE( &worker->wq, nvgpu_worker_pending(worker, get) || - nvgpu_worker_wakeup_condition(worker), + nvgpu_worker_wakeup_condition(worker) || + nvgpu_worker_should_stop(worker), nvgpu_worker_wakeup_timeout(worker)); if (nvgpu_worker_wakeup_early_exit(worker)) {