Blame view

arch/powerpc/oprofile/common.c 6.27 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
  /*
86a5cddbd   Stephen Rothwell   [PATCH] powerpc: ...
2
   * PPC 64 oprofile support:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3
   * Copyright (C) 2004 Anton Blanchard <anton@au.ibm.com>, IBM
86a5cddbd   Stephen Rothwell   [PATCH] powerpc: ...
4
5
6
   * PPC 32 oprofile support: (based on PPC 64 support)
   * Copyright (C) Freescale Semiconductor, Inc 2004
   *	Author: Andy Fleming
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
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   Anton Blanchard   [PATCH] ppc64: Us...
23
  #include <asm/cputable.h>
dca859329   Anton Blanchard   [PATCH] ppc64: Mo...
24
  #include <asm/oprofile_impl.h>
2191fe3e3   Kelly Daly   [POWERPC] re-enab...
25
  #include <asm/firmware.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
26

a3e48c10c   Stephen Rothwell   [PATCH] powerpc: ...
27
  static struct op_powerpc_model *model;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
28
29
30
  
  static struct op_counter_config ctr[OP_MAX_COUNTER];
  static struct op_system_config sys;
1474855d0   Bob Nelson   [CELL] oprofile: ...
31
  static int op_per_cpu_rc;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
32
33
34
35
  static void op_handle_interrupt(struct pt_regs *regs)
  {
  	model->handle_interrupt(regs, ctr);
  }
dd6c89f68   Andy Fleming   [POWERPC] Fix opr...
36
37
  static void op_powerpc_cpu_setup(void *dummy)
  {
1474855d0   Bob Nelson   [CELL] oprofile: ...
38
39
40
41
42
43
  	int ret;
  
  	ret = model->cpu_setup(ctr);
  
  	if (ret != 0)
  		op_per_cpu_rc = ret;
dd6c89f68   Andy Fleming   [POWERPC] Fix opr...
44
  }
86a5cddbd   Stephen Rothwell   [PATCH] powerpc: ...
45
  static int op_powerpc_setup(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
47
  {
  	int err;
1474855d0   Bob Nelson   [CELL] oprofile: ...
48
  	op_per_cpu_rc = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
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   Bob Nelson   [CELL] oprofile: ...
55
  	op_per_cpu_rc = model->reg_setup(ctr, &sys, model->num_counters);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
56

1474855d0   Bob Nelson   [CELL] oprofile: ...
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   Jens Axboe   on_each_cpu(): ki...
62
  	on_each_cpu(op_powerpc_cpu_setup, NULL, 1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
63

1474855d0   Bob Nelson   [CELL] oprofile: ...
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   Linus Torvalds   Linux-2.6.12-rc2
70
  }
86a5cddbd   Stephen Rothwell   [PATCH] powerpc: ...
71
  static void op_powerpc_shutdown(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
72
73
74
  {
  	release_pmc_hardware();
  }
86a5cddbd   Stephen Rothwell   [PATCH] powerpc: ...
75
  static void op_powerpc_cpu_start(void *dummy)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
76
  {
1474855d0   Bob Nelson   [CELL] oprofile: ...
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   Linus Torvalds   Linux-2.6.12-rc2
86
  }
86a5cddbd   Stephen Rothwell   [PATCH] powerpc: ...
87
  static int op_powerpc_start(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
88
  {
1474855d0   Bob Nelson   [CELL] oprofile: ...
89
  	op_per_cpu_rc = 0;
18f2190d7   Maynard Johnson   [POWERPC] cell: A...
90
  	if (model->global_start)
1474855d0   Bob Nelson   [CELL] oprofile: ...
91
92
  		return model->global_start(ctr);
  	if (model->start) {
15c8b6c1a   Jens Axboe   on_each_cpu(): ki...
93
  		on_each_cpu(op_powerpc_cpu_start, NULL, 1);
1474855d0   Bob Nelson   [CELL] oprofile: ...
94
95
96
97
  		return op_per_cpu_rc;
  	}
  	return -EIO; /* No start function is defined for this
  			power architecture */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
98
  }
86a5cddbd   Stephen Rothwell   [PATCH] powerpc: ...
99
  static inline void op_powerpc_cpu_stop(void *dummy)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
100
101
102
  {
  	model->stop();
  }
