drm/ttm: improve idle/busy handling v5
Subsystems (4)
PATCH 1/2 drm/ttm: improve idle/busy handling v5
Previously we would never try to move a BO into the preferred placements when it ever landed in a busy placement since those were considered compatible.
Rework the whole handling and finally unify the idle and busy handling. ttm_bo_validate() is now responsible to try idle placement first and then use the busy placement if that didn't worked.
Drawback is that we now always try the idle placement first for each validation which might cause some additional CPU overhead on overcommit.
v2: fix kerneldoc warning and coding style
v3: take care of XE as well
v4: keep the ttm_bo_mem_space functionality as it is for now, only add
new handling for ttm_bo_validate as suggested by Thomas
v5: fix bug pointed out by Matthew
--- drivers/gpu/drm/ttm/ttm_bo.c | 231 +++++++++++++---------------- drivers/gpu/drm/ttm/ttm_resource.c | 16 +- include/drm/ttm/ttm_resource.h | 3 +- 3 files changed, 121 insertions(+), 129 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +107 -124
@@ -724,64 +724,36 @@ static int ttm_bo_add_move_fence(struct ttm_buffer_object *bo,return ret; } -/* -* Repeatedly evict memory from the LRU for @mem_type until we create enough -* space, or we've evicted everything and there isn't enough space. -*/ -static int ttm_bo_mem_force_space (struct ttm_buffer_object *bo, -const struct ttm_place *place, -struct ttm_resource **mem, -struct ttm_operation_ctx *ctx) -{ -struct ttm_device *bdev = bo->bdev; -struct ttm_resource_manager *man; -struct ww_acquire_ctx *ticket; -int ret; - - man =ttm_manager_type (bdev, place->mem_type); - ticket =dma_resv_locking_ctx (bo->base.resv); -do { - ret =ttm_resource_alloc (bo, place, mem); -if (likely (!ret)) -break ; -if (unlikely (ret != -ENOSPC )) -return ret; - ret =ttm_mem_evict_first (bdev, man, place, ctx, - ticket); -if (unlikely (ret !=0 )) -return ret; - }while (1 ); - -return ttm_bo_add_move_fence (bo, man, *mem, ctx->no_wait_gpu); -} -/** -* ttm_bo_mem_space +* ttm_bo_alloc_resource - Allocate backing store for a BO * -* @bo: Pointer to a struct ttm_buffer_object. the data of which -* we want to allocate space for. -* @placement: Proposed new placement for the buffer object. -* @mem: A struct ttm_resource. +* @bo: Pointer to a struct ttm_buffer_object of which we want a resource for +* @placement: Proposed new placement for the buffer object * @ctx: if and how to sleep, lock buffers and alloc memory +* @force_space: If we should evict buffers to force space +* @res: The resulting struct ttm_resource. * -* Allocate memory space for the buffer object pointed to by @bo, using -* the placement flags in @placement, potentially evicting other idle buffer objects. -* This function may sleep while waiting for space to become available. +* Allocates a resource for the buffer object pointed to by @bo, using the +* placement flags in @placement, potentially evicting other buffer objects when +* @force_space is true. +* This function may sleep while waiting for resources to become available. * Returns: -* -EBUSY: No space available (only if no_wait == 1). +* -EBUSY: No space available (only if no_wait == true). * -ENOSPC: Could not allocate space for the buffer object, either due to * fragmentation or concurrent allocators. * -ERESTARTSYS: An interruptible sleep was interrupted by a signal. */ -int ttm_bo_mem_space (struct ttm_buffer_object *bo, -struct ttm_placement *placement, -struct ttm_resource **mem, -struct ttm_operation_ctx *ctx) +static int ttm_bo_alloc_resource (struct ttm_buffer_object *bo, +struct ttm_placement *placement, +struct ttm_operation_ctx *ctx, +bool force_space, +struct ttm_resource **res) {struct ttm_device *bdev = bo->bdev; -bool type_found = false; +struct ww_acquire_ctx *ticket;int i, ret; + ticket =dma_resv_locking_ctx (bo->base.resv); ret =dma_resv_reserve_fences (bo->base.resv,1 );if (unlikely (ret))return ret;
@@ -790,98 +762,73 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,const struct ttm_place *place = &placement->placement[i];struct ttm_resource_manager *man; -if (place->flags &TTM_PL_FLAG_FALLBACK ) -continue ; - man =ttm_manager_type (bdev, place->mem_type);if (!man || !ttm_resource_manager_used (man))continue ; - type_found = true; - ret =ttm_resource_alloc (bo, place, mem); -if (ret == -ENOSPC ) +if (place->flags & (force_space ?TTM_PL_FLAG_DESIRED : +TTM_PL_FLAG_FALLBACK )) +continue ; + +do { + ret =ttm_resource_alloc (bo, place, res); +if (unlikely (ret && ret != -ENOSPC )) +return ret; +if (likely (!ret) || !force_space) +break ; + + ret =ttm_mem_evict_first (bdev, man, place, ctx, + ticket); +if (unlikely (ret == -EBUSY )) +break ; +if (unlikely (ret)) +return ret; + }while (1 ); +if (ret)continue ; -if (unlikely (ret)) - goto error; - ret =ttm_bo_add_move_fence (bo, man, *mem, ctx->no_wait_gpu); + ret =ttm_bo_add_move_fence (bo, man, *res, ctx->no_wait_gpu);if (unlikely (ret)) { -ttm_resource_free (bo, mem); +ttm_resource_free (bo, res);if (ret == -EBUSY )continue ; - goto error; +return ret; }return 0 ; } -for (i =0 ; i < placement->num_placement; ++i) { -const struct ttm_place *place = &placement->placement[i]; -struct ttm_resource_manager *man; - -if (place->flags &TTM_PL_FLAG_DESIRED ) -continue ; - - man =ttm_manager_type (bdev, place->mem_type); -if (!man || !ttm_resource_manager_used (man)) -continue ; - - type_found = true; - ret =ttm_bo_mem_force_space (bo, place, mem, ctx); -if (likely (!ret)) -return 0 ; - -if (ret && ret != -EBUSY ) - goto error; - } - - ret = -ENOSPC ; -if (!type_found) { -pr_err (TTM_PFX "No compatible memory type found\n" ); - ret = -EINVAL ; - } - -error: -return ret; +return -ENOSPC ; } -EXPORT_SYMBOL (ttm_bo_mem_space); -static int ttm_bo_move_buffer (struct ttm_buffer_object *bo, -struct ttm_placement *placement, -struct ttm_operation_ctx *ctx) +/* +* ttm_bo_mem_space - Wrapper around ttm_bo_alloc_resource +* +* @bo: Pointer to a struct ttm_buffer_object of which we want a resource for +* @placement: Proposed new placement for the buffer object +* @res: The resulting struct ttm_resource. +* @ctx: if and how to sleep, lock buffers and alloc memory +* +* Tries both idle allocation and forcefully eviction of buffers. See +* ttm_bo_alloc_resource for details. +*/ +int ttm_bo_mem_space (struct ttm_buffer_object *bo, +struct ttm_placement *placement, +struct ttm_resource **res, +struct ttm_operation_ctx *ctx) { -struct ttm_resource *mem; -struct ttm_place hop; +bool force_space = false;int ret; -dma_resv_assert_held (bo->base.resv); +do { + ret =ttm_bo_alloc_resource (bo, placement, ctx, + force_space, res); + force_space = !force_space; + }while (ret == -ENOSPC && force_space); -/* -* Determine where to move the buffer. -* -* If driver determines move is going to need -* an extra step then it will return -EMULTIHOP -* and the buffer will be moved to the temporary -* stop and the driver will be called to make -* the second hop. -*/ - ret =ttm_bo_mem_space (bo, placement, &mem, ctx); -if (ret) -return ret; -bounce: - ret =ttm_bo_handle_move_mem (bo, mem, false, ctx, &hop); -if (ret == -EMULTIHOP ) { - ret =ttm_bo_bounce_temp_buffer (bo, &mem, ctx, &hop); -if (ret) - goto out; -/* try and move to final place now. */ - goto bounce; - } -out: -if (ret) -ttm_resource_free (bo, &mem);return ret; } +EXPORT_SYMBOL (ttm_bo_mem_space);/** * ttm_bo_validate
@@ -902,6 +849,9 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,struct ttm_placement *placement, struct ttm_operation_ctx *ctx) { + struct ttm_resource *res; +struct ttm_place hop; +bool force_space;int ret;dma_resv_assert_held (bo->base.resv);
@@ -912,20 +862,53 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,if (!placement->num_placement)return ttm_bo_pipeline_gutting (bo); -/* Check whether we need to move buffer. */ -if (bo->resource &&ttm_resource_compatible (bo->resource, placement)) -return 0 ; + force_space = false; +do { +/* Check whether we need to move buffer. */ +if (bo->resource && +ttm_resource_compatible (bo->resource, placement, + force_space)) +return 0 ; -/* Moving of pinned BOs is forbidden */ -if (bo->pin_count) -return -EINVAL ; +/* Moving of pinned BOs is forbidden */ +if (bo->pin_count) +return -EINVAL ; + +/* +* Determine where to move the buffer. +* +* If driver determines move is going to need +* an extra step then it will return -EMULTIHOP +* and the buffer will be moved to the temporary +* stop and the driver will be called to make +* the second hop. +*/ + ret =ttm_bo_alloc_resource (bo, placement, ctx, force_space, + &res); + force_space = !force_space; +if (ret == -ENOSPC ) +continue ; +if (ret) +return ret; + +bounce: + ret =ttm_bo_handle_move_mem (bo, res, false, ctx, &hop); +if (ret == -EMULTIHOP ) { + ret =ttm_bo_bounce_temp_buffer (bo, &res, ctx, &hop); +/* try and move to final place now. */ +if (!ret) + goto bounce; + } +if (ret) { +ttm_resource_free (bo, &res); +return ret; + } + + }while (ret && force_space); - ret =ttm_bo_move_buffer (bo, placement, ctx);/* For backward compatibility with userspace */ if (ret == -ENOSPC )return -ENOMEM ; -if (ret) -return ret;/* * We might need to add a TTM.
drivers/gpu/drm/ttm/ttm_resource.c +12 -4
@@ -295,11 +295,13 @@ bool ttm_resource_intersects(struct ttm_device *bdev,* * @res: the resource to check * @placement: the placement to check against +* @evicting: true if the caller is doing evictions * * Returns true if the placement is compatible. */ bool ttm_resource_compatible (struct ttm_resource *res, -struct ttm_placement *placement) +struct ttm_placement *placement, +bool evicting) {struct ttm_buffer_object *bo = res->bo;struct ttm_device *bdev = bo->bdev;
@@ -315,14 +317,20 @@ bool ttm_resource_compatible(struct ttm_resource *res,if (res->mem_type != place->mem_type)continue ; +if (place->flags & (evicting ?TTM_PL_FLAG_DESIRED : +TTM_PL_FLAG_FALLBACK )) +continue ; + +if (place->flags &TTM_PL_FLAG_CONTIGUOUS && + !(res->placement &TTM_PL_FLAG_CONTIGUOUS )) +continue ; + man =ttm_manager_type (bdev, res->mem_type);if (man->func->compatible && !man->func->compatible (man, res, place, bo->base.size))continue ; -if ((!(place->flags &TTM_PL_FLAG_CONTIGUOUS ) || - (res->placement &TTM_PL_FLAG_CONTIGUOUS ))) -return true; +return true; }return false; }
include/drm/ttm/ttm_resource.h +2 -1
@@ -366,7 +366,8 @@ bool ttm_resource_intersects(struct ttm_device *bdev,const struct ttm_place *place, size_t size);bool ttm_resource_compatible (struct ttm_resource *res, -struct ttm_placement *placement); +struct ttm_placement *placement, +bool evicting);void ttm_resource_set_bo (struct ttm_resource *res,struct ttm_buffer_object *bo);
Signature · 1 line
2.34.1
PATCH 2/2 drm/amdgpu: use GTT only as fallback for VRAM|GTT
Try to fill up VRAM as well by setting the busy flag on GTT allocations.
This fixes the issue that when VRAM was evacuated for suspend it's never filled up again unless the application is restarted.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +6 -0
@@ -173,6 +173,12 @@ void amdgpu_bo_placement_from_domain(struct amdgpu_bo *abo, u32 domain) abo->flags &AMDGPU_GEM_CREATE_PREEMPTIBLE ?AMDGPU_PL_PREEMPT :TTM_PL_TT ; places[c].flags =0 ; +/* +* When GTT is just an alternative to VRAM make sure that we +* only use it as fallback and still try to fill up VRAM first. +*/ +if (domain & abo->preferred_domains &AMDGPU_GEM_DOMAIN_VRAM ) + places[c].flags |=TTM_PL_FLAG_FALLBACK ; c++; }
Signature · 1 line
2.34.1
✗ Fi.CI.CHECKPATCH: warning for series starting with [1/2] drm/ttm: improve idle/busy handling v5
In reply to Christian König== Series Details ==
== Series Details ==
Series: series starting with [1/2] drm/ttm: improve idle/busy handling v5
URL : https://patchwork.freedesktop.org/series/130561/
State : warning
== Summary ==
Error: dim checkpatch failede4e8442e7666 drm/ttm: improve idle/busy handling v5
-:27: WARNING:BAD_SIGN_OFF: Unexpected content after email: 'Zack Rusin <[email protected]> v3', should be: 'Zack Rusin <[email protected]> (v3)' #27:
-:388: WARNING:FROM_SIGN_OFF_MISMATCH: From:/Signed-off-by: email address mismatch: 'From: "Christian König" <[email protected]>' != 'Signed-off-by: Christian König <[email protected]>'
total: 0 errors, 2 warnings, 0 checks, 341 lines checked77aab0a47a3b drm/amdgpu: use GTT only as fallback for VRAM|GTT
-:33: WARNING:FROM_SIGN_OFF_MISMATCH: From:/Signed-off-by: email address mismatch: 'From: "Christian König" <[email protected]>' != 'Signed-off-by: Christian König <[email protected]>'
total: 0 errors, 1 warnings, 0 checks, 12 lines checked
Patchwork
CI✗ Fi.CI.SPARSE: warning for series starting with [1/2] drm/ttm: improve idle/busy handling v5
In reply to Christian König== Series Details ==
== Series Details ==
Series: series starting with [1/2] drm/ttm: improve idle/busy handling v5
URL : https://patchwork.freedesktop.org/series/130561/
State : warning
== Summary ==
Error: dim sparse failed
Sparse version: v0.6.2
Fast mode used, each commit won't be checked separately.
Patchwork
CI✗ Fi.CI.BAT: failure for series starting with [1/2] drm/ttm: improve idle/busy handling v5
In reply to Christian König== Series Details ==
== Series Details ==
Series: series starting with [1/2] drm/ttm: improve idle/busy handling v5
URL : https://patchwork.freedesktop.org/series/130561/
State : failure
== Summary ==
CI Bug Log - changes from CI_DRM_14368 -> Patchwork_130561v1
====================================================
Summary
-------
**FAILURE**
Serious unknown changes coming with Patchwork_130561v1 absolutely need to be verified manually.
If you think the reported changes have nothing to do with the changes
introduced in Patchwork_130561v1, please notify your bug team ([email protected]) to allow them to document this new failure mode, which will reduce false positives in CI.
External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130561v1/index.html
Participating hosts (43 -> 42)
------------------------------
Missing (1): fi-snb-2520m
Possible new issues
-------------------
Here are the unknown changes that may have been introduced in Patchwork_130561v1:
### IGT changes ###
#### Possible regressions ####
* igt@gem_exec_parallel@engines@userptr:
- bat-arls-2: [PASS][1] -> [FAIL][2]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14368/bat-arls-2/igt@gem_exec_parallel@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130561v1/bat-arls-2/igt@gem_exec_parallel@[email protected]
* igt@i915_selftest@live@sanitycheck:
- bat-arls-2: NOTRUN -> [ABORT][3]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130561v1/bat-arls-2/igt@i915_selftest@[email protected]
Known issues
------------
Here are the changes found in Patchwork_130561v1 that come from known issues:
### CI changes ###
#### Issues hit ####
* boot:
- bat-jsl-1: [PASS][4] -> [FAIL][5] ([i915#8293])
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14368/bat-jsl-1/boot.html
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130561v1/bat-jsl-1/boot.html
#### Possible fixes ####
* boot:
- fi-apl-guc: [FAIL][6] ([i915#8293]) -> [PASS][7]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14368/fi-apl-guc/boot.html
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130561v1/fi-apl-guc/boot.html
### IGT changes ###
#### Issues hit ####
* igt@gem_lmem_swapping@basic:
- fi-apl-guc: NOTRUN -> [SKIP][8] ([fdo#109271] / [i915#4613]) +3 other tests skip
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130561v1/fi-apl-guc/igt@[email protected]
* igt@gem_lmem_swapping@verify-random:
- bat-arls-2: NOTRUN -> [SKIP][9] ([i915#10213]) +3 other tests skip
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130561v1/bat-arls-2/igt@[email protected]
* igt@i915_pm_rps@basic-api:
- bat-arls-2: NOTRUN -> [SKIP][10] ([i915#10209])
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130561v1/bat-arls-2/igt@[email protected]
* igt@kms_addfb_basic@addfb25-y-tiled-small-legacy:
- bat-arls-2: NOTRUN -> [SKIP][11] ([i915#10200]) +9 other tests skip
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130561v1/bat-arls-2/igt@[email protected]
* igt@kms_cursor_legacy@basic-busy-flip-before-cursor-legacy:
- bat-arls-2: NOTRUN -> [SKIP][12] ([i915#10202]) +1 other test skip
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130561v1/bat-arls-2/igt@[email protected]
* igt@kms_dsc@dsc-basic:
- bat-arls-2: NOTRUN -> [SKIP][13] ([i915#9886])
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130561v1/bat-arls-2/igt@[email protected]
* igt@kms_force_connector_basic@force-load-detect:
- bat-arls-2: NOTRUN -> [SKIP][14] ([i915#10207])
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130561v1/bat-arls-2/igt@[email protected]
* igt@kms_hdmi_inject@inject-audio:
- fi-apl-guc: NOTRUN -> [SKIP][15] ([fdo#109271]) +17 other tests skip
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130561v1/fi-apl-guc/igt@[email protected]
* igt@kms_psr@psr-primary-mmap-gtt@edp-1:
- bat-arls-2: NOTRUN -> [SKIP][16] ([i915#10196] / [i915#4077] / [i915#9688])
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130561v1/bat-arls-2/igt@kms_psr@[email protected]
* igt@kms_setmode@basic-clone-single-crtc:
- bat-arls-2: NOTRUN -> [SKIP][17] ([i915#10208] / [i915#8809])
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130561v1/bat-arls-2/igt@[email protected]
* igt@prime_vgem@basic-fence-mmap:
- bat-arls-2: NOTRUN -> [SKIP][18] ([i915#10196] / [i915#3708] / [i915#4077]) +1 other test skip
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130561v1/bat-arls-2/igt@[email protected]
* igt@prime_vgem@basic-fence-read:
- bat-arls-2: NOTRUN -> [SKIP][19] ([i915#10212] / [i915#3708])
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130561v1/bat-arls-2/igt@[email protected]
* igt@prime_vgem@basic-read:
- bat-arls-2: NOTRUN -> [SKIP][20] ([i915#10214] / [i915#3708])
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130561v1/bat-arls-2/igt@[email protected]
* igt@prime_vgem@basic-write:
- bat-arls-2: NOTRUN -> [SKIP][21] ([i915#10216] / [i915#3708])
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130561v1/bat-arls-2/igt@[email protected]
#### Possible fixes ####
* igt@gem_wait@busy@all-engines:
- bat-arls-2: [ABORT][22] -> [PASS][23]
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14368/bat-arls-2/igt@gem_wait@[email protected]
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130561v1/bat-arls-2/igt@gem_wait@[email protected]
* igt@i915_selftest@live@hangcheck:
- {bat-rpls-3}: [DMESG-WARN][24] ([i915#5591]) -> [PASS][25]
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14368/bat-rpls-3/igt@i915_selftest@[email protected]
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130561v1/bat-rpls-3/igt@i915_selftest@[email protected]
- bat-dg2-14: [INCOMPLETE][26] ([i915#10137]) -> [PASS][27]
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14368/bat-dg2-14/igt@i915_selftest@[email protected]
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130561v1/bat-dg2-14/igt@i915_selftest@[email protected]
{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).
[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
[i915#10026]: https://gitlab.freedesktop.org/drm/intel/issues/10026
[i915#10137]: https://gitlab.freedesktop.org/drm/intel/issues/10137
[i915#10196]: https://gitlab.freedesktop.org/drm/intel/issues/10196
[i915#10200]: https://gitlab.freedesktop.org/drm/intel/issues/10200
[i915#10202]: https://gitlab.freedesktop.org/drm/intel/issues/10202
[i915#10207]: https://gitlab.freedesktop.org/drm/intel/issues/10207
[i915#10208]: https://gitlab.freedesktop.org/drm/intel/issues/10208
[i915#10209]: https://gitlab.freedesktop.org/drm/intel/issues/10209
[i915#10212]: https://gitlab.freedesktop.org/drm/intel/issues/10212
[i915#10213]: https://gitlab.freedesktop.org/drm/intel/issues/10213
[i915#10214]: https://gitlab.freedesktop.org/drm/intel/issues/10214
[i915#10216]: https://gitlab.freedesktop.org/drm/intel/issues/10216
[i915#3708]: https://gitlab.freedesktop.org/drm/intel/issues/3708
[i915#4077]: https://gitlab.freedesktop.org/drm/intel/issues/4077
[i915#4613]: https://gitlab.freedesktop.org/drm/intel/issues/4613
[i915#5591]: https://gitlab.freedesktop.org/drm/intel/issues/5591
[i915#8293]: https://gitlab.freedesktop.org/drm/intel/issues/8293
[i915#8809]: https://gitlab.freedesktop.org/drm/intel/issues/8809
[i915#9688]: https://gitlab.freedesktop.org/drm/intel/issues/9688
[i915#9886]: https://gitlab.freedesktop.org/drm/intel/issues/9886
Build changes
-------------
* Linux: CI_DRM_14368 -> Patchwork_130561v1
CI-20190529: 20190529
CI_DRM_14368: 68e66ae04f6f2718699716285e8ddb09a469af35 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_7738: 7738
Patchwork_130561v1: 68e66ae04f6f2718699716285e8ddb09a469af35 @ git://anongit.freedesktop.org/gfx-ci/linux
### Linux commits
f0ce1bba9fdf drm/amdgpu: use GTT only as fallback for VRAM|GTT 6f3039cfd158 drm/ttm: improve idle/busy handling v5
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130561v1/index.html
Hi, Christian
Quoted 22 lines · Christian König
Previously we would never try to move a BO into the preferred placements
when it ever landed in a busy placement since those were considered compatible.Rework the whole handling and finally unify the idle and busy handling.
ttm_bo_validate()is now responsible to try idle placement first and then
use the busy placement if that didn't worked.Drawback is that we now always try the idle placement first for each validation which might cause some additional CPU overhead on overcommit.
v2: fix kerneldoc warning and coding style
v3: take care of XE as well
v4: keep thettm_bo_mem_spacefunctionality as it is for now, only add
new handling forttm_bo_validateas suggested by Thomas
v5: fix bug pointed out by Matthew
Quoted 2 lines
Signed-off-by Christian König <[email protected]>Reviewed-by Zack Rusin <[email protected]> v3
Now Xe CI passes \o/
Still some checkpatch.pl warnings on both these lines.
For the first line I think it uses From: in the email as the author and when that doesn't match the SOB, it becomes unhappy.
With that fixed,
Quoted 400 lines
---
drivers/gpu/drm/ttm/ttm_bo.c | 231 +++++++++++++-------------- --
drivers/gpu/drm/ttm/ttm_resource.c | 16 +- include/drm/ttm/ttm_resource.h | 3 +-3 files changed, 121 insertions(+), 129 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +0
-0@@ -724,64 +724,36 @@ static int ttm_bo_add_move_fence(structttm_buffer_object *bo, return ret; }
-/*
- * Repeatedly evict memory from the LRU for @mem_type until we create enough
- * space, or we've evicted everything and there isn't enough space.
- */drivers/gpu/drm/ttm/ttm_bo.c +0
-25-static int ttm_bo_mem_force_space (struct ttm_buffer_object *bo, - const struct ttm_place *place, - struct ttm_resource **mem, - struct ttm_operation_ctx *ctx) -{ -struct ttm_device *bdev = bo->bdev; -struct ttm_resource_manager *man; -struct ww_acquire_ctx *ticket; -int ret; - - man =ttm_manager_type (bdev, place->mem_type); - ticket =dma_resv_locking_ctx (bo->base.resv); -do { - ret =ttm_resource_alloc (bo, place, mem); -if (likely (!ret)) -break ; -if (unlikely (ret != -ENOSPC )) -return ret; - ret =ttm_mem_evict_first (bdev, man, place, ctx, - ticket); -if (unlikely (ret !=0 )) -return ret; - }while (1 ); - - return ttm_bo_add_move_fence(bo, man, *mem, ctx-Quoted 1 line
no_wait_gpu);drivers/gpu/drm/ttm/ttm_bo.c +0
-2-} -/**
- *ttm_bo_mem_space
+ *ttm_bo_alloc_resource- Allocate backing store for a BO *
- * @bo: Pointer to a structttm_buffer_object. the data of which
- * we want to allocate space for.
- * @placement: Proposed new placement for the buffer object.
- * @mem: A structttm_resource.
+ * @bo: Pointer to a structttm_buffer_objectof which we want a resource for
+ * @placement: Proposed new placement for the buffer object
* @ctx: if and how to sleep, lock buffers and alloc memory
+ * @force_space: If we should evict buffers to force space
+ * @res: The resulting structttm_resource.
*
- * Allocate memory space for the buffer object pointed to by @bo, using
- * the placement flags in @placement, potentially evicting other idle buffer objects.
- * This function may sleep while waiting for space to become available.
+ * Allocates a resource for the buffer object pointed to by @bo, using the
+ * placement flags in @placement, potentially evicting other buffer objects when
+ * @force_space is true.
+ * This function may sleep while waiting for resources to become available.
* Returns:
- *-EBUSY: No space available (only ifno_wait== 1).
+ *-EBUSY: No space available (only ifno_wait== true).
*-ENOSPC: Could not allocate space for the buffer object, either due to
* fragmentation or concurrent allocators.
*-ERESTARTSYS: An interruptible sleep was interrupted by a signal. */drivers/gpu/drm/ttm/ttm_bo.c +5
-4-int ttm_bo_mem_space (struct ttm_buffer_object *bo, -struct ttm_placement *placement, -struct ttm_resource **mem, -struct ttm_operation_ctx *ctx) +static int ttm_bo_alloc_resource (struct ttm_buffer_object *bo, +struct ttm_placement *placement, +struct ttm_operation_ctx *ctx, +bool force_space, +struct ttm_resource **res){
structttm_device*bdev =bo->bdev;drivers/gpu/drm/ttm/ttm_bo.c +1
-1-bool type_found = false; +struct ww_acquire_ctx *ticket;int i, ret;
drivers/gpu/drm/ttm/ttm_bo.c +1
-0+ ticket =dma_resv_locking_ctx (bo->base.resv);ret =
dma_resv_reserve_fences(bo->base.resv, 1); if (unlikely(ret))
return ret;drivers/gpu/drm/ttm/ttm_bo.c +0
-0@@ -790,98 +762,73 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,const struct
ttm_place*place = &placement-Quoted 1 line
placement[i];
struct
ttm_resource_manager*man;drivers/gpu/drm/ttm/ttm_bo.c +0
-3-if (place->flags &TTM_PL_FLAG_FALLBACK ) -continue ; -man =
ttm_manager_type(bdev, place->mem_type); if (!man || !ttm_resource_manager_used(man)) continue;drivers/gpu/drm/ttm/ttm_bo.c +1
-3- type_found = true; - ret =ttm_resource_alloc (bo, place, mem); -if (ret == -ENOSPC ) + if (place->flags & (force_space ?
TTM_PL_FLAG_DESIRED:drivers/gpu/drm/ttm/ttm_bo.c +11
-0+ TTM_PL_FLAG_FALLBACK)) +continue ; + + do { + ret = ttm_resource_alloc(bo, place, res); + if (unlikely(ret && ret != -ENOSPC)) + return ret; + if (likely(!ret) || !force_space) + break; + + ret = ttm_mem_evict_first(bdev, man, place,ctx,
drivers/gpu/drm/ttm/ttm_bo.c +7
-0+ ticket); +if (unlikely (ret == -EBUSY )) +break ; +if (unlikely (ret)) +return ret; + }while (1 ); +if (ret)continue;
drivers/gpu/drm/ttm/ttm_bo.c +0
-2-if (unlikely (ret)) - goto error;drivers/gpu/drm/ttm/ttm_bo.c +0
-1- ret = ttm_bo_add_move_fence(bo, man, *mem, ctx-Quoted 1 line
no_wait_gpu);drivers/gpu/drm/ttm/ttm_bo.c +1
-0+ ret = ttm_bo_add_move_fence(bo, man, *res, ctx-Quoted 1 line
no_wait_gpu);if (unlikely(ret)) {
drivers/gpu/drm/ttm/ttm_bo.c +1
-1-ttm_resource_free (bo, mem); +ttm_resource_free (bo, res);if (ret ==
-EBUSY)
continue;drivers/gpu/drm/ttm/ttm_bo.c +1
-1- goto error; +return ret;}
return 0;
}drivers/gpu/drm/ttm/ttm_bo.c +0
-2-for (i =0 ; i < placement->num_placement; ++i) { - const struct ttm_place *place = &placement-Quoted 1 line
placement[i];
drivers/gpu/drm/ttm/ttm_bo.c +1
-26-struct ttm_resource_manager *man; - -if (place->flags &TTM_PL_FLAG_DESIRED ) -continue ; - - man =ttm_manager_type (bdev, place->mem_type); -if (!man || !ttm_resource_manager_used (man)) -continue ; - - type_found = true; - ret =ttm_bo_mem_force_space (bo, place, mem, ctx); -if (likely (!ret)) -return 0 ; - -if (ret && ret != -EBUSY ) - goto error; - } - - ret = -ENOSPC ; -if (!type_found) { -pr_err (TTM_PFX "No compatible memory type found\n" ); - ret = -EINVAL ; - } - -error: -return ret; +return -ENOSPC ;}
-EXPORT_SYMBOL(ttm_bo_mem_space);drivers/gpu/drm/ttm/ttm_bo.c +4
-3-static int ttm_bo_move_buffer (struct ttm_buffer_object *bo, - struct ttm_placement *placement, - struct ttm_operation_ctx *ctx) +/* +* ttm_bo_mem_space - Wrapper around ttm_bo_alloc_resource +* +* @bo: Pointer to a struct ttm_buffer_object of which we want a resource for
+ * @placement: Proposed new placement for the buffer object
+ * @res: The resulting structttm_resource.
+ * @ctx: if and how to sleep, lock buffers and alloc memory
+ *
+ * Tries both idle allocation and forcefully eviction of buffers. See
+ *ttm_bo_alloc_resourcefor details.
+ */drivers/gpu/drm/ttm/ttm_bo.c +4
-0+int ttm_bo_mem_space (struct ttm_buffer_object *bo, + struct ttm_placement *placement, + struct ttm_resource **res, + struct ttm_operation_ctx *ctx){
drivers/gpu/drm/ttm/ttm_bo.c +1
-2-struct ttm_resource *mem; -struct ttm_place hop; +bool force_space = false;int ret;
drivers/gpu/drm/ttm/ttm_bo.c +5
-1-dma_resv_assert_held (bo->base.resv); +do { + ret =ttm_bo_alloc_resource (bo, placement, ctx, + force_space, res); + force_space = !force_space; + }while (ret == -ENOSPC && force_space);drivers/gpu/drm/ttm/ttm_bo.c +0
-16-/* -* Determine where to move the buffer. -* -* If driver determines move is going to need -* an extra step then it will return -EMULTIHOP -* and the buffer will be moved to the temporary -* stop and the driver will be called to make -* the second hop. -*/ - ret =ttm_bo_mem_space (bo, placement, &mem, ctx); -if (ret) -return ret; -bounce: - ret =ttm_bo_handle_move_mem (bo, mem, false, ctx, &hop); -if (ret == -EMULTIHOP ) { - ret = ttm_bo_bounce_temp_buffer(bo, &mem, ctx,&hop);
drivers/gpu/drm/ttm/ttm_bo.c +0
-8-if (ret) - goto out; -/* try and move to final place now. */ - goto bounce; - } -out: -if (ret) -ttm_resource_free (bo, &mem);return ret;
}
+EXPORT_SYMBOL(ttm_bo_mem_space);
/**
*ttm_bo_validatedrivers/gpu/drm/ttm/ttm_bo.c +3
-0@@ -902,6 +849,9 @@ int ttm_bo_validate(struct ttm_buffer_object *bo, struct ttm_placement *placement, struct ttm_operation_ctx *ctx) { +struct ttm_resource *res; +struct ttm_place hop; +bool force_space; int ret;
dma_resv_assert_held(bo->base.resv);drivers/gpu/drm/ttm/ttm_bo.c +0
-0@@ -912,20 +862,53 @@ int ttm_bo_validate(struct ttm_buffer_object *bo, if (!placement->num_placement) return ttm_bo_pipeline_gutting(bo);drivers/gpu/drm/ttm/ttm_bo.c +0
-2-/* Check whether we need to move buffer. */ - if (bo->resource && ttm_resource_compatible(bo->resource,placement))
drivers/gpu/drm/ttm/ttm_bo.c +7
-1-return 0 ; + force_space = false; + do { + /* Check whether we need to move buffer. */ + if (bo->resource && + ttm_resource_compatible(bo->resource, placement, + force_space)) + return 0;drivers/gpu/drm/ttm/ttm_bo.c +14
-3-/* Moving of pinned BOs is forbidden */ -if (bo->pin_count) -return -EINVAL ; +/* Moving of pinned BOs is forbidden */ +if (bo->pin_count) +return -EINVAL ; + +/* +* Determine where to move the buffer. +* +* If driver determines move is going to need +* an extra step then it will return -EMULTIHOP +* and the buffer will be moved to the temporary +* stop and the driver will be called to make +* the second hop. +*/ + ret = ttm_bo_alloc_resource(bo, placement, ctx,
force_space,drivers/gpu/drm/ttm/ttm_bo.c +9
-0+ &res); + force_space = !force_space; +if (ret == -ENOSPC ) +continue ; +if (ret) +return ret; + +bounce: + ret = ttm_bo_handle_move_mem(bo, res, false, ctx,&hop);
drivers/gpu/drm/ttm/ttm_bo.c +2
-0+if (ret == -EMULTIHOP ) { + ret = ttm_bo_bounce_temp_buffer(bo, &res,ctx, &hop);
drivers/gpu/drm/ttm/ttm_bo.c +10
-0+/* try and move to final place now. */ +if (!ret) + goto bounce; + } +if (ret) { +ttm_resource_free (bo, &res); +return ret; + } + + }while (ret && force_space);drivers/gpu/drm/ttm/ttm_bo.c +0
-1- ret =ttm_bo_move_buffer (bo, placement, ctx);/* For backward compatibility with userspace */ if (ret ==
-ENOSPC)
return-ENOMEM;drivers/gpu/drm/ttm/ttm_bo.c +0
-2-if (ret) -return ret;
/*
* We might need to add a TTM.drivers/gpu/drm/ttm/ttm_resource.c +3
-1@@ -295,11 +295,13 @@ bool ttm_resource_intersects(struct ttm_device*bdev, * * @res: the resource to check * @placement: the placement to check against +* @evicting: true if the caller is doing evictions * * Returns true if the placement is compatible. */ bool ttm_resource_compatible(struct ttm_resource *res, - struct ttm_placement *placement) + struct ttm_placement *placement, + bool evicting) { struct ttm_buffer_object *bo = res->bo;struct
ttm_device*bdev =bo->bdev;drivers/gpu/drm/ttm/ttm_resource.c +0
-0@@ -315,14 +317,20 @@ bool ttm_resource_compatible(struct ttm_resource *res, if (res->mem_type != place->mem_type) continue;drivers/gpu/drm/ttm/ttm_resource.c +8
-0+if (place->flags & (evicting ?TTM_PL_FLAG_DESIRED : + TTM_PL_FLAG_FALLBACK)) +continue ; + +if (place->flags &TTM_PL_FLAG_CONTIGUOUS && + !(res->placement & TTM_PL_FLAG_CONTIGUOUS)) +continue ; +man =
ttm_manager_type(bdev, res->mem_type); if (man->func->compatible&& !man->func->compatible(man, res, place, bo-Quoted 1 line
base.size))
continue;
drivers/gpu/drm/ttm/ttm_resource.c +1
-3-if ((!(place->flags &TTM_PL_FLAG_CONTIGUOUS ) || - (res->placement & TTM_PL_FLAG_CONTIGUOUS))) -return true; +return true;}
return false;
}include/drm/ttm/ttm_resource.h +2
-1@@ -366,7 +366,8 @@ bool ttm_resource_intersects(struct ttm_device *bdev, const struct ttm_place *place, size_t size); bool ttm_resource_compatible(struct ttm_resource *res, - struct ttm_placement *placement); + struct ttm_placement *placement, + bool evicting); void ttm_resource_set_bo(struct ttm_resource *res, struct ttm_buffer_object *bo);