diff options
author | Paul Mundt <lethal@linux-sh.org> | 2008-12-15 19:33:53 -0500 |
---|---|---|
committer | Paul Mundt <lethal@linux-sh.org> | 2008-12-22 04:44:43 -0500 |
commit | 60a51fbe5dd2baef0f35bcf79f25ac1ee239a660 (patch) | |
tree | 5183e3e22c526129f6fa9ddbe973116f2bed08b1 /arch/sh | |
parent | 70fe224743c11b57f9b63326313988fdcceb54df (diff) |
sh: oprofile: Refactor common setup code for multiple driver support.
This re-implements the old op_model_null code in to something more
generic, where multiple drivers, backtrace, etc. can all be interfaced.
Based largely on arch/mips/oprofile/common.c.
Signed-off-by: Paul Mundt <lethal@linux-sh.org>
Diffstat (limited to 'arch/sh')
-rw-r--r-- | arch/sh/oprofile/Makefile | 11 | ||||
-rw-r--r-- | arch/sh/oprofile/common.c | 141 | ||||
-rw-r--r-- | arch/sh/oprofile/op_impl.h | 33 | ||||
-rw-r--r-- | arch/sh/oprofile/op_model_null.c | 23 |
4 files changed, 178 insertions, 30 deletions
diff --git a/arch/sh/oprofile/Makefile b/arch/sh/oprofile/Makefile index 3d48f2721287..8e6eec91c14c 100644 --- a/arch/sh/oprofile/Makefile +++ b/arch/sh/oprofile/Makefile | |||
@@ -6,11 +6,8 @@ DRIVER_OBJS = $(addprefix ../../../drivers/oprofile/, \ | |||
6 | oprofilefs.o oprofile_stats.o \ | 6 | oprofilefs.o oprofile_stats.o \ |
7 | timer_int.o ) | 7 | timer_int.o ) |
8 | 8 | ||
9 | profdrvr-y := op_model_null.o | 9 | oprofile-y := $(DRIVER_OBJS) common.o backtrace.o |
10 | 10 | ||
11 | # SH7750-style performance counters exist across 7750/7750S and 7091. | 11 | oprofile-$(CONFIG_CPU_SUBTYPE_SH7750S) += op_model_sh7750.o |
12 | profdrvr-$(CONFIG_CPU_SUBTYPE_SH7750S) := op_model_sh7750.o | 12 | oprofile-$(CONFIG_CPU_SUBTYPE_SH7750) += op_model_sh7750.o |
13 | profdrvr-$(CONFIG_CPU_SUBTYPE_SH7750) := op_model_sh7750.o | 13 | oprofile-$(CONFIG_CPU_SUBTYPE_SH7091) += op_model_sh7750.o |
14 | profdrvr-$(CONFIG_CPU_SUBTYPE_SH7091) := op_model_sh7750.o | ||
15 | |||
16 | oprofile-y := $(DRIVER_OBJS) $(profdrvr-y) | ||
diff --git a/arch/sh/oprofile/common.c b/arch/sh/oprofile/common.c new file mode 100644 index 000000000000..a4d8c0c9a63c --- /dev/null +++ b/arch/sh/oprofile/common.c | |||
@@ -0,0 +1,141 @@ | |||
1 | /* | ||
2 | * arch/sh/oprofile/init.c | ||
3 | * | ||
4 | * Copyright (C) 2003 - 2008 Paul Mundt | ||
5 | * | ||
6 | * Based on arch/mips/oprofile/common.c: | ||
7 | * | ||
8 | * Copyright (C) 2004, 2005 Ralf Baechle | ||
9 | * Copyright (C) 2005 MIPS Technologies, Inc. | ||
10 | * | ||
11 | * This file is subject to the terms and conditions of the GNU General Public | ||
12 | * License. See the file "COPYING" in the main directory of this archive | ||
13 | * for more details. | ||
14 | */ | ||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/oprofile.h> | ||
17 | #include <linux/init.h> | ||
18 | #include <linux/errno.h> | ||
19 | #include <linux/smp.h> | ||
20 | #include <asm/processor.h> | ||
21 | #include "op_impl.h" | ||
22 | |||
23 | extern struct op_sh_model op_model_sh7750_ops __weak; | ||
24 | extern struct op_sh_model op_model_sh4a_ops __weak; | ||
25 | |||
26 | static struct op_sh_model *model; | ||
27 | |||
28 | static struct op_counter_config ctr[20]; | ||
29 | |||
30 | static int op_sh_setup(void) | ||
31 | { | ||
32 | /* Pre-compute the values to stuff in the hardware registers. */ | ||
33 | model->reg_setup(ctr); | ||
34 | |||
35 | /* Configure the registers on all cpus. */ | ||
36 | on_each_cpu(model->cpu_setup, NULL, 1); | ||
37 | |||
38 | return 0; | ||
39 | } | ||
40 | |||
41 | static int op_sh_create_files(struct super_block *sb, struct dentry *root) | ||
42 | { | ||
43 | int i, ret = 0; | ||
44 | |||
45 | for (i = 0; i < model->num_counters; i++) { | ||
46 | struct dentry *dir; | ||
47 | char buf[4]; | ||
48 | |||
49 | snprintf(buf, sizeof(buf), "%d", i); | ||
50 | dir = oprofilefs_mkdir(sb, root, buf); | ||
51 | |||
52 | ret |= oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled); | ||
53 | ret |= oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event); | ||
54 | ret |= oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel); | ||
55 | ret |= oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user); | ||
56 | |||
57 | if (model->create_files) | ||
58 | ret |= model->create_files(sb, dir); | ||
59 | else | ||
60 | ret |= oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count); | ||
61 | |||
62 | /* Dummy entries */ | ||
63 | ret |= oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask); | ||
64 | } | ||
65 | |||
66 | return ret; | ||
67 | } | ||
68 | |||
69 | static int op_sh_start(void) | ||
70 | { | ||
71 | /* Enable performance monitoring for all counters. */ | ||
72 | on_each_cpu(model->cpu_start, NULL, 1); | ||
73 | |||
74 | return 0; | ||
75 | } | ||
76 | |||
77 | static void op_sh_stop(void) | ||
78 | { | ||
79 | /* Disable performance monitoring for all counters. */ | ||
80 | on_each_cpu(model->cpu_stop, NULL, 1); | ||
81 | } | ||
82 | |||
83 | int __init oprofile_arch_init(struct oprofile_operations *ops) | ||
84 | { | ||
85 | struct op_sh_model *lmodel = NULL; | ||
86 | int ret; | ||
87 | |||
88 | switch (current_cpu_data.type) { | ||
89 | /* SH-4 types */ | ||
90 | case CPU_SH7750: | ||
91 | case CPU_SH7750S: | ||
92 | lmodel = &op_model_sh7750_ops; | ||
93 | break; | ||
94 | |||
95 | /* SH-4A types */ | ||
96 | case CPU_SH7763: | ||
97 | case CPU_SH7770: | ||
98 | case CPU_SH7780: | ||
99 | case CPU_SH7781: | ||
100 | case CPU_SH7785: | ||
101 | case CPU_SH7723: | ||
102 | case CPU_SHX3: | ||
103 | lmodel = &op_model_sh4a_ops; | ||
104 | break; | ||
105 | |||
106 | /* SH4AL-DSP types */ | ||
107 | case CPU_SH7343: | ||
108 | case CPU_SH7722: | ||
109 | case CPU_SH7366: | ||
110 | lmodel = &op_model_sh4a_ops; | ||
111 | break; | ||
112 | } | ||
113 | |||
114 | if (!lmodel) | ||
115 | return -ENODEV; | ||
116 | if (!(current_cpu_data.flags & CPU_HAS_PERF_COUNTER)) | ||
117 | return -ENODEV; | ||
118 | |||
119 | ret = lmodel->init(); | ||
120 | if (unlikely(ret != 0)) | ||
121 | return ret; | ||
122 | |||
123 | model = lmodel; | ||
124 | |||
125 | ops->setup = op_sh_setup; | ||
126 | ops->create_files = op_sh_create_files; | ||
127 | ops->start = op_sh_start; | ||
128 | ops->stop = op_sh_stop; | ||
129 | ops->cpu_type = lmodel->cpu_type; | ||
130 | |||
131 | printk(KERN_INFO "oprofile: using %s performance monitoring.\n", | ||
132 | lmodel->cpu_type); | ||
133 | |||
134 | return 0; | ||
135 | } | ||
136 | |||
137 | void oprofile_arch_exit(void) | ||
138 | { | ||
139 | if (model && model->exit) | ||
140 | model->exit(); | ||
141 | } | ||
diff --git a/arch/sh/oprofile/op_impl.h b/arch/sh/oprofile/op_impl.h new file mode 100644 index 000000000000..4d509975eba6 --- /dev/null +++ b/arch/sh/oprofile/op_impl.h | |||
@@ -0,0 +1,33 @@ | |||
1 | #ifndef __OP_IMPL_H | ||
2 | #define __OP_IMPL_H | ||
3 | |||
4 | /* Per-counter configuration as set via oprofilefs. */ | ||
5 | struct op_counter_config { | ||
6 | unsigned long enabled; | ||
7 | unsigned long event; | ||
8 | |||
9 | unsigned long long count; | ||
10 | |||
11 | /* Dummy values for userspace tool compliance */ | ||
12 | unsigned long kernel; | ||
13 | unsigned long user; | ||
14 | unsigned long unit_mask; | ||
15 | }; | ||
16 | |||
17 | /* Per-architecture configury and hooks. */ | ||
18 | struct op_sh_model { | ||
19 | void (*reg_setup)(struct op_counter_config *); | ||
20 | int (*create_files)(struct super_block *sb, struct dentry *dir); | ||
21 | void (*cpu_setup)(void *dummy); | ||
22 | int (*init)(void); | ||
23 | void (*exit)(void); | ||
24 | void (*cpu_start)(void *args); | ||
25 | void (*cpu_stop)(void *args); | ||
26 | char *cpu_type; | ||
27 | unsigned char num_counters; | ||
28 | }; | ||
29 | |||
30 | /* arch/sh/oprofile/common.c */ | ||
31 | extern void sh_backtrace(struct pt_regs * const regs, unsigned int depth); | ||
32 | |||
33 | #endif /* __OP_IMPL_H */ | ||
diff --git a/arch/sh/oprofile/op_model_null.c b/arch/sh/oprofile/op_model_null.c deleted file mode 100644 index a845b088edb4..000000000000 --- a/arch/sh/oprofile/op_model_null.c +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | /* | ||
2 | * arch/sh/oprofile/op_model_null.c | ||
3 | * | ||
4 | * Copyright (C) 2003 Paul Mundt | ||
5 | * | ||
6 | * This file is subject to the terms and conditions of the GNU General Public | ||
7 | * License. See the file "COPYING" in the main directory of this archive | ||
8 | * for more details. | ||
9 | */ | ||
10 | #include <linux/kernel.h> | ||
11 | #include <linux/oprofile.h> | ||
12 | #include <linux/init.h> | ||
13 | #include <linux/errno.h> | ||
14 | |||
15 | int __init oprofile_arch_init(struct oprofile_operations *ops) | ||
16 | { | ||
17 | return -ENODEV; | ||
18 | } | ||
19 | |||
20 | void oprofile_arch_exit(void) | ||
21 | { | ||
22 | } | ||
23 | |||