Skip to content

Commit a78a8da

Browse files
Somalapuram AmaranathChristianKoenigAMD
authored andcommitted
drm/ttm: replace busy placement with flags v6
Instead of a list of separate busy placement add flags which indicate that a placement should only be used when there is room or if we need to evict. v2: add missing TTM_PL_FLAG_IDLE for i915 v3: fix auto build test ERROR on drm-tip/drm-tip v4: fix some typos pointed out by checkpatch v5: cleanup some rebase problems with VMWGFX v6: implement some missing VMWGFX functionality pointed out by Zack, rename the flags as suggested by Michel, rebase on drm-tip and adjust XE as well Signed-off-by: Christian König <[email protected]> Signed-off-by: Somalapuram Amaranath <[email protected]> Reviewed-by: Zack Rusin <[email protected]> Reviewed-by: Thomas Zimmermann <[email protected]> Reviewed-by: Thomas Hellström <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 28e5126 commit a78a8da

File tree

18 files changed

+103
-179
lines changed

18 files changed

+103
-179
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,6 @@ void amdgpu_bo_placement_from_domain(struct amdgpu_bo *abo, u32 domain)
220220

221221
placement->num_placement = c;
222222
placement->placement = places;
223-
224-
placement->num_busy_placement = c;
225-
placement->busy_placement = places;
226223
}
227224

228225
/**
@@ -1406,8 +1403,7 @@ vm_fault_t amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
14061403
AMDGPU_GEM_DOMAIN_GTT);
14071404

14081405
/* Avoid costly evictions; only set GTT as a busy placement */
1409-
abo->placement.num_busy_placement = 1;
1410-
abo->placement.busy_placement = &abo->placements[1];
1406+
abo->placements[0].flags |= TTM_PL_FLAG_DESIRED;
14111407

14121408
r = ttm_bo_validate(bo, &abo->placement, &ctx);
14131409
if (unlikely(r == -EBUSY || r == -ERESTARTSYS))

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,23 +102,19 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo,
102102
/* Don't handle scatter gather BOs */
103103
if (bo->type == ttm_bo_type_sg) {
104104
placement->num_placement = 0;
105-
placement->num_busy_placement = 0;
106105
return;
107106
}
108107

109108
/* Object isn't an AMDGPU object so ignore */
110109
if (!amdgpu_bo_is_amdgpu_bo(bo)) {
111110
placement->placement = &placements;
112-
placement->busy_placement = &placements;
113111
placement->num_placement = 1;
114-
placement->num_busy_placement = 1;
115112
return;
116113
}
117114

118115
abo = ttm_to_amdgpu_bo(bo);
119116
if (abo->flags & AMDGPU_GEM_CREATE_DISCARDABLE) {
120117
placement->num_placement = 0;
121-
placement->num_busy_placement = 0;
122118
return;
123119
}
124120

@@ -128,13 +124,13 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo,
128124
case AMDGPU_PL_OA:
129125
case AMDGPU_PL_DOORBELL:
130126
placement->num_placement = 0;
131-
placement->num_busy_placement = 0;
132127
return;
133128

