Skip to content

Commit 1f0dc9a

Browse files
author
Maarten Lankhorst
committed
drm/ttm: kill off some members to ttm_validate_buffer
This reorders the list to keep track of what buffers are reserved, so previous members are always unreserved. This gets rid of some bookkeeping that's no longer needed, while simplifying the code some. Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
1 parent 58b4d72 commit 1f0dc9a

4 files changed

Lines changed: 50 additions & 97 deletions

File tree

‎drivers/gpu/drm/qxl/qxl_release.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,6 @@ void qxl_release_fence_buffer_objects(struct qxl_release *release)
349349

350350
ttm_bo_add_to_lru(bo);
351351
__ttm_bo_unreserve(bo);
352-
entry->reserved = false;
353352
}
354353
spin_unlock(&glob->lru_lock);
355354
ww_acquire_fini(&release->ticket);

‎drivers/gpu/drm/ttm/ttm_execbuf_util.c‎

Lines changed: 50 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,12 @@
3232
#include <linux/sched.h>
3333
#include <linux/module.h>
3434

35-
static void ttm_eu_backoff_reservation_locked(struct list_head *list)
35+
static void ttm_eu_backoff_reservation_reverse(struct list_head *list,
36+
struct ttm_validate_buffer *entry)
3637
{
37-
struct ttm_validate_buffer *entry;
38-
39-
list_for_each_entry(entry, list, head) {
38+
list_for_each_entry_continue_reverse(entry, list, head) {
4039
struct ttm_buffer_object *bo = entry->bo;
41-
if (!entry->reserved)
42-
continue;
4340

44-
entry->reserved = false;
45-
if (entry->removed) {
46-
ttm_bo_add_to_lru(bo);
47-
entry->removed = false;
48-
}
4941
__ttm_bo_unreserve(bo);
5042
}
5143
}
@@ -56,27 +48,9 @@ static void ttm_eu_del_from_lru_locked(struct list_head *list)
5648

5749
list_for_each_entry(entry, list, head) {
5850
struct ttm_buffer_object *bo = entry->bo;
59-
if (!entry->reserved)
60-
continue;
51+
unsigned put_count = ttm_bo_del_from_lru(bo);
6152

62-
if (!entry->removed) {
63-
entry->put_count = ttm_bo_del_from_lru(bo);
64-
entry->removed = true;
65-
}
66-
}
67-
}
68-
69-
static void ttm_eu_list_ref_sub(struct list_head *list)
70-
{
71-
struct ttm_validate_buffer *entry;
72-
73-
list_for_each_entry(entry, list, head) {
74-
struct ttm_buffer_object *bo = entry->bo;
75-
76-
if (entry->put_count) {
77-
ttm_bo_list_ref_sub(bo, entry->put_count, true);
78-
entry->put_count = 0;
79-
}
53+
ttm_bo_list_ref_sub(bo, put_count, true);
8054
}
8155
}
8256

@@ -91,11 +65,18 @@ void ttm_eu_backoff_reservation(struct ww_acquire_ctx *ticket,
9165

9266
entry = list_first_entry(list, struct ttm_validate_buffer, head);
9367
glob = entry->bo->glob;
68+
9469
spin_lock(&glob->lru_lock);
95-
ttm_eu_backoff_reservation_locked(list);
70+
list_for_each_entry(entry, list, head) {
71+
struct ttm_buffer_object *bo = entry->bo;
72+
73+
ttm_bo_add_to_lru(bo);
74+
__ttm_bo_unreserve(bo);
75+
}
76+
spin_unlock(&glob->lru_lock);
77+
9678
if (ticket)
9779
ww_acquire_fini(ticket);
98-
spin_unlock(&glob->lru_lock);
9980
}
10081
EXPORT_SYMBOL(ttm_eu_backoff_reservation);
10182

