Skip to contentSkip to conversation

drm/amdgpu: set preferred_domain independent of fallback handling

PATCH In review Chunming Zhou 2 participants 3 messages Apr 18, 2018 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/amdgpu: set preferred_domain independent of fallback handling

When GEM needs to fallback to GTT for VRAM BOs we still want the preferred domain to be untouched so that the BO has a cance to move back to VRAM in the future.

Change-Id I8cfdf3f30532f7e5d80b8e4266b7800211de2f0b
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c    |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 15 +++++++++------
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  1 +
 3 files changed, 11 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1 -0
index 1200c5ba37da..ff606ce88837 100644
@@ -62,6 +62,7 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
 	bp.byte_align = alignment;
 	bp.type = type;
 	bp.resv = resv;
+	bp.preferred_domain = initial_domain;
 retry:
 	bp.flags = flags;
 	bp.domain = initial_domain;
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +9 -6
index cac65e32a0b9..9258f0694922 100644
@@ -360,6 +360,7 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,
 	};
 	struct amdgpu_bo *bo;
 	unsigned long page_align, size = bp->size;
+	u32 preferred_domains;
 	size_t acc_size;
 	int r;
 
@@ -380,12 +381,14 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,
 	drm_gem_private_object_init(adev->ddev, &bo->gem_base, size);
 	INIT_LIST_HEAD(&bo->shadow_list);
 	INIT_LIST_HEAD(&bo->va);
-	bo->preferred_domains = bp->domain & (AMDGPU_GEM_DOMAIN_VRAM |
-					      AMDGPU_GEM_DOMAIN_GTT |
-					      AMDGPU_GEM_DOMAIN_CPU |
-					      AMDGPU_GEM_DOMAIN_GDS |
-					      AMDGPU_GEM_DOMAIN_GWS |
-					      AMDGPU_GEM_DOMAIN_OA);
+	preferred_domains = bp->preferred_domain ? bp->preferred_domain :
+		bp->domain;
+	bo->preferred_domains = preferred_domains & (AMDGPU_GEM_DOMAIN_VRAM |
+						     AMDGPU_GEM_DOMAIN_GTT |
+						     AMDGPU_GEM_DOMAIN_CPU |
+						     AMDGPU_GEM_DOMAIN_GDS |
+						     AMDGPU_GEM_DOMAIN_GWS |
+						     AMDGPU_GEM_DOMAIN_OA);
 	bo->allowed_domains = bo->preferred_domains;
 	if (bp->type != ttm_bo_type_kernel &&
 	    bo->allowed_domains == AMDGPU_GEM_DOMAIN_VRAM)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -0
