pmc_proc.c
来自「是关于linux2.5.1的完全源码」· C语言 代码 · 共 648 行 · 第 1/2 页
C
648 行
int len = sprintf( page, "0x%08x", mfspr(PMC4) ); return pmc_calc_metrics( page, start, off, count, eof, len );}int proc_pmc_get_pmc5(char *page, char **start, off_t off, int count, int *eof, void *data){ int len = sprintf( page, "0x%08x", mfspr(PMC5) ); return pmc_calc_metrics( page, start, off, count, eof, len );}int proc_pmc_get_pmc6(char *page, char **start, off_t off, int count, int *eof, void *data){ int len = sprintf( page, "0x%08x", mfspr(PMC6) ); return pmc_calc_metrics( page, start, off, count, eof, len );}int proc_pmc_get_pmc7(char *page, char **start, off_t off, int count, int *eof, void *data){ int len = sprintf( page, "0x%08x", mfspr(PMC7) ); return pmc_calc_metrics( page, start, off, count, eof, len );}int proc_pmc_get_pmc8(char *page, char **start, off_t off, int count, int *eof, void *data){ int len = sprintf( page, "0x%08x", mfspr(PMC8) ); return pmc_calc_metrics( page, start, off, count, eof, len );}unsigned long proc_pmc_conv_int( const char *buf, unsigned count ){ const char * p; char b0, b1; unsigned v, multiplier, mult, i; unsigned long val; multiplier = 10; p = buf; if ( count >= 3 ) { b0 = buf[0]; b1 = buf[1]; if ( ( b0 == '0' ) && ( ( b1 == 'x' ) || ( b1 == 'X' ) ) ) { p = buf + 2; count -= 2; multiplier = 16; } } val = 0; for ( i=0; i<count; ++i ) { b0 = *p++; v = 0; mult = multiplier; if ( ( b0 >= '0' ) && ( b0 <= '9' ) ) v = b0 - '0'; else if ( multiplier == 16 ) { if ( ( b0 >= 'a' ) && ( b0 <= 'f' ) ) v = b0 - 'a' + 10; else if ( ( b0 >= 'A' ) && ( b0 <= 'F' ) ) v = b0 - 'A' + 10; else mult = 1; } else mult = 1; val *= mult; val += v; } return val;}static inline void proc_pmc_stop(void){ // Freeze all counters, leave everything else alone mtspr( MMCR0, mfspr( MMCR0 ) | 0x80000000 );}static inline void proc_pmc_start(void){ // Unfreeze all counters, leave everything else alone mtspr( MMCR0, mfspr( MMCR0 ) & ~0x80000000 );}static inline void proc_pmc_reset(void){ // Clear all the PMCs to zero // Assume a "stop" has already frozen the counters // Clear all the PMCs mtspr( PMC1, 0 ); mtspr( PMC2, 0 ); mtspr( PMC3, 0 ); mtspr( PMC4, 0 ); mtspr( PMC5, 0 ); mtspr( PMC6, 0 ); mtspr( PMC7, 0 ); mtspr( PMC8, 0 );}static inline void proc_pmc_cpi(void){ /* Configure the PMC registers to count cycles and instructions */ /* so we can compute cpi */ /* * MMCRA[30] = 1 Don't count in wait state (CTRL[31]=0) * MMCR0[6] = 1 Freeze counters when any overflow * MMCR0[19:25] = 0x01 PMC1 counts Thread Active Run Cycles * MMCR0[26:31] = 0x05 PMC2 counts Thread Active Cycles * MMCR1[0:4] = 0x07 PMC3 counts Instructions Dispatched * MMCR1[5:9] = 0x03 PMC4 counts Instructions Completed * MMCR1[10:14] = 0x06 PMC5 counts Machine Cycles * */ proc_pmc_control_mode = PMC_CONTROL_CPI; // Indicate to hypervisor that we are using the PMCs ((struct Paca *)mfspr(SPRG1))->xLpPacaPtr->xPMCRegsInUse = 1; // Freeze all counters mtspr( MMCR0, 0x80000000 ); mtspr( MMCR1, 0x00000000 ); // Clear all the PMCs mtspr( PMC1, 0 ); mtspr( PMC2, 0 ); mtspr( PMC3, 0 ); mtspr( PMC4, 0 ); mtspr( PMC5, 0 ); mtspr( PMC6, 0 ); mtspr( PMC7, 0 ); mtspr( PMC8, 0 ); // Freeze counters in Wait State (CTRL[31]=0) mtspr( MMCRA, 0x00000002 ); // PMC3<-0x07, PMC4<-0x03, PMC5<-0x06 mtspr( MMCR1, 0x38cc0000 ); mb(); // PMC1<-0x01, PMC2<-0x05 // Start all counters mtspr( MMCR0, 0x02000045 ); }static inline void proc_pmc_tlb(void){ /* Configure the PMC registers to count tlb misses */ /* * MMCR0[6] = 1 Freeze counters when any overflow * MMCR0[19:25] = 0x55 Group count * PMC1 counts I misses * PMC2 counts I miss duration (latency) * PMC3 counts D misses * PMC4 counts D miss duration (latency) * PMC5 counts IERAT misses * PMC6 counts D references (including PMC7) * PMC7 counts miss PTEs searched * PMC8 counts miss >8 PTEs searched * */ proc_pmc_control_mode = PMC_CONTROL_TLB; // Indicate to hypervisor that we are using the PMCs ((struct Paca *)mfspr(SPRG1))->xLpPacaPtr->xPMCRegsInUse = 1; // Freeze all counters mtspr( MMCR0, 0x80000000 ); mtspr( MMCR1, 0x00000000 ); // Clear all the PMCs mtspr( PMC1, 0 ); mtspr( PMC2, 0 ); mtspr( PMC3, 0 ); mtspr( PMC4, 0 ); mtspr( PMC5, 0 ); mtspr( PMC6, 0 ); mtspr( PMC7, 0 ); mtspr( PMC8, 0 ); mtspr( MMCRA, 0x00000000 ); mb(); // PMC1<-0x55 // Start all counters mtspr( MMCR0, 0x02001540 ); }int proc_pmc_set_control( struct file *file, const char *buffer, unsigned long count, void *data ){ if ( ! strncmp( buffer, "stop", 4 ) ) proc_pmc_stop(); else if ( ! strncmp( buffer, "start", 5 ) ) proc_pmc_start(); else if ( ! strncmp( buffer, "reset", 5 ) ) proc_pmc_reset(); else if ( ! strncmp( buffer, "cpi", 3 ) ) proc_pmc_cpi(); else if ( ! strncmp( buffer, "tlb", 3 ) ) proc_pmc_tlb(); /* IMPLEMENT ME */ return count;}int proc_pmc_set_mmcr0( struct file *file, const char *buffer, unsigned long count, void *data ){ unsigned long v; v = proc_pmc_conv_int( buffer, count ); v = v & ~0x04000000; /* Don't allow interrupts for now */ if ( v & ~0x80000000 ) /* Inform hypervisor we are using PMCs */ ((struct Paca *)mfspr(SPRG1))->xLpPacaPtr->xPMCRegsInUse = 1; else ((struct Paca *)mfspr(SPRG1))->xLpPacaPtr->xPMCRegsInUse = 0; mtspr( MMCR0, v ); return count; }int proc_pmc_set_mmcr1( struct file *file, const char *buffer, unsigned long count, void *data ){ unsigned long v; v = proc_pmc_conv_int( buffer, count ); mtspr( MMCR1, v ); return count;}int proc_pmc_set_mmcra( struct file *file, const char *buffer, unsigned long count, void *data ){ unsigned long v; v = proc_pmc_conv_int( buffer, count ); v = v & ~0x00008000; /* Don't allow interrupts for now */ mtspr( MMCRA, v ); return count;}int proc_pmc_set_pmc1( struct file *file, const char *buffer, unsigned long count, void *data ){ unsigned long v; v = proc_pmc_conv_int( buffer, count ); mtspr( PMC1, v ); return count;}int proc_pmc_set_pmc2( struct file *file, const char *buffer, unsigned long count, void *data ){ unsigned long v; v = proc_pmc_conv_int( buffer, count ); mtspr( PMC2, v ); return count;}int proc_pmc_set_pmc3( struct file *file, const char *buffer, unsigned long count, void *data ){ unsigned long v; v = proc_pmc_conv_int( buffer, count ); mtspr( PMC3, v ); return count;}int proc_pmc_set_pmc4( struct file *file, const char *buffer, unsigned long count, void *data ){ unsigned long v; v = proc_pmc_conv_int( buffer, count ); mtspr( PMC4, v ); return count;}int proc_pmc_set_pmc5( struct file *file, const char *buffer, unsigned long count, void *data ){ unsigned long v; v = proc_pmc_conv_int( buffer, count ); mtspr( PMC5, v ); return count;}int proc_pmc_set_pmc6( struct file *file, const char *buffer, unsigned long count, void *data ){ unsigned long v; v = proc_pmc_conv_int( buffer, count ); mtspr( PMC6, v ); return count;}int proc_pmc_set_pmc7( struct file *file, const char *buffer, unsigned long count, void *data ){ unsigned long v; v = proc_pmc_conv_int( buffer, count ); mtspr( PMC7, v ); return count;}int proc_pmc_set_pmc8( struct file *file, const char *buffer, unsigned long count, void *data ){ unsigned long v; v = proc_pmc_conv_int( buffer, count ); mtspr( PMC8, v ); return count;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?