patch-2_6_7-vs1_9_1_12
[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         /*
56          * We need to be sure we have cleared all pending exceptions before
57          * removing the interrupt handler. For the moment we play it safe and
58          * leave it in
59          */
60 #if 0
61         mb();
62
63         /* Remove our interrupt handler. We may be removing this module. */
64         perf_irq = save_perf_irq;
65 #endif
66 }
67
68 static void op_ppc64_cpu_start(void *dummy)
69 {
70         model->start(ctr);
71 }
72
73 static int op_ppc64_start(void)
74 {
75         on_each_cpu(op_ppc64_cpu_start, NULL, 0, 1);
76         return 0;
77 }
78
79 static inline void op_ppc64_cpu_stop(void *dummy)
80 {
81         model->stop();
82 }
83
84 static void op_ppc64_stop(void)
85 {
86         on_each_cpu(op_ppc64_cpu_stop, NULL, 0, 1);
87 }
88
89 static int op_ppc64_create_files(struct super_block *sb, struct dentry *root)
90 {
91         int i;
92
93         for (i = 0; i < model->num_counters; ++i) {
94                 struct dentry *dir;
95                 char buf[3];
96
97                 snprintf(buf, sizeof buf, "%d", i);
98                 dir = oprofilefs_mkdir(sb, root, buf);
99
100                 oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled);
101                 oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event);
102                 oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count);
103                 /*
104                  * We dont support per counter user/kernel selection, but
105                  * we leave the entries because userspace expects them
106                  */
107                 oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
108                 oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
109                 oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask);
110         }
111
112         oprofilefs_create_ulong(sb, root, "enable_kernel", &sys.enable_kernel);
113         oprofilefs_create_ulong(sb, root, "enable_user", &sys.enable_user);
114
115         return 0;
116 }
117
118 static struct oprofile_operations oprof_ppc64_ops = {
119         .create_files   = op_ppc64_create_files,
120         .setup          = op_ppc64_setup,
121         .shutdown       = op_ppc64_shutdown,
122         .start          = op_ppc64_start,
123         .stop           = op_ppc64_stop,
124         .cpu_type       = NULL          /* To be filled in below. */
125 };
126
127 int __init oprofile_arch_init(struct oprofile_operations **ops)
128 {
129         unsigned int pvr;
130
131         pvr = _get_PVR();
132
133         switch (PVR_VER(pvr)) {
134                 case PV_630:
135                 case PV_630p:
136                         model = &op_model_rs64;
137                         model->num_counters = 8;
138                         oprof_ppc64_ops.cpu_type = "ppc64/power3";
139                         break;
140
141                 case PV_NORTHSTAR:
142                 case PV_PULSAR:
143                 case PV_ICESTAR:
144                 case PV_SSTAR:
145                         model = &op_model_rs64;
146                         model->num_counters = 8;
147                         oprof_ppc64_ops.cpu_type = "ppc64/rs64";
148                         break;
149
150                 case PV_POWER4:
151                 case PV_POWER4p:
152                         model = &op_model_power4;
153                         model->num_counters = 8;
154                         oprof_ppc64_ops.cpu_type = "ppc64/power4";
155                         break;
156
157                 case PV_GPUL:
158                 case PV_GPULp:
159                         model = &op_model_power4;
160                         model->num_counters = 8;
161                         oprof_ppc64_ops.cpu_type = "ppc64/970";
162                         break;
163
164                 case PV_POWER5:
165                 case PV_POWER5p:
166                         model = &op_model_power4;
167                         model->num_counters = 6;
168                         oprof_ppc64_ops.cpu_type = "ppc64/power5";
169                         break;
170
171                 default:
172                         return -ENODEV;
173         }
174
175         *ops = &oprof_ppc64_ops;
176
177         printk(KERN_INFO "oprofile: using %s performance monitoring.\n",
178                oprof_ppc64_ops.cpu_type);
179
180         return 0;
181 }
182
183 void oprofile_arch_exit(void)
184 {
185 }