Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm: make drm-active- stats optional

When memory stats is generated fresh everytime by going though all the
BOs, their active information is quite easy to get. But if the stats are
tracked with BO's state this becomes harder since the job scheduling
part doesn't really deal with individual buffers.

Make drm-active- optional to enable amdgpu to switch to the second
method.

Signed-off-by: Yunxiang Li <Yunxiang.Li@amd.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20241219151411.1150-3-Yunxiang.Li@amd.com
Signed-off-by: Christian König <christian.koenig@amd.com>

authored by

Yunxiang Li and committed by
Christian König
bebf2ebd fd265d9e

+18 -12
+1
drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c
··· 97 97 98 98 drm_print_memory_stats(p, 99 99 &stats[i].drm, 100 + DRM_GEM_OBJECT_ACTIVE | 100 101 DRM_GEM_OBJECT_RESIDENT | 101 102 DRM_GEM_OBJECT_PURGEABLE, 102 103 pl_name[i]);
+7 -6
drivers/gpu/drm/drm_file.c
··· 870 870 { 871 871 print_size(p, "total", region, stats->private + stats->shared); 872 872 print_size(p, "shared", region, stats->shared); 873 - print_size(p, "active", region, stats->active); 873 + 874 + if (supported_status & DRM_GEM_OBJECT_ACTIVE) 875 + print_size(p, "active", region, stats->active); 874 876 875 877 if (supported_status & DRM_GEM_OBJECT_RESIDENT) 876 878 print_size(p, "resident", region, stats->resident); ··· 905 903 906 904 if (obj->funcs && obj->funcs->status) { 907 905 s = obj->funcs->status(obj); 908 - supported_status = DRM_GEM_OBJECT_RESIDENT | 909 - DRM_GEM_OBJECT_PURGEABLE; 906 + supported_status |= s; 910 907 } 911 908 912 - if (drm_gem_object_is_shared_for_memory_stats(obj)) { 909 + if (drm_gem_object_is_shared_for_memory_stats(obj)) 913 910 status.shared += obj->size; 914 - } else { 911 + else 915 912 status.private += obj->size; 916 - } 917 913 918 914 if (s & DRM_GEM_OBJECT_RESIDENT) { 919 915 status.resident += add_size; ··· 924 924 925 925 if (!dma_resv_test_signaled(obj->resv, dma_resv_usage_rw(true))) { 926 926 status.active += add_size; 927 + supported_status |= DRM_GEM_OBJECT_ACTIVE; 927 928 928 929 /* If still active, don't count as purgeable: */ 929 930 s &= ~DRM_GEM_OBJECT_PURGEABLE;
+1
drivers/gpu/drm/i915/i915_drm_client.c
··· 102 102 for_each_memory_region(mr, i915, id) 103 103 drm_print_memory_stats(p, 104 104 &stats[id], 105 + DRM_GEM_OBJECT_ACTIVE | 105 106 DRM_GEM_OBJECT_RESIDENT | 106 107 DRM_GEM_OBJECT_PURGEABLE, 107 108 mr->uabi_name);
+1
drivers/gpu/drm/xe/xe_drm_client.c
··· 261 261 if (man) { 262 262 drm_print_memory_stats(p, 263 263 &stats[mem_type], 264 + DRM_GEM_OBJECT_ACTIVE | 264 265 DRM_GEM_OBJECT_RESIDENT | 265 266 (mem_type != XE_PL_SYSTEM ? 0 : 266 267 DRM_GEM_OBJECT_PURGEABLE),
+8 -6
include/drm/drm_gem.h
··· 48 48 * enum drm_gem_object_status - bitmask of object state for fdinfo reporting 49 49 * @DRM_GEM_OBJECT_RESIDENT: object is resident in memory (ie. not unpinned) 50 50 * @DRM_GEM_OBJECT_PURGEABLE: object marked as purgeable by userspace 51 + * @DRM_GEM_OBJECT_ACTIVE: object is currently used by an active submission 51 52 * 52 53 * Bitmask of status used for fdinfo memory stats, see &drm_gem_object_funcs.status 53 - * and drm_show_fdinfo(). Note that an object can DRM_GEM_OBJECT_PURGEABLE if 54 - * it still active or not resident, in which case drm_show_fdinfo() will not 54 + * and drm_show_fdinfo(). Note that an object can report DRM_GEM_OBJECT_PURGEABLE 55 + * and be active or not resident, in which case drm_show_fdinfo() will not 55 56 * account for it as purgeable. So drivers do not need to check if the buffer 56 - * is idle and resident to return this bit. (Ie. userspace can mark a buffer 57 - * as purgeable even while it is still busy on the GPU.. it does not _actually_ 58 - * become puregeable until it becomes idle. The status gem object func does 59 - * not need to consider this.) 57 + * is idle and resident to return this bit, i.e. userspace can mark a buffer as 58 + * purgeable even while it is still busy on the GPU. It will not get reported in 59 + * the puregeable stats until it becomes idle. The status gem object func does 60 + * not need to consider this. 60 61 */ 61 62 enum drm_gem_object_status { 62 63 DRM_GEM_OBJECT_RESIDENT = BIT(0), 63 64 DRM_GEM_OBJECT_PURGEABLE = BIT(1), 65 + DRM_GEM_OBJECT_ACTIVE = BIT(2), 64 66 }; 65 67 66 68 /**