Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit ca6c1e2

Browse files
drm/amdgpu: use the new drm_exec object for CS v3
Use the new component here as well and remove the old handling. v2: drop dupplicate handling v3: fix memory leak pointed out by Tatsuyuki Signed-off-by: Christian König <[email protected]> Acked-by: Alex Deucher <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 2acc73f commit ca6c1e2

File tree

7 files changed

+115
-204
lines changed

7 files changed

+115
-204
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353

5454
#include <drm/ttm/ttm_bo.h>
5555
#include <drm/ttm/ttm_placement.h>
56-
#include <drm/ttm/ttm_execbuf_util.h>
5756

5857
#include <drm/amdgpu_drm.h>
5958
#include <drm/drm_gem.h>

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

Lines changed: 20 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
* Christian König <[email protected]>
2929
*/
3030

31+
#include <linux/sort.h>
3132
#include <linux/uaccess.h>
3233

3334
#include "amdgpu.h"
@@ -50,13 +51,20 @@ static void amdgpu_bo_list_free(struct kref *ref)
5051
refcount);
5152
struct amdgpu_bo_list_entry *e;
5253

53-
amdgpu_bo_list_for_each_entry(e, list) {
54-
struct amdgpu_bo *bo = ttm_to_amdgpu_bo(e->tv.bo);
54+
amdgpu_bo_list_for_each_entry(e, list)
55+
amdgpu_bo_unref(&e->bo);
56+
call_rcu(&list->rhead, amdgpu_bo_list_free_rcu);
57+
}
5558

56-
amdgpu_bo_unref(&bo);
57-
}
59+
static int amdgpu_bo_list_entry_cmp(const void *_a, const void *_b)
60+
{
61+
const struct amdgpu_bo_list_entry *a = _a, *b = _b;
5862

59-
call_rcu(&list->rhead, amdgpu_bo_list_free_rcu);
63+
if (a->priority > b->priority)
64+
return 1;
65+
if (a->priority < b->priority)
66+
return -1;
67+
return 0;
6068
}
6169

6270
int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp,
@@ -118,7 +126,7 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp,
118126

119127
entry->priority = min(info[i].bo_priority,
120128
AMDGPU_BO_LIST_MAX_PRIORITY);
121-
entry->tv.bo = &bo->tbo;
129+
entry->bo = bo;
122130

123131
if (bo->preferred_domains == AMDGPU_GEM_DOMAIN_GDS)
124132
list->gds_obj = bo;
@@ -133,6 +141,8 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp,
133141

134142
list->first_userptr = first_userptr;
135143
list->num_entries = num_entries;
144+
sort(array, last_entry, sizeof(struct amdgpu_bo_list_entry),
145+
amdgpu_bo_list_entry_cmp, NULL);
136146

137147
trace_amdgpu_cs_bo_status(list->num_entries, total_size);
138148

@@ -141,16 +151,10 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp,
141151
return 0;
142152

143153
error_free:
144-
for (i = 0; i < last_entry; ++i) {
145-
struct amdgpu_bo *bo = ttm_to_amdgpu_bo(array[i].tv.bo);
146-
147-
amdgpu_bo_unref(&bo);
148-
}
149-
for (i = first_userptr; i < num_entries; ++i) {
150-
struct amdgpu_bo *bo = ttm_to_amdgpu_bo(array[i].tv.bo);
151-
152-
amdgpu_bo_unref(&bo);
153-
}
154+
for (i = 0; i < last_entry; ++i)
155+
amdgpu_bo_unref(&array[i].bo);
156+
for (i = first_userptr; i < num_entries; ++i)
157+
amdgpu_bo_unref(&array[i].bo);
154158
kvfree(list);
155159
return r;
156160

@@ -182,41 +186,6 @@ int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
182186
return -ENOENT;
183187
}
184188

185-
void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
186-
struct list_head *validated)
187-
{
188-
/* This is based on the bucket sort with O(n) time complexity.
189-
* An item with priority "i" is added to bucket[i]. The lists are then
190-
* concatenated in descending order.
191-
*/
192-
struct list_head bucket[AMDGPU_BO_LIST_NUM_BUCKETS];
193-
struct amdgpu_bo_list_entry *e;
194-
unsigned i;
195-
196-
for (i = 0; i < AMDGPU_BO_LIST_NUM_BUCKETS; i++)
197-
INIT_LIST_HEAD(&bucket[i]);
198-
199-
/* Since buffers which appear sooner in the relocation list are
200-
* likely to be used more often than buffers which appear later
201-
* in the list, the sort mustn't change the ordering of buffers
202-
* with the same priority, i.e. it must be stable.
203-
*/
204-
amdgpu_bo_list_for_each_entry(e, list) {
205-
struct amdgpu_bo *bo = ttm_to_amdgpu_bo(e->tv.bo);
206-
unsigned priority = e->priority;
207-
208-
if (!bo->parent)
209-
list_add_tail(&e->tv.head, &bucket[priority]);
210-
211-
e->user_pages = NULL;
212-
e->range = NULL;
213-
}
214-
215-
/* Connect the sorted buckets in the output list. */
216-
for (i = 0; i < AMDGPU_BO_LIST_NUM_BUCKETS; i++)
217-
list_splice(&bucket[i], validated);
218-
}
219-
220189
void amdgpu_bo_list_put(struct amdgpu_bo_list *list)
221190
{
222191
kref_put(&list->refcount, amdgpu_bo_list_free);

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#ifndef __AMDGPU_BO_LIST_H__
2424
#define __AMDGPU_BO_LIST_H__
2525

26-
#include <drm/ttm/ttm_execbuf_util.h>
2726
#include <drm/amdgpu_drm.h>
2827

2928
struct hmm_range;
@@ -36,7 +35,7 @@ struct amdgpu_bo_va;
3635
struct amdgpu_fpriv;
3736

3837
struct amdgpu_bo_list_entry {
39-
struct ttm_validate_buffer tv;
38+
struct amdgpu_bo *bo;
4039
struct amdgpu_bo_va *bo_va;
4140
uint32_t priority;
4241
struct page **user_pages;
@@ -60,8 +59,6 @@ struct amdgpu_bo_list {
6059

6160
int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
6261
struct amdgpu_bo_list **result);
63-
void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
64-
struct list_head *validated);
6562
void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
6663
int amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in,
6764
struct drm_amdgpu_bo_list_entry **info_param);

0 commit comments

Comments
 (0)