From 00c3d98acba40e0ee549a174f212850aa15646a5 Mon Sep 17 00:00:00 2001 From: Sagar Kamble Date: Mon, 3 May 2021 21:46:17 +0530 Subject: gpu: nvgpu: create timed wait functions for stall and nonstall interrupts completion In order to process stalling interrupts during TSG unbind, we need a API to wait for the stalling interrupts to complete within certain duration. Prepare these APIs for stalling and non-stalling interrupts. Bug 200711183 Bug 200726848 Change-Id: I634738249ade64224326b356d6244ad4299f1baf Signed-off-by: Sagar Kamble Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2521970 (cherry picked from commit I0b7a64c0f3761bbd0ca0843aea28a591ed23739f) Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2523937 Reviewed-by: svc-mobile-coverity Reviewed-by: Deepak Nibade Reviewed-by: Bibek Basu Reviewed-by: mobile promotions Tested-by: mobile promotions GVS: Gerrit_Virtual_Submit --- drivers/gpu/nvgpu/os/linux/driver_common.c | 60 +++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 10 deletions(-) (limited to 'drivers/gpu/nvgpu/os/linux') diff --git a/drivers/gpu/nvgpu/os/linux/driver_common.c b/drivers/gpu/nvgpu/os/linux/driver_common.c index c76dabeb..602d325d 100644 --- a/drivers/gpu/nvgpu/os/linux/driver_common.c +++ b/drivers/gpu/nvgpu/os/linux/driver_common.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2018, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2016-2021, 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, @@ -312,30 +312,70 @@ static int cyclic_delta(int a, int b) } /** - * nvgpu_wait_for_deferred_interrupts - Wait for interrupts to complete + * nvgpu_wait_for_stall_interrupts - Wait for the stalling interrupts to + * complete. * * @g - The GPU to wait on. + * @timeout - maximum time period to wait for. * - * Waits until all interrupt handlers that have been scheduled to run have - * completed. + * Waits until all stalling interrupt handlers that have been scheduled to run + * have completed. */ -void nvgpu_wait_for_deferred_interrupts(struct gk20a *g) +int nvgpu_wait_for_stall_interrupts(struct gk20a *g, u32 timeout) { struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); int stall_irq_threshold = atomic_read(&l->hw_irq_stall_count); - int nonstall_irq_threshold = atomic_read(&l->hw_irq_nonstall_count); /* wait until all stalling irqs are handled */ - NVGPU_COND_WAIT(&l->sw_irq_stall_last_handled_wq, + return NVGPU_COND_WAIT(&l->sw_irq_stall_last_handled_wq, cyclic_delta(stall_irq_threshold, atomic_read(&l->sw_irq_stall_last_handled)) - <= 0, 0); + <= 0, timeout); +} + +/** + * nvgpu_wait_for_nonstall_interrupts - Wait for the nonstalling interrupts to + * complete. + * + * @g - The GPU to wait on. + * @timeout - maximum time period to wait for. + * + * Waits until all non-stalling interrupt handlers that have been scheduled to + * run have completed. + */ +int nvgpu_wait_for_nonstall_interrupts(struct gk20a *g, u32 timeout) +{ + struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); + int nonstall_irq_threshold = atomic_read(&l->hw_irq_nonstall_count); /* wait until all non-stalling irqs are handled */ - NVGPU_COND_WAIT(&l->sw_irq_nonstall_last_handled_wq, + return NVGPU_COND_WAIT(&l->sw_irq_nonstall_last_handled_wq, cyclic_delta(nonstall_irq_threshold, atomic_read(&l->sw_irq_nonstall_last_handled)) - <= 0, 0); + <= 0, timeout); +} + +/** + * nvgpu_wait_for_deferred_interrupts - Wait for interrupts to complete + * + * @g - The GPU to wait on. + * + * Waits until all interrupt handlers that have been scheduled to run have + * completed. + */ +void nvgpu_wait_for_deferred_interrupts(struct gk20a *g) +{ + int ret; + + ret = nvgpu_wait_for_stall_interrupts(g, 0U); + if (ret != 0) { + nvgpu_err(g, "wait for stall interrupts failed %d", ret); + } + + ret = nvgpu_wait_for_nonstall_interrupts(g, 0U); + if (ret != 0) { + nvgpu_err(g, "wait for nonstall interrupts failed %d", ret); + } } static void nvgpu_free_gk20a(struct gk20a *g) -- cgit v1.2.2