Skip to content

Commit 39f7f69

Browse files
ChristianKoenigAMDalexdeucher
authored andcommitted
drm/amdgpu: add bo_list iterators
Add helpers to iterate over all entries in a bo_list. Signed-off-by: Christian König <christian.koenig@amd.com> Reviewed-by: Chunming Zhou <david1.zhou@amd.com> Acked-by: Huang Rui <ray.huang@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent a0f2084 commit 39f7f69

3 files changed

Lines changed: 43 additions & 39 deletions

File tree

‎drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ static int amdgpu_bo_list_set(struct amdgpu_device *adev,
4343

4444
static void amdgpu_bo_list_release_rcu(struct kref *ref)
4545
{
46-
unsigned i;
4746
struct amdgpu_bo_list *list = container_of(ref, struct amdgpu_bo_list,
4847
refcount);
48+
struct amdgpu_bo_list_entry *e;
4949

50-
for (i = 0; i < list->num_entries; ++i)
51-
amdgpu_bo_unref(&list->array[i].robj);
50+
amdgpu_bo_list_for_each_entry(e, list)
51+
amdgpu_bo_unref(&e->robj);
5252

5353
kvfree(list->array);
5454
kfree_rcu(list, rhead);
@@ -103,6 +103,7 @@ static int amdgpu_bo_list_set(struct amdgpu_device *adev,
103103
struct amdgpu_bo *oa_obj = adev->gds.oa_gfx_bo;
104104

105105
unsigned last_entry = 0, first_userptr = num_entries;
106+
struct amdgpu_bo_list_entry *e;
106107
uint64_t total_size = 0;
107108
unsigned i;
108109
int r;
@@ -156,7 +157,7 @@ static int amdgpu_bo_list_set(struct amdgpu_device *adev,
156157
trace_amdgpu_bo_list_set(list, entry->robj);
157158
}
158159

159-
for (i = 0; i < list->num_entries; ++i)
160+
amdgpu_bo_list_for_each_entry(e, list)
160161
amdgpu_bo_unref(&list->array[i].robj);
161162

162163
kvfree(list->array);
@@ -201,6 +202,7 @@ void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
201202
* concatenated in descending order.
202203
*/
203204
struct list_head bucket[AMDGPU_BO_LIST_NUM_BUCKETS];
205+
struct amdgpu_bo_list_entry *e;
204206
unsigned i;
205207

206208
for (i = 0; i < AMDGPU_BO_LIST_NUM_BUCKETS; i++)
@@ -211,14 +213,13 @@ void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
211213
* in the list, the sort mustn't change the ordering of buffers
212214
* with the same priority, i.e. it must be stable.
213215
*/
214-
for (i = 0; i < list->num_entries; i++) {
215-
unsigned priority = list->array[i].priority;
216+
amdgpu_bo_list_for_each_entry(e, list) {
217+
unsigned priority = e->priority;
216218

217-
if (!list->array[i].robj->parent)
218-
list_add_tail(&list->array[i].tv.head,
219-
&bucket[priority]);
219+
if (!e->robj->parent)
220+
list_add_tail(&e->tv.head, &bucket[priority]);
220221

221-
list->array[i].user_pages = NULL;
222+
e->user_pages = NULL;
222223
}
223224

224225
/* Connect the sorted buckets in the output list. */

‎drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,14 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev,
6565
unsigned num_entries,
6666
struct amdgpu_bo_list **list);
6767

68+
#define amdgpu_bo_list_for_each_entry(e, list) \
69+
for (e = &(list)->array[0]; \
70+
e != &(list)->array[(list)->num_entries]; \
71+
++e)
72+
73+
#define amdgpu_bo_list_for_each_userptr_entry(e, list) \
74+
for (e = &(list)->array[(list)->first_userptr]; \
75+
e != &(list)->array[(list)->num_entries]; \
76+
++e)
77+
6878
#endif

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

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -563,10 +563,10 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
563563
struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
564564
struct amdgpu_bo_list_entry *e;
565565
struct list_head duplicates;
566-
unsigned i, tries = 10;
567566
struct amdgpu_bo *gds;
568567
struct amdgpu_bo *gws;
569568
struct amdgpu_bo *oa;
569+
unsigned tries = 10;
570570
int r;
571571

572572
INIT_LIST_HEAD(&p->validated);
@@ -596,7 +596,6 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
596596

597597
while (1) {
598598
struct list_head need_pages;
599-
unsigned i;
600599

601600
r = ttm_eu_reserve_buffers(&p->ticket, &p->validated, true,
602601
&duplicates);
@@ -611,12 +610,8 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
611610
break;
612611

613612
INIT_LIST_HEAD(&need_pages);
614-
for (i = p->bo_list->first_userptr;
615-
i < p->bo_list->num_entries; ++i) {
616-
struct amdgpu_bo *bo;
617-
618-
e = &p->bo_list->array[i];
619-
bo = e->robj;
613+
amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
614+
struct amdgpu_bo *bo = e->robj;
620615

621616
if (amdgpu_ttm_tt_userptr_invalidated(bo->tbo.ttm,
622617
&e->user_invalidated) && e->user_pages) {
@@ -710,16 +705,14 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
710705

711706
if (p->bo_list) {
712707
struct amdgpu_vm *vm = &fpriv->vm;
713-
unsigned i;
708+
struct amdgpu_bo_list_entry *e;
714709

715710
gds = p->bo_list->gds_obj;
716711
gws = p->bo_list->gws_obj;
717712
oa = p->bo_list->oa_obj;
718-
for (i = 0; i < p->bo_list->num_entries; i++) {
719-
struct amdgpu_bo *bo = p->bo_list->array[i].robj;
720713

721-
p->bo_list->array[i].bo_va = amdgpu_vm_bo_find(vm, bo);
722-
}
714+
amdgpu_bo_list_for_each_entry(e, p->bo_list)
715+
e->bo_va = amdgpu_vm_bo_find(vm, e->robj);
723716
} else {
724717
gds = p->adev->gds.gds_gfx_bo;
725718
gws = p->adev->gds.gws_gfx_bo;
@@ -753,10 +746,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
753746
error_free_pages:
754747

755748
if (p->bo_list) {
756-
for (i = p->bo_list->first_userptr;
757-
i < p->bo_list->num_entries; ++i) {
758-
e = &p->bo_list->array[i];
759-
749+
amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
760750
if (!e->user_pages)
761751
continue;
762752

@@ -830,7 +820,7 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
830820
struct amdgpu_vm *vm = &fpriv->vm;
831821
struct amdgpu_bo_va *bo_va;
832822
struct amdgpu_bo *bo;
833-
int i, r;
823+
int r;
834824

835825
r = amdgpu_vm_clear_freed(adev, vm, NULL);
836826
if (r)
@@ -861,15 +851,17 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
861851
}
862852

863853
if (p->bo_list) {
864-
for (i = 0; i < p->bo_list->num_entries; i++) {
854+
struct amdgpu_bo_list_entry *e;
855+
856+
amdgpu_bo_list_for_each_entry(e, p->bo_list) {
865857
struct dma_fence *f;
866858

867859
/* ignore duplicates */
868-
bo = p->bo_list->array[i].robj;
860+
bo = e->robj;
869861
if (!bo)
870862
continue;
871863

872-
bo_va = p->bo_list->array[i].bo_va;
864+
bo_va = e->bo_va;
873865
if (bo_va == NULL)
874866
continue;
875867

@@ -898,14 +890,15 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
898890
return r;
899891

900892
if (amdgpu_vm_debug && p->bo_list) {
893+
struct amdgpu_bo_list_entry *e;
894+
901895
/* Invalidate all BOs to test for userspace bugs */
902-
for (i = 0; i < p->bo_list->num_entries; i++) {
896+
amdgpu_bo_list_for_each_entry(e, p->bo_list) {
903897
/* ignore duplicates */
904-
bo = p->bo_list->array[i].robj;
905-
if (!bo)
898+
if (!e->robj)
906899
continue;
907900

908-
amdgpu_vm_bo_invalidate(adev, bo, false);
901+
amdgpu_vm_bo_invalidate(adev, e->robj, false);
909902
}
910903
}
911904

@@ -1225,16 +1218,16 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
12251218
struct drm_sched_entity *entity = &p->ctx->rings[ring->idx].entity;
12261219
enum drm_sched_priority priority;
12271220
struct amdgpu_job *job;
1228-
unsigned i;
12291221
uint64_t seq;
12301222

12311223
int r;
12321224

12331225
amdgpu_mn_lock(p->mn);
12341226
if (p->bo_list) {
1235-
for (i = p->bo_list->first_userptr;
1236-
i < p->bo_list->num_entries; ++i) {
1237-
struct amdgpu_bo *bo = p->bo_list->array[i].robj;
1227+
struct amdgpu_bo_list_entry *e;
1228+
1229+
amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
1230+
struct amdgpu_bo *bo = e->robj;
12381231

12391232
if (amdgpu_ttm_tt_userptr_needs_pages(bo->tbo.ttm)) {
12401233
amdgpu_mn_unlock(p->mn);

0 commit comments

Comments
 (0)