2 * PowerPC hash table management proc entry. Will show information
3 * about the current hash table and will allow changes to it.
5 * Written by Cort Dougan (cort@cs.nmt.edu)
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
13 #include <linux/errno.h>
14 #include <linux/sched.h>
15 #include <linux/proc_fs.h>
16 #include <linux/stat.h>
17 #include <linux/sysctl.h>
18 #include <linux/capability.h>
19 #include <linux/ctype.h>
20 #include <linux/threads.h>
21 #include <linux/seq_file.h>
22 #include <linux/init.h>
23 #include <linux/bitops.h>
25 #include <asm/uaccess.h>
27 #include <asm/residual.h>
29 #include <asm/pgtable.h>
30 #include <asm/cputable.h>
31 #include <asm/system.h>
34 static int ppc_htab_show(struct seq_file *m, void *v);
35 static ssize_t ppc_htab_write(struct file * file, const char __user * buffer,
36 size_t count, loff_t *ppos);
37 extern PTE *Hash, *Hash_end;
38 extern unsigned long Hash_size, Hash_mask;
39 extern unsigned long _SDR1;
40 extern unsigned long htab_reloads;
41 extern unsigned long htab_preloads;
42 extern unsigned long htab_evicts;
43 extern unsigned long pte_misses;
44 extern unsigned long pte_errors;
45 extern unsigned int primary_pteg_full;
46 extern unsigned int htab_hash_searches;
48 static int ppc_htab_open(struct inode *inode, struct file *file)
50 return single_open(file, ppc_htab_show, NULL);
53 const struct file_operations ppc_htab_operations = {
54 .open = ppc_htab_open,
57 .write = ppc_htab_write,
58 .release = single_release,
61 static char *pmc1_lookup(unsigned long mmcr0)
63 switch ( mmcr0 & (0x7f<<7) )
67 case MMCR0_PMC1_CYCLES:
69 case MMCR0_PMC1_ICACHEMISS:
78 static char *pmc2_lookup(unsigned long mmcr0)
80 switch ( mmcr0 & 0x3f )
84 case MMCR0_PMC2_CYCLES:
86 case MMCR0_PMC2_DCACHEMISS:
90 case MMCR0_PMC2_LOADMISSTIME:
91 return "load miss time";
98 * print some useful info about the hash table. This function
99 * is _REALLY_ slow (see the nested for loops below) but nothing
100 * in here should be really timing critical. -- Cort
102 static int ppc_htab_show(struct seq_file *m, void *v)
104 unsigned long mmcr0 = 0, pmc1 = 0, pmc2 = 0;
105 #if defined(CONFIG_PPC_STD_MMU)
106 unsigned int kptes = 0, uptes = 0;
108 #endif /* CONFIG_PPC_STD_MMU */
110 if (cpu_has_feature(CPU_FTR_604_PERF_MON)) {
111 mmcr0 = mfspr(SPRN_MMCR0);
112 pmc1 = mfspr(SPRN_PMC1);
113 pmc2 = mfspr(SPRN_PMC2);
115 "604 Performance Monitoring\n"
116 "MMCR0\t\t: %08lx %s%s ",
118 ( mmcr0>>28 & 0x2 ) ? "(user mode counted)" : "",
119 ( mmcr0>>28 & 0x4 ) ? "(kernel mode counted)" : "");
121 "\nPMC1\t\t: %08lx (%s)\n"
122 "PMC2\t\t: %08lx (%s)\n",
123 pmc1, pmc1_lookup(mmcr0),
124 pmc2, pmc2_lookup(mmcr0));
127 #ifdef CONFIG_PPC_STD_MMU
128 /* if we don't have a htab */
129 if ( Hash_size == 0 ) {
130 seq_printf(m, "No Hash Table used\n");
134 for (ptr = Hash; ptr < Hash_end; ptr++) {
135 unsigned int mctx, vsid;
139 /* undo the esid skew */
141 mctx = ((vsid - (vsid & 0xf) * 0x111) >> 4) & 0xfffff;
149 "PTE Hash Table Information\n"
152 "Address\t\t: %08lx\n"
155 "Kernel ptes\t: %u\n"
156 "Percent full\t: %lu%%\n"
157 , (unsigned long)(Hash_size>>10),
158 (Hash_size/(sizeof(PTE)*8)),
160 Hash_size/sizeof(PTE)
163 ((kptes+uptes)*100) / (Hash_size/sizeof(PTE))
172 htab_reloads, htab_preloads, htab_hash_searches,
173 primary_pteg_full, htab_evicts);
174 #endif /* CONFIG_PPC_STD_MMU */
177 "Non-error misses: %lu\n"
178 "Error misses\t: %lu\n",
179 pte_misses, pte_errors);
184 * Allow user to define performance counters and resize the hash table
186 static ssize_t ppc_htab_write(struct file * file, const char __user * ubuffer,
187 size_t count, loff_t *ppos)
189 #ifdef CONFIG_PPC_STD_MMU
193 if (!capable(CAP_SYS_ADMIN))
195 if (strncpy_from_user(buffer, ubuffer, 15))
199 /* don't set the htab size for now */
200 if ( !strncmp( buffer, "size ", 5) )
203 if ( !strncmp( buffer, "reset", 5) )
205 if (cpu_has_feature(CPU_FTR_604_PERF_MON)) {
206 /* reset PMC1 and PMC2 */
216 /* Everything below here requires the performance monitor feature. */
217 if (!cpu_has_feature(CPU_FTR_604_PERF_MON))
220 /* turn off performance monitoring */
221 if ( !strncmp( buffer, "off", 3) )
223 mtspr(SPRN_MMCR0, 0);
228 if ( !strncmp( buffer, "user", 4) )
230 /* setup mmcr0 and clear the correct pmc */
231 tmp = (mfspr(SPRN_MMCR0) & ~(0x60000000)) | 0x20000000;
232 mtspr(SPRN_MMCR0, tmp);
237 if ( !strncmp( buffer, "kernel", 6) )
239 /* setup mmcr0 and clear the correct pmc */
240 tmp = (mfspr(SPRN_MMCR0) & ~(0x60000000)) | 0x40000000;
241 mtspr(SPRN_MMCR0, tmp);
247 if ( !strncmp( buffer, "dtlb", 4) )
249 /* setup mmcr0 and clear the correct pmc */
250 tmp = (mfspr(SPRN_MMCR0) & ~(0x7F << 7)) | MMCR0_PMC1_DTLB;
251 mtspr(SPRN_MMCR0, tmp);
255 if ( !strncmp( buffer, "ic miss", 7) )
257 /* setup mmcr0 and clear the correct pmc */
258 tmp = (mfspr(SPRN_MMCR0) & ~(0x7F<<7)) | MMCR0_PMC1_ICACHEMISS;
259 mtspr(SPRN_MMCR0, tmp);
264 if ( !strncmp( buffer, "load miss time", 14) )
266 /* setup mmcr0 and clear the correct pmc */
268 "mfspr %0,%1\n\t" /* get current mccr0 */
269 "rlwinm %0,%0,0,0,31-6\n\t" /* clear bits [26-31] */
270 "ori %0,%0,%2 \n\t" /* or in mmcr0 settings */
271 "mtspr %1,%0 \n\t" /* set new mccr0 */
272 "mtspr %3,%4 \n\t" /* reset the pmc */
275 "i" (MMCR0_PMC2_LOADMISSTIME),
276 "i" (SPRN_PMC2), "r" (0) );
279 if ( !strncmp( buffer, "itlb", 4) )
281 /* setup mmcr0 and clear the correct pmc */
283 "mfspr %0,%1\n\t" /* get current mccr0 */
284 "rlwinm %0,%0,0,0,31-6\n\t" /* clear bits [26-31] */
285 "ori %0,%0,%2 \n\t" /* or in mmcr0 settings */
286 "mtspr %1,%0 \n\t" /* set new mccr0 */
287 "mtspr %3,%4 \n\t" /* reset the pmc */
289 : "i" (SPRN_MMCR0), "i" (MMCR0_PMC2_ITLB),
290 "i" (SPRN_PMC2), "r" (0) );
293 if ( !strncmp( buffer, "dc miss", 7) )
295 /* setup mmcr0 and clear the correct pmc */
297 "mfspr %0,%1\n\t" /* get current mccr0 */
298 "rlwinm %0,%0,0,0,31-6\n\t" /* clear bits [26-31] */
299 "ori %0,%0,%2 \n\t" /* or in mmcr0 settings */
300 "mtspr %1,%0 \n\t" /* set new mccr0 */
301 "mtspr %3,%4 \n\t" /* reset the pmc */
303 : "i" (SPRN_MMCR0), "i" (MMCR0_PMC2_DCACHEMISS),
304 "i" (SPRN_PMC2), "r" (0) );
308 #else /* CONFIG_PPC_STD_MMU */
310 #endif /* CONFIG_PPC_STD_MMU */
313 int proc_dol2crvec(ctl_table *table, int write, struct file *filp,
314 void __user *buffer_arg, size_t *lenp, loff_t *ppos)
316 int vleft, first=1, len, left, val;
317 char __user *buffer = (char __user *) buffer_arg;
318 #define TMPBUFLEN 256
319 char buf[TMPBUFLEN], *p;
320 static const char *sizestrings[4] = {
321 "2MB", "256KB", "512KB", "1MB"
323 static const char *clockstrings[8] = {
324 "clock disabled", "+1 clock", "+1.5 clock", "reserved(3)",
325 "+2 clock", "+2.5 clock", "+3 clock", "reserved(7)"
327 static const char *typestrings[4] = {
328 "flow-through burst SRAM", "reserved SRAM",
329 "pipelined burst SRAM", "pipelined late-write SRAM"
331 static const char *holdstrings[4] = {
332 "0.5", "1.0", "(reserved2)", "(reserved3)"
335 if (!cpu_has_feature(CPU_FTR_L2CR))
338 if ( /*!table->maxlen ||*/ (*ppos && !write)) {
343 vleft = table->maxlen / sizeof(int);
346 for (; left /*&& vleft--*/; first=0) {
350 if(get_user(c, buffer))
360 if (len > TMPBUFLEN-1)
362 if(copy_from_user(buf, buffer, len))
366 if (*p < '0' || *p > '9')
368 val = simple_strtoul(p, &p, 0);
370 if ((len < left) && *p && !isspace(*p))
380 p += sprintf(p, "0x%08x: ", val);
381 p += sprintf(p, " %s", (val >> 31) & 1 ? "enabled" :
383 p += sprintf(p, ", %sparity", (val>>30)&1 ? "" : "no ");
384 p += sprintf(p, ", %s", sizestrings[(val >> 28) & 3]);
385 p += sprintf(p, ", %s", clockstrings[(val >> 25) & 7]);
386 p += sprintf(p, ", %s", typestrings[(val >> 23) & 2]);
387 p += sprintf(p, "%s", (val>>22)&1 ? ", data only" : "");
388 p += sprintf(p, "%s", (val>>20)&1 ? ", ZZ enabled": "");
389 p += sprintf(p, ", %s", (val>>19)&1 ? "write-through" :
391 p += sprintf(p, "%s", (val>>18)&1 ? ", testing" : "");
392 p += sprintf(p, ", %sns hold",holdstrings[(val>>16)&3]);
393 p += sprintf(p, "%s", (val>>15)&1 ? ", DLL slow" : "");
394 p += sprintf(p, "%s", (val>>14)&1 ? ", diff clock" :"");
395 p += sprintf(p, "%s", (val>>13)&1 ? ", DLL bypass" :"");
397 p += sprintf(p,"\n");
402 if (copy_to_user(buffer, buf, len))
410 if (!write && !first && left) {
411 if(put_user('\n', (char __user *) buffer))
416 char __user *s = (char __user *) buffer;
435 * Register our sysctl.
437 static ctl_table htab_ctl_table[]={
439 .ctl_name = KERN_PPC_L2CR,
442 .proc_handler = &proc_dol2crvec,
446 static ctl_table htab_sysctl_root[] = {
448 .ctl_name = CTL_KERN,
449 .procname = "kernel",
451 .child = htab_ctl_table,
457 register_ppc_htab_sysctl(void)
459 register_sysctl_table(htab_sysctl_root);
464 __initcall(register_ppc_htab_sysctl);