@@ -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,
@@ -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
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@collabora.com> --- drivers/gpu/drm/panfrost/panfrost_mmu.c | 25 +++++++++++++++++++++++++ drivers/gpu/drm/panfrost/panfrost_mmu.h | 10 ++++++++++ 2 files changed, 35 insertions(+)