Skip to contentSkip to conversation

drm/omap: fix tiled buffer stride calculations

PATCH In review Tomi Valkeinen 3 participants 7 messages May 18, 2017

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

PATCH 1/1 drm/omap: fix tiled buffer stride calculations

omap_gem uses page alignment for buffer stride. The related calculations are a bit off, though, as byte stride of 4096 gets aligned to 8192, instead of 4096. This patch fixes those calculations.

---
 drivers/gpu/drm/omapdrm/omap_gem.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/omapdrm/omap_gem.c +2 -2
index 13abf221d153..4c41000ff4c4 100644
@@ -182,7 +182,7 @@ static void evict_entry(struct drm_gem_object *obj,
 	size_t size = PAGE_SIZE * n;
 	loff_t off = mmap_offset(obj) +
 			(entry->obj_pgoff << PAGE_SHIFT);
-	const int m = 1 + ((omap_obj->width << fmt) / PAGE_SIZE);
+	const int m = 1 + (((omap_obj->width - 1) << fmt) / PAGE_SIZE);
 
 	if (m > 1) {
 		int i;
@@ -424,7 +424,7 @@ static int fault_2d(struct drm_gem_object *obj,
 	 * into account in some of the math, so figure out virtual stride
 	 * in pages
 	 */
-	const int m = 1 + ((omap_obj->width << fmt) / PAGE_SIZE);
+	const int m = 1 + (((omap_obj->width - 1) << fmt) / PAGE_SIZE);
 
 	/* We don't use vmf->pgoff since that has the fake offset: */
 	pgoff = (vmf->address - vma->vm_start) >> PAGE_SHIFT;
Signature · 6 lines
2.7.4

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

Hi Tomi,

Thank you for the patch.

Quoted 15 lines · On Thursday 18 May 2017 13:28:26 Tomi Valkeinen wrote:

omap_gem uses page alignment for buffer stride. The related calculations are a bit off, though, as byte stride of 4096 gets aligned to 8192, instead of 4096. This patch fixes those calculations.

---
 drivers/gpu/drm/omapdrm/omap_gem.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/omapdrm/omap_gem.c index 13abf221d153..4c41000ff4c4 100644

drivers/gpu/drm/omapdrm/omap_gem.c static void evict_entry(struct drm_gem_object *obj, · line 185

Quoted 5 lines
drivers/gpu/drm/omapdrm/omap_gem.c +1 -1
@@ -182,7 +182,7 @@ static void evict_entry(struct drm_gem_object *obj,
 	size_t size = PAGE_SIZE * n;
 	loff_t off = mmap_offset(obj) +
 			(entry->obj_pgoff << PAGE_SHIFT);
-	const int m = 1 + ((omap_obj->width << fmt) / PAGE_SIZE);
+	const int m = 1 + (((omap_obj->width - 1) << fmt) / PAGE_SIZE);

How about

	int m = round_up(omap_obj->width << fmt, PAGE_SIZE);

instead of open-coding it ? I find that a bit easier to understand.

By the way, shifting left by fmt should be fine for TILFMT_8BIT, TILFMT_16BIT and TILFMT_32BIT that evaluate to 0, 1 and 2 respectively, but how does it work with TILFMT_PAGE ? fmt is computed by gem2fmt() in call cases, which returns TILFMT_PAGE in the default case (no tiled flag set). Can this happen in practice ?

Quoted 12 lines
drivers/gpu/drm/omapdrm/omap_gem.c +1 -1
 	if (m > 1) {
 		int i;
@@ -424,7 +424,7 @@ static int fault_2d(struct drm_gem_object *obj,
 	 * into account in some of the math, so figure out virtual stride
 	 * in pages
 	 */
-	const int m = 1 + ((omap_obj->width << fmt) / PAGE_SIZE);
+	const int m = 1 + (((omap_obj->width - 1) << fmt) / PAGE_SIZE);
 
 	/* We don't use vmf->pgoff since that has the fake offset: */
 	pgoff = (vmf->address - vma->vm_start) >> PAGE_SHIFT;
Signature · 8 lines
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw
Quoted 28 lines · Laurent Pinchart

Hi Tomi,

Thank you for the patch.

Quoted 15 lines · On Thursday 18 May 2017 13:28:26 Tomi Valkeinen wrote:

omap_gem uses page alignment for buffer stride. The related calculations are a bit off, though, as byte stride of 4096 gets aligned to 8192, instead of 4096. This patch fixes those calculations.

---
 drivers/gpu/drm/omapdrm/omap_gem.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/omapdrm/omap_gem.c index 13abf221d153..4c41000ff4c4 100644

drivers/gpu/drm/omapdrm/omap_gem.c static void evict_entry(struct drm_gem_object *obj, · line 185

Quoted 5 lines
drivers/gpu/drm/omapdrm/omap_gem.c +1 -1
@@ -182,7 +182,7 @@ static void evict_entry(struct drm_gem_object *obj,
 	size_t size = PAGE_SIZE * n;
 	loff_t off = mmap_offset(obj) +
 			(entry->obj_pgoff << PAGE_SHIFT);
-	const int m = 1 + ((omap_obj->width << fmt) / PAGE_SIZE);
+	const int m = 1 + (((omap_obj->width - 1) << fmt) / PAGE_SIZE);

How about

Quoted 3 lines
	int m = round_up(omap_obj->width << fmt, PAGE_SIZE);

instead of open-coding it ? I find that a bit easier to understand.

That should be:

round_up(omap_obj->width << fmt, PAGE_SIZE) / PAGE_SIZE;

Yes, I think that's more understandable.

Quoted 5 lines

By the way, shifting left by fmt should be fine for TILFMT_8BIT, TILFMT_16BIT and TILFMT_32BIT that evaluate to 0, 1 and 2 respectively, but how does it work with TILFMT_PAGE ? fmt is computed by gem2fmt() in call cases, which returns TILFMT_PAGE in the default case (no tiled flag set). Can this happen in practice ?

These functions are only called for 2D buffers. I do find shifting by 'enum tiler_fmt' quite ugly, though...

Tomi

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

#3 lore raw

Hi Tomi,

Quoted 26 lines · On Thursday 18 May 2017 14:14:35 Tomi Valkeinen wrote:
Quoted 25 lines · Laurent Pinchart
Quoted 16 lines · On Thursday 18 May 2017 13:28:26 Tomi Valkeinen wrote:

omap_gem uses page alignment for buffer stride. The related calculations are a bit off, though, as byte stride of 4096 gets aligned to 8192, instead of 4096. This patch fixes those calculations.

---

 drivers/gpu/drm/omapdrm/omap_gem.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/omapdrm/omap_gem.c index 13abf221d153..4c41000ff4c4 100644

drivers/gpu/drm/omapdrm/omap_gem.c static void evict_entry(struct drm_gem_object *obj, · line 185

Quoted 5 lines
drivers/gpu/drm/omapdrm/omap_gem.c +1 -1
@@ -182,7 +182,7 @@ static void evict_entry(struct drm_gem_object *obj,
 	size_t size = PAGE_SIZE * n;
 	loff_t off = mmap_offset(obj) +
 			(entry->obj_pgoff << PAGE_SHIFT);
-	const int m = 1 + ((omap_obj->width << fmt) / PAGE_SIZE);
+	const int m = 1 + (((omap_obj->width - 1) << fmt) / PAGE_SIZE);

How about

Quoted 7 lines
Quoted 3 lines
	int m = round_up(omap_obj->width << fmt, PAGE_SIZE);

instead of open-coding it ? I find that a bit easier to understand.

That should be:

round_up(omap_obj->width << fmt, PAGE_SIZE) / PAGE_SIZE;

Sorry, I meant DIV_ROUND_UP, not round_up.

Quoted 10 lines

Yes, I think that's more understandable.

Quoted 5 lines

By the way, shifting left by fmt should be fine for TILFMT_8BIT, TILFMT_16BIT and TILFMT_32BIT that evaluate to 0, 1 and 2 respectively, but how does it work with TILFMT_PAGE ? fmt is computed by gem2fmt() in call cases, which returns TILFMT_PAGE in the default case (no tiled flag set). Can this happen in practice ?

These functions are only called for 2D buffers. I do find shifting by 'enum tiler_fmt' quite ugly, though...

So do I. This should be added to the infinite todo list :-)

Signature · 8 lines
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw
Quoted 31 lines · Laurent Pinchart

Hi Tomi,

Quoted 28 lines · On Thursday 18 May 2017 14:14:35 Tomi Valkeinen wrote:
Quoted 27 lines · Laurent Pinchart
Quoted 16 lines · On Thursday 18 May 2017 13:28:26 Tomi Valkeinen wrote:

omap_gem uses page alignment for buffer stride. The related calculations are a bit off, though, as byte stride of 4096 gets aligned to 8192, instead of 4096. This patch fixes those calculations.

---

 drivers/gpu/drm/omapdrm/omap_gem.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/omapdrm/omap_gem.c index 13abf221d153..4c41000ff4c4 100644

drivers/gpu/drm/omapdrm/omap_gem.c static void evict_entry(struct drm_gem_object *obj, · line 185

Quoted 5 lines
drivers/gpu/drm/omapdrm/omap_gem.c +1 -1
@@ -182,7 +182,7 @@ static void evict_entry(struct drm_gem_object *obj,
 	size_t size = PAGE_SIZE * n;
 	loff_t off = mmap_offset(obj) +
 			(entry->obj_pgoff << PAGE_SHIFT);
-	const int m = 1 + ((omap_obj->width << fmt) / PAGE_SIZE);
+	const int m = 1 + (((omap_obj->width - 1) << fmt) / PAGE_SIZE);

How about

	int m = round_up(omap_obj->width << fmt, PAGE_SIZE);
Quoted 7 lines
Quoted 5 lines
Quoted 1 line

instead of open-coding it ? I find that a bit easier to understand.

That should be:

round_up(omap_obj->width << fmt, PAGE_SIZE) / PAGE_SIZE;

Sorry, I meant DIV_ROUND_UP, not round_up.

Ah, of course. Not my day... =)

From: Tomi Valkeinen <[email protected]>
Date: Thu, 18 May 2017 11:51:51 +0300
Subject: [PATCH] drm/omap: fix tiled buffer stride calculations

omap_gem uses page alignment for buffer stride. The related calculations are a bit off, though, as byte stride of 4096 gets aligned to 8192, instead of 4096.

This patch changes the code to use DIV_ROUND_UP(), which fixes those calculations and makes them more readable.

drivers/gpu/drm/omapdrm/omap_gem.c +2 -2
index 13abf221d153..5c5c86ddd6f4 100644
@@ -182,7 +182,7 @@ static void evict_entry(struct drm_gem_object *obj,
 	size_t size = PAGE_SIZE * n;
 	loff_t off = mmap_offset(obj) +
 			(entry->obj_pgoff << PAGE_SHIFT);
-	const int m = 1 + ((omap_obj->width << fmt) / PAGE_SIZE);
+	const int m = DIV_ROUND_UP(omap_obj->width << fmt, PAGE_SIZE);
 
 	if (m > 1) {
 		int i;
@@ -424,7 +424,7 @@ static int fault_2d(struct drm_gem_object *obj,
 	 * into account in some of the math, so figure out virtual stride
 	 * in pages
 	 */
-	const int m = 1 + ((omap_obj->width << fmt) / PAGE_SIZE);
+	const int m = DIV_ROUND_UP(omap_obj->width << fmt, PAGE_SIZE);
 
 	/* We don't use vmf->pgoff since that has the fake offset: */
 	pgoff = (vmf->address - vma->vm_start) >> PAGE_SHIFT;

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

Reviewed-by
#5 lore raw

Hi Tomi,

Quoted 46 lines · On Thursday 18 May 2017 14:34:09 Tomi Valkeinen wrote:
Quoted 31 lines · Laurent Pinchart
Quoted 30 lines · On Thursday 18 May 2017 14:14:35 Tomi Valkeinen wrote:
Quoted 29 lines · Laurent Pinchart
Quoted 17 lines · On Thursday 18 May 2017 13:28:26 Tomi Valkeinen wrote:

omap_gem uses page alignment for buffer stride. The related calculations
are a bit off, though, as byte stride of 4096 gets aligned to 8192, instead of 4096. This patch fixes those calculations.

---

 drivers/gpu/drm/omapdrm/omap_gem.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/omapdrm/omap_gem.c index 13abf221d153..4c41000ff4c4 100644

drivers/gpu/drm/omapdrm/omap_gem.c static void evict_entry(struct drm_gem_object *obj, · line 186

Quoted 6 lines
drivers/gpu/drm/omapdrm/omap_gem.c +1 -1
@@ -182,7 +182,7 @@ static void evict_entry(struct drm_gem_object *obj,
 	size_t size = PAGE_SIZE * n;
 	loff_t off = mmap_offset(obj) +
 			(entry->obj_pgoff << PAGE_SHIFT);
-	const int m = 1 + ((omap_obj->width << fmt) / PAGE_SIZE);
+	const int m = 1 + (((omap_obj->width - 1) << fmt) /
 PAGE_SIZE);

How about

	int m = round_up(omap_obj->width << fmt, PAGE_SIZE);
Quoted 7 lines
Quoted 5 lines
Quoted 1 line

instead of open-coding it ? I find that a bit easier to understand.

That should be:

round_up(omap_obj->width << fmt, PAGE_SIZE) / PAGE_SIZE;

Sorry, I meant DIV_ROUND_UP, not round_up.

Ah, of course. Not my day... =)

From: Tomi Valkeinen <[email protected]>
Date: Thu, 18 May 2017 11:51:51 +0300
Subject: [PATCH] drm/omap: fix tiled buffer stride calculations

Quoted 8 lines

omap_gem uses page alignment for buffer stride. The related calculations are a bit off, though, as byte stride of 4096 gets aligned to 8192, instead of 4096.

This patch changes the code to use DIV_ROUND_UP(), which fixes those calculations and makes them more readable.

Quoted 23 lines
(quoted diff) +0 -0

b/drivers/gpu/drm/omapdrm/omap_gem.c index 13abf221d153..5c5c86ddd6f4 100644

drivers/gpu/drm/omapdrm/omap_gem.c +2 -2
@@ -182,7 +182,7 @@ static void evict_entry(struct drm_gem_object *obj,
 	size_t size = PAGE_SIZE * n;
 	loff_t off = mmap_offset(obj) +
 			(entry->obj_pgoff << PAGE_SHIFT);
-	const int m = 1 + ((omap_obj->width << fmt) / PAGE_SIZE);
+	const int m = DIV_ROUND_UP(omap_obj->width << fmt, PAGE_SIZE);
 
 	if (m > 1) {
 		int i;
@@ -424,7 +424,7 @@ static int fault_2d(struct drm_gem_object *obj,
 	 * into account in some of the math, so figure out virtual stride
 	 * in pages
 	 */
-	const int m = 1 + ((omap_obj->width << fmt) / PAGE_SIZE);
+	const int m = DIV_ROUND_UP(omap_obj->width << fmt, PAGE_SIZE);
 
 	/* We don't use vmf->pgoff since that has the fake offset: */
 	pgoff = (vmf->address - vma->vm_start) >> PAGE_SHIFT;
Signature · 8 lines
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#6 lore raw
In reply to Tomi Valkeinen
Quoted 29 lines · Tomi Valkeinen
Quoted 28 lines · Laurent Pinchart

Hi Tomi,

Thank you for the patch.

Quoted 15 lines · On Thursday 18 May 2017 13:28:26 Tomi Valkeinen wrote:

omap_gem uses page alignment for buffer stride. The related calculations are a bit off, though, as byte stride of 4096 gets aligned to 8192, instead of 4096. This patch fixes those calculations.

---
 drivers/gpu/drm/omapdrm/omap_gem.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/omapdrm/omap_gem.c index 13abf221d153..4c41000ff4c4 100644

drivers/gpu/drm/omapdrm/omap_gem.c static void evict_entry(struct drm_gem_object *obj, · line 185

Quoted 5 lines
drivers/gpu/drm/omapdrm/omap_gem.c +1 -1
@@ -182,7 +182,7 @@ static void evict_entry(struct drm_gem_object *obj,
 	size_t size = PAGE_SIZE * n;
 	loff_t off = mmap_offset(obj) +
 			(entry->obj_pgoff << PAGE_SHIFT);
-	const int m = 1 + ((omap_obj->width << fmt) / PAGE_SIZE);
+	const int m = 1 + (((omap_obj->width - 1) << fmt) / PAGE_SIZE);

How about

Quoted 7 lines
Quoted 3 lines
	int m = round_up(omap_obj->width << fmt, PAGE_SIZE);

instead of open-coding it ? I find that a bit easier to understand.

That should be:

round_up(omap_obj->width << fmt, PAGE_SIZE) / PAGE_SIZE;

Or a bit more optimally just DIV_ROUND_UP()

Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel