1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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>
30#include <asm/machdep.h>
31
32
33struct hcall_stats {
34 unsigned long num_calls;
35 unsigned long tb_total;
36 unsigned long purr_total;
37 unsigned long tb_start;
38 unsigned long purr_start;
39};
40#define HCALL_STAT_ARRAY_SIZE ((MAX_HCALL_OPCODE >> 2) + 1)
41
42DEFINE_PER_CPU(struct hcall_stats[HCALL_STAT_ARRAY_SIZE], hcall_stats);
43
44
45
46
47static void *hc_start(struct seq_file *m, loff_t *pos)
48{
49 if ((int)*pos < (HCALL_STAT_ARRAY_SIZE-1))
50 return (void *)(unsigned long)(*pos + 1);
51
52 return NULL;
53}
54
55static void *hc_next(struct seq_file *m, void *p, loff_t * pos)
56{
57 ++*pos;
58
59 return hc_start(m, pos);
60}
61
62static void hc_stop(struct seq_file *m, void *p)
63{
64}
65
66static int hc_show(struct seq_file *m, void *p)
67{
68 unsigned long h_num = (unsigned long)p;
69 struct hcall_stats *hs = m->private;
70
71 if (hs[h_num].num_calls) {
72 if (cpu_has_feature(CPU_FTR_PURR))
73 seq_printf(m, "%lu %lu %lu %lu\n", h_num<<2,
74 hs[h_num].num_calls,
75 hs[h_num].tb_total,
76 hs[h_num].purr_total);
77 else
78 seq_printf(m, "%lu %lu %lu\n", h_num<<2,
79 hs[h_num].num_calls,
80 hs[h_num].tb_total);
81 }
82
83 return 0;
84}
85
86static const struct seq_operations hcall_inst_seq_ops = {
87 .start = hc_start,
88 .next = hc_next,
89 .stop = hc_stop,
90 .show = hc_show
91};
92
93static int hcall_inst_seq_open(struct inode *inode, struct file *file)
94{
95 int rc;
96 struct seq_file *seq;
97
98 rc = seq_open(file, &hcall_inst_seq_ops);
99 seq = file->private_data;
100 seq->private = file_inode(file)->i_private;
101
102 return rc;
103}
104
105static const struct file_operations hcall_inst_seq_fops = {
106 .open = hcall_inst_seq_open,
107 .read = seq_read,
108 .llseek = seq_lseek,
109 .release = seq_release,
110};
111
112#define HCALL_ROOT_DIR "hcall_inst"
113#define CPU_NAME_BUF_SIZE 32
114
115
116static void probe_hcall_entry(void *ignored, unsigned long opcode, unsigned long *args)
117{
118 struct hcall_stats *h;
119
120 if (opcode > MAX_HCALL_OPCODE)
121 return;
122
123 h = this_cpu_ptr(&hcall_stats[opcode / 4]);
124 h->tb_start = mftb();
125 h->purr_start = mfspr(SPRN_PURR);
126}
127
128static void probe_hcall_exit(void *ignored, unsigned long opcode, unsigned long retval,
129 unsigned long *retbuf)
130{
131 struct hcall_stats *h;
132
133 if (opcode > MAX_HCALL_OPCODE)
134 return;
135
136 h = this_cpu_ptr(&hcall_stats[opcode / 4]);
137 h->num_calls++;
138 h->tb_total += mftb() - h->tb_start;
139 h->purr_total += mfspr(SPRN_PURR) - h->purr_start;
140}
141
142static int __init hcall_inst_init(void)
143{
144 struct dentry *hcall_root;
145 struct dentry *hcall_file;
146 char cpu_name_buf[CPU_NAME_BUF_SIZE];
147 int cpu;
148
149 if (!firmware_has_feature(FW_FEATURE_LPAR))
150 return 0;
151
152 if (register_trace_hcall_entry(probe_hcall_entry, NULL))
153 return -EINVAL;
154
155 if (register_trace_hcall_exit(probe_hcall_exit, NULL)) {
156 unregister_trace_hcall_entry(probe_hcall_entry, NULL);
157 return -EINVAL;
158 }
159
160 hcall_root = debugfs_create_dir(HCALL_ROOT_DIR, NULL);
161 if (!hcall_root)
162 return -ENOMEM;
163
164 for_each_possible_cpu(cpu) {
165 snprintf(cpu_name_buf, CPU_NAME_BUF_SIZE, "cpu%d", cpu);
166 hcall_file = debugfs_create_file(cpu_name_buf, 0444,
167 hcall_root,
168 per_cpu(hcall_stats, cpu),
169 &hcall_inst_seq_fops);
170 if (!hcall_file)
171 return -ENOMEM;
172 }
173
174 return 0;
175}
176machine_device_initcall(pseries, hcall_inst_init);
177