drm: add drm_memory_stats_is_zero
authorYunxiang Li <Yunxiang.Li@amd.com>
Thu, 19 Dec 2024 15:14:07 +0000 (10:14 -0500)
committerChristian König <christian.koenig@amd.com>
Thu, 19 Dec 2024 15:56:05 +0000 (16:56 +0100)
Add a helper to check if the memory stats is zero, this will be used to
check for memory accounting errors.

Signed-off-by: Yunxiang Li <Yunxiang.Li@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20241219151411.1150-2-Yunxiang.Li@amd.com
Signed-off-by: Christian König <christian.koenig@amd.com>
drivers/gpu/drm/drm_file.c
include/drm/drm_file.h

index cb5f22f5bbb674f799862a3fde31c80cb655efdb..f10b6938c57726a4d3e1ffd302fc347e996a4da2 100644 (file)
@@ -845,6 +845,16 @@ static void print_size(struct drm_printer *p, const char *stat,
        drm_printf(p, "drm-%s-%s:\t%llu%s\n", stat, region, sz, units[u]);
 }
 
+int drm_memory_stats_is_zero(const struct drm_memory_stats *stats)
+{
+       return (stats->shared == 0 &&
+               stats->private == 0 &&
+               stats->resident == 0 &&
+               stats->purgeable == 0 &&
+               stats->active == 0);
+}
+EXPORT_SYMBOL(drm_memory_stats_is_zero);
+
 /**
  * drm_print_memory_stats - A helper to print memory stats
  * @p: The printer to print output to
index f0ef32e9fa5e372d222efed7735fb443ed530bed..ef817926cddd36f0679ca2ee5af76bbf679c2941 100644 (file)
@@ -494,6 +494,7 @@ struct drm_memory_stats {
 
 enum drm_gem_object_status;
 
+int drm_memory_stats_is_zero(const struct drm_memory_stats *stats);
 void drm_print_memory_stats(struct drm_printer *p,
                            const struct drm_memory_stats *stats,
                            enum drm_gem_object_status supported_status,