Commit | Line | Data |
---|---|---|
1da177e4 LT |
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 | #include <asm/pmc.h> | |
a6908cd0 | 19 | #include <asm/cputable.h> |
1da177e4 LT |
20 | |
21 | #include "op_impl.h" | |
22 | ||
23 | extern struct op_ppc64_model op_model_rs64; | |
24 | extern struct op_ppc64_model op_model_power4; | |
25 | static struct op_ppc64_model *model; | |
26 | ||
27 | static struct op_counter_config ctr[OP_MAX_COUNTER]; | |
28 | static struct op_system_config sys; | |
29 | ||
30 | static void op_handle_interrupt(struct pt_regs *regs) | |
31 | { | |
32 | model->handle_interrupt(regs, ctr); | |
33 | } | |
34 | ||
35 | static int op_ppc64_setup(void) | |
36 | { | |
37 | int err; | |
38 | ||
39 | /* Grab the hardware */ | |
40 | err = reserve_pmc_hardware(op_handle_interrupt); | |
41 | if (err) | |
42 | return err; | |
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 | release_pmc_hardware(); | |
56 | } | |
57 | ||
58 | static void op_ppc64_cpu_start(void *dummy) | |
59 | { | |
60 | model->start(ctr); | |
61 | } | |
62 | ||
63 | static int op_ppc64_start(void) | |
64 | { | |
65 | on_each_cpu(op_ppc64_cpu_start, NULL, 0, 1); | |
66 | return 0; | |
67 | } | |
68 | ||
69 | static inline void op_ppc64_cpu_stop(void *dummy) | |
70 | { | |
71 | model->stop(); | |
72 | } | |
73 | ||
74 | static void op_ppc64_stop(void) | |
75 | { | |
76 | on_each_cpu(op_ppc64_cpu_stop, NULL, 0, 1); | |
77 | } | |
78 | ||
79 | static int op_ppc64_create_files(struct super_block *sb, struct dentry *root) | |
80 | { | |
81 | int i; | |
82 | ||
83 | /* | |
84 | * There is one mmcr0, mmcr1 and mmcra for setting the events for | |
85 | * all of the counters. | |
86 | */ | |
87 | oprofilefs_create_ulong(sb, root, "mmcr0", &sys.mmcr0); | |
88 | oprofilefs_create_ulong(sb, root, "mmcr1", &sys.mmcr1); | |
89 | oprofilefs_create_ulong(sb, root, "mmcra", &sys.mmcra); | |
90 | ||
91 | for (i = 0; i < model->num_counters; ++i) { | |
92 | struct dentry *dir; | |
93 | char buf[3]; | |
94 | ||
95 | snprintf(buf, sizeof buf, "%d", i); | |
96 | dir = oprofilefs_mkdir(sb, root, buf); | |
97 | ||
98 | oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled); | |
99 | oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event); | |
100 | oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count); | |
101 | /* | |
102 | * We dont support per counter user/kernel selection, but | |
103 | * we leave the entries because userspace expects them | |
104 | */ | |
105 | oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel); | |
106 | oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user); | |
107 | oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask); | |
108 | } | |
109 | ||
110 | oprofilefs_create_ulong(sb, root, "enable_kernel", &sys.enable_kernel); | |
111 | oprofilefs_create_ulong(sb, root, "enable_user", &sys.enable_user); | |
112 | oprofilefs_create_ulong(sb, root, "backtrace_spinlocks", | |
113 | &sys.backtrace_spinlocks); | |
114 | ||
115 | /* Default to tracing both kernel and user */ | |
116 | sys.enable_kernel = 1; | |
117 | sys.enable_user = 1; | |
118 | ||
119 | /* Turn on backtracing through spinlocks by default */ | |
120 | sys.backtrace_spinlocks = 1; | |
121 | ||
122 | return 0; | |
123 | } | |
124 | ||
125 | int __init oprofile_arch_init(struct oprofile_operations *ops) | |
126 | { | |
127 | unsigned int pvr; | |
128 | ||
129 | pvr = mfspr(SPRN_PVR); | |
130 | ||
131 | switch (PVR_VER(pvr)) { | |
132 | case PV_630: | |
133 | case PV_630p: | |
134 | model = &op_model_rs64; | |
1da177e4 LT |
135 | break; |
136 | ||
137 | case PV_NORTHSTAR: | |
138 | case PV_PULSAR: | |
139 | case PV_ICESTAR: | |
140 | case PV_SSTAR: | |
141 | model = &op_model_rs64; | |
1da177e4 LT |
142 | break; |
143 | ||
144 | case PV_POWER4: | |
145 | case PV_POWER4p: | |
146 | model = &op_model_power4; | |
1da177e4 LT |
147 | break; |
148 | ||
149 | case PV_970: | |
150 | case PV_970FX: | |
04ed6519 | 151 | case PV_970MP: |
1da177e4 | 152 | model = &op_model_power4; |
1da177e4 LT |
153 | break; |
154 | ||
155 | case PV_POWER5: | |
156 | case PV_POWER5p: | |
157 | model = &op_model_power4; | |
1da177e4 LT |
158 | break; |
159 | ||
160 | default: | |
161 | return -ENODEV; | |
162 | } | |
163 | ||
1a410d88 | 164 | ops->cpu_type = cur_cpu_spec->oprofile_cpu_type; |
a6908cd0 | 165 | model->num_counters = cur_cpu_spec->num_pmcs; |
1da177e4 LT |
166 | ops->create_files = op_ppc64_create_files; |
167 | ops->setup = op_ppc64_setup; | |
168 | ops->shutdown = op_ppc64_shutdown; | |
169 | ops->start = op_ppc64_start; | |
170 | ops->stop = op_ppc64_stop; | |
171 | ||
172 | printk(KERN_INFO "oprofile: using %s performance monitoring.\n", | |
173 | ops->cpu_type); | |
174 | ||
175 | return 0; | |
176 | } | |
177 | ||
178 | void oprofile_arch_exit(void) | |
179 | { | |
180 | } |