Re: [Intel-gfx] [PATCH] drm/i915: introduce & use i915_gem_object_{set, clear, is}_dirty()

2016-09-14 Thread Dave Gordon

On 12/09/16 16:48, Tvrtko Ursulin wrote:


Hi,

On 09/09/16 20:48, Dave Gordon wrote:

This just hides the existing obj->dirty flag inside a trivial inline
setter, to discourage non-GEM code from looking too closely. The
flag is renamed to emphasise that it is private to the GEM memory-
management code and ensure that no legacy code continues to use it
directly.

v2:
   Use Chris Wilson's preferred names for flag-related functions

Inspired-by: http://www.spinics.net/lists/intel-gfx/msg92390.html
Cc: Chris Wilson 
Signed-off-by: Dave Gordon 
---
  drivers/gpu/drm/i915/i915_debugfs.c|  2 +-
  drivers/gpu/drm/i915/i915_drv.h| 22 +-
  drivers/gpu/drm/i915/i915_gem.c| 25
++---
  drivers/gpu/drm/i915/i915_gem_context.c|  7 +--
  drivers/gpu/drm/i915/i915_gem_execbuffer.c |  2 +-
  drivers/gpu/drm/i915/i915_gem_userptr.c| 12 +++-
  drivers/gpu/drm/i915/i915_gpu_error.c  |  2 +-
  drivers/gpu/drm/i915/intel_lrc.c   | 29
-
  8 files changed, 66 insertions(+), 35 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_debugfs.c
b/drivers/gpu/drm/i915/i915_debugfs.c
index 02b627e..b77fc27 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -160,7 +160,7 @@ static u64 i915_gem_obj_total_ggtt_size(struct
drm_i915_gem_object *obj)
 i915_gem_active_get_seqno(>last_write,
   >base.dev->struct_mutex),
 i915_cache_level_str(dev_priv, obj->cache_level),
-   obj->dirty ? " dirty" : "",
+   i915_gem_object_is_dirty(obj) ? " dirty" : "",
 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
  if (obj->base.name)
  seq_printf(m, " (name: %d)", obj->base.name);
