# HG changeset patch # User Nathan Keynes # Date 1322668244 -36000 # Node ID 1cc9bb0b384811a241d64e6f1830c783f47241a0 # Parent 266e7a1bae902c7a8374796fa25167e499837541 Rearrange the profile dump code so as to avoid xlat => SH4 references --- a/src/sh4/sh4.c Tue Nov 29 17:52:43 2011 +1000 +++ b/src/sh4/sh4.c Thu Dec 01 01:50:44 2011 +1000 @@ -236,7 +236,7 @@ sh4r.new_pc = sh4r.pc+2; sh4r.in_delay_slot = FALSE; if( sh4_translate_get_profile_blocks() ) { - xlat_dump_cache_by_activity(30); + sh4_translate_dump_cache_by_activity(30); } } --- a/src/sh4/sh4trans.c Tue Nov 29 17:52:43 2011 +1000 +++ b/src/sh4/sh4trans.c Thu Dec 01 01:50:44 2011 +1000 @@ -292,3 +292,14 @@ sh4_translate_disasm_block( stderr, code, sh4_pc, NULL ); } +void sh4_translate_dump_cache_by_activity( unsigned int topN ) +{ + struct xlat_block_ref blocks[topN]; + topN = xlat_get_cache_blocks_by_activity(blocks, topN); + unsigned int i; + for( i=0; icode, blocks[i].block->active); + sh4_translate_disasm_block( stderr, blocks[i].block->code, blocks[i].pc, NULL ); + fprintf( stderr, "\n" ); + } +} --- a/src/sh4/sh4trans.h Tue Nov 29 17:52:43 2011 +1000 +++ b/src/sh4/sh4trans.h Thu Dec 01 01:50:44 2011 +1000 @@ -171,6 +171,11 @@ */ void sh4_translate_disasm_block( FILE *out, void *code, sh4addr_t source_start, void *native_pc ); +/** + * Dump the top N blocks in the SH4 translation cache + */ +void sh4_translate_dump_cache_by_activity( unsigned int topN ); + #ifdef __cplusplus } #endif --- a/src/xlat/xltcache.c Tue Nov 29 17:52:43 2011 +1000 +++ b/src/xlat/xltcache.c Thu Dec 01 01:50:44 2011 +1000 @@ -583,11 +583,6 @@ #endif } -typedef struct { - xlat_cache_block_t block; - sh4addr_t sh4_pc; -} block_sh4_entry; - unsigned int xlat_get_active_block_count() { unsigned int count = 0; @@ -601,14 +596,14 @@ return count; } -unsigned int xlat_get_active_blocks( block_sh4_entry *blocks, unsigned int size ) +unsigned int xlat_get_active_blocks( struct xlat_block_ref *blocks, unsigned int size ) { unsigned int count = 0; xlat_cache_block_t ptr = xlat_new_cache; while( ptr->size != 0 ) { if( ptr->active != 0 ) { blocks[count].block = ptr; - blocks[count].sh4_pc = 0; + blocks[count].pc = 0; count++; } if( count >= size ) @@ -618,7 +613,7 @@ return count; } -void xlat_get_block_sh4addrs( block_sh4_entry *blocks, unsigned int size ) +void xlat_get_block_sh4addrs( struct xlat_block_ref *blocks, unsigned int size ) { unsigned i; for( i=0; ichain; if( ptr == NULL ) break; @@ -649,26 +644,23 @@ static int xlat_compare_active_field( const void *a, const void *b ) { - const block_sh4_entry *ptra = (const block_sh4_entry *)a; - const block_sh4_entry *ptrb = (const block_sh4_entry *)b; + const struct xlat_block_ref *ptra = (const struct xlat_block_ref *)a; + const struct xlat_block_ref *ptrb = (const struct xlat_block_ref *)b; return ptrb->block->active - ptra->block->active; } -void xlat_dump_cache_by_activity( unsigned int topN ) +unsigned int xlat_get_cache_blocks_by_activity( xlat_block_ref_t outblocks, size_t topN ) { int i=0; int count = xlat_get_active_block_count(); - block_sh4_entry blocks[count]; + struct xlat_block_ref blocks[count]; xlat_get_active_blocks(blocks, count); xlat_get_block_sh4addrs(blocks,count); - qsort(blocks, count, sizeof(block_sh4_entry), xlat_compare_active_field); + qsort(blocks, count, sizeof(struct xlat_block_ref), xlat_compare_active_field); - if( topN == 0 || topN > count ) + if( topN > count ) topN = count; - for( unsigned int i=0; icode, blocks[i].block->active); - sh4_translate_disasm_block( stderr, blocks[i].block->code, blocks[i].sh4_pc, NULL ); - fprintf(stderr, "\n"); - } + memcpy(outblocks, blocks, topN*sizeof(struct xlat_block_ref)); + return topN; } --- a/src/xlat/xltcache.h Tue Nov 29 17:52:43 2011 +1000 +++ b/src/xlat/xltcache.h Thu Dec 01 01:50:44 2011 +1000 @@ -183,10 +183,21 @@ void xlat_check_integrity(); /** - * Dump out the top N translated blocks by number of executions (requires block + * Short record with block + pc, used for activity dumps + */ +typedef struct xlat_block_ref { + xlat_cache_block_t block; + uint32_t pc; +} *xlat_block_ref_t; + +/** + * Fetch the top numRecords translated blocks by number of executions (requires block * profiling to be turned on in order to give meaningful results). - * @param topN Number of blocks to print. If 0, print all blocks in the cache + * @param topN Number of blocks to print. + * @return the number of records retrieved */ +unsigned int xlat_get_cache_blocks_by_activity( xlat_block_ref_t records, size_t numRecords ); + void xlat_dump_cache_by_activity( unsigned int topN ); #endif /* lxdream_xltcache_H */