diff mbox series

[v9,03/11] drm/gem: Add evict() callback to drm_gem_object_funcs

Message ID 20221123025723.695075-4-dmitry.osipenko@collabora.com (mailing list archive)
State New, archived
Headers show
Series Add generic memory shrinker to VirtIO-GPU and Panfrost DRM drivers | expand

Commit Message

Dmitry Osipenko Nov. 23, 2022, 2:57 a.m. UTC
Add new common evict() callback to drm_gem_object_funcs and corresponding
drm_gem_object_evict() helper. This is a first step on a way to providing
common GEM-shrinker API for DRM drivers.

Suggested-by: Thomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
---
 drivers/gpu/drm/drm_gem.c | 15 +++++++++++++++
 include/drm/drm_gem.h     | 12 ++++++++++++
 2 files changed, 27 insertions(+)

Comments

Steven Price Nov. 23, 2022, 3:58 p.m. UTC | #1
On 23/11/2022 02:57, Dmitry Osipenko wrote:
> Add new common evict() callback to drm_gem_object_funcs and corresponding
> drm_gem_object_evict() helper. This is a first step on a way to providing
> common GEM-shrinker API for DRM drivers.
> 
> Suggested-by: Thomas Zimmermann <tzimmermann@suse.de>
> Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
> ---
>  drivers/gpu/drm/drm_gem.c | 15 +++++++++++++++
>  include/drm/drm_gem.h     | 12 ++++++++++++
>  2 files changed, 27 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
> index 299bca1390aa..c0510b8080d2 100644
> --- a/drivers/gpu/drm/drm_gem.c
> +++ b/drivers/gpu/drm/drm_gem.c
> @@ -1458,3 +1458,18 @@ drm_gem_lru_scan(struct drm_gem_lru *lru,
>  	return freed;
>  }
>  EXPORT_SYMBOL(drm_gem_lru_scan);
> +
> +/**
> + * drm_gem_object_evict - helper to evict backing pages for a GEM object
> + * @obj: obj in question
> + */
> +bool
> +drm_gem_object_evict(struct drm_gem_object *obj)
> +{
> +	dma_resv_assert_held(obj->resv);
> +
> +	if (obj->funcs->evict)
> +		return obj->funcs->evict(obj);
> +
> +	return false;
> +}

This function needs exporting for the module build to work correctly.

Steve

> diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h
> index b46ade812443..add1371453f0 100644
> --- a/include/drm/drm_gem.h
> +++ b/include/drm/drm_gem.h
> @@ -172,6 +172,16 @@ struct drm_gem_object_funcs {
>  	 * This is optional but necessary for mmap support.
>  	 */
>  	const struct vm_operations_struct *vm_ops;
> +
> +	/**
> +	 * @evict:
> +	 *
> +	 * Evicts gem object out from memory. Used by the drm_gem_object_evict()
> +	 * helper. Returns true on success, false otherwise.
> +	 *
> +	 * This callback is optional.
> +	 */
> +	bool (*evict)(struct drm_gem_object *obj);
>  };
>  
>  /**
> @@ -480,4 +490,6 @@ unsigned long drm_gem_lru_scan(struct drm_gem_lru *lru,
>  			       unsigned long *remaining,
>  			       bool (*shrink)(struct drm_gem_object *obj));
>  
> +bool drm_gem_object_evict(struct drm_gem_object *obj);
> +
>  #endif /* __DRM_GEM_H__ */
Dmitry Osipenko Nov. 23, 2022, 4:40 p.m. UTC | #2
On 11/23/22 18:58, Steven Price wrote:
> On 23/11/2022 02:57, Dmitry Osipenko wrote:
>> Add new common evict() callback to drm_gem_object_funcs and corresponding
>> drm_gem_object_evict() helper. This is a first step on a way to providing
>> common GEM-shrinker API for DRM drivers.
>>
>> Suggested-by: Thomas Zimmermann <tzimmermann@suse.de>
>> Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
>> ---
>>  drivers/gpu/drm/drm_gem.c | 15 +++++++++++++++
>>  include/drm/drm_gem.h     | 12 ++++++++++++
>>  2 files changed, 27 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
>> index 299bca1390aa..c0510b8080d2 100644
>> --- a/drivers/gpu/drm/drm_gem.c
>> +++ b/drivers/gpu/drm/drm_gem.c
>> @@ -1458,3 +1458,18 @@ drm_gem_lru_scan(struct drm_gem_lru *lru,
>>  	return freed;
>>  }
>>  EXPORT_SYMBOL(drm_gem_lru_scan);
>> +
>> +/**
>> + * drm_gem_object_evict - helper to evict backing pages for a GEM object
>> + * @obj: obj in question
>> + */
>> +bool
>> +drm_gem_object_evict(struct drm_gem_object *obj)
>> +{
>> +	dma_resv_assert_held(obj->resv);
>> +
>> +	if (obj->funcs->evict)
>> +		return obj->funcs->evict(obj);
>> +
>> +	return false;
>> +}
> 
> This function needs exporting for the module build to work correctly.

Indeed, I missed that drm-shmem can be built as a separate module.
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index 299bca1390aa..c0510b8080d2 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -1458,3 +1458,18 @@  drm_gem_lru_scan(struct drm_gem_lru *lru,
 	return freed;
 }
 EXPORT_SYMBOL(drm_gem_lru_scan);
+
+/**
+ * drm_gem_object_evict - helper to evict backing pages for a GEM object
+ * @obj: obj in question
+ */
+bool
+drm_gem_object_evict(struct drm_gem_object *obj)
+{
+	dma_resv_assert_held(obj->resv);
+
+	if (obj->funcs->evict)
+		return obj->funcs->evict(obj);
+
+	return false;
+}
diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h
index b46ade812443..add1371453f0 100644
--- a/include/drm/drm_gem.h
+++ b/include/drm/drm_gem.h
@@ -172,6 +172,16 @@  struct drm_gem_object_funcs {
 	 * This is optional but necessary for mmap support.
 	 */
 	const struct vm_operations_struct *vm_ops;
+
+	/**
+	 * @evict:
+	 *
+	 * Evicts gem object out from memory. Used by the drm_gem_object_evict()
+	 * helper. Returns true on success, false otherwise.
+	 *
+	 * This callback is optional.
+	 */
+	bool (*evict)(struct drm_gem_object *obj);
 };
 
 /**
@@ -480,4 +490,6 @@  unsigned long drm_gem_lru_scan(struct drm_gem_lru *lru,
 			       unsigned long *remaining,
 			       bool (*shrink)(struct drm_gem_object *obj));
 
+bool drm_gem_object_evict(struct drm_gem_object *obj);
+
 #endif /* __DRM_GEM_H__ */