pmc_proc.c

来自「是关于linux2.5.1的完全源码」· C语言 代码 · 共 648 行 · 第 1/2 页

C
648
字号
/* * pmc_proc.c * Copyright (C) 2001 Mike Corrigan  IBM Corporation *  * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. *  * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. *  * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA *//* Change Activity: *//* End Change Activity */#ifndef _PMC_PROC_H#include <asm/iSeries/pmc_proc.h>#endif#include <asm/iSeries/Paca.h>#include <asm/iSeries/ItLpPaca.h>#include <asm/iSeries/ItLpQueue.h>#include <asm/processor.h>#define MMCR0 795#define MMCR1 798#define MMCRA 786#define PMC1  787#define PMC2  788#define PMC3  789#define PMC4  790#define PMC5  791#define PMC6  792#define PMC7  793#define PMC8  794static int proc_pmc_control_mode = 0;#define PMC_CONTROL_CPI 1#define PMC_CONTROL_TLB 2static struct proc_dir_entry *pmc_proc_root = NULL;int proc_get_lpevents( char *page, char **start, off_t off, int count, int *eof, void *data);int proc_reset_lpevents( struct file *file, const char *buffer, unsigned long count, void *data);int proc_pmc_get_control( char *page, char **start, off_t off, int count, int *eof, void *data);int proc_pmc_get_mmcr0( char *page, char **start, off_t off, int count, int *eof, void *data);int proc_pmc_get_mmcr1( char *page, char **start, off_t off, int count, int *eof, void *data);int proc_pmc_get_mmcra( char *page, char **start, off_t off, int count, int *eof, void *data);int proc_pmc_get_pmc1(  char *page, char **start, off_t off, int count, int *eof, void *data);int proc_pmc_get_pmc2(  char *page, char **start, off_t off, int count, int *eof, void *data);int proc_pmc_get_pmc3(  char *page, char **start, off_t off, int count, int *eof, void *data);int proc_pmc_get_pmc4(  char *page, char **start, off_t off, int count, int *eof, void *data);int proc_pmc_get_pmc5(  char *page, char **start, off_t off, int count, int *eof, void *data);int proc_pmc_get_pmc6(  char *page, char **start, off_t off, int count, int *eof, void *data);int proc_pmc_get_pmc7(  char *page, char **start, off_t off, int count, int *eof, void *data);int proc_pmc_get_pmc8(  char *page, char **start, off_t off, int count, int *eof, void *data);int proc_pmc_set_control( struct file *file, const char *buffer, unsigned long count, void *data);int proc_pmc_set_mmcr0( struct file *file, const char *buffer, unsigned long count, void *data);int proc_pmc_set_mmcr1( struct file *file, const char *buffer, unsigned long count, void *data);int proc_pmc_set_mmcra( struct file *file, const char *buffer, unsigned long count, void *data);int proc_pmc_set_pmc1(  struct file *file, const char *buffer, unsigned long count, void *data);int proc_pmc_set_pmc2(  struct file *file, const char *buffer, unsigned long count, void *data);int proc_pmc_set_pmc3(  struct file *file, const char *buffer, unsigned long count, void *data);int proc_pmc_set_pmc4(  struct file *file, const char *buffer, unsigned long count, void *data);int proc_pmc_set_pmc5(  struct file *file, const char *buffer, unsigned long count, void *data);int proc_pmc_set_pmc6(  struct file *file, const char *buffer, unsigned long count, void *data);int proc_pmc_set_pmc7(  struct file *file, const char *buffer, unsigned long count, void *data);int proc_pmc_set_pmc8(  struct file *file, const char *buffer, unsigned long count, void *data);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;        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;        ent = create_proc_entry("mmcr0", 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_mmcr0;    ent->write_proc = proc_pmc_set_mmcr0;    ent = create_proc_entry("mmcr1", 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_mmcr1;    ent->write_proc = proc_pmc_set_mmcr1;    ent = create_proc_entry("mmcra", 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_mmcra;    ent->write_proc = proc_pmc_set_mmcra;    ent = create_proc_entry("pmc1", 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_pmc1;    ent->write_proc = proc_pmc_set_pmc1;    ent = create_proc_entry("pmc2", 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_pmc2;    ent->write_proc = proc_pmc_set_pmc2;    ent = create_proc_entry("pmc3", 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_pmc3;    ent->write_proc = proc_pmc_set_pmc3;    ent = create_proc_entry("pmc4", 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_pmc4;    ent->write_proc = proc_pmc_set_pmc4;    ent = create_proc_entry("pmc5", 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_pmc5;    ent->write_proc = proc_pmc_set_pmc5;    ent = create_proc_entry("pmc6", 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_pmc6;    ent->write_proc = proc_pmc_set_pmc6;    ent = create_proc_entry("pmc7", 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_pmc7;    ent->write_proc = proc_pmc_set_pmc7;    ent = create_proc_entry("pmc8", 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_pmc8;    ent->write_proc = proc_pmc_set_pmc8;}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] );	}	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;}	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             : %12u\n", mfspr( PMC1 ) );		len += sprintf( page+len, "I-miss latency           : %12u\n", mfspr( PMC2 ) );		len += sprintf( page+len, "D-miss count             : %12u\n", mfspr( PMC3 ) );		len += sprintf( page+len, "D-miss latency           : %12u\n", mfspr( PMC4 ) );		len += sprintf( page+len, "IERAT miss count         : %12u\n", mfspr( PMC5 ) );		len += sprintf( page+len, "D-reference count        : %12u\n", mfspr( PMC6 ) );		len += sprintf( page+len, "miss PTEs searched       : %12u\n", mfspr( PMC7 ) );		len += sprintf( page+len, "miss >8 PTEs searched    : %12u\n", mfspr( PMC8 ) );	}	/* IMPLEMENT ME */	return pmc_calc_metrics( page, start, off, count, eof, len );}int proc_pmc_get_mmcr0(char *page, char **start, off_t off, int count, int *eof, void *data){	int len = sprintf( page, "0x%08x", mfspr(MMCR0) );	return pmc_calc_metrics( page, start, off, count, eof, len );}int proc_pmc_get_mmcr1(char *page, char **start, off_t off, int count, int *eof, void *data){	int len = sprintf( page, "0x%08x", mfspr(MMCR1) );	return pmc_calc_metrics( page, start, off, count, eof, len );}int proc_pmc_get_mmcra(char *page, char **start, off_t off, int count, int *eof, void *data){	int len = sprintf( page, "0x%08x", mfspr(MMCRA) );	return pmc_calc_metrics( page, start, off, count, eof, len );}int proc_pmc_get_pmc1(char *page, char **start, off_t off, int count, int *eof, void *data){	int len = sprintf( page, "0x%08x", mfspr(PMC1) );	return pmc_calc_metrics( page, start, off, count, eof, len );}int proc_pmc_get_pmc2(char *page, char **start, off_t off, int count, int *eof, void *data){	int len = sprintf( page, "0x%08x", mfspr(PMC2) );	return pmc_calc_metrics( page, start, off, count, eof, len );}int proc_pmc_get_pmc3(char *page, char **start, off_t off, int count, int *eof, void *data){	int len = sprintf( page, "0x%08x", mfspr(PMC3) );	return pmc_calc_metrics( page, start, off, count, eof, len );}int proc_pmc_get_pmc4(char *page, char **start, off_t off, int count, int *eof, void *data){

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?