diff --git a/drivers/gpu/drm/i915/i915_drv.h
b/drivers/gpu/drm/i915/i915_drv.h
index f39bede..333e21b 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -2209,7 +2209,7 @@ struct drm_i915_gem_object {
   * This is set if the object has been written to since last bound
   * to the GTT
   */
-unsigned int dirty:1;
+unsigned int __dirty:1;

  /**
   * Advice: are the backing pages purgeable?
@@ -3156,6 +3156,26 @@ static inline void
i915_gem_object_pin_pages(struct drm_i915_gem_object *obj)
  obj->pages_pin_count++;
  }

+/*
+ * Flag the object content as having changed since the last call to
+ * i915_gem_object_pin_pages() above, so that the new content is not
+ * lost after the next call to i915_gem_object_unpin_pages() below
+ */
+static inline void i915_gem_object_set_dirty(struct
drm_i915_gem_object *obj)
+{
+obj->__dirty = true;
+}
+
+static inline void i915_gem_object_clear_dirty(struct
drm_i915_gem_object *obj)
+{
+obj->__dirty = false;
+}
+
+static inline bool i915_gem_object_is_dirty(struct
drm_i915_gem_object *obj)
+{
+return obj->__dirty;
+}
+
  static inline void i915_gem_object_unpin_pages(struct
drm_i915_gem_object *obj)
  {
  BUG_ON(obj->pages_pin_count == 0);
diff --git a/drivers/gpu/drm/i915/i915_gem.c
b/drivers/gpu/drm/i915/i915_gem.c
index 2401818..f571a02 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -234,9 +234,8 @@ int i915_mutex_lock_interruptible(struct
drm_device *dev)
  }

  if (obj->madv == I915_MADV_DONTNEED)
-obj->dirty = 0;
-
-if (obj->dirty) {
+i915_gem_object_clear_dirty(obj);
+else if (i915_gem_object_is_dirty(obj)) {
  struct address_space *mapping = obj->base.filp->f_mapping;
  char *vaddr = obj->phys_handle->vaddr;
  int i;
@@ -260,7 +259,7 @@ int i915_mutex_lock_interruptible(struct
drm_device *dev)
  put_page(page);
  vaddr += PAGE_SIZE;
  }
-obj->dirty = 0;
+i915_gem_object_clear_dirty(obj);
  }

  sg_free_table(obj->pages);
@@ -703,7 +702,7 @@ int i915_gem_obj_prepare_shmem_write(struct
drm_i915_gem_object *obj,
  obj->cache_dirty = true;

  intel_fb_obj_invalidate(obj, ORIGIN_CPU);
-obj->dirty = 1;
+i915_gem_object_set_dirty(obj);
  /* return with the pages pinned */
  return 0;

@@ -1156,7 +1155,7 @@ int i915_gem_obj_prepare_shmem_write(struct
drm_i915_gem_object *obj,
  goto out_unpin;


I wonder why diff got so confused with this one, because this isn't
i915_gem_obj_prepare_shmem_write any longer.


It has to do with functions containing labels. A workaround that 
sometimes works is to tell git-diff that it's C++ code rather than C, as 
it then handles labels slightly differently, in a way that usually 
happens to fix the misidentification of which function the code is in.



  intel_fb_obj_invalidate(obj, ORIGIN_CPU);
-obj->dirty = true;
+i915_gem_object_set_dirty(obj);

  user_data = u64_to_user_ptr(args->data_ptr);
  offset = 

Re: [Intel-gfx] [PATCH] drm/i915: introduce & use i915_gem_object_{set, clear, is}_dirty()

2016-09-12 Thread Chris Wilson
On Mon, Sep 12, 2016 at 04:48:51PM +0100, Tvrtko Ursulin wrote:
> >  * able to defer doing this until we know the object would be
> >  * swapped, but there is no way to do that yet.
> >  */
> >-i915_vma_move_to_active(from->engine[RCS].state, req, 0);
> >+i915_vma_move_to_active(from_vma, req, 0);
> >+i915_gem_object_set_dirty(from_vma->obj);
> 
> Commit message should mention this.

No. This should not be here as we removed it because we always mark the
object as dirty when active on the GPU.

I don't see any improvement in this patch over mine, so what's the
reason for it? Certainly the lack of debug checks is odd.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH] drm/i915: introduce & use i915_gem_object_{set, clear, is}_dirty()

2016-09-12 Thread Tvrtko Ursulin


Hi,

On 09/09/16 20:48, Dave Gordon wrote:

This just hides the existing obj->dirty flag inside a trivial inline
setter, to discourage non-GEM code from looking too closely. The
flag is renamed to emphasise that it is private to the GEM memory-
management code and ensure that no legacy code continues to use it
directly.

v2:
   Use Chris Wilson's preferred names for flag-related functions

Inspired-by: http://www.spinics.net/lists/intel-gfx/msg92390.html
Cc: Chris Wilson 
Signed-off-by: Dave Gordon 
---
  drivers/gpu/drm/i915/i915_debugfs.c|  2 +-
  drivers/gpu/drm/i915/i915_drv.h| 22 +-
  drivers/gpu/drm/i915/i915_gem.c| 25 ++---
  drivers/gpu/drm/i915/i915_gem_context.c|  7 +--
  drivers/gpu/drm/i915/i915_gem_execbuffer.c |  2 +-
  drivers/gpu/drm/i915/i915_gem_userptr.c| 12 +++-
  drivers/gpu/drm/i915/i915_gpu_error.c  |  2 +-
  drivers/gpu/drm/i915/intel_lrc.c   | 29 -
  8 files changed, 66 insertions(+), 35 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_debugfs.c 
b/drivers/gpu/drm/i915/i915_debugfs.c
index 02b627e..b77fc27 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -160,7 +160,7 @@ static u64 i915_gem_obj_total_ggtt_size(struct 
drm_i915_gem_object *obj)
   i915_gem_active_get_seqno(>last_write,
 >base.dev->struct_mutex),
   i915_cache_level_str(dev_priv, obj->cache_level),
-  obj->dirty ? " dirty" : "",
+  i915_gem_object_is_dirty(obj) ? " dirty" : "",
   obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
if (obj->base.name)
seq_printf(m, " (name: %d)", obj->base.name);
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index f39bede..333e21b 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -2209,7 +2209,7 @@ struct drm_i915_gem_object {
 * This is set if the object has been written to since last bound
 * to the GTT
 */
-   unsigned int dirty:1;
+   unsigned int __dirty:1;

/**
 * Advice: are the backing pages purgeable?
@@ -3156,6 +3156,26 @@ static inline void i915_gem_object_pin_pages(struct 
drm_i915_gem_object *obj)
obj->pages_pin_count++;
  }

+/*
+ * Flag the object content as having changed since the last call to
+ * i915_gem_object_pin_pages() above, so that the new content is not
+ * lost after the next call to i915_gem_object_unpin_pages() below
+ */
+static inline void i915_gem_object_set_dirty(struct drm_i915_gem_object *obj)
+{
+   obj->__dirty = true;
+}
+
+static inline void i915_gem_object_clear_dirty(struct drm_i915_gem_object *obj)
+{
+   obj->__dirty = false;
+}
+
+static inline bool i915_gem_object_is_dirty(struct drm_i915_gem_object *obj)
+{
+   return obj->__dirty;
+}
+
  static inline void i915_gem_object_unpin_pages(struct drm_i915_gem_object 
*obj)
  {
BUG_ON(obj->pages_pin_count == 0);
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 2401818..f571a02 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -234,9 +234,8 @@ int i915_mutex_lock_interruptible(struct drm_device *dev)
}

if (obj->madv == I915_MADV_DONTNEED)
-   obj->dirty = 0;
-
-   if (obj->dirty) {
+   i915_gem_object_clear_dirty(obj);
+   else if (i915_gem_object_is_dirty(obj)) {
struct address_space *mapping = obj->base.filp->f_mapping;
char *vaddr = obj->phys_handle->vaddr;
int i;
@@ -260,7 +259,7 @@ int i915_mutex_lock_interruptible(struct drm_device *dev)
put_page(page);
vaddr += PAGE_SIZE;
}
-   obj->dirty = 0;
+   i915_gem_object_clear_dirty(obj);
}

sg_free_table(obj->pages);
@@ -703,7 +702,7 @@ int i915_gem_obj_prepare_shmem_write(struct 
drm_i915_gem_object *obj,
obj->cache_dirty = true;

intel_fb_obj_invalidate(obj, ORIGIN_CPU);
-   obj->dirty = 1;
+   i915_gem_object_set_dirty(obj);
/* return with the pages pinned */
return 0;

@@ -1156,7 +1155,7 @@ int i915_gem_obj_prepare_shmem_write(struct 
drm_i915_gem_object *obj,
goto out_unpin;


I wonder why diff got so confused with this one, because this isn't 
i915_gem_obj_prepare_shmem_write any longer.




intel_fb_obj_invalidate(obj, ORIGIN_CPU);
-   obj->dirty = true;
+   i915_gem_object_set_dirty(obj);

user_data = u64_to_user_ptr(args->data_ptr);
offset = args->offset;
@@ -1327,6 +1326,8 @@ int i915_gem_obj_prepare_shmem_write(struct 
drm_i915_gem_object *obj,

[Intel-gfx] [PATCH] drm/i915: introduce & use i915_gem_object_{set, clear, is}_dirty()

2016-09-09 Thread Dave Gordon
This just hides the existing obj->dirty flag inside a trivial inline
setter, to discourage non-GEM code from looking too closely. The
flag is renamed to emphasise that it is private to the GEM memory-
management code and ensure that no legacy code continues to use it
directly.

v2:
  Use Chris Wilson's preferred names for flag-related functions

Inspired-by: http://www.spinics.net/lists/intel-gfx/msg92390.html
Cc: Chris Wilson 
Signed-off-by: Dave Gordon 
---
 drivers/gpu/drm/i915/i915_debugfs.c|  2 +-
 drivers/gpu/drm/i915/i915_drv.h| 22 +-
 drivers/gpu/drm/i915/i915_gem.c| 25 ++---
 drivers/gpu/drm/i915/i915_gem_context.c|  7 +--
 drivers/gpu/drm/i915/i915_gem_execbuffer.c |  2 +-
 drivers/gpu/drm/i915/i915_gem_userptr.c| 12 +++-
 drivers/gpu/drm/i915/i915_gpu_error.c  |  2 +-
 drivers/gpu/drm/i915/intel_lrc.c   | 29 -
 8 files changed, 66 insertions(+), 35 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_debugfs.c 
b/drivers/gpu/drm/i915/i915_debugfs.c
index 02b627e..b77fc27 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -160,7 +160,7 @@ static u64 i915_gem_obj_total_ggtt_size(struct 
drm_i915_gem_object *obj)
   i915_gem_active_get_seqno(>last_write,
 >base.dev->struct_mutex),
   i915_cache_level_str(dev_priv, obj->cache_level),
-  obj->dirty ? " dirty" : "",
+  i915_gem_object_is_dirty(obj) ? " dirty" : "",
   obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
if (obj->base.name)
seq_printf(m, " (name: %d)", obj->base.name);
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index f39bede..333e21b 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -2209,7 +2209,7 @@ struct drm_i915_gem_object {
 * This is set if the object has been written to since last bound
 * to the GTT
 */
-   unsigned int dirty:1;
+   unsigned int __dirty:1;
 
/**
 * Advice: are the backing pages purgeable?
@@ -3156,6 +3156,26 @@ static inline void i915_gem_object_pin_pages(struct 
drm_i915_gem_object *obj)
obj->pages_pin_count++;
 }
 
+/*
+ * Flag the object content as having changed since the last call to
+ * i915_gem_object_pin_pages() above, so that the new content is not
+ * lost after the next call to i915_gem_object_unpin_pages() below
+ */
+static inline void i915_gem_object_set_dirty(struct drm_i915_gem_object *obj)
+{
+   obj->__dirty = true;
+}
+
+static inline void i915_gem_object_clear_dirty(struct drm_i915_gem_object *obj)
+{
+   obj->__dirty = false;
+}
+
+static inline bool i915_gem_object_is_dirty(struct drm_i915_gem_object *obj)
+{
+   return obj->__dirty;
+}
+
 static inline void i915_gem_object_unpin_pages(struct drm_i915_gem_object *obj)
 {
BUG_ON(obj->pages_pin_count == 0);
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 2401818..f571a02 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -234,9 +234,8 @@ int i915_mutex_lock_interruptible(struct drm_device *dev)
}
 
if (obj->madv == I915_MADV_DONTNEED)
-   obj->dirty = 0;
-
-   if (obj->dirty) {
+   i915_gem_object_clear_dirty(obj);
+   else if (i915_gem_object_is_dirty(obj)) {
struct address_space *mapping = obj->base.filp->f_mapping;
char *vaddr = obj->phys_handle->vaddr;
int i;
@@ -260,7 +259,7 @@ int i915_mutex_lock_interruptible(struct drm_device *dev)
put_page(page);
vaddr += PAGE_SIZE;
}
-   obj->dirty = 0;
+   i915_gem_object_clear_dirty(obj);
}
 
sg_free_table(obj->pages);
@@ -703,7 +702,7 @@ int i915_gem_obj_prepare_shmem_write(struct 
drm_i915_gem_object *obj,
obj->cache_dirty = true;
 
intel_fb_obj_invalidate(obj, ORIGIN_CPU);
-   obj->dirty = 1;
+   i915_gem_object_set_dirty(obj);
/* return with the pages pinned */
return 0;
 
@@ -1156,7 +1155,7 @@ int i915_gem_obj_prepare_shmem_write(struct 
drm_i915_gem_object *obj,
goto out_unpin;
 
intel_fb_obj_invalidate(obj, ORIGIN_CPU);
-   obj->dirty = true;
+   i915_gem_object_set_dirty(obj);
 
user_data = u64_to_user_ptr(args->data_ptr);
offset = args->offset;
@@ -1327,6 +1326,8 @@ int i915_gem_obj_prepare_shmem_write(struct 
drm_i915_gem_object *obj,
offset = args->offset;
remain = args->size;
 
+   i915_gem_object_set_dirty(obj);
+
for_each_sg_page(obj->pages->sgl, _iter, obj->pages->nents,