Skip to contentSkip to conversation

drm/radeon: Add RADEON_GEM_CPU_ACCESS BO creation flag

PATCH Applied Michel Dänzer 4 participants 12 messages Aug 28, 2014 – Sep 10, 2014

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

PATCH 1/1 drm/radeon: Add RADEON_GEM_CPU_ACCESS BO creation flag

From: Michel Dänzer <[email protected]>

This flag is a hint that userspace expects the BO to be accessed by the CPU. We can use that hint to prevent such BOs from ever being stored in the CPU inaccessible part of VRAM.

---
 drivers/gpu/drm/radeon/radeon_object.c | 11 +++++++++--
 include/uapi/drm/radeon_drm.h          |  2 ++
 2 files changed, 11 insertions(+), 2 deletions(-)
drivers/gpu/drm/radeon/radeon_object.c +9 -2
index dc74cc5..908ea541 100644
@@ -143,7 +143,12 @@ void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain)
 
 	for (i = 0; i < c; ++i) {
 		rbo->placements[i].fpfn = 0;
-		rbo->placements[i].lpfn = 0;
+		if ((rbo->flags & RADEON_GEM_CPU_ACCESS) &&
+		    (rbo->placements[i].flags & TTM_PL_FLAG_VRAM))
+			rbo->placements[i].lpfn =
+				rbo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
+		else
+			rbo->placements[i].lpfn = 0;
 	}
 
 	/*
@@ -151,7 +156,9 @@ void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain)
 	 * improve fragmentation quality.
 	 * 512kb was measured as the most optimal number.
 	 */
