[Mesa-dev] [PATCH 5/6] winsys/radeon: track the amount of mapped memory
Marek Olšák
maraeo at gmail.com
Sat Aug 6 18:05:00 UTC 2016
From: Marek Olšák <marek.olsak at amd.com>
---
src/gallium/winsys/radeon/drm/radeon_drm_bo.c | 13 ++++++++++++-
src/gallium/winsys/radeon/drm/radeon_drm_winsys.c | 4 ++++
src/gallium/winsys/radeon/drm/radeon_drm_winsys.h | 2 ++
3 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_bo.c b/src/gallium/winsys/radeon/drm/radeon_drm_bo.c
index 897b536..56aab48 100644
--- a/src/gallium/winsys/radeon/drm/radeon_drm_bo.c
+++ b/src/gallium/winsys/radeon/drm/radeon_drm_bo.c
@@ -368,22 +368,27 @@ void *radeon_bo_do_map(struct radeon_bo *bo)
ptr = os_mmap(0, args.size, PROT_READ|PROT_WRITE, MAP_SHARED,
bo->rws->fd, args.addr_ptr);
if (ptr == MAP_FAILED) {
pipe_mutex_unlock(bo->map_mutex);
fprintf(stderr, "radeon: mmap failed, errno: %i\n", errno);
return NULL;
}
}
bo->ptr = ptr;
bo->map_count = 1;
- pipe_mutex_unlock(bo->map_mutex);
+ if (bo->initial_domain & RADEON_DOMAIN_VRAM)
+ bo->rws->mapped_vram += bo->base.size;
+ else
+ bo->rws->mapped_gtt += bo->base.size;
+
+ pipe_mutex_unlock(bo->map_mutex);
return bo->ptr;
}
static void *radeon_bo_map(struct pb_buffer *buf,
struct radeon_winsys_cs *rcs,
enum pipe_transfer_usage usage)
{
struct radeon_bo *bo = (struct radeon_bo*)buf;
struct radeon_drm_cs *cs = (struct radeon_drm_cs*)rcs;
@@ -472,20 +477,26 @@ static void radeon_bo_unmap(struct pb_buffer *_buf)
}
assert(bo->map_count);
if (--bo->map_count) {
pipe_mutex_unlock(bo->map_mutex);
return; /* it's been mapped multiple times */
}
os_munmap(bo->ptr, bo->base.size);
bo->ptr = NULL;
+
+ if (bo->initial_domain & RADEON_DOMAIN_VRAM)
+ bo->rws->mapped_vram -= bo->base.size;
+ else
+ bo->rws->mapped_gtt -= bo->base.size;
+
pipe_mutex_unlock(bo->map_mutex);
}
static const struct pb_vtbl radeon_bo_vtbl = {
radeon_bo_destroy_or_cache
/* other functions are never called */
};
#ifndef RADEON_GEM_GTT_WC
#define RADEON_GEM_GTT_WC (1 << 2)
diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
index 1b32c37..b1cc3d5 100644
--- a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
+++ b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
@@ -596,20 +596,24 @@ static uint64_t radeon_query_value(struct radeon_winsys *rws,
enum radeon_value_id value)
{
struct radeon_drm_winsys *ws = (struct radeon_drm_winsys*)rws;
uint64_t retval = 0;
switch (value) {
case RADEON_REQUESTED_VRAM_MEMORY:
return ws->allocated_vram;
case RADEON_REQUESTED_GTT_MEMORY:
return ws->allocated_gtt;
+ case RADEON_MAPPED_VRAM:
+ return ws->mapped_vram;
+ case RADEON_MAPPED_GTT:
+ return ws->mapped_gtt;
case RADEON_BUFFER_WAIT_TIME_NS:
return ws->buffer_wait_time;
case RADEON_TIMESTAMP:
if (ws->info.drm_minor < 20 || ws->gen < DRV_R600) {
assert(0);
return 0;
}
radeon_get_drm_value(ws->fd, RADEON_INFO_TIMESTAMP, "timestamp",
(uint32_t*)&retval);
diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.h b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.h
index fdbaebe..27fbe90 100644
--- a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.h
+++ b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.h
@@ -64,20 +64,22 @@ enum radeon_generation {
struct radeon_drm_winsys {
struct radeon_winsys base;
struct pipe_reference reference;
struct pb_cache bo_cache;
int fd; /* DRM file descriptor */
int num_cs; /* The number of command streams created. */
uint64_t allocated_vram;
uint64_t allocated_gtt;
+ uint64_t mapped_vram;
+ uint64_t mapped_gtt;
uint64_t buffer_wait_time; /* time spent in buffer_wait in ns */
uint64_t num_cs_flushes;
enum radeon_generation gen;
struct radeon_info info;
uint32_t va_start;
uint32_t va_unmap_working;
uint32_t accel_working2;
/* List of buffer GEM names. Protected by bo_handles_mutex. */
--
2.7.4
More information about the mesa-dev
mailing list