134129
case TTM_PL_VRAM:
135130
if (!adev->mman.buffer_funcs_enabled) {
136131
/* Move to system memory */
137132
amdgpu_bo_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_CPU);
133+
138134
} else if (!amdgpu_gmc_vram_full_visible(&adev->gmc) &&
139135
!(abo->flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) &&
140136
amdgpu_bo_in_cpu_visible_vram(abo)) {
@@ -149,8 +145,7 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo,
149145
AMDGPU_GEM_DOMAIN_CPU);
150146
abo->placements[0].fpfn = adev->gmc.visible_vram_size >> PAGE_SHIFT;
151147
abo->placements[0].lpfn = 0;
152-
abo->placement.busy_placement = &abo->placements[1];
153-
abo->placement.num_busy_placement = 1;
148+
abo->placements[0].flags |= TTM_PL_FLAG_DESIRED;
154149
} else {
155150
/* Move to GTT memory */
156151
amdgpu_bo_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_GTT |
@@ -967,8 +962,6 @@ int amdgpu_ttm_alloc_gart(struct ttm_buffer_object *bo)
967962
/* allocate GART space */
968963
placement.num_placement = 1;
969964
placement.placement = &placements;
970-
placement.num_busy_placement = 1;
971-
placement.busy_placement = &placements;
972965
placements.fpfn = 0;
973966
placements.lpfn = adev->gmc.gart_size >> PAGE_SHIFT;
974967
placements.mem_type = TTM_PL_TT;

drivers/gpu/drm/drm_gem_vram_helper.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ static void drm_gem_vram_placement(struct drm_gem_vram_object *gbo,
147147
invariant_flags = TTM_PL_FLAG_TOPDOWN;
148148

149149
gbo->placement.placement = gbo->placements;
150-
gbo->placement.busy_placement = gbo->placements;
151150

152151
if (pl_flag & DRM_GEM_VRAM_PL_FLAG_VRAM) {
153152
gbo->placements[c].mem_type = TTM_PL_VRAM;
@@ -160,7 +159,6 @@ static void drm_gem_vram_placement(struct drm_gem_vram_object *gbo,
160159
}
161160

162161
gbo->placement.num_placement = c;
163-
gbo->placement.num_busy_placement = c;
164162

165163
for (i = 0; i < c; ++i) {
166164
gbo->placements[i].fpfn = 0;

drivers/gpu/drm/i915/gem/i915_gem_ttm.c

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ static const struct ttm_place sys_placement_flags = {
6565
static struct ttm_placement i915_sys_placement = {
6666
.num_placement = 1,
6767
.placement = &sys_placement_flags,
68-
.num_busy_placement = 1,
69-
.busy_placement = &sys_placement_flags,
7068
};
7169

7270
/**
@@ -157,32 +155,28 @@ i915_ttm_place_from_region(const struct intel_memory_region *mr,
157155

158156
static void
159157
i915_ttm_placement_from_obj(const struct drm_i915_gem_object *obj,
160-
struct ttm_place *requested,
161-
struct ttm_place *busy,
158+
struct ttm_place *places,
162159
struct ttm_placement *placement)
163160
{
164161
unsigned int num_allowed = obj->mm.n_placements;
165162
unsigned int flags = obj->flags;
166163
unsigned int i;
167164

168-
placement->num_placement = 1;
165+
places[0].flags |= TTM_PL_FLAG_DESIRED;
169166
i915_ttm_place_from_region(num_allowed ? obj->mm.placements[0] :
170-
obj->mm.region, requested, obj->bo_offset,
167+
obj->mm.region, &places[0], obj->bo_offset,
171168
obj->base.size, flags);
172169

173170
/* Cache this on object? */
174-
placement->num_busy_placement = num_allowed;
175-
for (i = 0; i < placement->num_busy_placement; ++i)
176-
i915_ttm_place_from_region(obj->mm.placements[i], busy + i,
177-
obj->bo_offset, obj->base.size, flags);
178-
179-
if (num_allowed == 0) {
180-
*busy = *requested;
181-
placement->num_busy_placement = 1;
171+
for (i = 0; i < num_allowed; ++i) {
172+
i915_ttm_place_from_region(obj->mm.placements[i],
173+
&places[i + 1], obj->bo_offset,
174+
obj->base.size, flags);
175+
places[i + 1].flags |= TTM_PL_FLAG_FALLBACK;
182176
}
183177

184-
placement->placement = requested;
185-
placement->busy_placement = busy;
178+
placement->num_placement = num_allowed + 1;
179+
placement->placement = places;
186180
}
187181

188182
static int i915_ttm_tt_shmem_populate(struct ttm_device *bdev,
@@ -789,7 +783,8 @@ static int __i915_ttm_get_pages(struct drm_i915_gem_object *obj,
789783
int ret;
790784

791785
/* First try only the requested placement. No eviction. */
792-
real_num_busy = fetch_and_zero(&placement->num_busy_placement);
786+
real_num_busy = placement->num_placement;
787+
placement->num_placement = 1;
793788
ret = ttm_bo_validate(bo, placement, &ctx);
794789
if (ret) {
795790
ret = i915_ttm_err_to_gem(ret);
@@ -805,7 +800,7 @@ static int __i915_ttm_get_pages(struct drm_i915_gem_object *obj,
805800
* If the initial attempt fails, allow all accepted placements,
806801
* evicting if necessary.
807802
*/
808-
placement->num_busy_placement = real_num_busy;
803+
placement->num_placement = real_num_busy;
809804
ret = ttm_bo_validate(bo, placement, &ctx);
810805
if (ret)
811806
return i915_ttm_err_to_gem(ret);
@@ -839,7 +834,7 @@ static int __i915_ttm_get_pages(struct drm_i915_gem_object *obj,
839834

840835
static int i915_ttm_get_pages(struct drm_i915_gem_object *obj)
841836
{
842-
struct ttm_place requested, busy[I915_TTM_MAX_PLACEMENTS];
837+
struct ttm_place places[I915_TTM_MAX_PLACEMENTS + 1];
843838
struct ttm_placement placement;
844839

845840
/* restricted by sg_alloc_table */
@@ -849,7 +844,7 @@ static int i915_ttm_get_pages(struct drm_i915_gem_object *obj)
849844
GEM_BUG_ON(obj->mm.n_placements > I915_TTM_MAX_PLACEMENTS);
850845

851846
/* Move to the requested placement. */
852-
i915_ttm_placement_from_obj(obj, &requested, busy, &placement);
847+
i915_ttm_placement_from_obj(obj, places, &placement);
853848

854849
return __i915_ttm_get_pages(obj, &placement);
855850
}
@@ -879,9 +874,7 @@ static int __i915_ttm_migrate(struct drm_i915_gem_object *obj,
879874
i915_ttm_place_from_region(mr, &requested, obj->bo_offset,
880875
obj->base.size, flags);
881876
placement.num_placement = 1;
882-
placement.num_busy_placement = 1;
883877
placement.placement = &requested;
884-
placement.busy_placement = &requested;
885878

886879
ret = __i915_ttm_get_pages(obj, &placement);
887880
if (ret)

drivers/gpu/drm/loongson/lsdc_ttm.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ static void lsdc_bo_set_placement(struct lsdc_bo *lbo, u32 domain)
5454
pflags |= TTM_PL_FLAG_TOPDOWN;
5555

5656
lbo->placement.placement = lbo->placements;
57-
lbo->placement.busy_placement = lbo->placements;
5857

5958
if (domain & LSDC_GEM_DOMAIN_VRAM) {
6059
lbo->placements[c].mem_type = TTM_PL_VRAM;
@@ -77,7 +76,6 @@ static void lsdc_bo_set_placement(struct lsdc_bo *lbo, u32 domain)
7776
}
7877

7978
lbo->placement.num_placement = c;
80-
lbo->placement.num_busy_placement = c;
8179

8280
for (i = 0; i < c; ++i) {
8381
lbo->placements[i].fpfn = 0;

drivers/gpu/drm/nouveau/nouveau_bo.c

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -403,27 +403,6 @@ nouveau_bo_new(struct nouveau_cli *cli, u64 size, int align,
403403
return 0;
404404
}
405405

406-
static void
407-
set_placement_list(struct ttm_place *pl, unsigned *n, uint32_t domain)
408-
{
409-
*n = 0;
410-
411-
if (domain & NOUVEAU_GEM_DOMAIN_VRAM) {
412-
pl[*n].mem_type = TTM_PL_VRAM;
413-
pl[*n].flags = 0;
414-
(*n)++;
415-
}
416-
if (domain & NOUVEAU_GEM_DOMAIN_GART) {
417-
pl[*n].mem_type = TTM_PL_TT;
418-
pl[*n].flags = 0;
419-
(*n)++;
420-
}
421-
if (domain & NOUVEAU_GEM_DOMAIN_CPU) {
422-
pl[*n].mem_type = TTM_PL_SYSTEM;
423-
pl[(*n)++].flags = 0;
424-
}
425-
}
426-
427406
static void
428407
set_placement_range(struct nouveau_bo *nvbo, uint32_t domain)
429408
{
@@ -451,26 +430,39 @@ set_placement_range(struct nouveau_bo *nvbo, uint32_t domain)
451430
nvbo->placements[i].fpfn = fpfn;
452431
nvbo->placements[i].lpfn = lpfn;
453432
}
454-
for (i = 0; i < nvbo->placement.num_busy_placement; ++i) {
455-
nvbo->busy_placements[i].fpfn = fpfn;
456-
nvbo->busy_placements[i].lpfn = lpfn;
457-
}
458433
}
459434
}
460435

461436
void
462437
nouveau_bo_placement_set(struct nouveau_bo *nvbo, uint32_t domain,
463438
uint32_t busy)
464439
{
465-
struct ttm_placement *pl = &nvbo->placement;
440+
unsigned int *n = &nvbo->placement.num_placement;
441+
struct ttm_place *pl = nvbo->placements;
466442

467-
pl->placement = nvbo->placements;
468-
set_placement_list(nvbo->placements, &pl->num_placement, domain);
443+
domain |= busy;
469444

470-
pl->busy_placement = nvbo->busy_placements;
471-
set_placement_list(nvbo->busy_placements, &pl->num_busy_placement,
472-
domain | busy);
445+
*n = 0;
446+
if (domain & NOUVEAU_GEM_DOMAIN_VRAM) {
447+
pl[*n].mem_type = TTM_PL_VRAM;
448+
pl[*n].flags = busy & NOUVEAU_GEM_DOMAIN_VRAM ?
449+
TTM_PL_FLAG_FALLBACK : 0;
450+
(*n)++;
451+
}
452+
if (domain & NOUVEAU_GEM_DOMAIN_GART) {
453+
pl[*n].mem_type = TTM_PL_TT;
454+
pl[*n].flags = busy & NOUVEAU_GEM_DOMAIN_GART ?
455+
TTM_PL_FLAG_FALLBACK : 0;
456+
(*n)++;
457+
}
458+
if (domain & NOUVEAU_GEM_DOMAIN_CPU) {
459+
pl[*n].mem_type = TTM_PL_SYSTEM;
460+
pl[*n].flags = busy & NOUVEAU_GEM_DOMAIN_CPU ?
461+
TTM_PL_FLAG_FALLBACK : 0;
462+
(*n)++;
463+
}
473464

465+
nvbo->placement.placement = nvbo->placements;
474466
set_placement_range(nvbo, domain);
475467
}
476468

@@ -1313,11 +1305,6 @@ vm_fault_t nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo)
13131305
nvbo->placements[i].lpfn = mappable;
13141306
}
13151307

1316-
for (i = 0; i < nvbo->placement.num_busy_placement; ++i) {
1317-
nvbo->busy_placements[i].fpfn = 0;
1318-
nvbo->busy_placements[i].lpfn = mappable;
1319-
}
1320-
13211308
nouveau_bo_placement_set(nvbo, NOUVEAU_GEM_DOMAIN_VRAM, 0);
13221309
}
13231310

drivers/gpu/drm/nouveau/nouveau_bo.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ struct nouveau_bo {
1515
struct ttm_placement placement;
1616
u32 valid_domains;
1717
struct ttm_place placements[3];
18-
struct ttm_place busy_placements[3];
1918
bool force_coherent;
2019
struct ttm_bo_kmap_obj kmap;
2120
struct list_head head;

drivers/gpu/drm/qxl/qxl_object.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ void qxl_ttm_placement_from_domain(struct qxl_bo *qbo, u32 domain)
6666
pflag |= TTM_PL_FLAG_TOPDOWN;
6767

6868
qbo->placement.placement = qbo->placements;
69-
qbo->placement.busy_placement = qbo->placements;
7069
if (domain == QXL_GEM_DOMAIN_VRAM) {
7170
qbo->placements[c].mem_type = TTM_PL_VRAM;
7271
qbo->placements[c++].flags = pflag;
@@ -86,7 +85,6 @@ void qxl_ttm_placement_from_domain(struct qxl_bo *qbo, u32 domain)
8685
qbo->placements[c++].flags = 0;
8786
}
8887
qbo->placement.num_placement = c;
89-
qbo->placement.num_busy_placement = c;
9088
for (i = 0; i < c; ++i) {
9189
qbo->placements[i].fpfn = 0;
9290
qbo->placements[i].lpfn = 0;

drivers/gpu/drm/qxl/qxl_ttm.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ static void qxl_evict_flags(struct ttm_buffer_object *bo,
6060

6161
if (!qxl_ttm_bo_is_qxl_bo(bo)) {
6262
placement->placement = &placements;
63-
placement->busy_placement = &placements;
6463
placement->num_placement = 1;
65-
placement->num_busy_placement = 1;
6664
return;
6765
}
6866
qbo = to_qxl_bo(bo);

drivers/gpu/drm/radeon/radeon_object.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain)
7878
u32 c = 0, i;
7979

8080
rbo->placement.placement = rbo->placements;
81-
rbo->placement.busy_placement = rbo->placements;
8281
if (domain & RADEON_GEM_DOMAIN_VRAM) {
8382
/* Try placing BOs which don't need CPU access outside of the
8483
* CPU accessible part of VRAM
@@ -114,7 +113,6 @@ void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain)
114113
}
115114

116115
rbo->placement.num_placement = c;
117-
rbo->placement.num_busy_placement = c;
118116

119117
for (i = 0; i < c; ++i) {
120118
if ((rbo->flags & RADEON_GEM_CPU_ACCESS) &&

drivers/gpu/drm/radeon/radeon_ttm.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ static void radeon_evict_flags(struct ttm_buffer_object *bo,
9292

9393
if (!radeon_ttm_bo_is_radeon_bo(bo)) {
9494
placement->placement = &placements;
95-
placement->busy_placement = &placements;
9695
placement->num_placement = 1;
97-
placement->num_busy_placement = 1;
9896
return;
9997
}
10098
rbo = container_of(bo, struct radeon_bo, tbo);
@@ -114,15 +112,11 @@ static void radeon_evict_flags(struct ttm_buffer_object *bo,
114112
*/
115113
radeon_ttm_placement_from_domain(rbo, RADEON_GEM_DOMAIN_VRAM |
116114
RADEON_GEM_DOMAIN_GTT);
117-
rbo->placement.num_busy_placement = 0;
118115
for (i = 0; i < rbo->placement.num_placement; i++) {
119116
if (rbo->placements[i].mem_type == TTM_PL_VRAM) {
120117
if (rbo->placements[i].fpfn < fpfn)
121118
rbo->placements[i].fpfn = fpfn;
122-
} else {
123-
rbo->placement.busy_placement =
124-
&rbo->placements[i];
125-
rbo->placement.num_busy_placement = 1;
119+
rbo->placements[0].flags |= TTM_PL_FLAG_DESIRED;
126120
}
127121
}
128122
} else

drivers/gpu/drm/radeon/radeon_uvd.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ void radeon_uvd_force_into_uvd_segment(struct radeon_bo *rbo,
324324
rbo->placements[1].fpfn += (256 * 1024 * 1024) >> PAGE_SHIFT;
325325
rbo->placements[1].lpfn += (256 * 1024 * 1024) >> PAGE_SHIFT;
326326
rbo->placement.num_placement++;
327-
rbo->placement.num_busy_placement++;
328327
}
329328

330329
void radeon_uvd_free_handles(struct radeon_device *rdev, struct drm_file *filp)

0 commit comments

Comments
 (0)