static int do_profile( caddr_t start, unsigned long plength, unsigned scale, int thresh, int bucket, unsigned int mask ) { int i, retval; unsigned long blength; int num_buckets,j=0; int num_bufs = num_events; int event = num_events; int events[MAX_TEST_EVENTS]; char header[BUFSIZ]; strncpy(header,"address\t\t",BUFSIZ); //= "address\t\t\tcyc\tins\tfp_ins\n"; for(i=0;i<MAX_TEST_EVENTS;i++) { if (mask & test_events[i].mask) { events[j]=test_events[i].event; if (events[j]==PAPI_TOT_CYC) { strncat(header,"\tcyc",BUFSIZ-1); } if (events[j]==PAPI_TOT_INS) { strncat(header,"\tins",BUFSIZ-1); } if (events[j]==PAPI_FP_INS) { strncat(header,"\tfp_ins",BUFSIZ-1); } if (events[j]==PAPI_FP_OPS) { strncat(header,"\tfp_ops",BUFSIZ-1); } if (events[j]==PAPI_L2_TCM) { strncat(header,"\tl2_tcm",BUFSIZ-1); } j++; } } strncat(header,"\n",BUFSIZ-1); blength = prof_size( plength, scale, bucket, &num_buckets ); prof_alloc( num_bufs, blength ); if ( !TESTS_QUIET ) printf( "Overall event counts:\n" ); for ( i = 0; i < num_events; i++ ) { if ( ( retval = PAPI_profil( profbuf[i], ( unsigned int ) blength, start, scale, EventSet, events[i], thresh, PAPI_PROFIL_POSIX | bucket ) ) != PAPI_OK ) { if (retval == PAPI_EINVAL) { test_warn( __FILE__, __LINE__, "Trying to profile with derived event", 1); num_events=i; break; } else { printf("Failed with event %d 0x%x\n",i,events[i]); test_fail( __FILE__, __LINE__, "PAPI_profil", retval ); } } } if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_start", retval ); my_main( ); if ( ( retval = PAPI_stop( EventSet, values[0] ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); if ( !TESTS_QUIET ) { printf( TAB1, "PAPI_TOT_CYC:", ( values[0] )[--event] ); if ( strcmp( hw_info->model_string, "POWER6" ) != 0 ) { printf( TAB1, "PAPI_TOT_INS:", ( values[0] )[--event] ); } #if defined(__powerpc__) printf( TAB1, "PAPI_FP_INS", ( values[0] )[--event] ); #else if ( strcmp( hw_info->model_string, "Intel Pentium III" ) != 0 ) { printf( TAB1, "PAPI_FP_OPS:", ( values[0] )[--event] ); printf( TAB1, "PAPI_L2_TCM:", ( values[0] )[--event] ); } #endif } for ( i = 0; i < num_events; i++ ) { if ( ( retval = PAPI_profil( profbuf[i], ( unsigned int ) blength, start, scale, EventSet, events[i], 0, PAPI_PROFIL_POSIX ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_profil", retval ); } prof_head( blength, bucket, num_buckets, header ); prof_out( start, num_events, bucket, num_buckets, scale ); retval = prof_check( num_bufs, bucket, num_buckets ); for ( i = 0; i < num_bufs; i++ ) { free( profbuf[i] ); } return retval; }
void gb_run() { #ifdef PROFILE prof_enter(PF_GB_RUN); #endif //if (rom_get_loaded()){ if (g_regs.LCDC&0x80){ // LCDC 起動時 g_regs.LY=(g_regs.LY+1)%154; g_regs.STAT&=0xF8; if (g_regs.LYC==g_regs.LY){ g_regs.STAT|=4; if (g_regs.STAT&0x40) cpu_irq(INT_LCDC); } if (g_regs.LY==0){ renderer_refresh(); if (now_frame>=skip){ //pgFillvram(0); render_screen(vframe); now_frame=0; } else now_frame++; lcd_clear_win_count(); // skip=skip_buf; } if (g_regs.LY>=144){ // VBlank 期間中 g_regs.STAT|=1; if (g_regs.LY==144){ cpu_exec(72); cpu_irq(INT_VBLANK); if (g_regs.STAT&0x10) cpu_irq(INT_LCDC); cpu_exec(456-80); } else if (g_regs.LY==153){ cpu_exec(80); g_regs.LY=0; cpu_exec(456-80); // 前のラインのかなり早目から0になるようだ。 g_regs.LY=153; } else cpu_exec(456); } else{ // VBlank 期間外 g_regs.STAT|=2; if (g_regs.STAT&0x20) cpu_irq(INT_LCDC); cpu_exec(80); // state=2 g_regs.STAT|=3; cpu_exec(169); // state=3 if (dma_executing){ // HBlank DMA if (b_dma_first){ dma_dest_bank=vram_bank; if (dma_src<0x4000) dma_src_bank=get_rom(); else if (dma_src<0x8000) dma_src_bank=mbc_get_rom(); else if (dma_src>=0xA000&&dma_src<0xC000) dma_src_bank=mbc_get_sram()-0xA000; else if (dma_src>=0xC000&&dma_src<0xD000) dma_src_bank=ram-0xC000; else if (dma_src>=0xD000&&dma_src<0xE000) dma_src_bank=ram_bank-0xD000; else dma_src_bank=NULL; b_dma_first=false; } memcpy(dma_dest_bank+(dma_dest&0x1ff0),dma_src_bank+dma_src,16); // fprintf(cpu_file,"%03d : dma exec %04X -> %04X rest %d\n",g_regs.LY,cpu_dma_src,cpu_dma_dest,cpu_dma_rest); dma_src+=16; dma_src&=0xfff0; dma_dest+=16; dma_dest&=0xfff0; dma_rest--; if (!dma_rest) dma_executing=false; // cpu_total_clock+=207*(cpu_speed?2:1); // cpu_sys_clock+=207*(cpu_speed?2:1); // cpu_div_clock+=207*(cpu_speed?2:1); // g_regs.STAT|=3; if (now_frame>=skip && !sgb_mask) lcd_render(vframe,g_regs.LY); g_regs.STAT&=0xfc; cpu_exec(207); // state=3 } else{ /* if (lcd_get_sprite_count()){ if (lcd_get_sprite_count()>=10){ cpu_exec(129); if ((g_regs.STAT&0x08)) cpu_irq(INT_LCDC); g_regs.STAT&=0xfc; if (now_frame>=skip) lcd_render(vframe,g_regs.LY); cpu_exec(78); // state=0 } else{ cpu_exec(129*lcd_get_sprite_count()/10); if ((g_regs.STAT&0x08)) cpu_irq(INT_LCDC); g_regs.STAT&=0xfc; if (now_frame>=skip) lcd_render(vframe,g_regs.LY); cpu_exec(207-(129*lcd_get_sprite_count()/10)); // state=0 } } else{ */ g_regs.STAT&=0xfc; if (now_frame>=skip && !sgb_mask) lcd_render(vframe,g_regs.LY); if ((g_regs.STAT&0x08)) cpu_irq(INT_LCDC); cpu_exec(207); // state=0 // } } } } else{ // LCDC 停止時 g_regs.LY=0; // g_regs.LY=(g_regs.LY+1)%154; re_render++; if (re_render>=154){ gb_fill_vframe(0xff); renderer_refresh(); if (now_frame>=skip){ //pgFillvram(0); render_screen(vframe); now_frame=0; } else now_frame++; lcd_clear_win_count(); re_render=0; } g_regs.STAT&=0xF8; cpu_exec(456); } //} #ifdef PROFILE prof_out(); #endif }
static int do_profile(caddr_t start, unsigned long plength, unsigned scale, int thresh, int bucket) { int i, retval; unsigned long blength; int num_buckets; char *profstr[5] = {"PAPI_PROFIL_POSIX", "PAPI_PROFIL_RANDOM", "PAPI_PROFIL_WEIGHTED", "PAPI_PROFIL_COMPRESS", "PAPI_PROFIL_<all>" }; int profflags[5] = {PAPI_PROFIL_POSIX, PAPI_PROFIL_POSIX | PAPI_PROFIL_RANDOM, PAPI_PROFIL_POSIX | PAPI_PROFIL_WEIGHTED, PAPI_PROFIL_POSIX | PAPI_PROFIL_COMPRESS, PAPI_PROFIL_POSIX | PAPI_PROFIL_WEIGHTED | PAPI_PROFIL_RANDOM | PAPI_PROFIL_COMPRESS }; do_no_profile(); blength = prof_size(plength, scale, bucket, &num_buckets); prof_alloc(5, blength); for (i=0;i<5;i++) { if (!TESTS_QUIET) printf("Test type : \t%s\n", profstr[i]); #ifndef SWPROFILE if ((retval = PAPI_profil(profbuf[i], blength, start, scale, EventSet, PAPI_event, thresh, profflags[i] | bucket)) != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_profil", retval); } #else if ((retval = PAPI_profil(profbuf[i], blength, start, scale, EventSet, PAPI_event, thresh, profflags[i] | bucket | PAPI_PROFIL_FORCE_SW)) != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_profil", retval); } #endif if ((retval = PAPI_start(EventSet)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); do_flops(getenv("NUM_FLOPS") ? atoi(getenv("NUM_FLOPS")) : NUM_FLOPS); if ((retval = PAPI_stop(EventSet, values[1])) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); if (!TESTS_QUIET) { printf(TAB1, event_name, (values[1])[0]); printf(TAB1, "PAPI_TOT_CYC", (values[1])[1]); } if ((retval = PAPI_profil(profbuf[i], blength, start, scale, EventSet, PAPI_event, 0, profflags[i])) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_profil", retval); } prof_head(blength, bucket, num_buckets, "address\t\t\tflat\trandom\tweight\tcomprs\tall\n"); prof_out(start, 5, bucket, num_buckets, scale); retval = prof_check(5, bucket, num_buckets); for (i=0;i<5;i++) { free(profbuf[i]); } return(retval); }