blob: 2f33992f6dff00dbf54321a5f00089e73acd14e5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
Ralf Baechle54176732005-02-07 02:54:29 +00006 * Copyright (C) 2004, 2005 Ralf Baechle
7 * Copyright (C) 2005 MIPS Technologies, Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
Wu Zhangjine52dd9f2010-01-26 23:02:34 +08009#include <linux/compiler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/errno.h>
11#include <linux/init.h>
12#include <linux/oprofile.h>
13#include <linux/smp.h>
14#include <asm/cpu-info.h>
Ralf Baechle69f24d12013-09-17 10:25:47 +020015#include <asm/cpu-type.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17#include "op_impl.h"
18
Wu Zhangjine52dd9f2010-01-26 23:02:34 +080019extern struct op_mips_model op_model_mipsxx_ops __weak;
Wu Zhangjine52dd9f2010-01-26 23:02:34 +080020extern struct op_mips_model op_model_loongson2_ops __weak;
Huacai Chen89467e72014-11-04 14:15:07 +080021extern struct op_mips_model op_model_loongson3_ops __weak;
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23static struct op_mips_model *model;
24
25static struct op_counter_config ctr[20];
26
27static int op_mips_setup(void)
28{
29 /* Pre-compute the values to stuff in the hardware registers. */
30 model->reg_setup(ctr);
31
Ralf Baechle70342282013-01-22 12:59:30 +010032 /* Configure the registers on all cpus. */
Jens Axboe15c8b6c2008-05-09 09:39:44 +020033 on_each_cpu(model->cpu_setup, NULL, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Ralf Baechle70342282013-01-22 12:59:30 +010035 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036}
37
Al Viroef7bca12013-07-19 15:52:42 +040038static int op_mips_create_files(struct dentry *root)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039{
40 int i;
41
42 for (i = 0; i < model->num_counters; ++i) {
43 struct dentry *dir;
Markus Armbruster0c6856f2006-06-26 00:24:34 -070044 char buf[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46 snprintf(buf, sizeof buf, "%d", i);
Al Viroecde2822013-07-19 15:58:27 +040047 dir = oprofilefs_mkdir(root, buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Al Viro6af4ea02013-07-19 16:10:36 +040049 oprofilefs_create_ulong(dir, "enabled", &ctr[i].enabled);
50 oprofilefs_create_ulong(dir, "event", &ctr[i].event);
51 oprofilefs_create_ulong(dir, "count", &ctr[i].count);
52 oprofilefs_create_ulong(dir, "kernel", &ctr[i].kernel);
53 oprofilefs_create_ulong(dir, "user", &ctr[i].user);
54 oprofilefs_create_ulong(dir, "exl", &ctr[i].exl);
Ralf Baechle54176732005-02-07 02:54:29 +000055 /* Dummy. */
Al Viro6af4ea02013-07-19 16:10:36 +040056 oprofilefs_create_ulong(dir, "unit_mask", &ctr[i].unit_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 }
58
59 return 0;
60}
61
62static int op_mips_start(void)
63{
Jens Axboe15c8b6c2008-05-09 09:39:44 +020064 on_each_cpu(model->cpu_start, NULL, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66 return 0;
67}
68
69static void op_mips_stop(void)
70{
71 /* Disable performance monitoring for all counters. */
Jens Axboe15c8b6c2008-05-09 09:39:44 +020072 on_each_cpu(model->cpu_stop, NULL, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073}
74
Ralf Baechle54176732005-02-07 02:54:29 +000075int __init oprofile_arch_init(struct oprofile_operations *ops)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
77 struct op_mips_model *lmodel = NULL;
Ralf Baechle54176732005-02-07 02:54:29 +000078 int res;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Yanjiang Jinfa0c8792015-12-09 11:15:27 +080080 switch (boot_cpu_type()) {
Ralf Baechle20659882005-12-09 12:42:13 +000081 case CPU_5KC:
Steven J. Hill113c62d2012-07-06 23:56:00 +020082 case CPU_M14KC:
Steven J. Hillf8fa4812012-12-07 03:51:35 +000083 case CPU_M14KEC:
Ralf Baechle20659882005-12-09 12:42:13 +000084 case CPU_20KC:
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 case CPU_24K:
Ralf Baechle20659882005-12-09 12:42:13 +000086 case CPU_25KF:
Ralf Baechlefcfd9802006-02-01 17:54:30 +000087 case CPU_34K:
Ralf Baechle39b8d522008-04-28 17:14:26 +010088 case CPU_1004K:
Chris Dearmanc6209532006-05-02 14:08:46 +010089 case CPU_74K:
Steven J. Hill442e14a2014-01-17 15:03:50 -060090 case CPU_1074K:
Leonid Yegoshin26ab96d2013-11-27 10:07:53 +000091 case CPU_INTERAPTIV:
Leonid Yegoshin708ac4b2013-11-14 16:12:27 +000092 case CPU_PROAPTIV:
James Hogan8c7f6ba2014-01-22 16:19:41 +000093 case CPU_P5600:
Markos Chandras4e88a862015-07-09 10:40:36 +010094 case CPU_I6400:
Leonid Yegoshinf36c4722014-03-04 13:34:43 +000095 case CPU_M5150:
Kelvin Cheung2fa36392012-06-20 20:05:32 +010096 case CPU_LOONGSON1:
Mark Masonc03bc122006-01-17 12:06:32 -080097 case CPU_SB1:
98 case CPU_SB1A:
Ralf Baechle714cfe72006-10-23 00:44:02 +010099 case CPU_R10000:
100 case CPU_R12000:
101 case CPU_R14000:
Joshua Kinard30577392015-01-21 07:59:45 -0500102 case CPU_R16000:
Madhusudan Bhatc7833902012-10-31 12:01:27 +0000103 case CPU_XLR:
Atsushi Nemoto1acf1ca2006-05-23 16:42:38 +0900104 lmodel = &op_model_mipsxx_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 break;
106
Wu Zhangjin67b35e52009-07-02 23:25:46 +0800107 case CPU_LOONGSON2:
108 lmodel = &op_model_loongson2_ops;
109 break;
Huacai Chen89467e72014-11-04 14:15:07 +0800110 case CPU_LOONGSON3:
111 lmodel = &op_model_loongson3_ops;
112 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 };
114
Aaro Koskinen1b481422014-10-17 18:10:25 +0300115 /*
116 * Always set the backtrace. This allows unsupported CPU types to still
117 * use timer-based oprofile.
118 */
119 ops->backtrace = op_mips_backtrace;
120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 if (!lmodel)
Ralf Baechle54176732005-02-07 02:54:29 +0000122 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
Ralf Baechle54176732005-02-07 02:54:29 +0000124 res = lmodel->init();
125 if (res)
126 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128 model = lmodel;
129
Ralf Baechle54176732005-02-07 02:54:29 +0000130 ops->create_files = op_mips_create_files;
131 ops->setup = op_mips_setup;
Ralf Baechle70342282013-01-22 12:59:30 +0100132 //ops->shutdown = op_mips_shutdown;
Ralf Baechle54176732005-02-07 02:54:29 +0000133 ops->start = op_mips_start;
134 ops->stop = op_mips_stop;
135 ops->cpu_type = lmodel->cpu_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137 printk(KERN_INFO "oprofile: using %s performance monitoring.\n",
138 lmodel->cpu_type);
Ralf Baechle54176732005-02-07 02:54:29 +0000139
140 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141}
142
143void oprofile_arch_exit(void)
144{
Ralf Baechle49e31ca2006-04-24 10:48:54 +0100145 if (model)
146 model->exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147}