-	if (rbo->tbo.mem.size > 512 * 1024) {
+	if (!((rbo->flags & RADEON_GEM_CPU_ACCESS) &&
+	      (rbo->placements[i].flags & TTM_PL_FLAG_VRAM)) &&
+	    rbo->tbo.mem.size > 512 * 1024) {
 		for (i = 0; i < c; i++) {
 			rbo->placements[i].flags |= TTM_PL_FLAG_TOPDOWN;
 		}
include/uapi/drm/radeon_drm.h +2 -0
index 509b2d7..bf0067b 100644
@@ -799,6 +799,8 @@ struct drm_radeon_gem_info {
 #define RADEON_GEM_NO_BACKING_STORE	(1 << 0)
 #define RADEON_GEM_GTT_UC		(1 << 1)
 #define RADEON_GEM_GTT_WC		(1 << 2)
+/* BO is expected to be accessed by the CPU */
+#define RADEON_GEM_CPU_ACCESS		(1 << 3)
 
 struct drm_radeon_gem_create {
 	uint64_t	size;
Signature · 6 lines
2.1.0

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH 1/1 r600g, radeonsi: Inform the kernel if a BO will likely be accessed by the CPU

From: Michel Dänzer <[email protected]>

This allows the kernel to prevent such BOs from ever being stored in the CPU inaccessible part of VRAM.

---
 src/gallium/drivers/radeon/r600_buffer_common.c | 23 ++++++++++++++---------
 src/gallium/winsys/radeon/drm/radeon_drm_bo.c   |  8 +++++++-
 src/gallium/winsys/radeon/drm/radeon_winsys.h   |  3 ++-
 3 files changed, 23 insertions(+), 11 deletions(-)
src/gallium/drivers/radeon/r600_buffer_common.c +14 -9
index acdabc0..1a6e97d 100644
@@ -126,6 +126,7 @@ bool r600_init_resource(struct r600_common_screen *rscreen,
 			flags = RADEON_FLAG_GTT_WC;
 			break;
 		}
+		flags = RADEON_FLAG_CPU_ACCESS;
 		/* fall through */
 	case PIPE_USAGE_DEFAULT:
 	case PIPE_USAGE_IMMUTABLE:
@@ -136,23 +137,27 @@ bool r600_init_resource(struct r600_common_screen *rscreen,
 		break;
 	}
 
-	/* Use GTT for all persistent mappings with older kernels, because they
-	 * didn't always flush the HDP cache before CS execution.
-	 *
-	 * Write-combined CPU mappings are fine, the kernel ensures all CPU
-	 * writes finish before the GPU executes a command stream.
-	 */
-	if (rscreen->info.drm_minor < 40 &&
-	    res->b.b.target == PIPE_BUFFER &&
+	if (res->b.b.target == PIPE_BUFFER &&
 	    res->b.b.flags & (PIPE_RESOURCE_FLAG_MAP_PERSISTENT |
 			      PIPE_RESOURCE_FLAG_MAP_COHERENT)) {
-		res->domains = RADEON_DOMAIN_GTT;
+		/* Use GTT for all persistent mappings with older kernels,
+		 * because they didn't always flush the HDP cache before CS
+		 * execution.
+		 *
+		 * Write-combined CPU mappings are fine, the kernel ensures all CPU
+		 * writes finish before the GPU executes a command stream.
+		 */
+		if (rscreen->info.drm_minor < 40)
+			res->domains = RADEON_DOMAIN_GTT;
+		else if (res->domains & RADEON_DOMAIN_VRAM)
+			flags |= RADEON_FLAG_CPU_ACCESS;
 	}
 
 	/* Tiled textures are unmappable. Always put them in VRAM. */
 	if (res->b.b.target != PIPE_BUFFER &&
 	    rtex->surface.level[0].mode >= RADEON_SURF_MODE_1D) {
 		res->domains = RADEON_DOMAIN_VRAM;
+		flags &= ~RADEON_FLAG_CPU_ACCESS;
 	}
 
 	/* Allocate a new resource. */
src/gallium/winsys/radeon/drm/radeon_drm_bo.c +7 -1
index 73f8d38..03b9b1d 100644
@@ -478,7 +478,11 @@ const struct pb_vtbl radeon_bo_vtbl = {
 };
 
 #ifndef RADEON_GEM_GTT_WC
-#define RADEON_GEM_GTT_WC (1 << 2)
+#define RADEON_GEM_GTT_WC	(1 << 2)
+#endif
+#ifndef RADEON_GTM_CPU_ACCESS
+/* BO is expected to be accessed by the CPU */
+#define RADEON_GEM_CPU_ACCESS	(1 << 3)
 #endif
 
 static struct pb_buffer *radeon_bomgr_create_bo(struct pb_manager *_mgr,
@@ -505,6 +509,8 @@ static struct pb_buffer *radeon_bomgr_create_bo(struct pb_manager *_mgr,
 
     if (rdesc->flags & RADEON_FLAG_GTT_WC)
         args.flags |= RADEON_GEM_GTT_WC;
+    if (rdesc->flags & RADEON_FLAG_CPU_ACCESS)
+        args.flags |= RADEON_GEM_CPU_ACCESS;
 
     if (drmCommandWriteRead(rws->fd, DRM_RADEON_GEM_CREATE,
                             &args, sizeof(args))) {
src/gallium/winsys/radeon/drm/radeon_winsys.h +2 -1
index dbd58f1..69bf6ed 100644
@@ -66,7 +66,8 @@ enum radeon_bo_domain { /* bitfield */
 };
 
 enum radeon_bo_flag { /* bitfield */
-   RADEON_FLAG_GTT_WC = (1 << 0)
+    RADEON_FLAG_GTT_WC =     (1 << 0),
+    RADEON_FLAG_CPU_ACCESS = (1 << 1),
 };
 
 enum radeon_bo_usage { /* bitfield */
Signature · 6 lines
2.1.0

_______________________________________________
mesa-dev mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-dev
Reviewed-by on v1 1/1
#2 lore raw

Re: [Mesa-dev] [PATCH] r600g, radeonsi: Inform the kernel if a BO will likely be accessed by the CPU

Marek

Quoted 104 lines · Michel Dänzer

From: Michel Dänzer <[email protected]>

This allows the kernel to prevent such BOs from ever being stored in the CPU inaccessible part of VRAM.

---
 src/gallium/drivers/radeon/r600_buffer_common.c | 23 ++++++++++++++---------
 src/gallium/winsys/radeon/drm/radeon_drm_bo.c   |  8 +++++++-
 src/gallium/winsys/radeon/drm/radeon_winsys.h   |  3 ++-
 3 files changed, 23 insertions(+), 11 deletions(-)
src/gallium/drivers/radeon/r600_buffer_common.c +14 -9
index acdabc0..1a6e97d 100644
@@ -126,6 +126,7 @@ bool r600_init_resource(struct r600_common_screen *rscreen,
                        flags = RADEON_FLAG_GTT_WC;
                        break;
                }
+               flags = RADEON_FLAG_CPU_ACCESS;
                /* fall through */
        case PIPE_USAGE_DEFAULT:
        case PIPE_USAGE_IMMUTABLE:
@@ -136,23 +137,27 @@ bool r600_init_resource(struct r600_common_screen *rscreen,
                break;
        }
 
-       /* Use GTT for all persistent mappings with older kernels, because they
-        * didn't always flush the HDP cache before CS execution.
-        *
-        * Write-combined CPU mappings are fine, the kernel ensures all CPU
-        * writes finish before the GPU executes a command stream.
-        */
-       if (rscreen->info.drm_minor < 40 &&
-           res->b.b.target == PIPE_BUFFER &&
+       if (res->b.b.target == PIPE_BUFFER &&
            res->b.b.flags & (PIPE_RESOURCE_FLAG_MAP_PERSISTENT |
                              PIPE_RESOURCE_FLAG_MAP_COHERENT)) {
-               res->domains = RADEON_DOMAIN_GTT;
+               /* Use GTT for all persistent mappings with older kernels,
+                * because they didn't always flush the HDP cache before CS
+                * execution.
+                *
+                * Write-combined CPU mappings are fine, the kernel ensures all CPU
+                * writes finish before the GPU executes a command stream.
+                */
+               if (rscreen->info.drm_minor < 40)
+                       res->domains = RADEON_DOMAIN_GTT;
+               else if (res->domains & RADEON_DOMAIN_VRAM)
+                       flags |= RADEON_FLAG_CPU_ACCESS;
        }
 
        /* Tiled textures are unmappable. Always put them in VRAM. */
        if (res->b.b.target != PIPE_BUFFER &&
            rtex->surface.level[0].mode >= RADEON_SURF_MODE_1D) {
                res->domains = RADEON_DOMAIN_VRAM;
+               flags &= ~RADEON_FLAG_CPU_ACCESS;
        }
 
        /* Allocate a new resource. */
src/gallium/winsys/radeon/drm/radeon_drm_bo.c +7 -1
index 73f8d38..03b9b1d 100644
@@ -478,7 +478,11 @@ const struct pb_vtbl radeon_bo_vtbl = {
 };
 
 #ifndef RADEON_GEM_GTT_WC
-#define RADEON_GEM_GTT_WC (1 << 2)
+#define RADEON_GEM_GTT_WC      (1 << 2)
+#endif
+#ifndef RADEON_GTM_CPU_ACCESS
+/* BO is expected to be accessed by the CPU */
+#define RADEON_GEM_CPU_ACCESS  (1 << 3)
 #endif
 
 static struct pb_buffer *radeon_bomgr_create_bo(struct pb_manager *_mgr,
@@ -505,6 +509,8 @@ static struct pb_buffer *radeon_bomgr_create_bo(struct pb_manager *_mgr,
 
     if (rdesc->flags & RADEON_FLAG_GTT_WC)
         args.flags |= RADEON_GEM_GTT_WC;
+    if (rdesc->flags & RADEON_FLAG_CPU_ACCESS)
+        args.flags |= RADEON_GEM_CPU_ACCESS;
 
     if (drmCommandWriteRead(rws->fd, DRM_RADEON_GEM_CREATE,
                             &args, sizeof(args))) {
src/gallium/winsys/radeon/drm/radeon_winsys.h +2 -2
index dbd58f1..69bf6ed 100644
@@ -66,7 +66,8 @@ enum radeon_bo_domain { /* bitfield */
 };
 
 enum radeon_bo_flag { /* bitfield */
-   RADEON_FLAG_GTT_WC = (1 << 0)
+    RADEON_FLAG_GTT_WC =     (1 << 0),
+    RADEON_FLAG_CPU_ACCESS = (1 << 1),
 };
 
 enum radeon_bo_usage { /* bitfield */
--

2.1.0

Quoted 4 lines

_______________________________________________
mesa-dev mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw
In reply to Michel Dänzer

Am 28.08.2014 um 08:56 schrieb Michel Dänzer:

Quoted 7 lines

From: Michel Dänzer <[email protected]>

This flag is a hint that userspace expects the BO to be accessed by the CPU. We can use that hint to prevent such BOs from ever being stored in the CPU inaccessible part of VRAM.

This patch is Reviewed-by: Christian König <[email protected]>

I think we need a similar negative flags as well, e.g. RADEON_GEM_NO_CPU_ACCESS.

This way we can stop forcing buffers into the visible VRAM while pinning them for scanout.

Regards,
Christian.

Quoted 39 lines
---
  drivers/gpu/drm/radeon/radeon_object.c | 11 +++++++++--
  include/uapi/drm/radeon_drm.h          |  2 ++
  2 files changed, 11 insertions(+), 2 deletions(-)
drivers/gpu/drm/radeon/radeon_object.c +9 -2
index dc74cc5..908ea541 100644
@@ -143,7 +143,12 @@ void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain)
 
  	for (i = 0; i < c; ++i) {
  		rbo->placements[i].fpfn = 0;
-		rbo->placements[i].lpfn = 0;
+		if ((rbo->flags & RADEON_GEM_CPU_ACCESS) &&
+		    (rbo->placements[i].flags & TTM_PL_FLAG_VRAM))
+			rbo->placements[i].lpfn =
+				rbo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
+		else
+			rbo->placements[i].lpfn = 0;
  	}
 
  	/*
@@ -151,7 +156,9 @@ void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain)
  	 * improve fragmentation quality.
  	 * 512kb was measured as the most optimal number.
  	 */
-	if (rbo->tbo.mem.size > 512 * 1024) {
+	if (!((rbo->flags & RADEON_GEM_CPU_ACCESS) &&
+	      (rbo->placements[i].flags & TTM_PL_FLAG_VRAM)) &&
+	    rbo->tbo.mem.size > 512 * 1024) {
  		for (i = 0; i < c; i++) {
  			rbo->placements[i].flags |= TTM_PL_FLAG_TOPDOWN;
  		}
include/uapi/drm/radeon_drm.h +0 -0
index 509b2d7..bf0067b 100644

include/uapi/drm/radeon_drm.h struct drm_radeon_gem_info { · line 806

Quoted 8 lines
include/uapi/drm/radeon_drm.h +2 -0
@@ -799,6 +799,8 @@ struct drm_radeon_gem_info {
  #define RADEON_GEM_NO_BACKING_STORE	(1 << 0)
  #define RADEON_GEM_GTT_UC		(1 << 1)
  #define RADEON_GEM_GTT_WC		(1 << 2)
+/* BO is expected to be accessed by the CPU */
+#define RADEON_GEM_CPU_ACCESS		(1 << 3)
 
  struct drm_radeon_gem_create {
  	uint64_t	size;

_______________________________________________
mesa-dev mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Applied
#4 lore raw
Quoted 4 lines · Christian König

Am 28.08.2014 um 08:56 schrieb Michel Dänzer:

Quoted 2 lines

From: Michel Dänzer <[email protected]>

Quoted 8 lines
Quoted 5 lines

This flag is a hint that userspace expects the BO to be accessed by the CPU. We can use that hint to prevent such BOs from ever being stored in the CPU inaccessible part of VRAM.

This patch is Reviewed-by: Christian König <[email protected]>

Applied to my -next tree.

Quoted 6 lines

I think we need a similar negative flags as well, e.g. RADEON_GEM_NO_CPU_ACCESS.

This way we can stop forcing buffers into the visible VRAM while pinning them for scanout.

How about the attached patch?

Alex

Quoted 51 lines

Regards,
Christian.

Quoted 46 lines
---
  drivers/gpu/drm/radeon/radeon_object.c | 11 +++++++++--
  include/uapi/drm/radeon_drm.h          |  2 ++
  2 files changed, 11 insertions(+), 2 deletions(-)
drivers/gpu/drm/radeon/radeon_object.c +9 -2
index dc74cc5..908ea541 100644
@@ -143,7 +143,12 @@ void radeon_ttm_placement_from_domain(struct
 radeon_bo *rbo, u32 domain)
        for (i = 0; i < c; ++i) {
                rbo->placements[i].fpfn = 0;
-               rbo->placements[i].lpfn = 0;
+               if ((rbo->flags & RADEON_GEM_CPU_ACCESS) &&
+                   (rbo->placements[i].flags & TTM_PL_FLAG_VRAM))
+                       rbo->placements[i].lpfn =
+                               rbo->rdev->mc.visible_vram_size >>
 PAGE_SHIFT;
+               else
+                       rbo->placements[i].lpfn = 0;
        }
        /*
@@ -151,7 +156,9 @@ void radeon_ttm_placement_from_domain(struct radeon_bo
 *rbo, u32 domain)
         * improve fragmentation quality.
         * 512kb was measured as the most optimal number.
         */
-       if (rbo->tbo.mem.size > 512 * 1024) {
+       if (!((rbo->flags & RADEON_GEM_CPU_ACCESS) &&
+             (rbo->placements[i].flags & TTM_PL_FLAG_VRAM)) &&
+           rbo->tbo.mem.size > 512 * 1024) {
                for (i = 0; i < c; i++) {
                        rbo->placements[i].flags |= TTM_PL_FLAG_TOPDOWN;
                }
include/uapi/drm/radeon_drm.h +2 -0
index 509b2d7..bf0067b 100644
@@ -799,6 +799,8 @@ struct drm_radeon_gem_info {
  #define RADEON_GEM_NO_BACKING_STORE   (1 << 0)
  #define RADEON_GEM_GTT_UC             (1 << 1)
  #define RADEON_GEM_GTT_WC             (1 << 2)
+/* BO is expected to be accessed by the CPU */
+#define RADEON_GEM_CPU_ACCESS          (1 << 3)
Quoted 8 lines

include/uapi/drm/radeon_drm.h struct drm_radeon_gem_info { · line 805

Quoted 2 lines
include/uapi/drm/radeon_drm.h +0 -0
    struct drm_radeon_gem_create {
        uint64_t        size;

_______________________________________________
mesa-dev mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

From d6a65c62241fe2b3c1a0dd799f2af0802297446c Mon Sep 17 00:00:00 2001
From: Alex Deucher <[email protected]>
Date: Thu, 28 Aug 2014 10:59:05 -0400
Subject: [PATCH] drm/radeon: add RADEON_GEM_NO_CPU_ACCESS BO creation flag

Allows pinning of buffers in the non-CPU visible portion of vram.

---
 drivers/gpu/drm/radeon/radeon_object.c | 10 +++++++---
 include/uapi/drm/radeon_drm.h          |  2 ++
 2 files changed, 9 insertions(+), 3 deletions(-)
drivers/gpu/drm/radeon/radeon_object.c +7 -3
index 09b039a..b71e8e0 100644
@@ -314,10 +314,14 @@ int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset,
 		unsigned lpfn = 0;
 
 		/* force to pin into visible video ram */
-		if (bo->placements[i].flags & TTM_PL_FLAG_VRAM)
-			lpfn = bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
-		else
+		if (bo->placements[i].flags & TTM_PL_FLAG_VRAM) {
+			if (bo->flags & RADEON_GEM_NO_CPU_ACCESS)
+				lpfn = bo->rdev->mc.real_vram_size >> PAGE_SHIFT;
+			else
+				lpfn = bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
+		} else {
 			lpfn = bo->rdev->mc.gtt_size >> PAGE_SHIFT; /* ??? */
+		}
 
 		if (max_offset)
 			lpfn = min (lpfn, (unsigned)(max_offset >> PAGE_SHIFT));
include/uapi/drm/radeon_drm.h +2 -0
index f755f20..d2346fd 100644
@@ -803,6 +803,8 @@ struct drm_radeon_gem_info {
 #define RADEON_GEM_GTT_WC		(1 << 2)
 /* BO is expected to be accessed by the CPU */
 #define RADEON_GEM_CPU_ACCESS		(1 << 3)
+/* BO is expected to not be accessed by the CPU */
+#define RADEON_GEM_NO_CPU_ACCESS	(1 << 4)
 
 struct drm_radeon_gem_create {
 	uint64_t	size;
Signature · 1 line
1.8.3.1

_______________________________________________
mesa-dev mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

#5 lore raw
Quoted 10 lines · Alex Deucher
Quoted 8 lines · Christian König

Am 28.08.2014 um 08:56 schrieb Michel Dänzer:

Quoted 6 lines

From: Michel Dänzer <[email protected]>

This flag is a hint that userspace expects the BO to be accessed by the CPU. We can use that hint to prevent such BOs from ever being stored in the CPU inaccessible part of VRAM.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

This patch is Reviewed-by: Christian König <[email protected]>

Applied to my -next tree.

Thanks!

Quoted 7 lines
Quoted 5 lines

I think we need a similar negative flags as well, e.g. RADEON_GEM_NO_CPU_ACCESS.

This way we can stop forcing buffers into the visible VRAM while pinning them for scanout.

How about the attached patch?

[...]

Quoted 6 lines
drivers/gpu/drm/radeon/radeon_object.c +0 -0
index 09b039a..b71e8e0 100644
@@ -314,10 +314,14 @@ int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset,
 		unsigned lpfn = 0;

drivers/gpu/drm/radeon/radeon_object.c int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset, · line 321

Quoted 10 lines
drivers/gpu/drm/radeon/radeon_object.c +5 -3
 
 		/* force to pin into visible video ram */
-		if (bo->placements[i].flags & TTM_PL_FLAG_VRAM)
-			lpfn = bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
-		else
+		if (bo->placements[i].flags & TTM_PL_FLAG_VRAM) {
+			if (bo->flags & RADEON_GEM_NO_CPU_ACCESS)
+				lpfn = bo->rdev->mc.real_vram_size >> PAGE_SHIFT;
+			else
+				lpfn = bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;

lpfn can be left at 0 if RADEON_GEM_NO_CPU_ACCESS is set, so this can be simplified to:

			if (!(bo->flags & RADEON_GEM_NO_CPU_ACCESS))
				lpfn = bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;

include/uapi/drm/radeon_drm.h struct drm_radeon_gem_info { · line 807

Quoted 10 lines
include/uapi/drm/radeon_drm.h +2 -0
index f755f20..d2346fd 100644
@@ -803,6 +803,8 @@ struct drm_radeon_gem_info {
 #define RADEON_GEM_GTT_WC		(1 << 2)
 /* BO is expected to be accessed by the CPU */
 #define RADEON_GEM_CPU_ACCESS		(1 << 3)
+/* BO is expected to not be accessed by the CPU */
+#define RADEON_GEM_NO_CPU_ACCESS	(1 << 4)

I'd use stronger wording for this, e.g.

/* CPU access is not expected to work for this BO */

Signature · 2 lines
Earthling Michel Dänzer            |                  http://www.amd.com
Libre software enthusiast          |                Mesa and X developer
#6 lore raw
Quoted 68 lines · Michel Dänzer
Quoted 10 lines · Alex Deucher
Quoted 8 lines · Christian König

Am 28.08.2014 um 08:56 schrieb Michel Dänzer:

Quoted 6 lines

From: Michel Dänzer <[email protected]>

This flag is a hint that userspace expects the BO to be accessed by the CPU. We can use that hint to prevent such BOs from ever being stored in the CPU inaccessible part of VRAM.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

This patch is Reviewed-by: Christian König <[email protected]>

Applied to my -next tree.

Thanks!

Quoted 7 lines
Quoted 5 lines

I think we need a similar negative flags as well, e.g. RADEON_GEM_NO_CPU_ACCESS.

This way we can stop forcing buffers into the visible VRAM while pinning them for scanout.

How about the attached patch?

[...]

Quoted 6 lines
drivers/gpu/drm/radeon/radeon_object.c +0 -0
index 09b039a..b71e8e0 100644
@@ -314,10 +314,14 @@ int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset,
              unsigned lpfn = 0;

drivers/gpu/drm/radeon/radeon_object.c int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset, · line 321

Quoted 10 lines
drivers/gpu/drm/radeon/radeon_object.c +5 -3
 
              /* force to pin into visible video ram */
-             if (bo->placements[i].flags & TTM_PL_FLAG_VRAM)
-                     lpfn = bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
-             else
+             if (bo->placements[i].flags & TTM_PL_FLAG_VRAM) {
+                     if (bo->flags & RADEON_GEM_NO_CPU_ACCESS)
+                             lpfn = bo->rdev->mc.real_vram_size >> PAGE_SHIFT;
+                     else
+                             lpfn = bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;

lpfn can be left at 0 if RADEON_GEM_NO_CPU_ACCESS is set, so this can be simplified to:

                        if (!(bo->flags & RADEON_GEM_NO_CPU_ACCESS))
                                lpfn = bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;

include/uapi/drm/radeon_drm.h struct drm_radeon_gem_info { · line 807

Quoted 10 lines
include/uapi/drm/radeon_drm.h +2 -0
index f755f20..d2346fd 100644
@@ -803,6 +803,8 @@ struct drm_radeon_gem_info {
 #define RADEON_GEM_GTT_WC            (1 << 2)
 /* BO is expected to be accessed by the CPU */
 #define RADEON_GEM_CPU_ACCESS                (1 << 3)
+/* BO is expected to not be accessed by the CPU */
+#define RADEON_GEM_NO_CPU_ACCESS     (1 << 4)

I'd use stronger wording for this, e.g.

Quoted 1 line

/* CPU access is not expected to work for this BO */

Updated version with comments integrated.

Alex

From 8e0fe1b090f75e5b7cadc9c316d1a9e3668c8ed2 Mon Sep 17 00:00:00 2001
From: Alex Deucher <[email protected]>
Date: Thu, 28 Aug 2014 10:59:05 -0400
Subject: [PATCH] drm/radeon: add RADEON_GEM_NO_CPU_ACCESS BO creation flag
(v2)

Allows pinning of buffers in the non-CPU visible portion of vram.

v2: incorporate Michel's comments.

---
 drivers/gpu/drm/radeon/radeon_object.c | 8 +++++---
 include/uapi/drm/radeon_drm.h          | 2 ++
 2 files changed, 7 insertions(+), 3 deletions(-)
drivers/gpu/drm/radeon/radeon_object.c +5 -3
index eef60aa..c7ad231d 100644
@@ -314,10 +314,12 @@ int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset,
 		unsigned lpfn = 0;
 
 		/* force to pin into visible video ram */
-		if (bo->placements[i].flags & TTM_PL_FLAG_VRAM)
-			lpfn = bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
-		else
+		if (bo->placements[i].flags & TTM_PL_FLAG_VRAM) {
+			if (!(bo->flags & RADEON_GEM_NO_CPU_ACCESS))
+				lpfn = bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
+		} else {
 			lpfn = bo->rdev->mc.gtt_size >> PAGE_SHIFT; /* ??? */
+		}
 
 		if (max_offset)
 			lpfn = min (lpfn, (unsigned)(max_offset >> PAGE_SHIFT));
include/uapi/drm/radeon_drm.h +2 -0
index f755f20..50d0fb4 100644
@@ -803,6 +803,8 @@ struct drm_radeon_gem_info {
 #define RADEON_GEM_GTT_WC		(1 << 2)
 /* BO is expected to be accessed by the CPU */
 #define RADEON_GEM_CPU_ACCESS		(1 << 3)
+/* CPU access is not expected to work for this BO */
+#define RADEON_GEM_NO_CPU_ACCESS	(1 << 4)
 
 struct drm_radeon_gem_create {
 	uint64_t	size;
Signature · 1 line
1.8.3.1

_______________________________________________
mesa-dev mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

author Reviewed-by
#7 lore raw
Quoted 2 lines · Alex Deucher

Updated version with comments integrated.

[...]

drivers/gpu/drm/radeon/radeon_object.c int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset, · line 322

Quoted 13 lines
drivers/gpu/drm/radeon/radeon_object.c +5 -3
@@ -314,10 +314,12 @@ int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset,
 		unsigned lpfn = 0;
 
 		/* force to pin into visible video ram */
-		if (bo->placements[i].flags & TTM_PL_FLAG_VRAM)
-			lpfn = bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
-		else
+		if (bo->placements[i].flags & TTM_PL_FLAG_VRAM) {
+			if (!(bo->flags & RADEON_GEM_NO_CPU_ACCESS))
+				lpfn = bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
+		} else {
 			lpfn = bo->rdev->mc.gtt_size >> PAGE_SHIFT; /* ??? */
+		}

The else block can be removed as well, but that can be done in another patch.

Either way, v2 is

Signature · 2 lines
Earthling Michel Dänzer            |                  http://www.amd.com
Libre software enthusiast          |                Mesa and X developer
#8 lore raw
Quoted 10 lines · Michel Dänzer
Quoted 2 lines · Alex Deucher

Updated version with comments integrated.

[...]

Quoted 4 lines
(quoted diff) +0 -0
@@ -314,10 +314,12 @@ int radeon_bo_pin_restricted(struct radeon_bo 
 *bo, u32 domain, u64 max_offset,
         unsigned lpfn = 0;
 
Quoted 13 lines

Review int radeon_bo_pin_restricted(struct radeon_bo · line 323

Quoted 10 lines
(quoted diff) +5 -3
         /* force to pin into visible video ram */
-        if (bo->placements[i].flags & TTM_PL_FLAG_VRAM)
-            lpfn = bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
-        else
+        if (bo->placements[i].flags & TTM_PL_FLAG_VRAM) {
+            if (!(bo->flags & RADEON_GEM_NO_CPU_ACCESS))
+                lpfn = bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
+        } else {
             lpfn = bo->rdev->mc.gtt_size >> PAGE_SHIFT; /* ??? */
+        }

The else block can be removed as well, but that can be done in another patch.

Actually, I just noticed a problem, the following if statement:

Review

Quoted 2 lines
(quoted diff) +0 -0
 		if (max_offset)
 			lpfn = min (lpfn, (unsigned)(max_offset >> PAGE_SHIFT));

This will ignore max_offset if lpfn is 0. So either go with v1 of this hunk, or rebase on top of the patch below.

From: =?UTF-8?q?Michel=20D=C3=A4nzer?= <[email protected]>
Date: Tue, 9 Sep 2014 10:09:23 +0900
Subject: [PATCH] drm/radeon: Clean up assignment of TTM placement lpfn member
for pinning
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 drivers/gpu/drm/radeon/radeon_object.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/gpu/drm/radeon/radeon_object.c +4 -8
index 908ea541..8ec8150 100644
@@ -307,18 +307,14 @@ int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset,
 	}
 	radeon_ttm_placement_from_domain(bo, domain);
 	for (i = 0; i < bo->placement.num_placement; i++) {
-		unsigned lpfn = 0;
-
 		/* force to pin into visible video ram */
 		if (bo->placements[i].flags & TTM_PL_FLAG_VRAM)
-			lpfn = bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
+			bo->placements[i].lpfn =
+				min(bo->rdev->mc.visible_vram_size, max_offset)
+				>> PAGE_SHIFT;
 		else
-			lpfn = bo->rdev->mc.gtt_size >> PAGE_SHIFT; /* ??? */
-
-		if (max_offset)
-			lpfn = min (lpfn, (unsigned)(max_offset >> PAGE_SHIFT));
+			bo->placements[i].lpfn = max_offset >> PAGE_SHIFT;
 
-		bo->placements[i].lpfn = lpfn;
 		bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT;
 	}
 
Signature · 6 lines
2.1.0


-- 
Earthling Michel Dänzer            |                  http://www.amd.com
Libre software enthusiast          |                Mesa and X developer
#9 lore raw
Quoted 25 lines · Michel Dänzer
Quoted 10 lines · Michel Dänzer
Quoted 2 lines · Alex Deucher

Updated version with comments integrated.

[...]

Quoted 4 lines
(quoted diff) +0 -0
@@ -314,10 +314,12 @@ int radeon_bo_pin_restricted(struct radeon_bo
 *bo, u32 domain, u64 max_offset,
         unsigned lpfn = 0;
 
Quoted 13 lines

Review int radeon_bo_pin_restricted(struct radeon_bo · line 323

Quoted 10 lines
(quoted diff) +5 -3
         /* force to pin into visible video ram */
-        if (bo->placements[i].flags & TTM_PL_FLAG_VRAM)
-            lpfn = bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
-        else
+        if (bo->placements[i].flags & TTM_PL_FLAG_VRAM) {
+            if (!(bo->flags & RADEON_GEM_NO_CPU_ACCESS))
+                lpfn = bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
+        } else {
             lpfn = bo->rdev->mc.gtt_size >> PAGE_SHIFT; /* ??? */
+        }

The else block can be removed as well, but that can be done in another patch.

Quoted 8 lines

Actually, I just noticed a problem, the following if statement:

Quoted 2 lines
              if (max_offset)
                      lpfn = min (lpfn, (unsigned)(max_offset >> PAGE_SHIFT));

This will ignore max_offset if lpfn is 0. So either go with v1 of this hunk, or rebase on top of the patch below.

Rebased on your patch and attached.

Alex

Quoted 45 lines

From: =?UTF-8?q?Michel=20D=C3=A4nzer?= <[email protected]>
Date: Tue, 9 Sep 2014 10:09:23 +0900
Subject: [PATCH] drm/radeon: Clean up assignment of TTM placement lpfn member
for pinning
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 drivers/gpu/drm/radeon/radeon_object.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/gpu/drm/radeon/radeon_object.c +4 -9
index 908ea541..8ec8150 100644
@@ -307,18 +307,14 @@ int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset,
        }
        radeon_ttm_placement_from_domain(bo, domain);
        for (i = 0; i < bo->placement.num_placement; i++) {
-               unsigned lpfn = 0;
-
                /* force to pin into visible video ram */
                if (bo->placements[i].flags & TTM_PL_FLAG_VRAM)
-                       lpfn = bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
+                       bo->placements[i].lpfn =
+                               min(bo->rdev->mc.visible_vram_size, max_offset)
+                               >> PAGE_SHIFT;
                else
-                       lpfn = bo->rdev->mc.gtt_size >> PAGE_SHIFT; /* ??? */
-
-               if (max_offset)
-                       lpfn = min (lpfn, (unsigned)(max_offset >> PAGE_SHIFT));
+                       bo->placements[i].lpfn = max_offset >> PAGE_SHIFT;
 
-               bo->placements[i].lpfn = lpfn;
                bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT;
        }
 
--

2.1.0

Quoted 3 lines

--
Earthling Michel Dänzer | http://www.amd.com
Libre software enthusiast | Mesa and X developer

From 998fabb91851cef7c70e0f3920e45c70da301647 Mon Sep 17 00:00:00 2001
From: Alex Deucher <[email protected]>
Date: Tue, 9 Sep 2014 12:24:33 -0400
Subject: [PATCH] drm/radeon: add RADEON_GEM_NO_CPU_ACCESS BO creation flag
(v3)

Allows pinning of buffers in the non-CPU visible portion of vram.

v2: incorporate Michel's comments.
v3: rebase on Michel's patch

---
 drivers/gpu/drm/radeon/radeon_object.c | 3 ++-
 include/uapi/drm/radeon_drm.h          | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/radeon/radeon_object.c +2 -1
index 68ab122..0d54993 100644
@@ -312,7 +312,8 @@ int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset,
 	radeon_ttm_placement_from_domain(bo, domain);
 	for (i = 0; i < bo->placement.num_placement; i++) {
 		/* force to pin into visible video ram */
-		if (bo->placements[i].flags & TTM_PL_FLAG_VRAM)
+		if ((bo->placements[i].flags & TTM_PL_FLAG_VRAM) &&
+		    (!(bo->flags & RADEON_GEM_NO_CPU_ACCESS)))
 			bo->placements[i].lpfn =
 				min(bo->rdev->mc.visible_vram_size, max_offset)
 				>> PAGE_SHIFT;
include/uapi/drm/radeon_drm.h +2 -0
index f755f20..50d0fb4 100644
@@ -803,6 +803,8 @@ struct drm_radeon_gem_info {
 #define RADEON_GEM_GTT_WC		(1 << 2)
 /* BO is expected to be accessed by the CPU */
 #define RADEON_GEM_CPU_ACCESS		(1 << 3)
+/* CPU access is not expected to work for this BO */
+#define RADEON_GEM_NO_CPU_ACCESS	(1 << 4)
 
 struct drm_radeon_gem_create {
 	uint64_t	size;
Signature · 1 line
1.8.3.1

_______________________________________________
mesa-dev mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

author Reviewed-by
#10 lore raw
Quoted 28 lines · Alex Deucher
Quoted 27 lines · Michel Dänzer
Quoted 10 lines · Michel Dänzer
Quoted 2 lines · Alex Deucher

Updated version with comments integrated.

[...]

Quoted 4 lines
(quoted diff) +0 -0
@@ -314,10 +314,12 @@ int radeon_bo_pin_restricted(struct radeon_bo
 *bo, u32 domain, u64 max_offset,
          unsigned lpfn = 0;
 
Quoted 13 lines

Review int radeon_bo_pin_restricted(struct radeon_bo · line 323

Quoted 10 lines
(quoted diff) +5 -3
          /* force to pin into visible video ram */
-        if (bo->placements[i].flags & TTM_PL_FLAG_VRAM)
-            lpfn = bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
-        else
+        if (bo->placements[i].flags & TTM_PL_FLAG_VRAM) {
+            if (!(bo->flags & RADEON_GEM_NO_CPU_ACCESS))
+                lpfn = bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
+        } else {
              lpfn = bo->rdev->mc.gtt_size >> PAGE_SHIFT; /* ??? */
+        }

The else block can be removed as well, but that can be done in another patch.

Actually, I just noticed a problem, the following if statement:

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
               if (max_offset)
                       lpfn = min (lpfn, (unsigned)(max_offset >> PAGE_SHIFT));

This will ignore max_offset if lpfn is 0. So either go with v1 of this hunk, or rebase on top of the patch below.

Rebased on your patch and attached.

My patch didn't handle max_offset == 0 correctly. Attaching a fixed v2 patch and your patch rebased on top of that.

Signature · 2 lines
Earthling Michel Dänzer            |                  http://www.amd.com
Libre software enthusiast          |                Mesa and X developer
Quoted 1 line

From 0428f396173e458288a5f0e1807033ebe9931ce0 Mon Sep 17 00:00:00 2001

From: =?UTF-8?q?Michel=20D=C3=A4nzer?= <[email protected]>
Date: Tue, 9 Sep 2014 10:09:23 +0900
Subject: [PATCH v2 1/2] drm/radeon: Clean up assignment of TTM placement lpfn
member for pinning
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This sets the lpfn member to 0 instead of the full domain size. TTM uses the full domain size when lpfn is 0.

---

v2: Handle max_offset == 0 correctly

 drivers/gpu/drm/radeon/radeon_object.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/gpu/drm/radeon/radeon_object.c +5 -9
index 908ea541..24c8772 100644
@@ -307,18 +307,14 @@ int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset,
 	}
 	radeon_ttm_placement_from_domain(bo, domain);
 	for (i = 0; i < bo->placement.num_placement; i++) {
-		unsigned lpfn = 0;
-
 		/* force to pin into visible video ram */
-		if (bo->placements[i].flags & TTM_PL_FLAG_VRAM)
-			lpfn = bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
+		if ((bo->placements[i].flags & TTM_PL_FLAG_VRAM) &&
+		    (!max_offset || max_offset > bo->rdev->mc.visible_vram_size))
+			bo->placements[i].lpfn =
+				bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
 		else
-			lpfn = bo->rdev->mc.gtt_size >> PAGE_SHIFT; /* ??? */
-
-		if (max_offset)
-			lpfn = min (lpfn, (unsigned)(max_offset >> PAGE_SHIFT));
+			bo->placements[i].lpfn = max_offset >> PAGE_SHIFT;
 
-		bo->placements[i].lpfn = lpfn;
 		bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT;
 	}
 
Signature · 1 line
2.1.0
Quoted 1 line

From 8e896486464526add633b6809b6d020ad810315c Mon Sep 17 00:00:00 2001

From: Alex Deucher <[email protected]>
Date: Thu, 28 Aug 2014 10:59:05 -0400
Subject: [PATCH 2/2] drm/radeon: add RADEON_GEM_NO_CPU_ACCESS BO creation flag
(v4)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Allows pinning of buffers in the non-CPU visible portion of vram.

v2: incorporate Michel's comments.
v3: rebase on Michel's patch
v4: rebase on Michel's v2 patch

---
 drivers/gpu/drm/radeon/radeon_object.c | 1 +
 include/uapi/drm/radeon_drm.h          | 2 ++
 2 files changed, 3 insertions(+)
drivers/gpu/drm/radeon/radeon_object.c +1 -0
index 24c8772..d3f0a19 100644
@@ -309,6 +309,7 @@ int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset,
 	for (i = 0; i < bo->placement.num_placement; i++) {
 		/* force to pin into visible video ram */
 		if ((bo->placements[i].flags & TTM_PL_FLAG_VRAM) &&
+		    !(bo->flags & RADEON_GEM_NO_CPU_ACCESS) &&
 		    (!max_offset || max_offset > bo->rdev->mc.visible_vram_size))
 			bo->placements[i].lpfn =
 				bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
include/uapi/drm/radeon_drm.h +2 -0
index bf0067b..017f869 100644
@@ -801,6 +801,8 @@ struct drm_radeon_gem_info {
 #define RADEON_GEM_GTT_WC		(1 << 2)
 /* BO is expected to be accessed by the CPU */
 #define RADEON_GEM_CPU_ACCESS		(1 << 3)
+/* CPU access is not expected to work for this BO */
+#define RADEON_GEM_NO_CPU_ACCESS	(1 << 4)
 
 struct drm_radeon_gem_create {
 	uint64_t	size;
Signature · 1 line
2.1.0

_______________________________________________
mesa-dev mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Applied
#11 lore raw
Quoted 46 lines · Michel Dänzer
Quoted 45 lines · Alex Deucher
Quoted 42 lines · Michel Dänzer
Quoted 13 lines · Michel Dänzer
Quoted 3 lines · Alex Deucher

Updated version with comments integrated.

[...]

Quoted 4 lines
(quoted diff) +0 -0
@@ -314,10 +314,12 @@ int radeon_bo_pin_restricted(struct radeon_bo
 *bo, u32 domain, u64 max_offset,
          unsigned lpfn = 0;
 
Quoted 14 lines

Review int radeon_bo_pin_restricted(struct radeon_bo · line 323

Quoted 10 lines
(quoted diff) +5 -3
          /* force to pin into visible video ram */
-        if (bo->placements[i].flags & TTM_PL_FLAG_VRAM)
-            lpfn = bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
-        else
+        if (bo->placements[i].flags & TTM_PL_FLAG_VRAM) {
+            if (!(bo->flags & RADEON_GEM_NO_CPU_ACCESS))
+                lpfn = bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
+        } else {
              lpfn = bo->rdev->mc.gtt_size >> PAGE_SHIFT; /* ??? */
+        }

The else block can be removed as well, but that can be done in another patch.

Actually, I just noticed a problem, the following if statement:

Quoted 3 lines

if (max_offset)
lpfn = min (lpfn, (unsigned)(max_offset >>
PAGE_SHIFT));

This will ignore max_offset if lpfn is 0. So either go with v1 of this hunk,
or rebase on top of the patch below.

Quoted 5 lines
Quoted 1 line

Rebased on your patch and attached.

My patch didn't handle max_offset == 0 correctly. Attaching a fixed v2 patch and your patch rebased on top of that.

Applied. thanks!

Alex
_______________________________________________
mesa-dev mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-dev