Blame view
arch/powerpc/oprofile/common.c
6.27 KB
1da177e4c
|
1 |
/* |
86a5cddbd
|
2 |
* PPC 64 oprofile support: |
1da177e4c
|
3 |
* Copyright (C) 2004 Anton Blanchard <anton@au.ibm.com>, IBM |
86a5cddbd
|
4 5 6 |
* PPC 32 oprofile support: (based on PPC 64 support) * Copyright (C) Freescale Semiconductor, Inc 2004 * Author: Andy Fleming |
1da177e4c
|
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
* * Based on alpha version. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ #include <linux/oprofile.h> #include <linux/init.h> #include <linux/smp.h> #include <linux/errno.h> #include <asm/ptrace.h> #include <asm/system.h> #include <asm/pmc.h> |
a6908cd00
|
23 |
#include <asm/cputable.h> |
dca859329
|
24 |
#include <asm/oprofile_impl.h> |
2191fe3e3
|
25 |
#include <asm/firmware.h> |
1da177e4c
|
26 |
|
a3e48c10c
|
27 |
static struct op_powerpc_model *model; |
1da177e4c
|
28 29 30 |
static struct op_counter_config ctr[OP_MAX_COUNTER]; static struct op_system_config sys; |
1474855d0
|
31 |
static int op_per_cpu_rc; |
1da177e4c
|
32 33 34 35 |
static void op_handle_interrupt(struct pt_regs *regs) { model->handle_interrupt(regs, ctr); } |
dd6c89f68
|
36 37 |
static void op_powerpc_cpu_setup(void *dummy) { |
1474855d0
|
38 39 40 41 42 43 |
int ret; ret = model->cpu_setup(ctr); if (ret != 0) op_per_cpu_rc = ret; |
dd6c89f68
|
44 |
} |
86a5cddbd
|
45 |
static int op_powerpc_setup(void) |
1da177e4c
|
46 47 |
{ int err; |
1474855d0
|
48 |
op_per_cpu_rc = 0; |
1da177e4c
|
49 50 51 52 53 54 |
/* Grab the hardware */ err = reserve_pmc_hardware(op_handle_interrupt); if (err) return err; /* Pre-compute the values to stuff in the hardware registers. */ |
1474855d0
|
55 |
op_per_cpu_rc = model->reg_setup(ctr, &sys, model->num_counters); |
1da177e4c
|
56 |
|
1474855d0
|
57 58 59 60 61 |
if (op_per_cpu_rc) goto out; /* Configure the registers on all cpus. If an error occurs on one * of the cpus, op_per_cpu_rc will be set to the error */ |
15c8b6c1a
|
62 |
on_each_cpu(op_powerpc_cpu_setup, NULL, 1); |
1da177e4c
|
63 |
|
1474855d0
|
64 65 66 67 68 69 |
out: if (op_per_cpu_rc) { /* error on setup release the performance counter hardware */ release_pmc_hardware(); } return op_per_cpu_rc; |
1da177e4c
|
70 |
} |
86a5cddbd
|
71 |
static void op_powerpc_shutdown(void) |
1da177e4c
|
72 73 74 |
{ release_pmc_hardware(); } |
86a5cddbd
|
75 |
static void op_powerpc_cpu_start(void *dummy) |
1da177e4c
|
76 |
{ |
1474855d0
|
77 78 79 80 81 82 83 84 85 |
/* If any of the cpus have return an error, set the * global flag to the error so it can be returned * to the generic OProfile caller. */ int ret; ret = model->start(ctr); if (ret != 0) op_per_cpu_rc = ret; |
1da177e4c
|
86 |
} |
86a5cddbd
|
87 |
static int op_powerpc_start(void) |
1da177e4c
|
88 |
{ |
1474855d0
|
89 |
op_per_cpu_rc = 0; |
18f2190d7
|
90 |
if (model->global_start) |
1474855d0
|
91 92 |
return model->global_start(ctr); if (model->start) { |
15c8b6c1a
|
93 |
on_each_cpu(op_powerpc_cpu_start, NULL, 1); |
1474855d0
|
94 95 96 97 |
return op_per_cpu_rc; } return -EIO; /* No start function is defined for this power architecture */ |
1da177e4c
|
98 |
} |
86a5cddbd
|
99 |
static inline void op_powerpc_cpu_stop(void *dummy) |
1da177e4c
|
100 101 102 |
{ model->stop(); } |
86a5cddbd
|
103 |
static void op_powerpc_stop(void) |
1da177e4c
|
104 |
{ |
18f2190d7
|
105 |
if (model->stop) |
15c8b6c1a
|
106 |
on_each_cpu(op_powerpc_cpu_stop, NULL, 1); |
18f2190d7
|
107 108 |
if (model->global_stop) model->global_stop(); |
1da177e4c
|
109 |
} |
86a5cddbd
|
110 |
static int op_powerpc_create_files(struct super_block *sb, struct dentry *root) |
1da177e4c
|
111 112 |
{ int i; |
555d97ac8
|
113 |
#ifdef CONFIG_PPC64 |
1da177e4c
|
114 115 116 117 118 119 120 |
/* * There is one mmcr0, mmcr1 and mmcra for setting the events for * all of the counters. */ oprofilefs_create_ulong(sb, root, "mmcr0", &sys.mmcr0); oprofilefs_create_ulong(sb, root, "mmcr1", &sys.mmcr1); oprofilefs_create_ulong(sb, root, "mmcra", &sys.mmcra); |
883823291
|
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
#ifdef CONFIG_OPROFILE_CELL /* create a file the user tool can check to see what level of profiling * support exits with this kernel. Initialize bit mask to indicate * what support the kernel has: * bit 0 - Supports SPU event profiling in addition to PPU * event and cycles; and SPU cycle profiling * bits 1-31 - Currently unused. * * If the file does not exist, then the kernel only supports SPU * cycle profiling, PPU event and cycle profiling. */ oprofilefs_create_ulong(sb, root, "cell_support", &sys.cell_support); sys.cell_support = 0x1; /* Note, the user OProfile tool must check * that this bit is set before attempting to * user SPU event profiling. Older kernels * will not have this file, hence the user * tool is not allowed to do SPU event * profiling on older kernels. Older kernels * will accept SPU events but collected data * is garbage. */ #endif |
555d97ac8
|
143 |
#endif |
1da177e4c
|
144 145 146 |
for (i = 0; i < model->num_counters; ++i) { struct dentry *dir; |
0c6856f70
|
147 |
char buf[4]; |
1da177e4c
|
148 149 150 151 152 153 154 |
snprintf(buf, sizeof buf, "%d", i); dir = oprofilefs_mkdir(sb, root, buf); oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled); oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event); oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count); |
555d97ac8
|
155 |
|
1da177e4c
|
156 |
/* |
555d97ac8
|
157 158 159 160 161 |
* Classic PowerPC doesn't support per-counter * control like this, but the options are * expected, so they remain. For Freescale * Book-E style performance monitors, we do * support them. |
1da177e4c
|
162 163 164 |
*/ oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel); oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user); |
86a5cddbd
|
165 |
|
1da177e4c
|
166 167 168 169 170 |
oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask); } oprofilefs_create_ulong(sb, root, "enable_kernel", &sys.enable_kernel); oprofilefs_create_ulong(sb, root, "enable_user", &sys.enable_user); |
1da177e4c
|
171 172 173 174 |
/* Default to tracing both kernel and user */ sys.enable_kernel = 1; sys.enable_user = 1; |
1da177e4c
|
175 176 177 178 179 180 |
return 0; } int __init oprofile_arch_init(struct oprofile_operations *ops) { |
32a33994d
|
181 |
if (!cur_cpu_spec->oprofile_cpu_type) |
8fef0306f
|
182 |
return -ENODEV; |
32a33994d
|
183 |
|
2191fe3e3
|
184 185 |
if (firmware_has_feature(FW_FEATURE_ISERIES)) return -ENODEV; |
32a33994d
|
186 |
switch (cur_cpu_spec->oprofile_type) { |
1caca371e
|
187 |
#ifdef CONFIG_PPC_BOOK3S_64 |
1474855d0
|
188 |
#ifdef CONFIG_OPROFILE_CELL |
18f2190d7
|
189 |
case PPC_OPROFILE_CELL: |
ef66f7967
|
190 191 |
if (firmware_has_feature(FW_FEATURE_LPAR)) return -ENODEV; |
18f2190d7
|
192 |
model = &op_model_cell; |
1474855d0
|
193 194 |
ops->sync_start = model->sync_start; ops->sync_stop = model->sync_stop; |
18f2190d7
|
195 196 |
break; #endif |
7a45fb19c
|
197 |
case PPC_OPROFILE_RS64: |
32a33994d
|
198 199 |
model = &op_model_rs64; break; |
7a45fb19c
|
200 |
case PPC_OPROFILE_POWER4: |
32a33994d
|
201 202 |
model = &op_model_power4; break; |
25fc530ee
|
203 204 205 |
case PPC_OPROFILE_PA6T: model = &op_model_pa6t; break; |
dd6c89f68
|
206 207 |
#endif #ifdef CONFIG_6xx |
7a45fb19c
|
208 |
case PPC_OPROFILE_G4: |
32a33994d
|
209 210 211 |
model = &op_model_7450; break; #endif |
39aef685a
|
212 213 214 |
#if defined(CONFIG_FSL_EMB_PERFMON) case PPC_OPROFILE_FSL_EMB: model = &op_model_fsl_emb; |
32a33994d
|
215 216 217 218 219 |
break; #endif default: return -ENODEV; } |
a6908cd00
|
220 |
model->num_counters = cur_cpu_spec->num_pmcs; |
8fef0306f
|
221 222 |
ops->cpu_type = cur_cpu_spec->oprofile_cpu_type; |
86a5cddbd
|
223 224 225 226 227 |
ops->create_files = op_powerpc_create_files; ops->setup = op_powerpc_setup; ops->shutdown = op_powerpc_shutdown; ops->start = op_powerpc_start; ops->stop = op_powerpc_stop; |
6c6bd754b
|
228 |
ops->backtrace = op_powerpc_backtrace; |
1da177e4c
|
229 |
|
5e1415c3f
|
230 231 |
printk(KERN_DEBUG "oprofile: using %s performance monitoring. ", |
1da177e4c
|
232 233 234 235 236 237 238 239 |
ops->cpu_type); return 0; } void oprofile_arch_exit(void) { } |