2 * Copyright (C) 2004 Anton Blanchard <anton@au.ibm.com>, IBM
4 * Based on alpha version.
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.
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>
22 extern struct op_ppc64_model op_model_rs64
;
23 extern struct op_ppc64_model op_model_power4
;
24 static struct op_ppc64_model
*model
;
26 static struct op_counter_config ctr
[OP_MAX_COUNTER
];
27 static struct op_system_config sys
;
29 static void op_handle_interrupt(struct pt_regs
*regs
)
31 model
->handle_interrupt(regs
, ctr
);
34 static int op_ppc64_setup(void)
38 /* Grab the hardware */
39 err
= reserve_pmc_hardware(op_handle_interrupt
);
43 /* Pre-compute the values to stuff in the hardware registers. */
44 model
->reg_setup(ctr
, &sys
, model
->num_counters
);
46 /* Configure the registers on all cpus. */
47 on_each_cpu(model
->cpu_setup
, NULL
, 0, 1);
52 static void op_ppc64_shutdown(void)
54 release_pmc_hardware();
57 static void op_ppc64_cpu_start(void *dummy
)
62 static int op_ppc64_start(void)
64 on_each_cpu(op_ppc64_cpu_start
, NULL
, 0, 1);
68 static inline void op_ppc64_cpu_stop(void *dummy
)
73 static void op_ppc64_stop(void)
75 on_each_cpu(op_ppc64_cpu_stop
, NULL
, 0, 1);
78 static int op_ppc64_create_files(struct super_block
*sb
, struct dentry
*root
)
83 * There is one mmcr0, mmcr1 and mmcra for setting the events for
84 * all of the counters.
86 oprofilefs_create_ulong(sb
, root
, "mmcr0", &sys
.mmcr0
);
87 oprofilefs_create_ulong(sb
, root
, "mmcr1", &sys
.mmcr1
);
88 oprofilefs_create_ulong(sb
, root
, "mmcra", &sys
.mmcra
);
90 for (i
= 0; i
< model
->num_counters
; ++i
) {
94 snprintf(buf
, sizeof buf
, "%d", i
);
95 dir
= oprofilefs_mkdir(sb
, root
, buf
);
97 oprofilefs_create_ulong(sb
, dir
, "enabled", &ctr
[i
].enabled
);
98 oprofilefs_create_ulong(sb
, dir
, "event", &ctr
[i
].event
);
99 oprofilefs_create_ulong(sb
, dir
, "count", &ctr
[i
].count
);
101 * We dont support per counter user/kernel selection, but
102 * we leave the entries because userspace expects them
104 oprofilefs_create_ulong(sb
, dir
, "kernel", &ctr
[i
].kernel
);
105 oprofilefs_create_ulong(sb
, dir
, "user", &ctr
[i
].user
);
106 oprofilefs_create_ulong(sb
, dir
, "unit_mask", &ctr
[i
].unit_mask
);
109 oprofilefs_create_ulong(sb
, root
, "enable_kernel", &sys
.enable_kernel
);
110 oprofilefs_create_ulong(sb
, root
, "enable_user", &sys
.enable_user
);
111 oprofilefs_create_ulong(sb
, root
, "backtrace_spinlocks",
112 &sys
.backtrace_spinlocks
);
114 /* Default to tracing both kernel and user */
115 sys
.enable_kernel
= 1;
118 /* Turn on backtracing through spinlocks by default */
119 sys
.backtrace_spinlocks
= 1;
124 int __init
oprofile_arch_init(struct oprofile_operations
*ops
)
128 pvr
= mfspr(SPRN_PVR
);
130 switch (PVR_VER(pvr
)) {
133 model
= &op_model_rs64
;
134 model
->num_counters
= 8;
135 ops
->cpu_type
= "ppc64/power3";
142 model
= &op_model_rs64
;
143 model
->num_counters
= 8;
144 ops
->cpu_type
= "ppc64/rs64";
149 model
= &op_model_power4
;
150 model
->num_counters
= 8;
151 ops
->cpu_type
= "ppc64/power4";
156 model
= &op_model_power4
;
157 model
->num_counters
= 8;
158 ops
->cpu_type
= "ppc64/970";
163 model
= &op_model_power4
;
164 model
->num_counters
= 6;
165 ops
->cpu_type
= "ppc64/power5";
172 ops
->create_files
= op_ppc64_create_files
;
173 ops
->setup
= op_ppc64_setup
;
174 ops
->shutdown
= op_ppc64_shutdown
;
175 ops
->start
= op_ppc64_start
;
176 ops
->stop
= op_ppc64_stop
;
178 printk(KERN_INFO
"oprofile: using %s performance monitoring.\n",
184 void oprofile_arch_exit(void)