Stephen Rothwell | 86a5cdd | 2005-09-19 23:24:08 +1000 | [diff] [blame] | 1 | /* |
| 2 | * PPC 64 oprofile support: |
| 3 | * Copyright (C) 2004 Anton Blanchard <anton@au.ibm.com>, IBM |
| 4 | * PPC 32 oprofile support: (based on PPC 64 support) |
| 5 | * Copyright (C) Freescale Semiconductor, Inc 2004 |
| 6 | * Author: Andy Fleming |
| 7 | * |
| 8 | * Based on alpha version. |
| 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> |
Stephen Rothwell | 86a5cdd | 2005-09-19 23:24:08 +1000 | [diff] [blame] | 17 | #include <linux/init.h> |
| 18 | #include <linux/smp.h> |
| 19 | #include <linux/errno.h> |
| 20 | #include <asm/ptrace.h> |
| 21 | #include <asm/system.h> |
Stephen Rothwell | 86a5cdd | 2005-09-19 23:24:08 +1000 | [diff] [blame] | 22 | #include <asm/pmc.h> |
Stephen Rothwell | 86a5cdd | 2005-09-19 23:24:08 +1000 | [diff] [blame] | 23 | #include <asm/cputable.h> |
| 24 | #include <asm/oprofile_impl.h> |
| 25 | |
| 26 | static struct op_powerpc_model *model; |
| 27 | |
| 28 | static struct op_counter_config ctr[OP_MAX_COUNTER]; |
| 29 | static struct op_system_config sys; |
| 30 | |
Stephen Rothwell | 86a5cdd | 2005-09-19 23:24:08 +1000 | [diff] [blame] | 31 | static void op_handle_interrupt(struct pt_regs *regs) |
| 32 | { |
| 33 | model->handle_interrupt(regs, ctr); |
| 34 | } |
| 35 | |
| 36 | static int op_powerpc_setup(void) |
| 37 | { |
Stephen Rothwell | 86a5cdd | 2005-09-19 23:24:08 +1000 | [diff] [blame] | 38 | int err; |
| 39 | |
| 40 | /* Grab the hardware */ |
| 41 | err = reserve_pmc_hardware(op_handle_interrupt); |
| 42 | if (err) |
| 43 | return err; |
Stephen Rothwell | 86a5cdd | 2005-09-19 23:24:08 +1000 | [diff] [blame] | 44 | |
| 45 | /* Pre-compute the values to stuff in the hardware registers. */ |
| 46 | model->reg_setup(ctr, &sys, model->num_counters); |
| 47 | |
| 48 | /* Configure the registers on all cpus. */ |
Stephen Rothwell | 86a5cdd | 2005-09-19 23:24:08 +1000 | [diff] [blame] | 49 | on_each_cpu(model->cpu_setup, NULL, 0, 1); |
Stephen Rothwell | 86a5cdd | 2005-09-19 23:24:08 +1000 | [diff] [blame] | 50 | |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | static void op_powerpc_shutdown(void) |
| 55 | { |
Stephen Rothwell | 86a5cdd | 2005-09-19 23:24:08 +1000 | [diff] [blame] | 56 | release_pmc_hardware(); |
Stephen Rothwell | 86a5cdd | 2005-09-19 23:24:08 +1000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | static void op_powerpc_cpu_start(void *dummy) |
| 60 | { |
| 61 | model->start(ctr); |
| 62 | } |
| 63 | |
| 64 | static int op_powerpc_start(void) |
| 65 | { |
| 66 | on_each_cpu(op_powerpc_cpu_start, NULL, 0, 1); |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | static inline void op_powerpc_cpu_stop(void *dummy) |
| 71 | { |
| 72 | model->stop(); |
| 73 | } |
| 74 | |
| 75 | static void op_powerpc_stop(void) |
| 76 | { |
| 77 | on_each_cpu(op_powerpc_cpu_stop, NULL, 0, 1); |
| 78 | } |
| 79 | |
| 80 | static int op_powerpc_create_files(struct super_block *sb, struct dentry *root) |
| 81 | { |
| 82 | int i; |
| 83 | |
Andy Fleming | 555d97a | 2005-12-15 20:02:04 -0600 | [diff] [blame] | 84 | #ifdef CONFIG_PPC64 |
Stephen Rothwell | 86a5cdd | 2005-09-19 23:24:08 +1000 | [diff] [blame] | 85 | /* |
| 86 | * There is one mmcr0, mmcr1 and mmcra for setting the events for |
| 87 | * all of the counters. |
| 88 | */ |
| 89 | oprofilefs_create_ulong(sb, root, "mmcr0", &sys.mmcr0); |
| 90 | oprofilefs_create_ulong(sb, root, "mmcr1", &sys.mmcr1); |
| 91 | oprofilefs_create_ulong(sb, root, "mmcra", &sys.mmcra); |
Andy Fleming | 555d97a | 2005-12-15 20:02:04 -0600 | [diff] [blame] | 92 | #endif |
Stephen Rothwell | 86a5cdd | 2005-09-19 23:24:08 +1000 | [diff] [blame] | 93 | |
| 94 | for (i = 0; i < model->num_counters; ++i) { |
| 95 | struct dentry *dir; |
| 96 | char buf[3]; |
| 97 | |
| 98 | snprintf(buf, sizeof buf, "%d", i); |
| 99 | dir = oprofilefs_mkdir(sb, root, buf); |
| 100 | |
| 101 | oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled); |
| 102 | oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event); |
| 103 | oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count); |
Andy Fleming | 555d97a | 2005-12-15 20:02:04 -0600 | [diff] [blame] | 104 | |
Stephen Rothwell | 86a5cdd | 2005-09-19 23:24:08 +1000 | [diff] [blame] | 105 | /* |
Andy Fleming | 555d97a | 2005-12-15 20:02:04 -0600 | [diff] [blame] | 106 | * Classic PowerPC doesn't support per-counter |
| 107 | * control like this, but the options are |
| 108 | * expected, so they remain. For Freescale |
| 109 | * Book-E style performance monitors, we do |
| 110 | * support them. |
Stephen Rothwell | 86a5cdd | 2005-09-19 23:24:08 +1000 | [diff] [blame] | 111 | */ |
Stephen Rothwell | 86a5cdd | 2005-09-19 23:24:08 +1000 | [diff] [blame] | 112 | oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel); |
| 113 | oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user); |
| 114 | |
Stephen Rothwell | 86a5cdd | 2005-09-19 23:24:08 +1000 | [diff] [blame] | 115 | oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask); |
| 116 | } |
| 117 | |
| 118 | oprofilefs_create_ulong(sb, root, "enable_kernel", &sys.enable_kernel); |
| 119 | oprofilefs_create_ulong(sb, root, "enable_user", &sys.enable_user); |
Andy Fleming | 555d97a | 2005-12-15 20:02:04 -0600 | [diff] [blame] | 120 | #ifdef CONFIG_PPC64 |
Stephen Rothwell | 86a5cdd | 2005-09-19 23:24:08 +1000 | [diff] [blame] | 121 | oprofilefs_create_ulong(sb, root, "backtrace_spinlocks", |
| 122 | &sys.backtrace_spinlocks); |
Andy Fleming | 555d97a | 2005-12-15 20:02:04 -0600 | [diff] [blame] | 123 | #endif |
Stephen Rothwell | 86a5cdd | 2005-09-19 23:24:08 +1000 | [diff] [blame] | 124 | |
| 125 | /* Default to tracing both kernel and user */ |
| 126 | sys.enable_kernel = 1; |
| 127 | sys.enable_user = 1; |
Andy Fleming | 555d97a | 2005-12-15 20:02:04 -0600 | [diff] [blame] | 128 | #ifdef CONFIG_PPC64 |
Stephen Rothwell | 86a5cdd | 2005-09-19 23:24:08 +1000 | [diff] [blame] | 129 | /* Turn on backtracing through spinlocks by default */ |
| 130 | sys.backtrace_spinlocks = 1; |
Andy Fleming | 555d97a | 2005-12-15 20:02:04 -0600 | [diff] [blame] | 131 | #endif |
Stephen Rothwell | 86a5cdd | 2005-09-19 23:24:08 +1000 | [diff] [blame] | 132 | |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | int __init oprofile_arch_init(struct oprofile_operations *ops) |
| 137 | { |
Anton Blanchard | 32a3399 | 2006-01-09 15:41:31 +1100 | [diff] [blame] | 138 | if (!cur_cpu_spec->oprofile_cpu_type) |
Stephen Rothwell | 86a5cdd | 2005-09-19 23:24:08 +1000 | [diff] [blame] | 139 | return -ENODEV; |
Anton Blanchard | 32a3399 | 2006-01-09 15:41:31 +1100 | [diff] [blame] | 140 | |
| 141 | switch (cur_cpu_spec->oprofile_type) { |
| 142 | #ifdef CONFIG_PPC64 |
| 143 | case RS64: |
| 144 | model = &op_model_rs64; |
| 145 | break; |
| 146 | case POWER4: |
| 147 | model = &op_model_power4; |
| 148 | break; |
| 149 | #else |
| 150 | case G4: |
| 151 | model = &op_model_7450; |
| 152 | break; |
| 153 | #endif |
| 154 | #ifdef CONFIG_FSL_BOOKE |
| 155 | case BOOKE: |
| 156 | model = &op_model_fsl_booke; |
| 157 | break; |
| 158 | #endif |
| 159 | default: |
| 160 | return -ENODEV; |
| 161 | } |
| 162 | |
Stephen Rothwell | 86a5cdd | 2005-09-19 23:24:08 +1000 | [diff] [blame] | 163 | model->num_counters = cur_cpu_spec->num_pmcs; |
| 164 | |
| 165 | ops->cpu_type = cur_cpu_spec->oprofile_cpu_type; |
Stephen Rothwell | 86a5cdd | 2005-09-19 23:24:08 +1000 | [diff] [blame] | 166 | ops->create_files = op_powerpc_create_files; |
| 167 | ops->setup = op_powerpc_setup; |
| 168 | ops->shutdown = op_powerpc_shutdown; |
| 169 | ops->start = op_powerpc_start; |
| 170 | ops->stop = op_powerpc_stop; |
| 171 | |
| 172 | printk(KERN_INFO "oprofile: using %s performance monitoring.\n", |
| 173 | ops->cpu_type); |
| 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | void oprofile_arch_exit(void) |
| 179 | { |
Stephen Rothwell | 86a5cdd | 2005-09-19 23:24:08 +1000 | [diff] [blame] | 180 | } |