blob: 3e8daabf10218ec6b2a4ea54a1441da3aa9543e2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Anton Blancharda6908cd2005-09-06 14:52:12 +100019#include <asm/cputable.h>
Anton Blancharddca85932005-09-06 14:55:35 +100020#include <asm/oprofile_impl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Linus Torvalds1da177e2005-04-16 15:20:36 -070022static struct op_ppc64_model *model;
23
24static struct op_counter_config ctr[OP_MAX_COUNTER];
25static struct op_system_config sys;
26
27static void op_handle_interrupt(struct pt_regs *regs)
28{
29 model->handle_interrupt(regs, ctr);
30}
31
32static int op_ppc64_setup(void)
33{
34 int err;
35
36 /* Grab the hardware */
37 err = reserve_pmc_hardware(op_handle_interrupt);
38 if (err)
39 return err;
40
41 /* Pre-compute the values to stuff in the hardware registers. */
42 model->reg_setup(ctr, &sys, model->num_counters);
43
44 /* Configure the registers on all cpus. */
45 on_each_cpu(model->cpu_setup, NULL, 0, 1);
46
47 return 0;
48}
49
50static void op_ppc64_shutdown(void)
51{
52 release_pmc_hardware();
53}
54
55static void op_ppc64_cpu_start(void *dummy)
56{
57 model->start(ctr);
58}
59
60static int op_ppc64_start(void)
61{
62 on_each_cpu(op_ppc64_cpu_start, NULL, 0, 1);
63 return 0;
64}
65
66static inline void op_ppc64_cpu_stop(void *dummy)
67{
68 model->stop();
69}
70
71static void op_ppc64_stop(void)
72{
73 on_each_cpu(op_ppc64_cpu_stop, NULL, 0, 1);
74}
75
76static int op_ppc64_create_files(struct super_block *sb, struct dentry *root)
77{
78 int i;
79
80 /*
81 * There is one mmcr0, mmcr1 and mmcra for setting the events for
82 * all of the counters.
83 */
84 oprofilefs_create_ulong(sb, root, "mmcr0", &sys.mmcr0);
85 oprofilefs_create_ulong(sb, root, "mmcr1", &sys.mmcr1);
86 oprofilefs_create_ulong(sb, root, "mmcra", &sys.mmcra);
87
88 for (i = 0; i < model->num_counters; ++i) {
89 struct dentry *dir;
90 char buf[3];
91
92 snprintf(buf, sizeof buf, "%d", i);
93 dir = oprofilefs_mkdir(sb, root, buf);
94
95 oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled);
96 oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event);
97 oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count);
98 /*
99 * We dont support per counter user/kernel selection, but
100 * we leave the entries because userspace expects them
101 */
102 oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
103 oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
104 oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask);
105 }
106
107 oprofilefs_create_ulong(sb, root, "enable_kernel", &sys.enable_kernel);
108 oprofilefs_create_ulong(sb, root, "enable_user", &sys.enable_user);
109 oprofilefs_create_ulong(sb, root, "backtrace_spinlocks",
110 &sys.backtrace_spinlocks);
111
112 /* Default to tracing both kernel and user */
113 sys.enable_kernel = 1;
114 sys.enable_user = 1;
115
116 /* Turn on backtracing through spinlocks by default */
117 sys.backtrace_spinlocks = 1;
118
119 return 0;
120}
121
122int __init oprofile_arch_init(struct oprofile_operations *ops)
123{
124 unsigned int pvr;
125
126 pvr = mfspr(SPRN_PVR);
127
128 switch (PVR_VER(pvr)) {
129 case PV_630:
130 case PV_630p:
131 model = &op_model_rs64;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 break;
133
134 case PV_NORTHSTAR:
135 case PV_PULSAR:
136 case PV_ICESTAR:
137 case PV_SSTAR:
138 model = &op_model_rs64;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 break;
140
141 case PV_POWER4:
142 case PV_POWER4p:
143 model = &op_model_power4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 break;
145
146 case PV_970:
147 case PV_970FX:
Jake Moilanen04ed6512005-08-24 15:22:12 -0500148 case PV_970MP:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 model = &op_model_power4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 break;
151
152 case PV_POWER5:
153 case PV_POWER5p:
154 model = &op_model_power4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 break;
156
157 default:
158 return -ENODEV;
159 }
160
Anton Blanchard1a410d82005-09-06 14:53:57 +1000161 ops->cpu_type = cur_cpu_spec->oprofile_cpu_type;
Anton Blancharda6908cd2005-09-06 14:52:12 +1000162 model->num_counters = cur_cpu_spec->num_pmcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 ops->create_files = op_ppc64_create_files;
164 ops->setup = op_ppc64_setup;
165 ops->shutdown = op_ppc64_shutdown;
166 ops->start = op_ppc64_start;
167 ops->stop = op_ppc64_stop;
168
169 printk(KERN_INFO "oprofile: using %s performance monitoring.\n",
170 ops->cpu_type);
171
172 return 0;
173}
174
175void oprofile_arch_exit(void)
176{
177}