hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c
....@@ -28,7 +28,6 @@
2828 * Christian König <christian.koenig@amd.com>
2929 */
3030
31
-#include <drm/drmP.h>
3231 #include "amdgpu.h"
3332 #include "amdgpu_trace.h"
3433 #include "amdgpu_amdkfd.h"
....@@ -36,7 +35,6 @@
3635 struct amdgpu_sync_entry {
3736 struct hlist_node node;
3837 struct dma_fence *fence;
39
- bool explicit;
4038 };
4139
4240 static struct kmem_cache *amdgpu_sync_slab;
....@@ -130,7 +128,7 @@
130128 * Tries to add the fence to an existing hash entry. Returns true when an entry
131129 * was found, false otherwise.
132130 */
133
-static bool amdgpu_sync_add_later(struct amdgpu_sync *sync, struct dma_fence *f, bool explicit)
131
+static bool amdgpu_sync_add_later(struct amdgpu_sync *sync, struct dma_fence *f)
134132 {
135133 struct amdgpu_sync_entry *e;
136134
....@@ -139,10 +137,6 @@
139137 continue;
140138
141139 amdgpu_sync_keep_later(&e->fence, f);
142
-
143
- /* Preserve eplicit flag to not loose pipe line sync */
144
- e->explicit |= explicit;
145
-
146140 return true;
147141 }
148142 return false;
....@@ -152,28 +146,23 @@
152146 * amdgpu_sync_fence - remember to sync to this fence
153147 *
154148 * @sync: sync object to add fence to
155
- * @fence: fence to sync to
149
+ * @f: fence to sync to
156150 *
151
+ * Add the fence to the sync object.
157152 */
158
-int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync,
159
- struct dma_fence *f, bool explicit)
153
+int amdgpu_sync_fence(struct amdgpu_sync *sync, struct dma_fence *f)
160154 {
161155 struct amdgpu_sync_entry *e;
162156
163157 if (!f)
164158 return 0;
165
- if (amdgpu_sync_same_dev(adev, f) &&
166
- amdgpu_sync_get_owner(f) == AMDGPU_FENCE_OWNER_VM)
167
- amdgpu_sync_keep_later(&sync->last_vm_update, f);
168159
169
- if (amdgpu_sync_add_later(sync, f, explicit))
160
+ if (amdgpu_sync_add_later(sync, f))
170161 return 0;
171162
172163 e = kmem_cache_alloc(amdgpu_sync_slab, GFP_KERNEL);
173164 if (!e)
174165 return -ENOMEM;
175
-
176
- e->explicit = explicit;
177166
178167 hash_add(sync->fences, &e->node, f->context);
179168 e->fence = dma_fence_get(f);
....@@ -181,22 +170,39 @@
181170 }
182171
183172 /**
173
+ * amdgpu_sync_vm_fence - remember to sync to this VM fence
174
+ *
175
+ * @adev: amdgpu device
176
+ * @sync: sync object to add fence to
177
+ * @fence: the VM fence to add
178
+ *
179
+ * Add the fence to the sync object and remember it as VM update.
180
+ */
181
+int amdgpu_sync_vm_fence(struct amdgpu_sync *sync, struct dma_fence *fence)
182
+{
183
+ if (!fence)
184
+ return 0;
185
+
186
+ amdgpu_sync_keep_later(&sync->last_vm_update, fence);
187
+ return amdgpu_sync_fence(sync, fence);
188
+}
189
+
190
+/**
184191 * amdgpu_sync_resv - sync to a reservation object
185192 *
186193 * @sync: sync object to add fences from reservation object to
187194 * @resv: reservation object with embedded fence
188
- * @explicit_sync: true if we should only sync to the exclusive fence
195
+ * @mode: how owner affects which fences we sync to
196
+ * @owner: owner of the planned job submission
189197 *
190198 * Sync to the fence
191199 */
192
-int amdgpu_sync_resv(struct amdgpu_device *adev,
193
- struct amdgpu_sync *sync,
194
- struct reservation_object *resv,
195
- void *owner, bool explicit_sync)
200
+int amdgpu_sync_resv(struct amdgpu_device *adev, struct amdgpu_sync *sync,
201
+ struct dma_resv *resv, enum amdgpu_sync_mode mode,
202
+ void *owner)
196203 {
197
- struct reservation_object_list *flist;
204
+ struct dma_resv_list *flist;
198205 struct dma_fence *f;
199
- void *fence_owner;
200206 unsigned i;
201207 int r = 0;
202208
....@@ -204,43 +210,64 @@
204210 return -EINVAL;
205211
206212 /* always sync to the exclusive fence */
207
- f = reservation_object_get_excl(resv);
208
- r = amdgpu_sync_fence(adev, sync, f, false);
213
+ f = dma_resv_get_excl(resv);
214
+ r = amdgpu_sync_fence(sync, f);
209215
210
- flist = reservation_object_get_list(resv);
216
+ flist = dma_resv_get_list(resv);
211217 if (!flist || r)
212218 return r;
213219
214220 for (i = 0; i < flist->shared_count; ++i) {
221
+ void *fence_owner;
222
+
215223 f = rcu_dereference_protected(flist->shared[i],
216
- reservation_object_held(resv));
224
+ dma_resv_held(resv));
225
+
226
+ fence_owner = amdgpu_sync_get_owner(f);
227
+
228
+ /* Always sync to moves, no matter what */
229
+ if (fence_owner == AMDGPU_FENCE_OWNER_UNDEFINED) {
230
+ r = amdgpu_sync_fence(sync, f);
231
+ if (r)
232
+ break;
233
+ }
234
+
217235 /* We only want to trigger KFD eviction fences on
218236 * evict or move jobs. Skip KFD fences otherwise.
219237 */
220
- fence_owner = amdgpu_sync_get_owner(f);
221238 if (fence_owner == AMDGPU_FENCE_OWNER_KFD &&
222239 owner != AMDGPU_FENCE_OWNER_UNDEFINED)
223240 continue;
224241
225
- if (amdgpu_sync_same_dev(adev, f)) {
226
- /* VM updates are only interesting
227
- * for other VM updates and moves.
228
- */
229
- if ((owner != AMDGPU_FENCE_OWNER_UNDEFINED) &&
230
- (fence_owner != AMDGPU_FENCE_OWNER_UNDEFINED) &&
231
- ((owner == AMDGPU_FENCE_OWNER_VM) !=
232
- (fence_owner == AMDGPU_FENCE_OWNER_VM)))
233
- continue;
242
+ /* Never sync to VM updates either. */
243
+ if (fence_owner == AMDGPU_FENCE_OWNER_VM &&
244
+ owner != AMDGPU_FENCE_OWNER_UNDEFINED)
245
+ continue;
234246
235
- /* Ignore fence from the same owner and explicit one as
236
- * long as it isn't undefined.
237
- */
238
- if (owner != AMDGPU_FENCE_OWNER_UNDEFINED &&
239
- (fence_owner == owner || explicit_sync))
247
+ /* Ignore fences depending on the sync mode */
248
+ switch (mode) {
249
+ case AMDGPU_SYNC_ALWAYS:
250
+ break;
251
+
252
+ case AMDGPU_SYNC_NE_OWNER:
253
+ if (amdgpu_sync_same_dev(adev, f) &&
254
+ fence_owner == owner)
240255 continue;
256
+ break;
257
+
258
+ case AMDGPU_SYNC_EQ_OWNER:
259
+ if (amdgpu_sync_same_dev(adev, f) &&
260
+ fence_owner != owner)
261
+ continue;
262
+ break;
263
+
264
+ case AMDGPU_SYNC_EXPLICIT:
265
+ continue;
241266 }
242267
243
- r = amdgpu_sync_fence(adev, sync, f, false);
268
+ WARN(debug_evictions && fence_owner == AMDGPU_FENCE_OWNER_KFD,
269
+ "Adding eviction fence to sync obj");
270
+ r = amdgpu_sync_fence(sync, f);
244271 if (r)
245272 break;
246273 }
....@@ -295,11 +322,10 @@
295322 * amdgpu_sync_get_fence - get the next fence from the sync object
296323 *
297324 * @sync: sync object to use
298
- * @explicit: true if the next fence is explicit
299325 *
300326 * Get and removes the next fence from the sync object not signaled yet.
301327 */
302
-struct dma_fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync, bool *explicit)
328
+struct dma_fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync)
303329 {
304330 struct amdgpu_sync_entry *e;
305331 struct hlist_node *tmp;
....@@ -308,8 +334,6 @@
308334 hash_for_each_safe(sync->fences, i, tmp, e, node) {
309335
310336 f = e->fence;
311
- if (explicit)
312
- *explicit = e->explicit;
313337
314338 hash_del(&e->node);
315339 kmem_cache_free(amdgpu_sync_slab, e);
....@@ -341,7 +365,7 @@
341365 hash_for_each_safe(source->fences, i, tmp, e, node) {
342366 f = e->fence;
343367 if (!dma_fence_is_signaled(f)) {
344
- r = amdgpu_sync_fence(NULL, clone, f, e->explicit);
368
+ r = amdgpu_sync_fence(clone, f);
345369 if (r)
346370 return r;
347371 } else {