From 7ddd6e261ed620dbb388202be89ca4e6843e3947 Mon Sep 17 00:00:00 2001 From: Deepak Nibade Date: Thu, 23 Apr 2015 17:10:42 +0530 Subject: gpu: nvgpu: wait for running jobs to finish before shutdown In gk20a_pm_shutdown(), we currently call __pm_runtime_disable() which prevents h/w access to new requests made after shutdown() call Also, once gk20a_pm_shutdown() completes, platform code will just rail gate the GPU But it is possible that some other thread is already accessing h/w while shutdown() was triggered and this can result in hang Hence, wait until all currently executing jobs are finished before returning from gk20a_pm_shutdown() Also, we need to wait for GPU's usage count to become 1 since platform code will increase the usage count and then call shutdown(). Hence usage count of 1 indicates that GPU is idle Bug 200099940 Change-Id: I1f2457829e2737c07302d13f355353a30c3b4e67 Signed-off-by: Deepak Nibade Reviewed-on: http://git-master/r/734920 Reviewed-by: Bharat Nihalani Tested-by: Bharat Nihalani --- drivers/gpu/nvgpu/gk20a/gk20a.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'drivers/gpu/nvgpu/gk20a/gk20a.c') diff --git a/drivers/gpu/nvgpu/gk20a/gk20a.c b/drivers/gpu/nvgpu/gk20a/gk20a.c index 8e7fbae0..f3b5544f 100644 --- a/drivers/gpu/nvgpu/gk20a/gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/gk20a.c @@ -1122,8 +1122,27 @@ static int gk20a_pm_disable_clk(struct device *dev) static void gk20a_pm_shutdown(struct platform_device *pdev) { +#ifdef CONFIG_PM_RUNTIME + unsigned long timeout = jiffies + + msecs_to_jiffies(GK20A_WAIT_FOR_IDLE_MS); + int ref_cnt; +#endif + dev_info(&pdev->dev, "shutting down"); + +#ifdef CONFIG_PM_RUNTIME + /* Prevent more requests by disabling Runtime PM */ __pm_runtime_disable(&pdev->dev, false); + + /* Wait until current running requests are finished */ + while (time_before(jiffies, timeout)) { + ref_cnt = atomic_read(&pdev->dev.power.usage_count); + if (ref_cnt > 1) + msleep(1); + else + break; + } +#endif } #ifdef CONFIG_PM -- cgit v1.2.2