2005-04-17 02:20:36 +04:00
|
|
|
/**
|
|
|
|
* @file common.c
|
|
|
|
*
|
|
|
|
* @remark Copyright 2004 Oprofile Authors
|
|
|
|
* @remark Read the file COPYING
|
|
|
|
*
|
|
|
|
* @author Zwane Mwaikambo
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/oprofile.h>
|
|
|
|
#include <linux/errno.h>
|
2006-03-16 14:32:51 +03:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/sysdev.h>
|
2006-03-16 14:38:16 +03:00
|
|
|
#include <linux/mutex.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
#include "op_counter.h"
|
|
|
|
#include "op_arm_model.h"
|
|
|
|
|
2005-10-28 17:54:21 +04:00
|
|
|
static struct op_arm_model_spec *op_arm_model;
|
|
|
|
static int op_arm_enabled;
|
2006-03-16 14:38:16 +03:00
|
|
|
static DEFINE_MUTEX(op_arm_mutex);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-03-16 14:32:51 +03:00
|
|
|
struct op_counter_config *counter_config;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-10-28 17:54:21 +04:00
|
|
|
static int op_arm_create_files(struct super_block *sb, struct dentry *root)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
2005-10-28 17:54:21 +04:00
|
|
|
for (i = 0; i < op_arm_model->num_counters; i++) {
|
2005-04-17 02:20:36 +04:00
|
|
|
struct dentry *dir;
|
2006-03-16 14:32:51 +03:00
|
|
|
char buf[4];
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
snprintf(buf, sizeof buf, "%d", i);
|
|
|
|
dir = oprofilefs_mkdir(sb, root, buf);
|
|
|
|
oprofilefs_create_ulong(sb, dir, "enabled", &counter_config[i].enabled);
|
|
|
|
oprofilefs_create_ulong(sb, dir, "event", &counter_config[i].event);
|
|
|
|
oprofilefs_create_ulong(sb, dir, "count", &counter_config[i].count);
|
|
|
|
oprofilefs_create_ulong(sb, dir, "unit_mask", &counter_config[i].unit_mask);
|
|
|
|
oprofilefs_create_ulong(sb, dir, "kernel", &counter_config[i].kernel);
|
|
|
|
oprofilefs_create_ulong(sb, dir, "user", &counter_config[i].user);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-10-28 17:54:21 +04:00
|
|
|
static int op_arm_setup(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
spin_lock(&oprofilefs_lock);
|
2005-10-28 17:54:21 +04:00
|
|
|
ret = op_arm_model->setup_ctrs();
|
2005-04-17 02:20:36 +04:00
|
|
|
spin_unlock(&oprofilefs_lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-10-28 17:54:21 +04:00
|
|
|
static int op_arm_start(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
int ret = -EBUSY;
|
|
|
|
|
2006-03-16 14:38:16 +03:00
|
|
|
mutex_lock(&op_arm_mutex);
|
2005-10-28 17:54:21 +04:00
|
|
|
if (!op_arm_enabled) {
|
|
|
|
ret = op_arm_model->start();
|
|
|
|
op_arm_enabled = !ret;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2006-03-16 14:38:16 +03:00
|
|
|
mutex_unlock(&op_arm_mutex);
|
2005-04-17 02:20:36 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-10-28 17:54:21 +04:00
|
|
|
static void op_arm_stop(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2006-03-16 14:38:16 +03:00
|
|
|
mutex_lock(&op_arm_mutex);
|
2005-10-28 17:54:21 +04:00
|
|
|
if (op_arm_enabled)
|
|
|
|
op_arm_model->stop();
|
|
|
|
op_arm_enabled = 0;
|
2006-03-16 14:38:16 +03:00
|
|
|
mutex_unlock(&op_arm_mutex);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2005-10-28 17:51:15 +04:00
|
|
|
#ifdef CONFIG_PM
|
2005-10-28 17:54:21 +04:00
|
|
|
static int op_arm_suspend(struct sys_device *dev, pm_message_t state)
|
2005-10-28 17:51:15 +04:00
|
|
|
{
|
2006-03-16 14:38:16 +03:00
|
|
|
mutex_lock(&op_arm_mutex);
|
2005-10-28 17:54:21 +04:00
|
|
|
if (op_arm_enabled)
|
|
|
|
op_arm_model->stop();
|
2006-03-16 14:38:16 +03:00
|
|
|
mutex_unlock(&op_arm_mutex);
|
2005-10-28 17:51:15 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-10-28 17:54:21 +04:00
|
|
|
static int op_arm_resume(struct sys_device *dev)
|
2005-10-28 17:51:15 +04:00
|
|
|
{
|
2006-03-16 14:38:16 +03:00
|
|
|
mutex_lock(&op_arm_mutex);
|
2005-10-28 17:54:21 +04:00
|
|
|
if (op_arm_enabled && op_arm_model->start())
|
|
|
|
op_arm_enabled = 0;
|
2006-03-16 14:38:16 +03:00
|
|
|
mutex_unlock(&op_arm_mutex);
|
2005-10-28 17:51:15 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct sysdev_class oprofile_sysclass = {
|
2007-12-20 04:09:39 +03:00
|
|
|
.name = "oprofile",
|
2005-10-28 17:54:21 +04:00
|
|
|
.resume = op_arm_resume,
|
|
|
|
.suspend = op_arm_suspend,
|
2005-10-28 17:51:15 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct sys_device device_oprofile = {
|
|
|
|
.id = 0,
|
|
|
|
.cls = &oprofile_sysclass,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init init_driverfs(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!(ret = sysdev_class_register(&oprofile_sysclass)))
|
|
|
|
ret = sysdev_register(&device_oprofile);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void exit_driverfs(void)
|
|
|
|
{
|
|
|
|
sysdev_unregister(&device_oprofile);
|
|
|
|
sysdev_class_unregister(&oprofile_sysclass);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define init_driverfs() do { } while (0)
|
|
|
|
#define exit_driverfs() do { } while (0)
|
|
|
|
#endif /* CONFIG_PM */
|
|
|
|
|
2005-10-28 17:56:04 +04:00
|
|
|
int __init oprofile_arch_init(struct oprofile_operations *ops)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-10-28 17:56:04 +04:00
|
|
|
struct op_arm_model_spec *spec = NULL;
|
|
|
|
int ret = -ENODEV;
|
|
|
|
|
2007-02-27 14:09:33 +03:00
|
|
|
ops->backtrace = arm_backtrace;
|
|
|
|
|
2005-10-28 17:56:04 +04:00
|
|
|
#ifdef CONFIG_CPU_XSCALE
|
|
|
|
spec = &op_xscale_spec;
|
|
|
|
#endif
|
|
|
|
|
2006-12-19 15:41:22 +03:00
|
|
|
#ifdef CONFIG_OPROFILE_ARMV6
|
|
|
|
spec = &op_armv6_spec;
|
|
|
|
#endif
|
|
|
|
|
2006-12-19 17:17:46 +03:00
|
|
|
#ifdef CONFIG_OPROFILE_MPCORE
|
|
|
|
spec = &op_mpcore_spec;
|
|
|
|
#endif
|
|
|
|
|
2008-08-12 22:07:39 +04:00
|
|
|
#ifdef CONFIG_OPROFILE_ARMV7
|
|
|
|
spec = &op_armv7_spec;
|
|
|
|
#endif
|
|
|
|
|
2005-10-28 17:56:04 +04:00
|
|
|
if (spec) {
|
2006-02-02 00:07:28 +03:00
|
|
|
ret = spec->init();
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2005-10-28 17:56:04 +04:00
|
|
|
|
2006-03-20 19:52:32 +03:00
|
|
|
counter_config = kcalloc(spec->num_counters, sizeof(struct op_counter_config),
|
2006-03-16 14:32:51 +03:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (!counter_config)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2005-10-28 17:56:04 +04:00
|
|
|
op_arm_model = spec;
|
|
|
|
init_driverfs();
|
|
|
|
ops->create_files = op_arm_create_files;
|
|
|
|
ops->setup = op_arm_setup;
|
|
|
|
ops->shutdown = op_arm_stop;
|
|
|
|
ops->start = op_arm_start;
|
|
|
|
ops->stop = op_arm_stop;
|
|
|
|
ops->cpu_type = op_arm_model->name;
|
|
|
|
printk(KERN_INFO "oprofile: using %s\n", spec->name);
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-10-28 17:56:04 +04:00
|
|
|
return ret;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2005-10-28 17:56:04 +04:00
|
|
|
void oprofile_arch_exit(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-10-28 17:54:21 +04:00
|
|
|
if (op_arm_model) {
|
2005-04-17 02:20:36 +04:00
|
|
|
exit_driverfs();
|
2005-10-28 17:54:21 +04:00
|
|
|
op_arm_model = NULL;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2006-03-16 14:32:51 +03:00
|
|
|
kfree(counter_config);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|