[PATCH 074/131] drm/i915: Micro-optimise i915_gem_object_get_dirty_page()

Chris Wilson chris at chris-wilson.co.uk
Sat Aug 6 07:36:41 UTC 2016


We can skip the set_page_dirty() calls if we already know that the
entire object is dirty. Furthermore, the WARN is redundant (we'll crash
shortly afterwards) but adds substantial overhead to the function
(roughly increasing the relocation per-page cost by 10%).

Fixes regression from
commit 033908aed5a596f6202c848c6bbc8a40fb1a8490
Author: Dave Gordon <david.s.gordon at intel.com>
Date:   Thu Dec 10 18:51:23 2015 +0000

    drm/i915: mark GEM object pages dirty when mapped & written by the CPU

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/i915_drv.h |  8 +++++---
 drivers/gpu/drm/i915/i915_gem.c | 12 +++++-------
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 02a411885bb6..1b7a60e69e43 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -3146,13 +3146,14 @@ int i915_gem_obj_prepare_shmem_write(struct drm_i915_gem_object *obj,
 
 int __must_check i915_gem_object_get_pages(struct drm_i915_gem_object *obj);
 
-static inline int __sg_page_count(struct scatterlist *sg)
+static inline int __sg_page_count(const struct scatterlist *sg)
 {
 	return sg->length >> PAGE_SHIFT;
 }
 
 struct page *
-i915_gem_object_get_dirty_page(struct drm_i915_gem_object *obj, int n);
+i915_gem_object_get_dirty_page(struct drm_i915_gem_object *obj,
+			       unsigned int n);
 
 static inline dma_addr_t
 i915_gem_object_get_dma_address(struct drm_i915_gem_object *obj, int n)
@@ -3172,7 +3173,8 @@ i915_gem_object_get_dma_address(struct drm_i915_gem_object *obj, int n)
 }
 
 static inline struct page *
-i915_gem_object_get_page(struct drm_i915_gem_object *obj, int n)
+i915_gem_object_get_page(struct drm_i915_gem_object *obj,
+			 unsigned int n)
 {
 	if (WARN_ON(n >= obj->base.size >> PAGE_SHIFT))
 		return NULL;
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 2bf39bbc2803..89092994d5bf 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -4611,16 +4611,14 @@ void i915_gem_track_fb(struct drm_i915_gem_object *old,
 
 /* Like i915_gem_object_get_page(), but mark the returned page dirty */
 struct page *
-i915_gem_object_get_dirty_page(struct drm_i915_gem_object *obj, int n)
+i915_gem_object_get_dirty_page(struct drm_i915_gem_object *obj,
+			       unsigned int n)
 {
-	struct page *page;
+	struct page *page = i915_gem_object_get_page(obj, n);
 
-	/* Only default objects have per-page dirty tracking */
-	if (WARN_ON(!i915_gem_object_has_struct_page(obj)))
-		return NULL;
+	if (!i915_gem_object_is_dirty(obj))
+		set_page_dirty(page);
 
-	page = i915_gem_object_get_page(obj, n);
-	set_page_dirty(page);
 	return page;
 }
 
-- 
2.8.1



More information about the Intel-gfx-trybot mailing list