86a5cddbd   Stephen Rothwell   [PATCH] powerpc: ...
103
  static void op_powerpc_stop(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
104
  {
18f2190d7   Maynard Johnson   [POWERPC] cell: A...
105
  	if (model->stop)
15c8b6c1a   Jens Axboe   on_each_cpu(): ki...
106
  		on_each_cpu(op_powerpc_cpu_stop, NULL, 1);
18f2190d7   Maynard Johnson   [POWERPC] cell: A...
107
108
          if (model->global_stop)
                  model->global_stop();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
109
  }
86a5cddbd   Stephen Rothwell   [PATCH] powerpc: ...
110
  static int op_powerpc_create_files(struct super_block *sb, struct dentry *root)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
111
112
  {
  	int i;
555d97ac8   Andy Fleming   [PATCH] powerpc: ...
113
  #ifdef CONFIG_PPC64
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
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   Carl Love   powerpc/oprofile:...
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   Andy Fleming   [PATCH] powerpc: ...
143
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
144
145
146
  
  	for (i = 0; i < model->num_counters; ++i) {
  		struct dentry *dir;
0c6856f70   Markus Armbruster   [PATCH] oprofile:...
147
  		char buf[4];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
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   Andy Fleming   [PATCH] powerpc: ...
155

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
156
  		/*
555d97ac8   Andy Fleming   [PATCH] powerpc: ...
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   Linus Torvalds   Linux-2.6.12-rc2
162
163
164
  		 */
  		oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
  		oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
86a5cddbd   Stephen Rothwell   [PATCH] powerpc: ...
165

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
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   Linus Torvalds   Linux-2.6.12-rc2
171
172
173
174
  
  	/* Default to tracing both kernel and user */
  	sys.enable_kernel = 1;
  	sys.enable_user = 1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
175
176
177
178
179
180
  
  	return 0;
  }
  
  int __init oprofile_arch_init(struct oprofile_operations *ops)
  {
32a33994d   Anton Blanchard   [PATCH] ppc64: Fi...
181
  	if (!cur_cpu_spec->oprofile_cpu_type)
8fef0306f   Anton Blanchard   [PATCH] ppc64: Mo...
182
  		return -ENODEV;
32a33994d   Anton Blanchard   [PATCH] ppc64: Fi...
183

2191fe3e3   Kelly Daly   [POWERPC] re-enab...
184
185
  	if (firmware_has_feature(FW_FEATURE_ISERIES))
  		return -ENODEV;
32a33994d   Anton Blanchard   [PATCH] ppc64: Fi...
186
  	switch (cur_cpu_spec->oprofile_type) {
1caca371e   Benjamin Herrenschmidt   powerpc/oprofile:...
187
  #ifdef CONFIG_PPC_BOOK3S_64
1474855d0   Bob Nelson   [CELL] oprofile: ...
188
  #ifdef CONFIG_OPROFILE_CELL
18f2190d7   Maynard Johnson   [POWERPC] cell: A...
189
  		case PPC_OPROFILE_CELL:
ef66f7967   Ishizaki Kou   [POWERPC] Fix opr...
190
191
  			if (firmware_has_feature(FW_FEATURE_LPAR))
  				return -ENODEV;
18f2190d7   Maynard Johnson   [POWERPC] cell: A...
192
  			model = &op_model_cell;
1474855d0   Bob Nelson   [CELL] oprofile: ...
193
194
  			ops->sync_start = model->sync_start;
  			ops->sync_stop = model->sync_stop;
18f2190d7   Maynard Johnson   [POWERPC] cell: A...
195
196
  			break;
  #endif
7a45fb19c   Andy Whitcroft   [PATCH] powerpc: ...
197
  		case PPC_OPROFILE_RS64:
32a33994d   Anton Blanchard   [PATCH] ppc64: Fi...
198
199
  			model = &op_model_rs64;
  			break;
7a45fb19c   Andy Whitcroft   [PATCH] powerpc: ...
200
  		case PPC_OPROFILE_POWER4:
32a33994d   Anton Blanchard   [PATCH] ppc64: Fi...
201
202
  			model = &op_model_power4;
  			break;
25fc530ee   Olof Johansson   [POWERPC] pasemi:...
203
204
205
  		case PPC_OPROFILE_PA6T:
  			model = &op_model_pa6t;
  			break;
dd6c89f68   Andy Fleming   [POWERPC] Fix opr...
206
207
  #endif
  #ifdef CONFIG_6xx
7a45fb19c   Andy Whitcroft   [PATCH] powerpc: ...
208
  		case PPC_OPROFILE_G4:
32a33994d   Anton Blanchard   [PATCH] ppc64: Fi...
209
210
211
  			model = &op_model_7450;
  			break;
  #endif
39aef685a   Andy Fleming   [POWERPC] Made FS...
212
213
214
  #if defined(CONFIG_FSL_EMB_PERFMON)
  		case PPC_OPROFILE_FSL_EMB:
  			model = &op_model_fsl_emb;
32a33994d   Anton Blanchard   [PATCH] ppc64: Fi...
215
216
217
218
219
  			break;
  #endif
  		default:
  			return -ENODEV;
  	}
a6908cd00   Anton Blanchard   [PATCH] ppc64: Us...
220
  	model->num_counters = cur_cpu_spec->num_pmcs;
8fef0306f   Anton Blanchard   [PATCH] ppc64: Mo...
221
222
  
  	ops->cpu_type = cur_cpu_spec->oprofile_cpu_type;
86a5cddbd   Stephen Rothwell   [PATCH] powerpc: ...
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   Brian Rogan   [PATCH] powerpc: ...
228
  	ops->backtrace = op_powerpc_backtrace;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
229

5e1415c3f   Olof Johansson   [PATCH] powerpc: ...
230
231
  	printk(KERN_DEBUG "oprofile: using %s performance monitoring.
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
232
233
234
235
236
237
238
239
  	       ops->cpu_type);
  
  	return 0;
  }
  
  void oprofile_arch_exit(void)
  {
  }