[PATCH 2/6] drm/radeon: track memory statistics about VRAM and GTT usage and buffer moves (original) (raw)

Christian König deathsimple at vodafone.de
Mon Feb 24 08:20:17 PST 2014


Am 24.02.2014 16:20, schrieb Marek Olšák:

From: Marek Olšák <marek.olsak at amd.com>

The statistics are: - VRAM usage in bytes - GTT usage in bytes - number of bytes moved by TTM The last one is actually a counter, so you need to sample it before and after command submission and take the difference. This is useful for finding performance bottlenecks. Userspace queries are also added. Signed-off-by: Marek Olšák <marek.olsak at amd.com> --- drivers/gpu/drm/radeon/radeon.h | 5 +++++ drivers/gpu/drm/radeon/radeondevice.c | 1 + drivers/gpu/drm/radeon/radeonkms.c | 15 ++++++++++++++ drivers/gpu/drm/radeon/radeonobject.c | 38 +++++++++++++++++++++++++++++++++- drivers/gpu/drm/radeon/radeonobject.h | 2 +- drivers/gpu/drm/radeon/radeonttm.c | 10 ++++++++- include/uapi/drm/radeondrm.h | 3 +++ 7 files changed, 71 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h index 3f10782..d37a57a 100644 --- a/drivers/gpu/drm/radeon/radeon.h +++ b/drivers/gpu/drm/radeon/radeon.h @@ -2307,6 +2307,11 @@ struct radeondevice { /* virtual memory */ struct radeonvmmanager vmmanager; struct mutex gpuclockmutex; + /* memory stats */ + struct mutex memorystatsmutex; + uint64t vramusage; + uint64t gttusage; + uint64t numbytesmoved;

As far as I can see you could make those tree values atomic64_t instead and avoid the mutex.

/* ACPI interface */ struct radeonatif atif; struct radeonatcs atcs; diff --git a/drivers/gpu/drm/radeon/radeondevice.c b/drivers/gpu/drm/radeon/radeondevice.c index b012cbb..6564af7 100644 --- a/drivers/gpu/drm/radeon/radeondevice.c +++ b/drivers/gpu/drm/radeon/radeondevice.c @@ -1184,6 +1184,7 @@ int radeondeviceinit(struct radeondevice *rdev, mutexinit(&rdev->gem.mutex); mutexinit(&rdev->pm.mutex); mutexinit(&rdev->gpuclockmutex); + mutexinit(&rdev->memorystatsmutex); mutexinit(&rdev->srbmmutex); initrwsem(&rdev->pm.mclklock); initrwsem(&rdev->exclusivelock); diff --git a/drivers/gpu/drm/radeon/radeonkms.c b/drivers/gpu/drm/radeon/radeonkms.c index 0b631eb..ddc8c74 100644 --- a/drivers/gpu/drm/radeon/radeonkms.c +++ b/drivers/gpu/drm/radeon/radeonkms.c @@ -486,6 +486,21 @@ static int radeoninfoioctl(struct drmdevice *dev, void *data, struct drmfile case RADEONINFOVCEFBVERSION: *value = rdev->vce.fbversion; break; + case RADEONINFONUMBYTESMOVED: + value = (uint32t*)&value64; + valuesize = sizeof(uint64t); + value64 = rdev->numbytesmoved; + break; + case RADEONINFOVRAMUSAGE: + value = (uint32t*)&value64; + valuesize = sizeof(uint64t); + value64 = rdev->vramusage; + break; + case RADEONINFOGTTUSAGE: + value = (uint32t*)&value64; + valuesize = sizeof(uint64t); + value64 = rdev->gttusage; + break; default: DRMDEBUGKMS("Invalid request %d\n", info->request); return -EINVAL; diff --git a/drivers/gpu/drm/radeon/radeonobject.c b/drivers/gpu/drm/radeon/radeonobject.c index dd12bb4..d676ee2 100644 --- a/drivers/gpu/drm/radeon/radeonobject.c +++ b/drivers/gpu/drm/radeon/radeonobject.c @@ -56,11 +56,38 @@ static void radeonboclearva(struct radeonbo *bo) } }

+static void radeonupdatememoryusage(struct radeonbo *bo, + unsigned memtype, int sign) +{ + struct radeondevice *rdev = bo->rdev; + u64 size = (u64)bo->tbo.numpages << PAGESHIFT;_ _+_ _+ mutexlock(&rdev->memorystatsmutex); + switch (memtype) { + case TTMPLTT: + if (sign > 0) + rdev->gttusage += size; + else + rdev->gttusage -= size; + break; + case TTMPLVRAM: + if (sign > 0) + rdev->vramusage += size; + else + rdev->vramusage -= size; + break; + } + mutexunlock(&rdev->memorystatsmutex); +} + static void radeonttmbodestroy(struct ttmbufferobject *tbo) { struct radeonbo *bo; bo = containerof(tbo, struct radeonbo, tbo); + + radeonupdatememoryusage(bo, bo->tbo.mem.memtype, -1); + mutexlock(&bo->rdev->gem.mutex); listdelinit(&bo->list); mutexunlock(&bo->rdev->gem.mutex); @@ -567,14 +594,23 @@ int radeonbochecktiling(struct radeonbo *bo, bool hasmoved, } void radeonbomovenotify(struct ttmbufferobject *bo, - struct ttmmemreg *mem) + struct ttmmemreg *newmem) { struct radeonbo *rbo; + if (!radeonttmboisradeonbo(bo)) return; + rbo = containerof(bo, struct radeonbo, tbo); radeonbochecktiling(rbo, 0, 1); radeonvmboinvalidate(rbo->rdev, rbo); + + /* update statistics */ + if (!newmem) + return; + + radeonupdatememoryusage(rbo, bo->mem.memtype, -1); + radeonupdatememoryusage(rbo, newmem->memtype, 1); } int radeonbofaultreservenotify(struct ttmbufferobject *bo) diff --git a/drivers/gpu/drm/radeon/radeonobject.h b/drivers/gpu/drm/radeon/radeonobject.h index 209b111..a9a8c11 100644 --- a/drivers/gpu/drm/radeon/radeonobject.h +++ b/drivers/gpu/drm/radeon/radeonobject.h @@ -151,7 +151,7 @@ extern void radeonbogettilingflags(struct radeonbo *bo, extern int radeonbochecktiling(struct radeonbo *bo, bool hasmoved, bool forcedrop); extern void radeonbomovenotify(struct ttmbufferobject *bo, - struct ttmmemreg *mem); + struct ttmmemreg *newmem); extern int radeonbofaultreservenotify(struct ttmbufferobject *bo); extern int radeonbogetsurfacereg(struct radeonbo *bo); diff --git a/drivers/gpu/drm/radeon/radeonttm.c b/drivers/gpu/drm/radeon/radeonttm.c index 77f5b0c..7e2e833 100644 --- a/drivers/gpu/drm/radeon/radeonttm.c +++ b/drivers/gpu/drm/radeon/radeonttm.c @@ -406,8 +406,16 @@ static int radeonbomove(struct ttmbufferobject *bo, if (r) { memcpy: r = ttmbomovememcpy(bo, evict, nowaitgpu, newmem); + if (r) { + return r; + } } - return r; + + /* update statistics */ + mutexlock(&rdev->memorystatsmutex); + rdev->numbytesmoved += (u64)bo->numpages << PAGESHIFT;_ _+ mutexunlock(&rdev->memorystatsmutex); + return 0; } static int radeonttmiomemreserve(struct ttmbodevice *bdev, struct ttmmemreg *mem) diff --git a/include/uapi/drm/radeondrm.h b/include/uapi/drm/radeondrm.h index cb5c93a..aefa2f6 100644 --- a/include/uapi/drm/radeondrm.h +++ b/include/uapi/drm/radeondrm.h @@ -1004,6 +1004,9 @@ struct drmradeoncs { #define RADEONINFOVCEFWVERSION 0x1b /* version of VCE feedback */ #define RADEONINFOVCEFBVERSION 0x1c +#define RADEONINFONUMBYTESMOVED 0x1d +#define RADEONINFOVRAMUSAGE 0x1e +#define RADEONINFOGTTUSAGE 0x1f

struct drmradeoninfo {



More information about the dri-devel mailing list