[Intel-gfx] [PATCH 3/7] drm/i915: Allow page pinning to be in the background
Matthew Auld
matthew.william.auld at gmail.com
Wed Jun 5 14:03:03 UTC 2019
On Mon, 3 Jun 2019 at 18:49, Chris Wilson <chris at chris-wilson.co.uk> wrote:
>
> Assume that pages may be pinned in a background task and use a
> completion event to synchronise with callers that must access the pages
> immediately.
>
> Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
> ---
> drivers/gpu/drm/i915/gem/i915_gem_object.c | 1 +
> drivers/gpu/drm/i915/gem/i915_gem_object.h | 7 +--
> .../gpu/drm/i915/gem/i915_gem_object_types.h | 3 ++
> drivers/gpu/drm/i915/gem/i915_gem_pages.c | 53 +++++++++++++++----
> 4 files changed, 52 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.c b/drivers/gpu/drm/i915/gem/i915_gem_object.c
> index 2702e060102e..2c5a02274170 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_object.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_object.c
> @@ -79,6 +79,7 @@ void i915_gem_object_init(struct drm_i915_gem_object *obj,
> obj->mm.madv = I915_MADV_WILLNEED;
> INIT_RADIX_TREE(&obj->mm.get_page.radix, GFP_KERNEL | __GFP_NOWARN);
> mutex_init(&obj->mm.get_page.lock);
> + init_completion(&obj->mm.completion);
> }
>
> /**
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.h b/drivers/gpu/drm/i915/gem/i915_gem_object.h
> index 7cb1871d7128..194e4fb6a259 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_object.h
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_object.h
> @@ -240,7 +240,7 @@ int ____i915_gem_object_get_pages(struct drm_i915_gem_object *obj);
> int __i915_gem_object_get_pages(struct drm_i915_gem_object *obj);
>
> static inline int __must_check
> -i915_gem_object_pin_pages(struct drm_i915_gem_object *obj)
> +i915_gem_object_pin_pages_async(struct drm_i915_gem_object *obj)
> {
> might_lock(&obj->mm.lock);
>
> @@ -250,6 +250,9 @@ i915_gem_object_pin_pages(struct drm_i915_gem_object *obj)
> return __i915_gem_object_get_pages(obj);
> }
>
> +int __must_check
> +i915_gem_object_pin_pages(struct drm_i915_gem_object *obj);
> +
> static inline bool
> i915_gem_object_has_pages(struct drm_i915_gem_object *obj)
> {
> @@ -273,9 +276,7 @@ i915_gem_object_has_pinned_pages(struct drm_i915_gem_object *obj)
> static inline void
> __i915_gem_object_unpin_pages(struct drm_i915_gem_object *obj)
> {
> - GEM_BUG_ON(!i915_gem_object_has_pages(obj));
> GEM_BUG_ON(!i915_gem_object_has_pinned_pages(obj));
> -
> atomic_dec(&obj->mm.pages_pin_count);
> }
>
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object_types.h b/drivers/gpu/drm/i915/gem/i915_gem_object_types.h
> index 41d2e7c8e332..615a59b927d6 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_object_types.h
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_object_types.h
> @@ -7,6 +7,7 @@
> #ifndef __I915_GEM_OBJECT_TYPES_H__
> #define __I915_GEM_OBJECT_TYPES_H__
>
> +#include <linux/completion.h>
> #include <linux/reservation.h>
>
> #include <drm/drm_gem.h>
> @@ -211,6 +212,8 @@ struct drm_i915_gem_object {
> */
> struct list_head link;
>
> + struct completion completion;
> +
> /**
> * Advice: are the backing pages purgeable?
> */
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_pages.c b/drivers/gpu/drm/i915/gem/i915_gem_pages.c
> index 7868dd48d931..68262231f56f 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_pages.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_pages.c
> @@ -72,21 +72,18 @@ void __i915_gem_object_set_pages(struct drm_i915_gem_object *obj,
>
> spin_unlock(&i915->mm.obj_lock);
> }
> +
> + complete_all(&obj->mm.completion);
> }
Worth having __i915_gem_object_set_pages_error(struct
drm_i915_gem_object, int err) at some point?
Reviewed-by: Matthew Auld <matthew.auld at intel.com>
More information about the Intel-gfx
mailing list