vserver 1.9.5.x5
[linux-2.6.git] / arch / ppc64 / oprofile / common.c
1 /*
2  * Copyright (C) 2004 Anton Blanchard <anton@au.ibm.com>, IBM
3  *
4  * Based on alpha version.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version
9  * 2 of the License, or (at your option) any later version.
10  */
11
12 #include <linux/oprofile.h>
13 #include <linux/init.h>
14 #include <linux/smp.h>
15 #include <linux/errno.h>
16 #include <asm/ptrace.h>
17 #include <asm/system.h>
18
19 #include "op_impl.h"
20
21 extern struct op_ppc64_model op_model_rs64;
22 extern struct op_ppc64_model op_model_power4;
23 static struct op_ppc64_model *model;
24
25 extern void (*perf_irq)(struct pt_regs *);
26 static void (*save_perf_irq)(struct pt_regs *);
27
28 static struct op_counter_config ctr[OP_MAX_COUNTER];
29 static struct op_system_config sys;
30
31 static void op_handle_interrupt(struct pt_regs *regs)
32 {
33         model->handle_interrupt(regs, ctr);
34 }
35
36 static int op_ppc64_setup(void)
37 {
38         /* Install our interrupt handler into the existing hook.  */
39         save_perf_irq = perf_irq;
40         perf_irq = op_handle_interrupt;
41
42         mb();
43
44         /* Pre-compute the values to stuff in the hardware registers.  */
45         model->reg_setup(ctr, &sys, model->num_counters);
46
47         /* Configure the registers on all cpus.  */
48         on_each_cpu(model->cpu_setup, NULL, 0, 1);
49
50         return 0;
51 }
52
53 static void op_ppc64_shutdown(void)
54 {
55         mb();
56
57         /* Remove our interrupt handler. We may be removing this module. */
58         perf_irq = save_perf_irq;
59 }
60
61 static void op_ppc64_cpu_start(void *dummy)
62 {
63         model->start(ctr);
64 }
65
66 static int op_ppc64_start(void)
67 {
68         on_each_cpu(op_ppc64_cpu_start, NULL, 0, 1);
69         return 0;
70 }
71
72 static inline void op_ppc64_cpu_stop(void *dummy)
73 {
74         model->stop();
75 }
76
77 static void op_ppc64_stop(void)
78 {
79         on_each_cpu(op_ppc64_cpu_stop, NULL, 0, 1);
80 }
81
82 static int op_ppc64_create_files(struct super_block *sb, struct dentry *root)
83 {
84         int i;
85
86         /*
87          * There is one mmcr0, mmcr1 and mmcra for setting the events for
88          * all of the counters.
89          */
90         oprofilefs_create_ulong(sb, root, "mmcr0", &sys.mmcr0);
91         oprofilefs_create_ulong(sb, root, "mmcr1", &sys.mmcr1);
92         oprofilefs_create_ulong(sb, root, "mmcra", &sys.mmcra);
93
94         for (i = 0; i < model->num_counters; ++i) {
95                 struct dentry *dir;
96                 char buf[3];
97
98                 snprintf(buf, sizeof buf, "%d", i);
99                 dir = oprofilefs_mkdir(sb, root, buf);
100
101                 oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled);
102                 oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event);
103                 oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count);
104                 /*
105                  * We dont support per counter user/kernel selection, but
106                  * we leave the entries because userspace expects them
107                  */
108                 oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
109                 oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
110                 oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask);
111         }
112
113         oprofilefs_create_ulong(sb, root, "enable_kernel", &sys.enable_kernel);
114         oprofilefs_create_ulong(sb, root, "enable_user", &sys.enable_user);
115         oprofilefs_create_ulong(sb, root, "backtrace_spinlocks",
116                                 &sys.backtrace_spinlocks);
117
118         /* Default to tracing both kernel and user */
119         sys.enable_kernel = 1;
120         sys.enable_user = 1;
121
122         /* Turn on backtracing through spinlocks by default */
123         sys.backtrace_spinlocks = 1;
124
125         return 0;
126 }
127
128 int __init oprofile_arch_init(struct oprofile_operations *ops)
129 {
130         unsigned int pvr;
131
132         pvr = mfspr(SPRN_PVR);
133
134         switch (PVR_VER(pvr)) {
135                 case PV_630:
136                 case PV_630p:
137                         model = &op_model_rs64;
138                         model->num_counters = 8;
139                         ops->cpu_type = "ppc64/power3";
140                         break;
141
142                 case PV_NORTHSTAR:
143                 case PV_PULSAR:
144                 case PV_ICESTAR:
145                 case PV_SSTAR:
146                         model = &op_model_rs64;
147                         model->num_counters = 8;
148                         ops->cpu_type = "ppc64/rs64";
149                         break;
150
151                 case PV_POWER4:
152                 case PV_POWER4p:
153                         model = &op_model_power4;
154                         model->num_counters = 8;
155                         ops->cpu_type = "ppc64/power4";
156                         break;
157
158                 case PV_970:
159                 case PV_970FX:
160                         model = &op_model_power4;
161                         model->num_counters = 8;
162                         ops->cpu_type = "ppc64/970";
163                         break;
164
165                 case PV_POWER5:
166                 case PV_POWER5p:
167                         model = &op_model_power4;
168                         model->num_counters = 6;
169                         ops->cpu_type = "ppc64/power5";
170                         break;
171
172                 default:
173                         return -ENODEV;
174         }
175
176         ops->create_files = op_ppc64_create_files;
177         ops->setup = op_ppc64_setup;
178         ops->shutdown = op_ppc64_shutdown;
179         ops->start = op_ppc64_start;
180         ops->stop = op_ppc64_stop;
181
182         printk(KERN_INFO "oprofile: using %s performance monitoring.\n",
183                ops->cpu_type);
184
185         return 0;
186 }
187
188 void oprofile_arch_exit(void)
189 {
190 }