]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - arch/powerpc/platforms/pseries/hvCall_inst.c
new helper: file_inode(file)
[mirror_ubuntu-artful-kernel.git] / arch / powerpc / platforms / pseries / hvCall_inst.c
CommitLineData
57852a85
MK
1/*
2 * Copyright (C) 2006 Mike Kravetz IBM Corporation
3 *
4 * Hypervisor Call Instrumentation
5 *
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.
10 *
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.
15 *
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
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>
c8cd093a 29#include <asm/trace.h>
57852a85
MK
30
31DEFINE_PER_CPU(struct hcall_stats[HCALL_STAT_ARRAY_SIZE], hcall_stats);
32
33/*
34 * Routines for displaying the statistics in debugfs
35 */
36static void *hc_start(struct seq_file *m, loff_t *pos)
37{
dc40127c 38 if ((int)*pos < (HCALL_STAT_ARRAY_SIZE-1))
57852a85
MK
39 return (void *)(unsigned long)(*pos + 1);
40
41 return NULL;
42}
43
44static void *hc_next(struct seq_file *m, void *p, loff_t * pos)
45{
46 ++*pos;
47
48 return hc_start(m, pos);
49}
50
51static void hc_stop(struct seq_file *m, void *p)
52{
53}
54
55static int hc_show(struct seq_file *m, void *p)
56{
57 unsigned long h_num = (unsigned long)p;
6d2ad1e3 58 struct hcall_stats *hs = m->private;
57852a85
MK
59
60 if (hs[h_num].num_calls) {
dc40127c 61 if (cpu_has_feature(CPU_FTR_PURR))
57852a85
MK
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);
70 }
71
72 return 0;
73}
74
88e9d34c 75static const struct seq_operations hcall_inst_seq_ops = {
57852a85
MK
76 .start = hc_start,
77 .next = hc_next,
78 .stop = hc_stop,
79 .show = hc_show
80};
81
82static int hcall_inst_seq_open(struct inode *inode, struct file *file)
83{
84 int rc;
85 struct seq_file *seq;
86
87 rc = seq_open(file, &hcall_inst_seq_ops);
88 seq = file->private_data;
496ad9aa 89 seq->private = file_inode(file)->i_private;
57852a85
MK
90
91 return rc;
92}
93
5dfe4c96 94static const struct file_operations hcall_inst_seq_fops = {
57852a85
MK
95 .open = hcall_inst_seq_open,
96 .read = seq_read,
97 .llseek = seq_lseek,
98 .release = seq_release,
99};
100
101#define HCALL_ROOT_DIR "hcall_inst"
102#define CPU_NAME_BUF_SIZE 32
103
c8cd093a 104
969ea5c5 105static void probe_hcall_entry(void *ignored, unsigned long opcode, unsigned long *args)
c8cd093a
AB
106{
107 struct hcall_stats *h;
108
109 if (opcode > MAX_HCALL_OPCODE)
110 return;
111
e4f387d8 112 h = &__get_cpu_var(hcall_stats)[opcode / 4];
c8cd093a
AB
113 h->tb_start = mftb();
114 h->purr_start = mfspr(SPRN_PURR);
115}
116
969ea5c5 117static void probe_hcall_exit(void *ignored, unsigned long opcode, unsigned long retval,
6f26353c 118 unsigned long *retbuf)
c8cd093a
AB
119{
120 struct hcall_stats *h;
121
122 if (opcode > MAX_HCALL_OPCODE)
123 return;
124
125 h = &__get_cpu_var(hcall_stats)[opcode / 4];
126 h->num_calls++;
25ef231d
WS
127 h->tb_total += mftb() - h->tb_start;
128 h->purr_total += mfspr(SPRN_PURR) - h->purr_start;
c8cd093a
AB
129}
130
57852a85
MK
131static int __init hcall_inst_init(void)
132{
133 struct dentry *hcall_root;
134 struct dentry *hcall_file;
135 char cpu_name_buf[CPU_NAME_BUF_SIZE];
136 int cpu;
137
138 if (!firmware_has_feature(FW_FEATURE_LPAR))
139 return 0;
140
969ea5c5 141 if (register_trace_hcall_entry(probe_hcall_entry, NULL))
c8cd093a
AB
142 return -EINVAL;
143
969ea5c5
SR
144 if (register_trace_hcall_exit(probe_hcall_exit, NULL)) {
145 unregister_trace_hcall_entry(probe_hcall_entry, NULL);
c8cd093a
AB
146 return -EINVAL;
147 }
148
57852a85
MK
149 hcall_root = debugfs_create_dir(HCALL_ROOT_DIR, NULL);
150 if (!hcall_root)
151 return -ENOMEM;
152
153 for_each_possible_cpu(cpu) {
154 snprintf(cpu_name_buf, CPU_NAME_BUF_SIZE, "cpu%d", cpu);
155 hcall_file = debugfs_create_file(cpu_name_buf, S_IRUGO,
156 hcall_root,
157 per_cpu(hcall_stats, cpu),
158 &hcall_inst_seq_fops);
159 if (!hcall_file)
160 return -ENOMEM;
161 }
162
163 return 0;
164}
165__initcall(hcall_inst_init);