📄 proc_pmc.c
字号:
int n, file; char *buffer = NULL; if (count < 0) return 0; spin_lock(&proc_ppc64_lock); /* Figure out which file is being request. */ file = proc_ppc64_pmc_find_file(data); /* Update the counters and the text buffer representation. */ buffer = ppc64_pmc_stab(file); /* Put the data into the requestor's buffer. */ n = proc_ppc64_pmc_read(page, start, off, count, eof, buffer); spin_unlock(&proc_ppc64_lock); return n;}int proc_ppc64_pmc_htab_read(char *page, char **start, off_t off, int count, int *eof, void *data){ int n, file; char *buffer = NULL; if (count < 0) return 0; spin_lock(&proc_ppc64_lock); /* Figure out which file is being request. */ file = proc_ppc64_pmc_find_file(data); /* Update the counters and the text buffer representation. */ buffer = ppc64_pmc_htab(file); /* Put the data into the requestor's buffer. */ n = proc_ppc64_pmc_read(page, start, off, count, eof, buffer); spin_unlock(&proc_ppc64_lock); return n;}static ssize_t read_profile(struct file *file, char *buf, size_t count, loff_t *ppos){ unsigned long p = *ppos; ssize_t read; char * pnt; unsigned int sample_step = 4; if (p >= (perfmon_base.profile_length+1)) return 0; if (count > (perfmon_base.profile_length+1) - p) count = (perfmon_base.profile_length+1) - p; read = 0; while (p < sizeof(unsigned int) && count > 0) { put_user(*((char *)(&sample_step)+p),buf); buf++; p++; count--; read++; } pnt = (char *)(perfmon_base.profile_buffer) + p - sizeof(unsigned int); copy_to_user(buf,(void *)pnt,count); p += count; read += count; *ppos = p; return read;}static ssize_t write_profile(struct file * file, const char * buf, size_t count, loff_t *ppos){ return(0);}static ssize_t read_trace(struct file *file, char *buf, size_t count, loff_t *ppos){ unsigned long p = *ppos; char * pnt; if (p >= (perfmon_base.trace_length)) return 0; if (count > (perfmon_base.trace_length) - p) count = (perfmon_base.trace_length) - p; pnt = (char *)(perfmon_base.trace_buffer) + p; copy_to_user(buf,(void *)pnt,count); p += count; *ppos = p; return count;}static ssize_t write_trace(struct file * file, const char * buf, size_t count, loff_t *ppos){ return(0);}static ssize_t read_timeslice(struct file *file, char *buf, size_t count, loff_t *ppos){ unsigned long p = *ppos; ssize_t read; char * pnt; if (p >= (perfmon_base.timeslice_length)) return 0; if (count > (perfmon_base.timeslice_length) - p) count = (perfmon_base.timeslice_length) - p; pnt = (char *)(perfmon_base.timeslice_buffer) + p; copy_to_user(buf,(void *)pnt,count); *ppos = p + count; return count;}static ssize_t write_timeslice(struct file * file, const char * buf, size_t count, loff_t *ppos){ return(0);}int proc_ppc64_pmc_hw_read(char *page, char **start, off_t off, int count, int *eof, void *data){ int n, file; char *buffer = NULL; if (count < 0) return 0; spin_lock(&proc_ppc64_lock); /* Figure out which file is being request. */ file = proc_ppc64_pmc_find_file(data); /* Update the counters and the text buffer representation. */ buffer = ppc64_pmc_hw(file); /* Put the data into the requestor's buffer. */ n = proc_ppc64_pmc_read(page, start, off, count, eof, buffer); spin_unlock(&proc_ppc64_lock); return n;}/* * DRENG the remainder of these functions still need work ... */void pmc_proc_init(struct proc_dir_entry *iSeries_proc){ struct proc_dir_entry *ent = NULL; ent = create_proc_entry("lpevents", S_IFREG|S_IRUGO, iSeries_proc); if (!ent) return; ent->nlink = 1; ent->data = (void *)0; ent->read_proc = proc_get_lpevents; ent->write_proc = proc_reset_lpevents; ent = create_proc_entry("titanTod", S_IFREG|S_IRUGO, iSeries_proc); if (!ent) return; ent->nlink = 1; ent->data = (void *)0; ent->size = 0; ent->read_proc = proc_get_titanTod; ent->write_proc = NULL; pmc_proc_root = proc_mkdir("pmc", iSeries_proc); if (!pmc_proc_root) return; ent = create_proc_entry("control", S_IFREG|S_IRUSR|S_IWUSR, pmc_proc_root); if (!ent) return; ent->nlink = 1; ent->data = (void *)0; ent->read_proc = proc_pmc_get_control; ent->write_proc = proc_pmc_set_control;}static int pmc_calc_metrics( char *page, char **start, off_t off, int count, int *eof, int len){ if ( len <= off+count) *eof = 1; *start = page+off; len -= off; if ( len > count ) len = count; if ( len < 0 ) len = 0; return len;}static char * lpEventTypes[9] = { "Hypervisor\t\t", "Machine Facilities\t", "Session Manager\t", "SPD I/O\t\t", "Virtual Bus\t\t", "PCI I/O\t\t", "RIO I/O\t\t", "Virtual Lan\t\t", "Virtual I/O\t\t" }; int proc_get_lpevents(char *page, char **start, off_t off, int count, int *eof, void *data){ unsigned i; int len = 0; len += sprintf( page+len, "LpEventQueue 0\n" ); len += sprintf( page+len, " events processed:\t%lu\n", (unsigned long)xItLpQueue.xLpIntCount ); for (i=0; i<9; ++i) { len += sprintf( page+len, " %s %10lu\n", lpEventTypes[i], (unsigned long)xItLpQueue.xLpIntCountByType[i] ); } len += sprintf( page+len, "\n events processed by processor:\n" ); for (i=0; i<systemcfg->processorCount; ++i) { len += sprintf( page+len, " CPU%02d %10u\n", i, paca[i].lpEvent_count ); } return pmc_calc_metrics( page, start, off, count, eof, len );}int proc_reset_lpevents( struct file *file, const char *buffer, unsigned long count, void *data ){ return count;}static unsigned long startTitan = 0;static unsigned long startTb = 0;int proc_get_titanTod(char *page, char **start, off_t off, int count, int *eof, void *data){ int len = 0; unsigned long tb0, titan_tod; tb0 = get_tb(); titan_tod = HvCallXm_loadTod(); len += sprintf( page+len, "Titan\n" ); len += sprintf( page+len, " time base = %016lx\n", tb0 ); len += sprintf( page+len, " titan tod = %016lx\n", titan_tod ); len += sprintf( page+len, " xProcFreq = %016x\n", xIoHriProcessorVpd[0].xProcFreq ); len += sprintf( page+len, " xTimeBaseFreq = %016x\n", xIoHriProcessorVpd[0].xTimeBaseFreq ); len += sprintf( page+len, " tb_ticks_per_jiffy = %lu\n", tb_ticks_per_jiffy ); len += sprintf( page+len, " tb_ticks_per_usec = %lu\n", tb_ticks_per_usec ); if ( !startTitan ) { startTitan = titan_tod; startTb = tb0; } else { unsigned long titan_usec = (titan_tod - startTitan) >> 12; unsigned long tb_ticks = (tb0 - startTb); unsigned long titan_jiffies = titan_usec / (1000000/HZ); unsigned long titan_jiff_usec = titan_jiffies * (1000000/HZ); unsigned long titan_jiff_rem_usec = titan_usec - titan_jiff_usec; unsigned long tb_jiffies = tb_ticks / tb_ticks_per_jiffy; unsigned long tb_jiff_ticks = tb_jiffies * tb_ticks_per_jiffy; unsigned long tb_jiff_rem_ticks = tb_ticks - tb_jiff_ticks; unsigned long tb_jiff_rem_usec = tb_jiff_rem_ticks / tb_ticks_per_usec; unsigned long new_tb_ticks_per_jiffy = (tb_ticks * (1000000/HZ))/titan_usec; len += sprintf( page+len, " titan elapsed = %lu uSec\n", titan_usec); len += sprintf( page+len, " tb elapsed = %lu ticks\n", tb_ticks); len += sprintf( page+len, " titan jiffies = %lu.%04lu \n", titan_jiffies, titan_jiff_rem_usec ); len += sprintf( page+len, " tb jiffies = %lu.%04lu\n", tb_jiffies, tb_jiff_rem_usec ); len += sprintf( page+len, " new tb_ticks_per_jiffy = %lu\n", new_tb_ticks_per_jiffy ); } return pmc_calc_metrics( page, start, off, count, eof, len );} int proc_pmc_get_control(char *page, char **start, off_t off, int count, int *eof, void *data){ int len = 0; if ( proc_pmc_control_mode == PMC_CONTROL_CPI ) { unsigned long mach_cycles = mfspr( PMC5 ); unsigned long inst_complete = mfspr( PMC4 ); unsigned long inst_dispatch = mfspr( PMC3 ); unsigned long thread_active_run = mfspr( PMC1 ); unsigned long thread_active = mfspr( PMC2 ); unsigned long cpi = 0; unsigned long cpithou = 0; unsigned long remain; if ( inst_complete ) { cpi = thread_active_run / inst_complete; remain = thread_active_run % inst_complete; if ( inst_complete > 1000000 ) cpithou = remain / ( inst_complete / 1000 ); else cpithou = ( remain * 1000 ) / inst_complete; } len += sprintf( page+len, "PMC CPI Mode\nRaw Counts\n" ); len += sprintf( page+len, "machine cycles : %12lu\n", mach_cycles ); len += sprintf( page+len, "thread active cycles : %12lu\n\n", thread_active ); len += sprintf( page+len, "instructions completed : %12lu\n", inst_complete ); len += sprintf( page+len, "instructions dispatched : %12lu\n", inst_dispatch ); len += sprintf( page+len, "thread active run cycles : %12lu\n", thread_active_run ); len += sprintf( page+len, "thread active run cycles/instructions completed\n" ); len += sprintf( page+len, "CPI = %lu.%03lu\n", cpi, cpithou ); } else if ( proc_pmc_control_mode == PMC_CONTROL_TLB ) { len += sprintf( page+len, "PMC TLB Mode\n" ); len += sprintf( page+len, "I-miss count : %12lu\n", mfspr( PMC1 ) ); len += sprintf( page+len, "I-miss latency : %12lu\n", mfspr( PMC2 ) ); len += sprintf( page+len, "D-miss count : %12lu\n", mfspr( PMC3 ) ); len += sprintf( page+len, "D-miss latency : %12lu\n", mfspr( PMC4 ) ); len += sprintf( page+len, "IERAT miss count : %12lu\n", mfspr( PMC5 ) ); len += sprintf( page+len, "D-reference count : %12lu\n", mfspr( PMC6 ) ); len += sprintf( page+len, "miss PTEs searched : %12lu\n", mfspr( PMC7 ) ); len += sprintf( page+len, "miss >8 PTEs searched : %12lu\n", mfspr( PMC8 ) ); } /* IMPLEMENT ME */ 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 );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -