[PATCH RFC 3/4] drm/panfrost: Add a helper to retrieve MMU context stats
Boris Brezillon
boris.brezillon at collabora.com
Wed Jan 4 13:03:07 UTC 2023
For now we only gather a few memory usage stats that we'll expose
through fdinfo, but this can be extended if needed.
Signed-off-by: Boris Brezillon <boris.brezillon at collabora.com>
---
drivers/gpu/drm/panfrost/panfrost_mmu.c | 25 +++++++++++++++++++++++++
drivers/gpu/drm/panfrost/panfrost_mmu.h | 10 ++++++++++
2 files changed, 35 insertions(+)
diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.c b/drivers/gpu/drm/panfrost/panfrost_mmu.c
index 454799d5a0ef..80c6e0e17195 100644
--- a/drivers/gpu/drm/panfrost/panfrost_mmu.c
+++ b/drivers/gpu/drm/panfrost/panfrost_mmu.c
@@ -435,6 +435,31 @@ addr_to_mapping(struct panfrost_device *pfdev, int as, u64 addr)
return mapping;
}
+void panfrost_mmu_get_stats(struct panfrost_mmu *mmu,
+ struct panfrost_mmu_stats *stats)
+{
+ struct drm_mm_node *node;
+
+ memset(stats, 0, sizeof(*stats));
+
+ spin_lock(&mmu->mm_lock);
+ drm_mm_for_each_node(node, &mmu->mm) {
+ struct panfrost_gem_mapping *mapping;
+ struct panfrost_gem_object *bo;
+
+ mapping = container_of(node, struct panfrost_gem_mapping, mmnode);
+ bo = mapping->obj;
+
+ stats->all += bo->base.base.size;
+ stats->resident += bo->resident_size;
+ if (bo->base.madv > 0)
+ stats->purgeable += bo->resident_size;
+ if (bo->base.base.dma_buf)
+ stats->shared += bo->base.base.size;
+ }
+ spin_unlock(&mmu->mm_lock);
+}
+
#define NUM_FAULT_PAGES (SZ_2M / PAGE_SIZE)
static int panfrost_mmu_map_fault_addr(struct panfrost_device *pfdev, int as,
diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.h b/drivers/gpu/drm/panfrost/panfrost_mmu.h
index cc2a0d307feb..bbffd39deaf3 100644
--- a/drivers/gpu/drm/panfrost/panfrost_mmu.h
+++ b/drivers/gpu/drm/panfrost/panfrost_mmu.h
@@ -8,6 +8,13 @@ struct panfrost_gem_mapping;
struct panfrost_file_priv;
struct panfrost_mmu;
+struct panfrost_mmu_stats {
+ u64 all;
+ u64 resident;
+ u64 purgeable;
+ u64 shared;
+};
+
int panfrost_mmu_map(struct panfrost_gem_mapping *mapping);
void panfrost_mmu_unmap(struct panfrost_gem_mapping *mapping);
@@ -22,4 +29,7 @@ struct panfrost_mmu *panfrost_mmu_ctx_get(struct panfrost_mmu *mmu);
void panfrost_mmu_ctx_put(struct panfrost_mmu *mmu);
struct panfrost_mmu *panfrost_mmu_ctx_create(struct panfrost_device *pfdev);
+void panfrost_mmu_get_stats(struct panfrost_mmu *mmu,
+ struct panfrost_mmu_stats *stats);
+
#endif
--
2.38.1
More information about the dri-devel
mailing list