@@ -121,85 +102,63 @@ int ttm_eu_reserve_buffers(struct ww_acquire_ctx *ticket,
121102
if (list_empty(list))
122103
return 0;
123104

124-
list_for_each_entry(entry, list, head) {
125-
entry->reserved = false;
126-
entry->put_count = 0;
127-
entry->removed = false;
128-
}
129-
130105
entry = list_first_entry(list, struct ttm_validate_buffer, head);
131106
glob = entry->bo->glob;
132107

133108
if (ticket)
134109
ww_acquire_init(ticket, &reservation_ww_class);
135-
retry:
110+
136111
list_for_each_entry(entry, list, head) {
137112
struct ttm_buffer_object *bo = entry->bo;
138113

139-
/* already slowpath reserved? */
140-
if (entry->reserved)
141-
continue;
142-
143114
ret = __ttm_bo_reserve(bo, intr, (ticket == NULL), true,
144115
ticket);
116+
if (!ret && unlikely(atomic_read(&bo->cpu_writers) > 0)) {
117+
__ttm_bo_unreserve(bo);
145118

146-
if (ret == -EDEADLK) {
147-
/* uh oh, we lost out, drop every reservation and try
148-
* to only reserve this buffer, then start over if
149-
* this succeeds.
150-
*/
151-
BUG_ON(ticket == NULL);
152-
spin_lock(&glob->lru_lock);
153-
ttm_eu_backoff_reservation_locked(list);
154-
spin_unlock(&glob->lru_lock);
155-
ttm_eu_list_ref_sub(list);
156-
157-
if (intr) {
158-
ret = ww_mutex_lock_slow_interruptible(&bo->resv->lock,
159-
ticket);
160-
if (unlikely(ret != 0)) {
161-
if (ret == -EINTR)
162-
ret = -ERESTARTSYS;
163-
goto err_fini;
164-
}
165-
} else
166-
ww_mutex_lock_slow(&bo->resv->lock, ticket);
167-
168-
entry->reserved = true;
169-
if (unlikely(atomic_read(&bo->cpu_writers) > 0)) {
170-
ret = -EBUSY;
171-
goto err;
172-
}
173-
goto retry;
174-
} else if (ret)
175-
goto err;
176-
177-
entry->reserved = true;
178-
if (unlikely(atomic_read(&bo->cpu_writers) > 0)) {
179119
ret = -EBUSY;
180-
goto err;
181120
}
121+
122+
if (!ret)
123+
continue;
124+
125+
/* uh oh, we lost out, drop every reservation and try
126+
* to only reserve this buffer, then start over if
127+
* this succeeds.
128+
*/
129+
ttm_eu_backoff_reservation_reverse(list, entry);
130+
131+
if (ret == -EDEADLK && intr) {
132+
ret = ww_mutex_lock_slow_interruptible(&bo->resv->lock,
133+
ticket);
134+
} else if (ret == -EDEADLK) {
135+
ww_mutex_lock_slow(&bo->resv->lock, ticket);
136+
ret = 0;
137+
}
138+
139+
if (unlikely(ret != 0)) {
140+
if (ret == -EINTR)
141+
ret = -ERESTARTSYS;
142+
if (ticket) {
143+
ww_acquire_done(ticket);
144+
ww_acquire_fini(ticket);
145+
}
146+
return ret;
147+
}
148+
149+
/* move this item to the front of the list,
150+
* forces correct iteration of the loop without keeping track
151+
*/
152+
list_del(&entry->head);
153+
list_add(&entry->head, list);
182154
}
183155

184156
if (ticket)
185157
ww_acquire_done(ticket);
186158
spin_lock(&glob->lru_lock);
187159
ttm_eu_del_from_lru_locked(list);
188160
spin_unlock(&glob->lru_lock);
189-
ttm_eu_list_ref_sub(list);
190161
return 0;
191-
192-
err:
193-
spin_lock(&glob->lru_lock);
194-
ttm_eu_backoff_reservation_locked(list);
195-
spin_unlock(&glob->lru_lock);
196-
ttm_eu_list_ref_sub(list);
197-
err_fini:
198-
if (ticket) {
199-
ww_acquire_done(ticket);
200-
ww_acquire_fini(ticket);
201-
}
202-
return ret;
203162
}
204163
EXPORT_SYMBOL(ttm_eu_reserve_buffers);
205164

@@ -228,7 +187,6 @@ void ttm_eu_fence_buffer_objects(struct ww_acquire_ctx *ticket,
228187
bo->sync_obj = driver->sync_obj_ref(sync_obj);
229188
ttm_bo_add_to_lru(bo);
230189
__ttm_bo_unreserve(bo);
231-
entry->reserved = false;
232190
}
233191
spin_unlock(&glob->lru_lock);
234192
if (ticket)

‎drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,6 @@ static int vmw_bo_to_validate_list(struct vmw_sw_context *sw_context,
346346
++sw_context->cur_val_buf;
347347
val_buf = &vval_buf->base;
348348
val_buf->bo = ttm_bo_reference(bo);
349-
val_buf->reserved = false;
350349
list_add_tail(&val_buf->head, &sw_context->validate_nodes);
351350
vval_buf->validate_as_mob = validate_as_mob;
352351
}

‎include/drm/ttm/ttm_execbuf_util.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@
4848
struct ttm_validate_buffer {
4949
struct list_head head;
5050
struct ttm_buffer_object *bo;
51-
bool reserved;
52-
bool removed;
53-
int put_count;
5451
void *old_sync_obj;
5552
};
5653

0 commit comments

Comments
 (0)