[PATCH RFC v2] drm/amdgpu: Set/clear CPU_ACCESS flag on page fault and move to VRAM
John Brooks
john at fastquake.com
Fri Jun 30 15:31:08 UTC 2017
When a BO is moved to VRAM, clear AMDGPU_BO_FLAG_CPU_ACCESS. This allows it
to potentially later move to invisible VRAM if the CPU does not access it
again.
Setting the CPU_ACCESS flag in amdgpu_bo_fault_reserve_notify() also means
that we can remove the loop to restrict lpfn to the end of visible VRAM,
because amdgpu_ttm_placement_init() will do it for us.
Signed-off-by: John Brooks <john at fastquake.com>
---
Whoops, I forgot to actually remove that loop.
Also, in the changelog: amdgpu_fault_reserve_notify -> amdgpu_bo_fault_reserve_notify
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 15 +++++----------
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 8 ++++++++
2 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index fa8aeca..7164f8c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -946,13 +946,16 @@ int amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
{
struct amdgpu_device *adev = amdgpu_ttm_adev(bo->bdev);
struct amdgpu_bo *abo;
- unsigned long offset, size, lpfn;
- int i, r;
+ unsigned long offset, size;
+ int r;
if (!amdgpu_ttm_bo_is_amdgpu_bo(bo))
return 0;
abo = container_of(bo, struct amdgpu_bo, tbo);
+
+ abo->flags |= AMDGPU_BO_FLAG_CPU_ACCESS;
+
if (bo->mem.mem_type != TTM_PL_VRAM)
return 0;
@@ -969,14 +972,6 @@ int amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
/* hurrah the memory is not visible ! */
atomic64_inc(&adev->num_vram_cpu_page_faults);
amdgpu_ttm_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_VRAM);
- lpfn = adev->mc.visible_vram_size >> PAGE_SHIFT;
- for (i = 0; i < abo->placement.num_placement; i++) {
- /* Force into visible VRAM */
- if ((abo->placements[i].flags & TTM_PL_FLAG_VRAM) &&
- (!abo->placements[i].lpfn ||
- abo->placements[i].lpfn > lpfn))
- abo->placements[i].lpfn = lpfn;
- }
r = ttm_bo_validate(bo, &abo->placement, false, false);
if (unlikely(r == -ENOMEM)) {
amdgpu_ttm_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_GTT);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index c9b131b..cc65cdd 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -417,6 +417,7 @@ static int amdgpu_move_ram_vram(struct ttm_buffer_object *bo,
struct ttm_mem_reg *new_mem)
{
struct amdgpu_device *adev;
+ struct amdgpu_bo *abo;
struct ttm_mem_reg *old_mem = &bo->mem;
struct ttm_mem_reg tmp_mem;
struct ttm_placement placement;
@@ -424,6 +425,7 @@ static int amdgpu_move_ram_vram(struct ttm_buffer_object *bo,
int r;
adev = amdgpu_ttm_adev(bo->bdev);
+ abo = container_of(bo, struct amdgpu_bo, tbo);
tmp_mem = *new_mem;
tmp_mem.mm_node = NULL;
placement.num_placement = 1;
@@ -446,6 +448,12 @@ static int amdgpu_move_ram_vram(struct ttm_buffer_object *bo,
if (unlikely(r)) {
goto out_cleanup;
}
+
+ /* The page fault handler will re-set this if the CPU accesses the BO
+ * after it's moved.
+ */
+ abo->flags &= ~AMDGPU_BO_FLAG_CPU_ACCESS;
+
out_cleanup:
ttm_bo_mem_put(bo, &tmp_mem);
return r;
--
2.7.4
More information about the amd-gfx
mailing list