r600g: reduce memory usage from range/block hash table.

This table covered a large range unnecessarily, reduce the address
range covered, use the fact that the bottom two bits aren't significant,
and remove unused fields from the range struct. It also drops the hash_size/shift in context in favour of a define, which should make doing the math
a bit less CPU intensive.

valgrind glxinfo
Before:
==320==     in use at exit: 419,754 bytes in 706 blocks
==320==   total heap usage: 3,691 allocs, 2,985 frees, 7,272,467 bytes allocated

After:
==967==     in use at exit: 419,754 bytes in 706 blocks
==967==   total heap usage: 3,552 allocs, 2,846 frees, 3,550,131 bytes allocated

Signed-off-by: Dave Airlie <airlied@redhat.com>
This commit is contained in:
Dave Airlie 2011-05-12 13:20:02 +10:00
parent 5e15497452
commit d015d2f391
4 changed files with 39 additions and 28 deletions

View File

@ -193,8 +193,6 @@ struct r600_block {
};
struct r600_range {
unsigned start_offset;
unsigned end_offset;
struct r600_block **blocks;
};
@ -239,9 +237,7 @@ struct r600_query {
struct r600_context {
struct radeon *radeon;
unsigned hash_size;
unsigned hash_shift;
struct r600_range range[256];
struct r600_range *range;
unsigned nblocks;
struct r600_block **blocks;
struct list_head dirty;

View File

@ -513,15 +513,18 @@ int evergreen_context_init(struct r600_context *ctx, struct radeon *radeon)
ctx->radeon = radeon;
LIST_INITHEAD(&ctx->query_list);
ctx->range = calloc(NUM_RANGES, sizeof(struct r600_range));
if (!ctx->range) {
r = -ENOMEM;
goto out_err;
}
/* initialize hash */
ctx->hash_size = 19;
ctx->hash_shift = 11;
for (int i = 0; i < 256; i++) {
ctx->range[i].start_offset = i << ctx->hash_shift;
ctx->range[i].end_offset = ((i + 1) << ctx->hash_shift) - 1;
ctx->range[i].blocks = calloc(1 << ctx->hash_shift, sizeof(void*));
for (int i = 0; i < NUM_RANGES; i++) {
ctx->range[i].blocks = calloc(1 << HASH_SHIFT, sizeof(void*));
if (ctx->range[i].blocks == NULL) {
return -ENOMEM;
r = -ENOMEM;
goto out_err;
}
}
@ -590,12 +593,12 @@ int evergreen_context_init(struct r600_context *ctx, struct radeon *radeon)
/* setup block table */
ctx->blocks = calloc(ctx->nblocks, sizeof(void*));
for (int i = 0, c = 0; i < 256; i++) {
for (int j = 0; j < (1 << ctx->hash_shift); j++) {
for (int i = 0, c = 0; i < NUM_RANGES; i++) {
for (int j = 0; j < (1 << HASH_SHIFT); j++) {
if (ctx->range[i].blocks[j]) {
assert(c < ctx->nblocks);
ctx->blocks[c++] = ctx->range[i].blocks[j];
j += (ctx->range[i].blocks[j]->nreg << 2) - 1;
j += (ctx->range[i].blocks[j]->nreg) - 1;
}
}
}

View File

@ -612,8 +612,8 @@ void r600_context_fini(struct r600_context *ctx)
struct r600_block *block;
struct r600_range *range;
for (int i = 0; i < 256; i++) {
for (int j = 0; j < (1 << ctx->hash_shift); j++) {
for (int i = 0; i < NUM_RANGES; i++) {
for (int j = 0; j < (1 << HASH_SHIFT); j++) {
block = ctx->range[i].blocks[j];
if (block) {
for (int k = 0, offset = block->start_offset; k < block->nreg; k++, offset += 4) {
@ -628,6 +628,7 @@ void r600_context_fini(struct r600_context *ctx)
}
free(ctx->range[i].blocks);
}
free(ctx->range);
free(ctx->blocks);
free(ctx->reloc);
free(ctx->bo);
@ -645,13 +646,15 @@ int r600_context_init(struct r600_context *ctx, struct radeon *radeon)
ctx->radeon = radeon;
LIST_INITHEAD(&ctx->query_list);
ctx->range = calloc(NUM_RANGES, sizeof(struct r600_range));
if (!ctx->range) {
r = -ENOMEM;
goto out_err;
}
/* initialize hash */
ctx->hash_size = 19;
ctx->hash_shift = 11;
for (int i = 0; i < 256; i++) {
ctx->range[i].start_offset = i << ctx->hash_shift;
ctx->range[i].end_offset = ((i + 1) << ctx->hash_shift) - 1;
ctx->range[i].blocks = calloc(1 << ctx->hash_shift, sizeof(void*));
for (int i = 0; i < NUM_RANGES; i++) {
ctx->range[i].blocks = calloc(1 << HASH_SHIFT, sizeof(void*));
if (ctx->range[i].blocks == NULL) {
r = -ENOMEM;
goto out_err;
@ -723,8 +726,8 @@ int r600_context_init(struct r600_context *ctx, struct radeon *radeon)
/* setup block table */
ctx->blocks = calloc(ctx->nblocks, sizeof(void*));
for (int i = 0, c = 0; i < 256; i++) {
for (int j = 0, add; j < (1 << ctx->hash_shift); j++) {
for (int i = 0, c = 0; i < NUM_RANGES; i++) {
for (int j = 0, add; j < (1 << HASH_SHIFT); j++) {
if (ctx->range[i].blocks[j]) {
add = 1;
for (int k = 0; k < c; k++) {
@ -736,7 +739,7 @@ int r600_context_init(struct r600_context *ctx, struct radeon *radeon)
if (add) {
assert(c < ctx->nblocks);
ctx->blocks[c++] = ctx->range[i].blocks[j];
j += (ctx->range[i].blocks[j]->nreg << 2) - 1;
j += (ctx->range[i].blocks[j]->nreg) - 1;
}
}
}

View File

@ -185,8 +185,17 @@ struct r600_bo *r600_bomgr_bo_create(struct r600_bomgr *mgr,
/*
* helpers
*/
#define CTX_RANGE_ID(ctx, offset) (((offset) >> (ctx)->hash_shift) & 255)
#define CTX_BLOCK_ID(ctx, offset) ((offset) & ((1 << (ctx)->hash_shift) - 1))
/* each range covers 9 bits of dword space = 512 dwords = 2k bytes */
/* there is a block entry for each register so 512 blocks */
/* we have no registers to read/write below 0x8000 (0x2000 in dw space) */
/* we use some fake offsets at 0x40000 to do evergreen sampler borders so take 0x42000 as a max bound*/
#define RANGE_OFFSET_START 0x8000
#define HASH_SHIFT 9
#define NUM_RANGES (0x42000 - RANGE_OFFSET_START) / (4 << HASH_SHIFT) /* 128 << 9 = 64k */
#define CTX_RANGE_ID(ctx, offset) ((((offset - RANGE_OFFSET_START) >> 2) >> HASH_SHIFT) & 255)
#define CTX_BLOCK_ID(ctx, offset) (((offset - RANGE_OFFSET_START) >> 2) & ((1 << HASH_SHIFT) - 1))
/*
* radeon_bo.c