Skip to content

Commit 60a51fb

Browse files
committed
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>
1 parent 70fe224 commit 60a51fb

4 files changed

Lines changed: 178 additions & 30 deletions

File tree

‎arch/sh/oprofile/Makefile‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ DRIVER_OBJS = $(addprefix ../../../drivers/oprofile/, \
66
oprofilefs.o oprofile_stats.o \
77
timer_int.o )
88

9-
profdrvr-y := op_model_null.o
9+
oprofile-y := $(DRIVER_OBJS) common.o backtrace.o
1010

11-
# SH7750-style performance counters exist across 7750/7750S and 7091.
12-
profdrvr-$(CONFIG_CPU_SUBTYPE_SH7750S) := op_model_sh7750.o
13-
profdrvr-$(CONFIG_CPU_SUBTYPE_SH7750) := op_model_sh7750.o
14-
profdrvr-$(CONFIG_CPU_SUBTYPE_SH7091) := op_model_sh7750.o
15-
16-
oprofile-y := $(DRIVER_OBJS) $(profdrvr-y)
11+
oprofile-$(CONFIG_CPU_SUBTYPE_SH7750S) += op_model_sh7750.o
12+
oprofile-$(CONFIG_CPU_SUBTYPE_SH7750) += op_model_sh7750.o
13+
oprofile-$(CONFIG_CPU_SUBTYPE_SH7091) += op_model_sh7750.o

‎arch/sh/oprofile/common.c‎

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

‎arch/sh/oprofile/op_impl.h‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 */

‎arch/sh/oprofile/op_model_null.c‎

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)