ppc_htab.c

来自「linux-2.4.29操作系统的源码」· C语言 代码 · 共 702 行 · 第 1/2 页

C
702
字号
/* * PowerPC hash table management proc entry.  Will show information * about the current hash table and will allow changes to it. * * Written by Cort Dougan (cort@cs.nmt.edu) * * 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. */#include <linux/config.h>#include <linux/errno.h>#include <linux/sched.h>#include <linux/proc_fs.h>#include <linux/stat.h>#include <linux/sysctl.h>#include <linux/ctype.h>#include <linux/threads.h>#include <asm/uaccess.h>#include <asm/bitops.h>#include <asm/mmu.h>#include <asm/processor.h>#include <asm/residual.h>#include <asm/io.h>#include <asm/pgtable.h>#include <asm/cputable.h>#include <asm/system.h>static ssize_t ppc_htab_read(struct file * file, char * buf,			     size_t count, loff_t *ppos);static ssize_t ppc_htab_write(struct file * file, const char * buffer,			      size_t count, loff_t *ppos);static long long ppc_htab_lseek(struct file * file, loff_t offset, int orig);int proc_dol2crvec(ctl_table *table, int write, struct file *filp,		  void *buffer, size_t *lenp);extern PTE *Hash, *Hash_end;extern unsigned long Hash_size, Hash_mask;extern unsigned long _SDR1;extern unsigned long htab_reloads;extern unsigned long htab_preloads;extern unsigned long htab_evicts;extern unsigned long pte_misses;extern unsigned long pte_errors;extern unsigned int primary_pteg_full;extern unsigned int htab_hash_searches;/* these will go into processor.h when I'm done debugging -- Cort */#define MMCR0 952#define MMCR0_PMC1_CYCLES (0x1<<7)#define MMCR0_PMC1_ICACHEMISS (0x5<<7)#define MMCR0_PMC1_DTLB (0x6<<7)#define MMCR0_PMC2_DCACHEMISS (0x6)#define MMCR0_PMC2_CYCLES (0x1)#define MMCR0_PMC2_ITLB (0x7)#define MMCR0_PMC2_LOADMISSTIME (0x5)#define PMC1 953#define PMC2 954struct file_operations ppc_htab_operations = {        llseek:         ppc_htab_lseek,        read:           ppc_htab_read,        write:          ppc_htab_write,};static char *pmc1_lookup(unsigned long mmcr0){	switch ( mmcr0 & (0x7f<<7) )	{	case 0x0:		return "none";	case MMCR0_PMC1_CYCLES:		return "cycles";	case MMCR0_PMC1_ICACHEMISS:		return "ic miss";	case MMCR0_PMC1_DTLB:		return "dtlb miss";	default:		return "unknown";	}}static char *pmc2_lookup(unsigned long mmcr0){	switch ( mmcr0 & 0x3f )	{	case 0x0:		return "none";	case MMCR0_PMC2_CYCLES:		return "cycles";	case MMCR0_PMC2_DCACHEMISS:		return "dc miss";	case MMCR0_PMC2_ITLB:		return "itlb miss";	case MMCR0_PMC2_LOADMISSTIME:		return "load miss time";	default:		return "unknown";	}}/* * print some useful info about the hash table.  This function * is _REALLY_ slow (see the nested for loops below) but nothing * in here should be really timing critical. -- Cort */static ssize_t ppc_htab_read(struct file * file, char * buf,			     size_t count, loff_t *ppos){	unsigned long mmcr0 = 0, pmc1 = 0, pmc2 = 0;	loff_t pos = *ppos;	int n = 0;#if defined(CONFIG_PPC_STD_MMU) && !defined(CONFIG_PPC64BRIDGE)	int valid;	unsigned int kptes = 0, uptes = 0, zombie_ptes = 0;	PTE *ptr;	struct task_struct *p;#endif /* CONFIG_PPC_STD_MMU */	char buffer[512];	if (count < 0)		return -EINVAL;	if (cur_cpu_spec[0]->cpu_features & CPU_FTR_604_PERF_MON) {		asm volatile ("mfspr %0,952 \n\t"		    "mfspr %1,953 \n\t"		    "mfspr %2,954 \n\t"		    : "=r" (mmcr0), "=r" (pmc1), "=r" (pmc2) );		n += sprintf( buffer + n,			      "604 Performance Monitoring\n"			      "MMCR0\t\t: %08lx %s%s ",			      mmcr0,			      ( mmcr0>>28 & 0x2 ) ? "(user mode counted)" : "",			      ( mmcr0>>28 & 0x4 ) ? "(kernel mode counted)" : "");		n += sprintf( buffer + n,			      "\nPMC1\t\t: %08lx (%s)\n"			      "PMC2\t\t: %08lx (%s)\n",			      pmc1, pmc1_lookup(mmcr0),			      pmc2, pmc2_lookup(mmcr0));	}#ifdef CONFIG_PPC_STD_MMU	/* if we don't have a htab */	if ( Hash_size == 0 )	{		n += sprintf( buffer + n, "No Hash Table used\n");		goto return_string;	}#ifndef CONFIG_PPC64BRIDGE	for ( ptr = Hash ; ptr < Hash_end ; ptr++)	{		unsigned int ctx, mctx, vsid;		if (!ptr->v)			continue;		/* make sure someone is using this context/vsid */		/* first undo the esid skew */		vsid = ptr->vsid;		mctx = ((vsid - (vsid & 0xf) * 0x111) >> 4) & 0xfffff;		if (mctx == 0) {			kptes++;			continue;		}		/* now undo the context skew; 801921 * 897 == 1 mod 2^20 */		ctx = (mctx * 801921) & 0xfffff;		valid = 0;		for_each_task(p) {			if (p->mm != NULL && ctx == p->mm->context) {				valid = 1;				uptes++;				break;			}		}		if (!valid)			zombie_ptes++;	}#endif	n += sprintf( buffer + n,		      "PTE Hash Table Information\n"		      "Size\t\t: %luKb\n"		      "Buckets\t\t: %lu\n" 		      "Address\t\t: %08lx\n"		      "Entries\t\t: %lu\n"#ifndef CONFIG_PPC64BRIDGE		      "User ptes\t: %u\n"		      "Kernel ptes\t: %u\n"		      "Zombies\t\t: %u\n"		      "Percent full\t: %lu%%\n"#endif                      , (unsigned long)(Hash_size>>10),		      (Hash_size/(sizeof(PTE)*8)),		      (unsigned long)Hash,		      Hash_size/sizeof(PTE)#ifndef CONFIG_PPC64BRIDGE                      , uptes,		      kptes,		      zombie_ptes,		      ((kptes+uptes)*100) / (Hash_size/sizeof(PTE))#endif		);	n += sprintf( buffer + n,		      "Reloads\t\t: %lu\n"		      "Preloads\t: %lu\n"		      "Searches\t: %u\n"		      "Overflows\t: %u\n"		      "Evicts\t\t: %lu\n",		      htab_reloads, htab_preloads, htab_hash_searches,		      primary_pteg_full, htab_evicts);return_string:#endif /* CONFIG_PPC_STD_MMU */	n += sprintf( buffer + n,		      "Non-error misses: %lu\n"		      "Error misses\t: %lu\n",		      pte_misses, pte_errors);	if (pos != (unsigned)pos || pos >= strlen(buffer))		return 0;	if (n > strlen(buffer) - pos)		n = strlen(buffer) - pos;	if (n > count)		n = count;	copy_to_user(buf, buffer + pos, n);	*ppos = pos + n;	return n;}/* * Allow user to define performance counters and resize the hash table */static ssize_t ppc_htab_write(struct file * file, const char * buffer,			      size_t count, loff_t *ppos){#ifdef CONFIG_PPC_STD_MMU	unsigned long tmp;	if ( current->uid != 0 )		return -EACCES;	/* don't set the htab size for now */	if ( !strncmp( buffer, "size ", 5) )		return -EBUSY;	/* turn off performance monitoring */	if ( !strncmp( buffer, "off", 3) )	{		if (cur_cpu_spec[0]->cpu_features & CPU_FTR_604_PERF_MON) {			asm volatile ("mtspr %0, %3 \n\t"			    "mtspr %1, %3 \n\t"			    "mtspr %2, %3 \n\t"			    :: "i" (MMCR0), "i" (PMC1), "i" (PMC2), "r" (0));		}	}	if ( !strncmp( buffer, "reset", 5) )	{		if (cur_cpu_spec[0]->cpu_features & CPU_FTR_604_PERF_MON) {			/* reset PMC1 and PMC2 */			asm volatile (				"mtspr 953, %0 \n\t"				"mtspr 954, %0 \n\t"				:: "r" (0));		}		htab_reloads = 0;		htab_evicts = 0;		pte_misses = 0;		pte_errors = 0;	}	if ( !strncmp( buffer, "user", 4) )	{		if (cur_cpu_spec[0]->cpu_features & CPU_FTR_604_PERF_MON) {			/* setup mmcr0 and clear the correct pmc */			asm("mfspr %0,%1\n\t"  : "=r" (tmp) : "i" (MMCR0));			tmp &= ~(0x60000000);			tmp |= 0x20000000;			asm volatile (				"mtspr %1,%0 \n\t"    /* set new mccr0 */				"mtspr %3,%4 \n\t"    /* reset the pmc */				"mtspr %5,%4 \n\t"    /* reset the pmc2 */				:: "r" (tmp), "i" (MMCR0), "i" (0),				"i" (PMC1),  "r" (0), "i"(PMC2) );		}	}	if ( !strncmp( buffer, "kernel", 6) )	{		if (cur_cpu_spec[0]->cpu_features & CPU_FTR_604_PERF_MON) {			/* setup mmcr0 and clear the correct pmc */			asm("mfspr %0,%1\n\t"  : "=r" (tmp) : "i" (MMCR0));			tmp &= ~(0x60000000);			tmp |= 0x40000000;			asm volatile (				"mtspr %1,%0 \n\t"    /* set new mccr0 */				"mtspr %3,%4 \n\t"    /* reset the pmc */				"mtspr %5,%4 \n\t"    /* reset the pmc2 */				:: "r" (tmp), "i" (MMCR0), "i" (0),				"i" (PMC1),  "r" (0), "i"(PMC2) );		}	}	/* PMC1 values */	if ( !strncmp( buffer, "dtlb", 4) )	{		if (cur_cpu_spec[0]->cpu_features & CPU_FTR_604_PERF_MON) {			/* setup mmcr0 and clear the correct pmc */			asm("mfspr %0,%1\n\t"  : "=r" (tmp) : "i" (MMCR0));			tmp &= ~(0x7f<<7);			tmp |= MMCR0_PMC1_DTLB;			asm volatile (				"mtspr %1,%0 \n\t"    /* set new mccr0 */				"mtspr %3,%4 \n\t"    /* reset the pmc */				:: "r" (tmp), "i" (MMCR0), "i" (MMCR0_PMC1_DTLB),				"i" (PMC1),  "r" (0) );		}	}	if ( !strncmp( buffer, "ic miss", 7) )	{		if (cur_cpu_spec[0]->cpu_features & CPU_FTR_604_PERF_MON) {			/* setup mmcr0 and clear the correct pmc */			asm("mfspr %0,%1\n\t"  : "=r" (tmp) : "i" (MMCR0));			tmp &= ~(0x7f<<7);			tmp |= MMCR0_PMC1_ICACHEMISS;			asm volatile (				"mtspr %1,%0 \n\t"    /* set new mccr0 */				"mtspr %3,%4 \n\t"    /* reset the pmc */				:: "r" (tmp), "i" (MMCR0),				"i" (MMCR0_PMC1_ICACHEMISS), "i" (PMC1),  "r" (0));		}	}	/* PMC2 values */	if ( !strncmp( buffer, "load miss time", 14) )	{		if (cur_cpu_spec[0]->cpu_features & CPU_FTR_604_PERF_MON) {			/* setup mmcr0 and clear the correct pmc */		       asm volatile(			       "mfspr %0,%1\n\t"     /* get current mccr0 */			       "rlwinm %0,%0,0,0,31-6\n\t"  /* clear bits [26-31] */			       "ori   %0,%0,%2 \n\t" /* or in mmcr0 settings */			       "mtspr %1,%0 \n\t"    /* set new mccr0 */			       "mtspr %3,%4 \n\t"    /* reset the pmc */			       : "=r" (tmp)			       : "i" (MMCR0), "i" (MMCR0_PMC2_LOADMISSTIME),			       "i" (PMC2),  "r" (0) );		}

⌨️ 快捷键说明

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