aboutsummaryrefslogtreecommitdiffstats
path: root/common/recipes-kernel/linux/linux-yocto-4.14.71/4266-drm-amdkfd-CMA-Add-intermediate-wait-if-mGPU.patch
blob: 8c8c2bbde11e6b02f26253f9bfe64c6607409478 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
From dcc8d6fb42976e899c75091092c3ecb1532b6afa Mon Sep 17 00:00:00 2001
From: Harish Kasiviswanathan <Harish.Kasiviswanathan@amd.com>
Date: Thu, 12 Apr 2018 14:24:22 -0400
Subject: [PATCH 4266/5725] drm/amdkfd: CMA: Add intermediate wait if mGPU

CMA can happen on multiple GPUs. The current approach of keeping track
of only the latest fence is not sufficient. Before throwing away the old
fence check if it belongs to the same context. If not wait before
releasing it.

The current approach will be suboptimal in a mGPU (> 2) system if CMA
ioctl is called with a long list of memory ranges where potentially each
range copy could be done by different GPU. In this situation, the better
approach would be to call the ioctl repeatedly with shorter list.

Change-Id: Icf522cf8bfa648e24900745622600f920c0de320
Signed-off-by: Harish Kasiviswanathan <Harish.Kasiviswanathan@amd.com>
---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index 9426a66..b07fe36 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -1853,6 +1853,20 @@ static int kfd_cma_fence_wait(struct dma_fence *f)
 	return ret;
 }
 
+/* Put previous (old) fence @pf but it waits for @pf to signal if the context
+ * of the current fence @cf is different.
+ */
+static int kfd_fence_put_wait_if_diff_context(struct dma_fence *cf,
+					      struct dma_fence *pf)
+{
+	int ret = 0;
+
+	if (pf && cf && cf->context != pf->context)
+		ret = kfd_cma_fence_wait(pf);
+	dma_fence_put(pf);
+	return ret;
+}
+
 /* Create a system BO by pinning underlying system pages of the given userptr
  * BO @ubo
  * @ubo: Userptr BO
@@ -2230,9 +2244,13 @@ static int kfd_copy_single_range(struct cma_iter *si, struct cma_iter *di,
 		}
 
 		if (fence) {
-			dma_fence_put(lfence);
+			err = kfd_fence_put_wait_if_diff_context(fence,
+								 lfence);
 			lfence = fence;
+			if (err)
+				break;
 		}
+
 		size -= n;
 		*copied += n;
 		err = kfd_cma_iter_advance(si, n);
@@ -2374,8 +2392,11 @@ static int kfd_ioctl_cross_memory_copy(struct file *filep,
 		 * new fence is created, then keep the preivous fence
 		 */
 		if (fence) {
-			dma_fence_put(lfence);
+			err = kfd_fence_put_wait_if_diff_context(fence,
+								 lfence);
 			lfence = fence;
+			if (err)
+				break;
 		}
 	}
 
-- 
2.7.4