Skip to content

Commit 1659074

Browse files
ChristianKoenigAMDalexdeucher
authored andcommitted
drm/amdgpu: use GFP_NOWAIT for memory allocations
In the critical submission path memory allocations can't wait for reclaim since that can potentially wait for submissions to finish. Finally clean that up and mark most memory allocations in the critical path with GFP_NOWAIT. The only exception left is the dma_fence_array() used when no VMID is available, but that will be cleaned up later on. Signed-off-by: Christian König <christian.koenig@amd.com> Acked-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent a67f009 commit 1659074

6 files changed

Lines changed: 32 additions & 23 deletions

File tree

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ static int vm_update_pds(struct amdgpu_vm *vm, struct amdgpu_sync *sync)
491491
if (ret)
492492
return ret;
493493

494-
return amdgpu_sync_fence(sync, vm->last_update);
494+
return amdgpu_sync_fence(sync, vm->last_update, GFP_KERNEL);
495495
}
496496

497497
static uint64_t get_pte_flags(struct amdgpu_device *adev, struct kgd_mem *mem)
@@ -1249,7 +1249,7 @@ static int unmap_bo_from_gpuvm(struct kgd_mem *mem,
12491249

12501250
(void)amdgpu_vm_clear_freed(adev, vm, &bo_va->last_pt_update);
12511251

1252-
(void)amdgpu_sync_fence(sync, bo_va->last_pt_update);
1252+
(void)amdgpu_sync_fence(sync, bo_va->last_pt_update, GFP_KERNEL);
12531253

12541254
return 0;
12551255
}
@@ -1273,7 +1273,7 @@ static int update_gpuvm_pte(struct kgd_mem *mem,
12731273
return ret;
12741274
}
12751275

1276-
return amdgpu_sync_fence(sync, bo_va->last_pt_update);
1276+
return amdgpu_sync_fence(sync, bo_va->last_pt_update, GFP_KERNEL);
12771277
}
12781278

12791279
static int map_bo_to_gpuvm(struct kgd_mem *mem,
@@ -2913,7 +2913,7 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence __rcu *
29132913
}
29142914
dma_resv_for_each_fence(&cursor, bo->tbo.base.resv,
29152915
DMA_RESV_USAGE_KERNEL, fence) {
2916-
ret = amdgpu_sync_fence(&sync_obj, fence);
2916+
ret = amdgpu_sync_fence(&sync_obj, fence, GFP_KERNEL);
29172917
if (ret) {
29182918
pr_debug("Memory eviction: Sync BO fence failed. Try again\n");
29192919
goto validate_map_fail;

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ static int amdgpu_cs_p2_dependencies(struct amdgpu_cs_parser *p,
428428
dma_fence_put(old);
429429
}
430430

431-
r = amdgpu_sync_fence(&p->sync, fence);
431+
r = amdgpu_sync_fence(&p->sync, fence, GFP_KERNEL);
432432
dma_fence_put(fence);
433433
if (r)
434434
return r;
@@ -450,7 +450,7 @@ static int amdgpu_syncobj_lookup_and_add(struct amdgpu_cs_parser *p,
450450
return r;
451451
}
452452

453-
r = amdgpu_sync_fence(&p->sync, fence);
453+
r = amdgpu_sync_fence(&p->sync, fence, GFP_KERNEL);
454454
dma_fence_put(fence);
455455
return r;
456456
}
@@ -1124,7 +1124,8 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser *p)
11241124
if (r)
11251125
return r;
11261126

1127-
r = amdgpu_sync_fence(&p->sync, fpriv->prt_va->last_pt_update);
1127+
r = amdgpu_sync_fence(&p->sync, fpriv->prt_va->last_pt_update,
1128+
GFP_KERNEL);
11281129
if (r)
11291130
return r;
11301131

@@ -1135,7 +1136,8 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser *p)
11351136
if (r)
11361137
return r;
11371138

1138-
r = amdgpu_sync_fence(&p->sync, bo_va->last_pt_update);
1139+
r = amdgpu_sync_fence(&p->sync, bo_va->last_pt_update,
1140+
GFP_KERNEL);
11391141
if (r)
11401142
return r;
11411143
}
@@ -1154,7 +1156,8 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser *p)
11541156
if (r)
11551157
return r;
11561158

1157-
r = amdgpu_sync_fence(&p->sync, bo_va->last_pt_update);
1159+
r = amdgpu_sync_fence(&p->sync, bo_va->last_pt_update,
1160+
GFP_KERNEL);
11581161
if (r)
11591162
return r;
11601163
}
@@ -1167,7 +1170,7 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser *p)
11671170
if (r)
11681171
return r;
11691172

1170-
r = amdgpu_sync_fence(&p->sync, vm->last_update);
1173+
r = amdgpu_sync_fence(&p->sync, vm->last_update, GFP_KERNEL);
11711174
if (r)
11721175
return r;
11731176

@@ -1248,7 +1251,8 @@ static int amdgpu_cs_sync_rings(struct amdgpu_cs_parser *p)
12481251
continue;
12491252
}
12501253

1251-
r = amdgpu_sync_fence(&p->gang_leader->explicit_sync, fence);
1254+
r = amdgpu_sync_fence(&p->gang_leader->explicit_sync, fence,
1255+
GFP_KERNEL);
12521256
dma_fence_put(fence);
12531257
if (r)
12541258
return r;

drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ static int amdgpu_vmid_grab_idle(struct amdgpu_ring *ring,
209209
return 0;
210210
}
211211

