Re: [PATCH v9 3/5] drm/panthor: Expose size of driver internal BO's over fdinfo

Boris Brezillon
2025-01-24T09:07:46Z

On Fri, 24 Jan 2025 09:48:30 +0100
Boris Brezillon <boris.brezillon@collabora.com> wrote:

> On Thu, 23 Jan 2025 22:53:00 +0000
> Adrián Larumbe <adrian.larumbe@collabora.com> wrote:
>
> > +/**
> > + * panthor_vm_heaps_sizes() - Calculate size of all heap chunks across all
> > + * heaps over all the heap pools in a VM
> > + * @pfile: File.
> > + * @stats: Memory stats to be updated.
> > + *
> > + * Calculate all heap chunk sizes in all heap pools bound to a VM. If the VM
> > + * is active, record the size as active as well.
> > + */
> > +void panthor_vm_heaps_sizes(struct panthor_file *pfile, struct drm_memory_stats *stats)
> > +{
> > + struct panthor_vm *vm;
> > + unsigned long i;
> > +
> > + if (!pfile->vms)
> > + return;
> > +
> > + xa_lock(&pfile->vms->xa);
> > + xa_for_each(&pfile->vms->xa, i, vm) {
> > + size_t size;
> > +
> > + mutex_lock(&vm->heaps.lock);
> > + if (!vm->heaps.pool) {
> > + mutex_unlock(&vm->heaps.lock);
> > + continue;
> > + }
> > + size = panthor_heap_pool_size(vm->heaps.pool);
> > + mutex_unlock(&vm->heaps.lock);
>
> Let's keep the locking scheme simple:
>
> size_t size = 0;
>
> mutex_lock(&vm->heaps.lock);
> if (vm->heaps.pool)
> size = panthor_heap_pool_size(vm->heaps.pool);
> mutex_unlock(&vm->heaps.lock);
>
> stats->resident += size;
> if (vm->as.id >= 0)
> stats->active += size;

With this addressed, you can add

Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>

>
> > +
> > + stats->resident += size;
> > + if (vm->as.id >= 0)
> > + stats->active += size;
> > + }
> > + xa_unlock(&pfile->vms->xa);
> > +}
> > +