GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / arch / powerpc / platforms / pseries / hvCall_inst.c
blobe19ff021e7111508580b5f6746d43d93e275fbf7
1 /*
2 * Copyright (C) 2006 Mike Kravetz IBM Corporation
4 * Hypervisor Call Instrumentation
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <linux/kernel.h>
22 #include <linux/percpu.h>
23 #include <linux/debugfs.h>
24 #include <linux/seq_file.h>
25 #include <linux/cpumask.h>
26 #include <asm/hvcall.h>
27 #include <asm/firmware.h>
28 #include <asm/cputable.h>
29 #include <asm/trace.h>
31 DEFINE_PER_CPU(struct hcall_stats[HCALL_STAT_ARRAY_SIZE], hcall_stats);
34 * Routines for displaying the statistics in debugfs
36 static void *hc_start(struct seq_file *m, loff_t *pos)
38 if ((int)*pos < (HCALL_STAT_ARRAY_SIZE-1))
39 return (void *)(unsigned long)(*pos + 1);
41 return NULL;
44 static void *hc_next(struct seq_file *m, void *p, loff_t * pos)
46 ++*pos;
48 return hc_start(m, pos);
51 static void hc_stop(struct seq_file *m, void *p)
55 static int hc_show(struct seq_file *m, void *p)
57 unsigned long h_num = (unsigned long)p;
58 struct hcall_stats *hs = (struct hcall_stats *)m->private;
60 if (hs[h_num].num_calls) {
61 if (cpu_has_feature(CPU_FTR_PURR))
62 seq_printf(m, "%lu %lu %lu %lu\n", h_num<<2,
63 hs[h_num].num_calls,
64 hs[h_num].tb_total,
65 hs[h_num].purr_total);
66 else
67 seq_printf(m, "%lu %lu %lu\n", h_num<<2,
68 hs[h_num].num_calls,
69 hs[h_num].tb_total);
72 return 0;
75 static const struct seq_operations hcall_inst_seq_ops = {
76 .start = hc_start,
77 .next = hc_next,
78 .stop = hc_stop,
79 .show = hc_show
82 static int hcall_inst_seq_open(struct inode *inode, struct file *file)
84 int rc;
85 struct seq_file *seq;
87 rc = seq_open(file, &hcall_inst_seq_ops);
88 seq = file->private_data;
89 seq->private = file->f_path.dentry->d_inode->i_private;
91 return rc;
94 static const struct file_operations hcall_inst_seq_fops = {
95 .open = hcall_inst_seq_open,
96 .read = seq_read,
97 .llseek = seq_lseek,
98 .release = seq_release,
101 #define HCALL_ROOT_DIR "hcall_inst"
102 #define CPU_NAME_BUF_SIZE 32
105 static void probe_hcall_entry(void *ignored, unsigned long opcode, unsigned long *args)
107 struct hcall_stats *h;
109 if (opcode > MAX_HCALL_OPCODE)
110 return;
112 h = &get_cpu_var(hcall_stats)[opcode / 4];
113 h->tb_start = mftb();
114 h->purr_start = mfspr(SPRN_PURR);
117 static void probe_hcall_exit(void *ignored, unsigned long opcode, unsigned long retval,
118 unsigned long *retbuf)
120 struct hcall_stats *h;
122 if (opcode > MAX_HCALL_OPCODE)
123 return;
125 h = &__get_cpu_var(hcall_stats)[opcode / 4];
126 h->num_calls++;
127 h->tb_total += mftb() - h->tb_start;
128 h->purr_total += mfspr(SPRN_PURR) - h->purr_start;
130 put_cpu_var(hcall_stats);
133 static int __init hcall_inst_init(void)
135 struct dentry *hcall_root;
136 struct dentry *hcall_file;
137 char cpu_name_buf[CPU_NAME_BUF_SIZE];
138 int cpu;
140 if (!firmware_has_feature(FW_FEATURE_LPAR))
141 return 0;
143 if (register_trace_hcall_entry(probe_hcall_entry, NULL))
144 return -EINVAL;
146 if (register_trace_hcall_exit(probe_hcall_exit, NULL)) {
147 unregister_trace_hcall_entry(probe_hcall_entry, NULL);
148 return -EINVAL;
151 hcall_root = debugfs_create_dir(HCALL_ROOT_DIR, NULL);
152 if (!hcall_root)
153 return -ENOMEM;
155 for_each_possible_cpu(cpu) {
156 snprintf(cpu_name_buf, CPU_NAME_BUF_SIZE, "cpu%d", cpu);
157 hcall_file = debugfs_create_file(cpu_name_buf, S_IRUGO,
158 hcall_root,
159 per_cpu(hcall_stats, cpu),
160 &hcall_inst_seq_fops);
161 if (!hcall_file)
162 return -ENOMEM;
165 return 0;
167 __initcall(hcall_inst_init);