212-
fences = kmalloc_array(id_mgr->num_ids, sizeof(void *), GFP_KERNEL);
212+
fences = kmalloc_array(id_mgr->num_ids, sizeof(void *), GFP_NOWAIT);
213213
if (!fences)
214214
return -ENOMEM;
215215

@@ -326,7 +326,8 @@ static int amdgpu_vmid_grab_reserved(struct amdgpu_vm *vm,
326326
/* Good we can use this VMID. Remember this submission as
327327
* user of the VMID.
328328
*/
329-
r = amdgpu_sync_fence(&(*id)->active, &job->base.s_fence->finished);
329+
r = amdgpu_sync_fence(&(*id)->active, &job->base.s_fence->finished,
330+
GFP_NOWAIT);
330331
if (r)
331332
return r;
332333

@@ -385,7 +386,8 @@ static int amdgpu_vmid_grab_used(struct amdgpu_vm *vm,
385386
* user of the VMID.
386387
*/
387388
r = amdgpu_sync_fence(&(*id)->active,
388-
&job->base.s_fence->finished);
389+
&job->base.s_fence->finished,
390+
GFP_NOWAIT);
389391
if (r)
390392
return r;
391393

@@ -437,7 +439,8 @@ int amdgpu_vmid_grab(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
437439

438440
/* Remember this submission as user of the VMID */
439441
r = amdgpu_sync_fence(&id->active,
440-
&job->base.s_fence->finished);
442+
&job->base.s_fence->finished,
443+
GFP_NOWAIT);
441444
if (r)
442445
goto error;
443446

drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,14 +1336,14 @@ int amdgpu_mes_ctx_map_meta_data(struct amdgpu_device *adev,
13361336
DRM_ERROR("failed to do vm_bo_update on meta data\n");
13371337
goto error_del_bo_va;
13381338
}
1339-
amdgpu_sync_fence(&sync, bo_va->last_pt_update);
1339+
amdgpu_sync_fence(&sync, bo_va->last_pt_update, GFP_KERNEL);
13401340

13411341
r = amdgpu_vm_update_pdes(adev, vm, false);
13421342
if (r) {
13431343
DRM_ERROR("failed to update pdes on meta data\n");
13441344
goto error_del_bo_va;
13451345
}
1346-
amdgpu_sync_fence(&sync, vm->last_update);
1346+
amdgpu_sync_fence(&sync, vm->last_update, GFP_KERNEL);
13471347

13481348
amdgpu_sync_wait(&sync, false);
13491349
drm_exec_fini(&exec);

drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ static bool amdgpu_sync_add_later(struct amdgpu_sync *sync, struct dma_fence *f)
152152
*
153153
* Add the fence to the sync object.
154154
*/
155-
int amdgpu_sync_fence(struct amdgpu_sync *sync, struct dma_fence *f)
155+
int amdgpu_sync_fence(struct amdgpu_sync *sync, struct dma_fence *f,
156+
gfp_t flags)
156157
{
157158
struct amdgpu_sync_entry *e;
158159

@@ -162,7 +163,7 @@ int amdgpu_sync_fence(struct amdgpu_sync *sync, struct dma_fence *f)
162163
if (amdgpu_sync_add_later(sync, f))
163164
return 0;
164165

165-
e = kmem_cache_alloc(amdgpu_sync_slab, GFP_KERNEL);
166+
e = kmem_cache_alloc(amdgpu_sync_slab, flags);
166167
if (!e)
167168
return -ENOMEM;
168169

@@ -249,7 +250,7 @@ int amdgpu_sync_resv(struct amdgpu_device *adev, struct amdgpu_sync *sync,
249250
struct dma_fence *tmp = dma_fence_chain_contained(f);
250251

251252
if (amdgpu_sync_test_fence(adev, mode, owner, tmp)) {
252-
r = amdgpu_sync_fence(sync, f);
253+
r = amdgpu_sync_fence(sync, f, GFP_KERNEL);
253254
dma_fence_put(f);
254255
if (r)
255256
return r;
@@ -281,7 +282,7 @@ int amdgpu_sync_kfd(struct amdgpu_sync *sync, struct dma_resv *resv)
281282
if (fence_owner != AMDGPU_FENCE_OWNER_KFD)
282283
continue;
283284

284-
r = amdgpu_sync_fence(sync, f);
285+
r = amdgpu_sync_fence(sync, f, GFP_KERNEL);
285286
if (r)
286287
break;
287288
}
@@ -388,7 +389,7 @@ int amdgpu_sync_clone(struct amdgpu_sync *source, struct amdgpu_sync *clone)
388389
hash_for_each_safe(source->fences, i, tmp, e, node) {
389390
f = e->fence;
390391
if (!dma_fence_is_signaled(f)) {
391-
r = amdgpu_sync_fence(clone, f);
392+
r = amdgpu_sync_fence(clone, f, GFP_KERNEL);
392393
if (r)
393394
return r;
394395
} else {

drivers/gpu/drm/amd/amdgpu/amdgpu_sync.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ struct amdgpu_sync {
4747
};
4848

4949
void amdgpu_sync_create(struct amdgpu_sync *sync);
50-
int amdgpu_sync_fence(struct amdgpu_sync *sync, struct dma_fence *f);
50+
int amdgpu_sync_fence(struct amdgpu_sync *sync, struct dma_fence *f,
51+
gfp_t flags);
5152
int amdgpu_sync_resv(struct amdgpu_device *adev, struct amdgpu_sync *sync,
5253
struct dma_resv *resv, enum amdgpu_sync_mode mode,
5354
void *owner);

0 commit comments

Comments
 (0)