Commit d1e86d64 authored by Will Deacon's avatar Will Deacon Committed by Russell King

ARM: 6074/1: oprofile: convert from sysdev to platform device

This is a reworking of an original patch posted by Aaro Koskinen:

oprofile does not work with PM, because sysdev_suspend() is done with
interrupts disabled and oprofile needs a mutex. Implementing oprofile
as a platform device solves this problem.

Cc: Aaro Koskinen <aaro.koskinen@nokia.com>
Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
Signed-off-by: default avatarAaro Koskinen <aaro.koskinen@nokia.com>
Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
parent fe166148
...@@ -10,13 +10,14 @@ ...@@ -10,13 +10,14 @@
*/ */
#include <linux/cpumask.h> #include <linux/cpumask.h>
#include <linux/err.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/oprofile.h> #include <linux/oprofile.h>
#include <linux/perf_event.h> #include <linux/perf_event.h>
#include <linux/platform_device.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/sysdev.h>
#include <asm/stacktrace.h> #include <asm/stacktrace.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
...@@ -227,7 +228,7 @@ static void op_arm_stop(void) ...@@ -227,7 +228,7 @@ static void op_arm_stop(void)
} }
#ifdef CONFIG_PM #ifdef CONFIG_PM
static int op_arm_suspend(struct sys_device *dev, pm_message_t state) static int op_arm_suspend(struct platform_device *dev, pm_message_t state)
{ {
mutex_lock(&op_arm_mutex); mutex_lock(&op_arm_mutex);
if (op_arm_enabled) if (op_arm_enabled)
...@@ -236,7 +237,7 @@ static int op_arm_suspend(struct sys_device *dev, pm_message_t state) ...@@ -236,7 +237,7 @@ static int op_arm_suspend(struct sys_device *dev, pm_message_t state)
return 0; return 0;
} }
static int op_arm_resume(struct sys_device *dev) static int op_arm_resume(struct platform_device *dev)
{ {
mutex_lock(&op_arm_mutex); mutex_lock(&op_arm_mutex);
if (op_arm_enabled && op_perf_start()) if (op_arm_enabled && op_perf_start())
...@@ -245,34 +246,42 @@ static int op_arm_resume(struct sys_device *dev) ...@@ -245,34 +246,42 @@ static int op_arm_resume(struct sys_device *dev)
return 0; return 0;
} }
static struct sysdev_class oprofile_sysclass = { static struct platform_driver oprofile_driver = {
.name = "oprofile", .driver = {
.name = "arm-oprofile",
},
.resume = op_arm_resume, .resume = op_arm_resume,
.suspend = op_arm_suspend, .suspend = op_arm_suspend,
}; };
static struct sys_device device_oprofile = { static struct platform_device *oprofile_pdev;
.id = 0,
.cls = &oprofile_sysclass,
};
static int __init init_driverfs(void) static int __init init_driverfs(void)
{ {
int ret; int ret;
if (!(ret = sysdev_class_register(&oprofile_sysclass))) ret = platform_driver_register(&oprofile_driver);
ret = sysdev_register(&device_oprofile); if (ret)
goto out;
oprofile_pdev = platform_device_register_simple(
oprofile_driver.driver.name, 0, NULL, 0);
if (IS_ERR(oprofile_pdev)) {
ret = PTR_ERR(oprofile_pdev);
platform_driver_unregister(&oprofile_driver);
}
out:
return ret; return ret;
} }
static void exit_driverfs(void) static void exit_driverfs(void)
{ {
sysdev_unregister(&device_oprofile); platform_device_unregister(oprofile_pdev);
sysdev_class_unregister(&oprofile_sysclass); platform_driver_unregister(&oprofile_driver);
} }
#else #else
#define init_driverfs() do { } while (0) static int __init init_driverfs(void) { return 0; }
#define exit_driverfs() do { } while (0) #define exit_driverfs() do { } while (0)
#endif /* CONFIG_PM */ #endif /* CONFIG_PM */
...@@ -353,6 +362,12 @@ int __init oprofile_arch_init(struct oprofile_operations *ops) ...@@ -353,6 +362,12 @@ int __init oprofile_arch_init(struct oprofile_operations *ops)
return -ENOMEM; return -ENOMEM;
} }
ret = init_driverfs();
if (ret) {
kfree(counter_config);
return ret;
}
for_each_possible_cpu(cpu) { for_each_possible_cpu(cpu) {
perf_events[cpu] = kcalloc(perf_num_counters, perf_events[cpu] = kcalloc(perf_num_counters,
sizeof(struct perf_event *), GFP_KERNEL); sizeof(struct perf_event *), GFP_KERNEL);
...@@ -365,7 +380,6 @@ int __init oprofile_arch_init(struct oprofile_operations *ops) ...@@ -365,7 +380,6 @@ int __init oprofile_arch_init(struct oprofile_operations *ops)
} }
} }
init_driverfs();
ops->backtrace = arm_backtrace; ops->backtrace = arm_backtrace;
ops->create_files = op_arm_create_files; ops->create_files = op_arm_create_files;
ops->setup = op_arm_setup; ops->setup = op_arm_setup;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment