xref: /OK3568_Linux_fs/kernel/arch/mips/oprofile/common.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * This file is subject to the terms and conditions of the GNU General Public
3*4882a593Smuzhiyun  * License.  See the file "COPYING" in the main directory of this archive
4*4882a593Smuzhiyun  * for more details.
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * Copyright (C) 2004, 2005 Ralf Baechle
7*4882a593Smuzhiyun  * Copyright (C) 2005 MIPS Technologies, Inc.
8*4882a593Smuzhiyun  */
9*4882a593Smuzhiyun #include <linux/compiler.h>
10*4882a593Smuzhiyun #include <linux/errno.h>
11*4882a593Smuzhiyun #include <linux/init.h>
12*4882a593Smuzhiyun #include <linux/oprofile.h>
13*4882a593Smuzhiyun #include <linux/smp.h>
14*4882a593Smuzhiyun #include <asm/cpu-info.h>
15*4882a593Smuzhiyun #include <asm/cpu-type.h>
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #include "op_impl.h"
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun extern struct op_mips_model op_model_mipsxx_ops __weak;
20*4882a593Smuzhiyun extern struct op_mips_model op_model_loongson2_ops __weak;
21*4882a593Smuzhiyun extern struct op_mips_model op_model_loongson3_ops __weak;
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun static struct op_mips_model *model;
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun static struct op_counter_config ctr[20];
26*4882a593Smuzhiyun 
op_mips_setup(void)27*4882a593Smuzhiyun static int op_mips_setup(void)
28*4882a593Smuzhiyun {
29*4882a593Smuzhiyun 	/* Pre-compute the values to stuff in the hardware registers.  */
30*4882a593Smuzhiyun 	model->reg_setup(ctr);
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun 	/* Configure the registers on all cpus.	 */
33*4882a593Smuzhiyun 	on_each_cpu(model->cpu_setup, NULL, 1);
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun 	return 0;
36*4882a593Smuzhiyun }
37*4882a593Smuzhiyun 
op_mips_create_files(struct dentry * root)38*4882a593Smuzhiyun static int op_mips_create_files(struct dentry *root)
39*4882a593Smuzhiyun {
40*4882a593Smuzhiyun 	int i;
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun 	for (i = 0; i < model->num_counters; ++i) {
43*4882a593Smuzhiyun 		struct dentry *dir;
44*4882a593Smuzhiyun 		char buf[4];
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun 		snprintf(buf, sizeof buf, "%d", i);
47*4882a593Smuzhiyun 		dir = oprofilefs_mkdir(root, buf);
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun 		oprofilefs_create_ulong(dir, "enabled", &ctr[i].enabled);
50*4882a593Smuzhiyun 		oprofilefs_create_ulong(dir, "event", &ctr[i].event);
51*4882a593Smuzhiyun 		oprofilefs_create_ulong(dir, "count", &ctr[i].count);
52*4882a593Smuzhiyun 		oprofilefs_create_ulong(dir, "kernel", &ctr[i].kernel);
53*4882a593Smuzhiyun 		oprofilefs_create_ulong(dir, "user", &ctr[i].user);
54*4882a593Smuzhiyun 		oprofilefs_create_ulong(dir, "exl", &ctr[i].exl);
55*4882a593Smuzhiyun 		/* Dummy.  */
56*4882a593Smuzhiyun 		oprofilefs_create_ulong(dir, "unit_mask", &ctr[i].unit_mask);
57*4882a593Smuzhiyun 	}
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun 	return 0;
60*4882a593Smuzhiyun }
61*4882a593Smuzhiyun 
op_mips_start(void)62*4882a593Smuzhiyun static int op_mips_start(void)
63*4882a593Smuzhiyun {
64*4882a593Smuzhiyun 	on_each_cpu(model->cpu_start, NULL, 1);
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun 	return 0;
67*4882a593Smuzhiyun }
68*4882a593Smuzhiyun 
op_mips_stop(void)69*4882a593Smuzhiyun static void op_mips_stop(void)
70*4882a593Smuzhiyun {
71*4882a593Smuzhiyun 	/* Disable performance monitoring for all counters.  */
72*4882a593Smuzhiyun 	on_each_cpu(model->cpu_stop, NULL, 1);
73*4882a593Smuzhiyun }
74*4882a593Smuzhiyun 
oprofile_arch_init(struct oprofile_operations * ops)75*4882a593Smuzhiyun int __init oprofile_arch_init(struct oprofile_operations *ops)
76*4882a593Smuzhiyun {
77*4882a593Smuzhiyun 	struct op_mips_model *lmodel = NULL;
78*4882a593Smuzhiyun 	int res;
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun 	switch (boot_cpu_type()) {
81*4882a593Smuzhiyun 	case CPU_5KC:
82*4882a593Smuzhiyun 	case CPU_M14KC:
83*4882a593Smuzhiyun 	case CPU_M14KEC:
84*4882a593Smuzhiyun 	case CPU_20KC:
85*4882a593Smuzhiyun 	case CPU_24K:
86*4882a593Smuzhiyun 	case CPU_25KF:
87*4882a593Smuzhiyun 	case CPU_34K:
88*4882a593Smuzhiyun 	case CPU_1004K:
89*4882a593Smuzhiyun 	case CPU_74K:
90*4882a593Smuzhiyun 	case CPU_1074K:
91*4882a593Smuzhiyun 	case CPU_INTERAPTIV:
92*4882a593Smuzhiyun 	case CPU_PROAPTIV:
93*4882a593Smuzhiyun 	case CPU_P5600:
94*4882a593Smuzhiyun 	case CPU_I6400:
95*4882a593Smuzhiyun 	case CPU_M5150:
96*4882a593Smuzhiyun 	case CPU_LOONGSON32:
97*4882a593Smuzhiyun 	case CPU_SB1:
98*4882a593Smuzhiyun 	case CPU_SB1A:
99*4882a593Smuzhiyun 	case CPU_R10000:
100*4882a593Smuzhiyun 	case CPU_R12000:
101*4882a593Smuzhiyun 	case CPU_R14000:
102*4882a593Smuzhiyun 	case CPU_R16000:
103*4882a593Smuzhiyun 	case CPU_XLR:
104*4882a593Smuzhiyun 		lmodel = &op_model_mipsxx_ops;
105*4882a593Smuzhiyun 		break;
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun 	case CPU_LOONGSON2EF:
108*4882a593Smuzhiyun 		lmodel = &op_model_loongson2_ops;
109*4882a593Smuzhiyun 		break;
110*4882a593Smuzhiyun 	case CPU_LOONGSON64:
111*4882a593Smuzhiyun 		lmodel = &op_model_loongson3_ops;
112*4882a593Smuzhiyun 		break;
113*4882a593Smuzhiyun 	}
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun 	/*
116*4882a593Smuzhiyun 	 * Always set the backtrace. This allows unsupported CPU types to still
117*4882a593Smuzhiyun 	 * use timer-based oprofile.
118*4882a593Smuzhiyun 	 */
119*4882a593Smuzhiyun 	ops->backtrace = op_mips_backtrace;
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun 	if (!lmodel)
122*4882a593Smuzhiyun 		return -ENODEV;
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun 	res = lmodel->init();
125*4882a593Smuzhiyun 	if (res)
126*4882a593Smuzhiyun 		return res;
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun 	model = lmodel;
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun 	ops->create_files	= op_mips_create_files;
131*4882a593Smuzhiyun 	ops->setup		= op_mips_setup;
132*4882a593Smuzhiyun 	//ops->shutdown		= op_mips_shutdown;
133*4882a593Smuzhiyun 	ops->start		= op_mips_start;
134*4882a593Smuzhiyun 	ops->stop		= op_mips_stop;
135*4882a593Smuzhiyun 	ops->cpu_type		= lmodel->cpu_type;
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun 	printk(KERN_INFO "oprofile: using %s performance monitoring.\n",
138*4882a593Smuzhiyun 	       lmodel->cpu_type);
139*4882a593Smuzhiyun 
140*4882a593Smuzhiyun 	return 0;
141*4882a593Smuzhiyun }
142*4882a593Smuzhiyun 
oprofile_arch_exit(void)143*4882a593Smuzhiyun void oprofile_arch_exit(void)
144*4882a593Smuzhiyun {
145*4882a593Smuzhiyun 	if (model)
146*4882a593Smuzhiyun 		model->exit();
147*4882a593Smuzhiyun }
148