aboutsummaryrefslogtreecommitdiffstats
path: root/arch/ppc/oprofile
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/ppc/oprofile
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'arch/ppc/oprofile')
-rw-r--r--arch/ppc/oprofile/Kconfig23
-rw-r--r--arch/ppc/oprofile/Makefile14
-rw-r--r--arch/ppc/oprofile/common.c161
-rw-r--r--arch/ppc/oprofile/op_impl.h45
-rw-r--r--arch/ppc/oprofile/op_model_fsl_booke.c184
5 files changed, 427 insertions, 0 deletions
diff --git a/arch/ppc/oprofile/Kconfig b/arch/ppc/oprofile/Kconfig
new file mode 100644
index 000000000000..19d37730b664
--- /dev/null
+++ b/arch/ppc/oprofile/Kconfig
@@ -0,0 +1,23 @@
1
2menu "Profiling support"
3 depends on EXPERIMENTAL
4
5config PROFILING
6 bool "Profiling support (EXPERIMENTAL)"
7 help
8 Say Y here to enable the extended profiling support mechanisms used
9 by profilers such as OProfile.
10
11
12config OPROFILE
13 tristate "OProfile system profiling (EXPERIMENTAL)"
14 depends on PROFILING
15 help
16 OProfile is a profiling system capable of profiling the
17 whole system, include the kernel, kernel modules, libraries,
18 and applications.
19
20 If unsure, say N.
21
22endmenu
23
diff --git a/arch/ppc/oprofile/Makefile b/arch/ppc/oprofile/Makefile
new file mode 100644
index 000000000000..e2218d32a4eb
--- /dev/null
+++ b/arch/ppc/oprofile/Makefile
@@ -0,0 +1,14 @@
1obj-$(CONFIG_OPROFILE) += oprofile.o
2
3DRIVER_OBJS := $(addprefix ../../../drivers/oprofile/, \
4 oprof.o cpu_buffer.o buffer_sync.o \
5 event_buffer.o oprofile_files.o \
6 oprofilefs.o oprofile_stats.o \
7 timer_int.o )
8
9oprofile-y := $(DRIVER_OBJS) common.o
10
11ifeq ($(CONFIG_FSL_BOOKE),y)
12 oprofile-y += op_model_fsl_booke.o
13endif
14
diff --git a/arch/ppc/oprofile/common.c b/arch/ppc/oprofile/common.c
new file mode 100644
index 000000000000..3169c67abea7
--- /dev/null
+++ b/arch/ppc/oprofile/common.c
@@ -0,0 +1,161 @@
1/*
2 * PPC 32 oprofile support
3 * Based on PPC64 oprofile support
4 * Copyright (C) 2004 Anton Blanchard <anton@au.ibm.com>, IBM
5 *
6 * Copyright (C) Freescale Semiconductor, Inc 2004
7 *
8 * Author: Andy Fleming
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
14 */
15
16#include <linux/oprofile.h>
17#include <linux/slab.h>
18#include <linux/init.h>
19#include <linux/smp.h>
20#include <linux/errno.h>
21#include <asm/ptrace.h>
22#include <asm/system.h>
23#include <asm/perfmon.h>
24#include <asm/cputable.h>
25
26#include "op_impl.h"
27
28static struct op_ppc32_model *model;
29
30static struct op_counter_config ctr[OP_MAX_COUNTER];
31static struct op_system_config sys;
32
33static void op_handle_interrupt(struct pt_regs *regs)
34{
35 model->handle_interrupt(regs, ctr);
36}
37
38static int op_ppc32_setup(void)
39{
40 /* Install our interrupt handler into the existing hook. */
41 if(request_perfmon_irq(&op_handle_interrupt))
42 return -EBUSY;
43
44 mb();
45
46 /* Pre-compute the values to stuff in the hardware registers. */
47 model->reg_setup(ctr, &sys, model->num_counters);
48
49#if 0
50 /* FIXME: Make multi-cpu work */
51 /* Configure the registers on all cpus. */
52 on_each_cpu(model->reg_setup, NULL, 0, 1);
53#endif
54
55 return 0;
56}
57
58static void op_ppc32_shutdown(void)
59{
60 mb();
61
62 /* Remove our interrupt handler. We may be removing this module. */
63 free_perfmon_irq();
64}
65
66static void op_ppc32_cpu_start(void *dummy)
67{
68 model->start(ctr);
69}
70
71static int op_ppc32_start(void)
72{
73 on_each_cpu(op_ppc32_cpu_start, NULL, 0, 1);
74 return 0;
75}
76
77static inline void op_ppc32_cpu_stop(void *dummy)
78{
79 model->stop();
80}
81
82static void op_ppc32_stop(void)
83{
84 on_each_cpu(op_ppc32_cpu_stop, NULL, 0, 1);
85}
86
87static int op_ppc32_create_files(struct super_block *sb, struct dentry *root)
88{
89 int i;
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 oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
102 oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
103
104 /* FIXME: Not sure if this is used */
105 oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask);
106 }
107
108 oprofilefs_create_ulong(sb, root, "enable_kernel", &sys.enable_kernel);
109 oprofilefs_create_ulong(sb, root, "enable_user", &sys.enable_user);
110
111 /* Default to tracing both kernel and user */
112 sys.enable_kernel = 1;
113 sys.enable_user = 1;
114
115 return 0;
116}
117
118static struct oprofile_operations oprof_ppc32_ops = {
119 .create_files = op_ppc32_create_files,
120 .setup = op_ppc32_setup,
121 .shutdown = op_ppc32_shutdown,
122 .start = op_ppc32_start,
123 .stop = op_ppc32_stop,
124 .cpu_type = NULL /* To be filled in below. */
125};
126
127int __init oprofile_arch_init(struct oprofile_operations *ops)
128{
129 char *name;
130 int cpu_id = smp_processor_id();
131
132#ifdef CONFIG_FSL_BOOKE
133 model = &op_model_fsl_booke;
134#else
135 return -ENODEV;
136#endif
137
138 name = kmalloc(32, GFP_KERNEL);
139
140 if (NULL == name)
141 return -ENOMEM;
142
143 sprintf(name, "ppc/%s", cur_cpu_spec[cpu_id]->cpu_name);
144
145 oprof_ppc32_ops.cpu_type = name;
146
147 model->num_counters = cur_cpu_spec[cpu_id]->num_pmcs;
148
149 *ops = oprof_ppc32_ops;
150
151 printk(KERN_INFO "oprofile: using %s performance monitoring.\n",
152 oprof_ppc32_ops.cpu_type);
153
154 return 0;
155}
156
157void oprofile_arch_exit(void)
158{
159 kfree(oprof_ppc32_ops.cpu_type);
160 oprof_ppc32_ops.cpu_type = NULL;
161}
diff --git a/arch/ppc/oprofile/op_impl.h b/arch/ppc/oprofile/op_impl.h
new file mode 100644
index 000000000000..bc336dc971e3
--- /dev/null
+++ b/arch/ppc/oprofile/op_impl.h
@@ -0,0 +1,45 @@
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#ifndef OP_IMPL_H
13#define OP_IMPL_H 1
14
15#define OP_MAX_COUNTER 8
16
17/* Per-counter configuration as set via oprofilefs. */
18struct op_counter_config {
19 unsigned long enabled;
20 unsigned long event;
21 unsigned long count;
22 unsigned long kernel;
23 unsigned long user;
24 unsigned long unit_mask;
25};
26
27/* System-wide configuration as set via oprofilefs. */
28struct op_system_config {
29 unsigned long enable_kernel;
30 unsigned long enable_user;
31};
32
33/* Per-arch configuration */
34struct op_ppc32_model {
35 void (*reg_setup) (struct op_counter_config *,
36 struct op_system_config *,
37 int num_counters);
38 void (*start) (struct op_counter_config *);
39 void (*stop) (void);
40 void (*handle_interrupt) (struct pt_regs *,
41 struct op_counter_config *);
42 int num_counters;
43};
44
45#endif /* OP_IMPL_H */
diff --git a/arch/ppc/oprofile/op_model_fsl_booke.c b/arch/ppc/oprofile/op_model_fsl_booke.c
new file mode 100644
index 000000000000..fc9c859358c6
--- /dev/null
+++ b/arch/ppc/oprofile/op_model_fsl_booke.c
@@ -0,0 +1,184 @@
1/*
2 * oprofile/op_model_e500.c
3 *
4 * Freescale Book-E oprofile support, based on ppc64 oprofile support
5 * Copyright (C) 2004 Anton Blanchard <anton@au.ibm.com>, IBM
6 *
7 * Copyright (c) 2004 Freescale Semiconductor, Inc
8 *
9 * Author: Andy Fleming
10 * Maintainer: Kumar Gala <Kumar.Gala@freescale.com>
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version
15 * 2 of the License, or (at your option) any later version.
16 */
17
18#include <linux/oprofile.h>
19#include <linux/init.h>
20#include <linux/smp.h>
21#include <asm/ptrace.h>
22#include <asm/system.h>
23#include <asm/processor.h>
24#include <asm/cputable.h>
25#include <asm/reg_booke.h>
26#include <asm/page.h>
27#include <asm/perfmon.h>
28
29#include "op_impl.h"
30
31static unsigned long reset_value[OP_MAX_COUNTER];
32
33static int num_counters;
34static int oprofile_running;
35
36static inline unsigned int ctr_read(unsigned int i)
37{
38 switch(i) {
39 case 0:
40 return mfpmr(PMRN_PMC0);
41 case 1:
42 return mfpmr(PMRN_PMC1);
43 case 2:
44 return mfpmr(PMRN_PMC2);
45 case 3:
46 return mfpmr(PMRN_PMC3);
47 default:
48 return 0;
49 }
50}
51
52static inline void ctr_write(unsigned int i, unsigned int val)
53{
54 switch(i) {
55 case 0:
56 mtpmr(PMRN_PMC0, val);
57 break;
58 case 1:
59 mtpmr(PMRN_PMC1, val);
60 break;
61 case 2:
62 mtpmr(PMRN_PMC2, val);
63 break;
64 case 3:
65 mtpmr(PMRN_PMC3, val);
66 break;
67 default:
68 break;
69 }
70}
71
72
73static void fsl_booke_reg_setup(struct op_counter_config *ctr,
74 struct op_system_config *sys,
75 int num_ctrs)
76{
77 int i;
78
79 num_counters = num_ctrs;
80
81 /* freeze all counters */
82 pmc_stop_ctrs();
83
84 /* Our counters count up, and "count" refers to
85 * how much before the next interrupt, and we interrupt
86 * on overflow. So we calculate the starting value
87 * which will give us "count" until overflow.
88 * Then we set the events on the enabled counters */
89 for (i = 0; i < num_counters; ++i) {
90 reset_value[i] = 0x80000000UL - ctr[i].count;
91
92 init_pmc_stop(i);
93
94 set_pmc_event(i, ctr[i].event);
95
96 set_pmc_user_kernel(i, ctr[i].user, ctr[i].kernel);
97 }
98}
99
100static void fsl_booke_start(struct op_counter_config *ctr)
101{
102 int i;
103
104 mtmsr(mfmsr() | MSR_PMM);
105
106 for (i = 0; i < num_counters; ++i) {
107 if (ctr[i].enabled) {
108 ctr_write(i, reset_value[i]);
109 /* Set Each enabled counterd to only
110 * count when the Mark bit is not set */
111 set_pmc_marked(i, 1, 0);
112 pmc_start_ctr(i, 1);
113 } else {
114 ctr_write(i, 0);
115
116 /* Set the ctr to be stopped */
117 pmc_start_ctr(i, 0);
118 }
119 }
120
121 /* Clear the freeze bit, and enable the interrupt.
122 * The counters won't actually start until the rfi clears
123 * the PMM bit */
124 pmc_start_ctrs(1);
125
126 oprofile_running = 1;
127
128 pr_debug("start on cpu %d, pmgc0 %x\n", smp_processor_id(),
129 mfpmr(PMRN_PMGC0));
130}
131
132static void fsl_booke_stop(void)
133{
134 /* freeze counters */
135 pmc_stop_ctrs();
136
137 oprofile_running = 0;
138
139 pr_debug("stop on cpu %d, pmgc0 %x\n", smp_processor_id(),
140 mfpmr(PMRN_PMGC0));
141
142 mb();
143}
144
145
146static void fsl_booke_handle_interrupt(struct pt_regs *regs,
147 struct op_counter_config *ctr)
148{
149 unsigned long pc;
150 int is_kernel;
151 int val;
152 int i;
153
154 /* set the PMM bit (see comment below) */
155 mtmsr(mfmsr() | MSR_PMM);
156
157 pc = regs->nip;
158 is_kernel = (pc >= KERNELBASE);
159
160 for (i = 0; i < num_counters; ++i) {
161 val = ctr_read(i);
162 if (val < 0) {
163 if (oprofile_running && ctr[i].enabled) {
164 oprofile_add_pc(pc, is_kernel, i);
165 ctr_write(i, reset_value[i]);
166 } else {
167 ctr_write(i, 0);
168 }
169 }
170 }
171
172 /* The freeze bit was set by the interrupt. */
173 /* Clear the freeze bit, and reenable the interrupt.
174 * The counters won't actually start until the rfi clears
175 * the PMM bit */
176 pmc_start_ctrs(1);
177}
178
179struct op_ppc32_model op_model_fsl_booke = {
180 .reg_setup = fsl_booke_reg_setup,
181 .start = fsl_booke_start,
182 .stop = fsl_booke_stop,
183 .handle_interrupt = fsl_booke_handle_interrupt,
184};