index e9a21d991e77..540e03fa159f 100644
@@ -37,6 +37,7 @@ struct amdgpu_bo_param {
 	unsigned long			size;
 	int				byte_align;
 	u32				domain;
+	u32				preferred_domain;
 	u64				flags;
 	enum ttm_bo_type		type;
 	struct reservation_object	*resv;
Signature · 6 lines
2.14.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

PATCH 2/2 drm/amdgpu: handle domain mask checking v2

if domain is illegal, we should return error.
v2:
remove duplicated domain checking.

Change-Id I65a738f5ac4fc34be76de867afb0db1d4bd27c24
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c    | 7 +------
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 7 +------
 include/uapi/drm/amdgpu_drm.h              | 6 ++++++
 3 files changed, 8 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1 -6
index ff606ce88837..c62c3dd4dcc6 100644
@@ -229,12 +229,7 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
 		return -EINVAL;
 
 	/* reject invalid gem domains */
-	if (args->in.domains & ~(AMDGPU_GEM_DOMAIN_CPU |
-				 AMDGPU_GEM_DOMAIN_GTT |
-				 AMDGPU_GEM_DOMAIN_VRAM |
-				 AMDGPU_GEM_DOMAIN_GDS |
-				 AMDGPU_GEM_DOMAIN_GWS |
-				 AMDGPU_GEM_DOMAIN_OA))
+	if (args->in.domains & ~AMDGPU_GEM_DOMAIN_MASK)
 		return -EINVAL;
 
 	/* create a gem object to contain this object in */
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -6
index 9258f0694922..42d3d1501da5 100644
@@ -383,12 +383,7 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,
 	INIT_LIST_HEAD(&bo->va);
 	preferred_domains = bp->preferred_domain ? bp->preferred_domain :
 		bp->domain;
-	bo->preferred_domains = preferred_domains & (AMDGPU_GEM_DOMAIN_VRAM |
-						     AMDGPU_GEM_DOMAIN_GTT |
-						     AMDGPU_GEM_DOMAIN_CPU |
-						     AMDGPU_GEM_DOMAIN_GDS |
-						     AMDGPU_GEM_DOMAIN_GWS |
-						     AMDGPU_GEM_DOMAIN_OA);
+	bo->preferred_domains = preferred_domains;
 	bo->allowed_domains = bo->preferred_domains;
 	if (bp->type != ttm_bo_type_kernel &&
 	    bo->allowed_domains == AMDGPU_GEM_DOMAIN_VRAM)
include/uapi/drm/amdgpu_drm.h +6 -0
index 0087799962cf..d023d3c4ee51 100644
@@ -81,6 +81,12 @@ extern "C" {
 #define AMDGPU_GEM_DOMAIN_GDS		0x8
 #define AMDGPU_GEM_DOMAIN_GWS		0x10
 #define AMDGPU_GEM_DOMAIN_OA		0x20
+#define AMDGPU_GEM_DOMAIN_MASK		(AMDGPU_GEM_DOMAIN_CPU | \
+					 AMDGPU_GEM_DOMAIN_GTT | \
+					 AMDGPU_GEM_DOMAIN_VRAM | \
+					 AMDGPU_GEM_DOMAIN_GDS | \
+					 AMDGPU_GEM_DOMAIN_GWS | \
+					 AMDGPU_GEM_DOMAIN_OA)
 
 /* Flag that CPU access will be required for the case of VRAM domain */
 #define AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED	(1 << 0)
Signature · 6 lines
2.14.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Reviewed-by
#3 lore raw
In reply to a message not in the archive

Am 18.04.2018 um 04:19 schrieb Chunming Zhou:

Quoted 6 lines

When GEM needs to fallback to GTT for VRAM BOs we still want the preferred domain to be untouched so that the BO has a cance to move back to VRAM in the future.

Change-Id I8cfdf3f30532f7e5d80b8e4266b7800211de2f0b
Quoted 56 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c    |  1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 15 +++++++++------
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  1 +
  3 files changed, 11 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1 -0
index 1200c5ba37da..ff606ce88837 100644
@@ -62,6 +62,7 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
  	bp.byte_align = alignment;
  	bp.type = type;
  	bp.resv = resv;
+	bp.preferred_domain = initial_domain;
  retry:
  	bp.flags = flags;
  	bp.domain = initial_domain;
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +9 -6
index cac65e32a0b9..9258f0694922 100644
@@ -360,6 +360,7 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,
  	};
  	struct amdgpu_bo *bo;
  	unsigned long page_align, size = bp->size;
+	u32 preferred_domains;
  	size_t acc_size;
  	int r;
 
@@ -380,12 +381,14 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,
  	drm_gem_private_object_init(adev->ddev, &bo->gem_base, size);
  	INIT_LIST_HEAD(&bo->shadow_list);
  	INIT_LIST_HEAD(&bo->va);
-	bo->preferred_domains = bp->domain & (AMDGPU_GEM_DOMAIN_VRAM |
-					      AMDGPU_GEM_DOMAIN_GTT |
-					      AMDGPU_GEM_DOMAIN_CPU |
-					      AMDGPU_GEM_DOMAIN_GDS |
-					      AMDGPU_GEM_DOMAIN_GWS |
-					      AMDGPU_GEM_DOMAIN_OA);
+	preferred_domains = bp->preferred_domain ? bp->preferred_domain :
+		bp->domain;
+	bo->preferred_domains = preferred_domains & (AMDGPU_GEM_DOMAIN_VRAM |
+						     AMDGPU_GEM_DOMAIN_GTT |
+						     AMDGPU_GEM_DOMAIN_CPU |
+						     AMDGPU_GEM_DOMAIN_GDS |
+						     AMDGPU_GEM_DOMAIN_GWS |
+						     AMDGPU_GEM_DOMAIN_OA);
  	bo->allowed_domains = bo->preferred_domains;
  	if (bp->type != ttm_bo_type_kernel &&
  	    bo->allowed_domains == AMDGPU_GEM_DOMAIN_VRAM)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0 -0
index e9a21d991e77..540e03fa159f 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_object.h struct amdgpu_bo_param { · line 43

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -0
@@ -37,6 +37,7 @@ struct amdgpu_bo_param {
  	unsigned long			size;
  	int				byte_align;
  	u32				domain;
+	u32				preferred_domain;
  	u64				flags;
  	enum ttm_bo_type		type;
  	struct reservation_object	*resv;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx