common.c 5.3 KB
Newer Older
L
Linus Torvalds 已提交
1
/*
2
 * PPC 64 oprofile support:
L
Linus Torvalds 已提交
3
 * Copyright (C) 2004 Anton Blanchard <anton@au.ibm.com>, IBM
4 5 6
 * PPC 32 oprofile support: (based on PPC 64 support)
 * Copyright (C) Freescale Semiconductor, Inc 2004
 *	Author: Andy Fleming
L
Linus Torvalds 已提交
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>
23
#include <asm/cputable.h>
24
#include <asm/oprofile_impl.h>
25
#include <asm/firmware.h>
L
Linus Torvalds 已提交
26

27
static struct op_powerpc_model *model;
L
Linus Torvalds 已提交
28 29 30 31

static struct op_counter_config ctr[OP_MAX_COUNTER];
static struct op_system_config sys;

32 33
static int op_per_cpu_rc;

L
Linus Torvalds 已提交
34 35 36 37 38
static void op_handle_interrupt(struct pt_regs *regs)
{
	model->handle_interrupt(regs, ctr);
}

39 40
static void op_powerpc_cpu_setup(void *dummy)
{
41 42 43 44 45 46
	int ret;

	ret = model->cpu_setup(ctr);

	if (ret != 0)
		op_per_cpu_rc = ret;
47 48
}

49
static int op_powerpc_setup(void)
L
Linus Torvalds 已提交
50 51 52
{
	int err;

53 54
	op_per_cpu_rc = 0;

L
Linus Torvalds 已提交
55 56 57 58 59 60
	/* Grab the hardware */
	err = reserve_pmc_hardware(op_handle_interrupt);
	if (err)
		return err;

	/* Pre-compute the values to stuff in the hardware registers.  */
61
	op_per_cpu_rc = model->reg_setup(ctr, &sys, model->num_counters);
L
Linus Torvalds 已提交
62

63 64 65 66 67
	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 */
68
	on_each_cpu(op_powerpc_cpu_setup, NULL, 0, 1);
L
Linus Torvalds 已提交
69

70 71 72 73 74 75
out:	if (op_per_cpu_rc) {
		/* error on setup release the performance counter hardware */
		release_pmc_hardware();
	}

	return op_per_cpu_rc;
L
Linus Torvalds 已提交
76 77
}

78
static void op_powerpc_shutdown(void)
L
Linus Torvalds 已提交
79 80 81 82
{
	release_pmc_hardware();
}

83
static void op_powerpc_cpu_start(void *dummy)
L
Linus Torvalds 已提交
84
{
85 86 87 88 89 90 91 92 93
	/* 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;
L
Linus Torvalds 已提交
94 95
}

96
static int op_powerpc_start(void)
L
Linus Torvalds 已提交
97
{
98 99
	op_per_cpu_rc = 0;

100
	if (model->global_start)
101 102
		return model->global_start(ctr);
	if (model->start) {
103
		on_each_cpu(op_powerpc_cpu_start, NULL, 0, 1);
104 105 106 107
		return op_per_cpu_rc;
	}
	return -EIO; /* No start function is defined for this
			power architecture */
L
Linus Torvalds 已提交
108 109
}

110
static inline void op_powerpc_cpu_stop(void *dummy)
L
Linus Torvalds 已提交
111 112 113 114
{
	model->stop();
}

115
static void op_powerpc_stop(void)
L
Linus Torvalds 已提交
116
{
117 118 119 120
	if (model->stop)
		on_each_cpu(op_powerpc_cpu_stop, NULL, 0, 1);
        if (model->global_stop)
                model->global_stop();
L
Linus Torvalds 已提交
121 122
}

123
static int op_powerpc_create_files(struct super_block *sb, struct dentry *root)
L
Linus Torvalds 已提交
124 125 126
{
	int i;

127
#ifdef CONFIG_PPC64
L
Linus Torvalds 已提交
128 129 130 131 132 133 134
	/*
	 * 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);
135
#endif
L
Linus Torvalds 已提交
136 137 138

	for (i = 0; i < model->num_counters; ++i) {
		struct dentry *dir;
139
		char buf[4];
L
Linus Torvalds 已提交
140 141 142 143 144 145 146

		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);
147

L
Linus Torvalds 已提交
148
		/*
149 150 151 152 153
		 * 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.
L
Linus Torvalds 已提交
154 155 156
		 */
		oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
		oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
157

L
Linus Torvalds 已提交
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
		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);

	/* Default to tracing both kernel and user */
	sys.enable_kernel = 1;
	sys.enable_user = 1;

	return 0;
}

int __init oprofile_arch_init(struct oprofile_operations *ops)
{
173
	if (!cur_cpu_spec->oprofile_cpu_type)
174
		return -ENODEV;
175

176 177 178
	if (firmware_has_feature(FW_FEATURE_ISERIES))
		return -ENODEV;

179 180
	switch (cur_cpu_spec->oprofile_type) {
#ifdef CONFIG_PPC64
181
#ifdef CONFIG_OPROFILE_CELL
182
		case PPC_OPROFILE_CELL:
183 184
			if (firmware_has_feature(FW_FEATURE_LPAR))
				return -ENODEV;
185
			model = &op_model_cell;
186 187
			ops->sync_start = model->sync_start;
			ops->sync_stop = model->sync_stop;
188 189
			break;
#endif
190
		case PPC_OPROFILE_RS64:
191 192
			model = &op_model_rs64;
			break;
193
		case PPC_OPROFILE_POWER4:
194 195
			model = &op_model_power4;
			break;
196 197 198
		case PPC_OPROFILE_PA6T:
			model = &op_model_pa6t;
			break;
199 200
#endif
#ifdef CONFIG_6xx
201
		case PPC_OPROFILE_G4:
202 203 204 205
			model = &op_model_7450;
			break;
#endif
#ifdef CONFIG_FSL_BOOKE
206
		case PPC_OPROFILE_BOOKE:
207 208 209 210 211 212 213
			model = &op_model_fsl_booke;
			break;
#endif
		default:
			return -ENODEV;
	}

214
	model->num_counters = cur_cpu_spec->num_pmcs;
215 216

	ops->cpu_type = cur_cpu_spec->oprofile_cpu_type;
217 218 219 220 221
	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;
222
	ops->backtrace = op_powerpc_backtrace;
L
Linus Torvalds 已提交
223

224
	printk(KERN_DEBUG "oprofile: using %s performance monitoring.\n",
L
Linus Torvalds 已提交
225 226 227 228 229 230 231 232
	       ops->cpu_type);

	return 0;
}

void oprofile_arch_exit(void)
{
}