From 93ad79496c8831552d5f8ca7c182f149cc3cf19a Mon Sep 17 00:00:00 2001 From: Russell King Date: Thu, 16 Mar 2006 11:38:16 +0000 Subject: [ARM] Oprofile: Convert semaphore to mutex op_arm_sem is being used as a mutex, so convert it to use real mutexes. Signed-off-by: Russell King --- arch/arm/oprofile/common.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'arch/arm/oprofile/common.c') diff --git a/arch/arm/oprofile/common.c b/arch/arm/oprofile/common.c index 6f8bc1f0e6a..b57b6d11c9f 100644 --- a/arch/arm/oprofile/common.c +++ b/arch/arm/oprofile/common.c @@ -11,14 +11,14 @@ #include #include #include -#include +#include #include "op_counter.h" #include "op_arm_model.h" static struct op_arm_model_spec *op_arm_model; static int op_arm_enabled; -static struct semaphore op_arm_sem; +static DEFINE_MUTEX(op_arm_mutex); struct op_counter_config counter_config[OP_MAX_COUNTER]; @@ -57,40 +57,40 @@ static int op_arm_start(void) { int ret = -EBUSY; - down(&op_arm_sem); + mutex_lock(&op_arm_mutex); if (!op_arm_enabled) { ret = op_arm_model->start(); op_arm_enabled = !ret; } - up(&op_arm_sem); + mutex_unlock(&op_arm_mutex); return ret; } static void op_arm_stop(void) { - down(&op_arm_sem); + mutex_lock(&op_arm_mutex); if (op_arm_enabled) op_arm_model->stop(); op_arm_enabled = 0; - up(&op_arm_sem); + mutex_unlock(&op_arm_mutex); } #ifdef CONFIG_PM static int op_arm_suspend(struct sys_device *dev, pm_message_t state) { - down(&op_arm_sem); + mutex_lock(&op_arm_mutex); if (op_arm_enabled) op_arm_model->stop(); - up(&op_arm_sem); + mutex_unlock(&op_arm_mutex); return 0; } static int op_arm_resume(struct sys_device *dev) { - down(&op_arm_sem); + mutex_lock(&op_arm_mutex); if (op_arm_enabled && op_arm_model->start()) op_arm_enabled = 0; - up(&op_arm_sem); + mutex_unlock(&op_arm_mutex); return 0; } @@ -135,8 +135,6 @@ int __init oprofile_arch_init(struct oprofile_operations *ops) #endif if (spec) { - init_MUTEX(&op_arm_sem); - ret = spec->init(); if (ret < 0) return ret; @@ -163,4 +161,3 @@ void oprofile_arch_exit(void) op_arm_model = NULL; } } - -- cgit v1.2.3-70-g09d2 From ae92dc9f7bc9018f1d043f102747a1f1e4dd96fb Mon Sep 17 00:00:00 2001 From: Russell King Date: Thu, 16 Mar 2006 11:32:51 +0000 Subject: [ARM] Oprofile: dynamically allocate counter_config Signed-off-by: Russell King --- arch/arm/oprofile/common.c | 11 +++++++++-- arch/arm/oprofile/op_counter.h | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'arch/arm/oprofile/common.c') diff --git a/arch/arm/oprofile/common.c b/arch/arm/oprofile/common.c index b57b6d11c9f..de72902ad0c 100644 --- a/arch/arm/oprofile/common.c +++ b/arch/arm/oprofile/common.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -20,7 +21,7 @@ static struct op_arm_model_spec *op_arm_model; static int op_arm_enabled; static DEFINE_MUTEX(op_arm_mutex); -struct op_counter_config counter_config[OP_MAX_COUNTER]; +struct op_counter_config *counter_config; static int op_arm_create_files(struct super_block *sb, struct dentry *root) { @@ -28,7 +29,7 @@ static int op_arm_create_files(struct super_block *sb, struct dentry *root) for (i = 0; i < op_arm_model->num_counters; i++) { struct dentry *dir; - char buf[2]; + char buf[4]; snprintf(buf, sizeof buf, "%d", i); dir = oprofilefs_mkdir(sb, root, buf); @@ -139,6 +140,11 @@ int __init oprofile_arch_init(struct oprofile_operations *ops) if (ret < 0) return ret; + counter_config = kmalloc(sizeof(struct op_counter_config) * spec->num_counters, + GFP_KERNEL); + if (!counter_config) + return -ENOMEM; + op_arm_model = spec; init_driverfs(); ops->create_files = op_arm_create_files; @@ -160,4 +166,5 @@ void oprofile_arch_exit(void) exit_driverfs(); op_arm_model = NULL; } + kfree(counter_config); } diff --git a/arch/arm/oprofile/op_counter.h b/arch/arm/oprofile/op_counter.h index 153c1d467f2..8c5351d751c 100644 --- a/arch/arm/oprofile/op_counter.h +++ b/arch/arm/oprofile/op_counter.h @@ -24,6 +24,6 @@ struct op_counter_config { unsigned long user; }; -extern struct op_counter_config counter_config[]; +extern struct op_counter_config *counter_config; #endif /* OP_COUNTER_H */ -- cgit v1.2.3-70-g09d2 From 58e9ff56382bdce340d50b6ff22c422dc617106c Mon Sep 17 00:00:00 2001 From: Russell King Date: Mon, 20 Mar 2006 16:52:32 +0000 Subject: [ARM] Use kcalloc to allocate counter_config array rather than kmalloc We need this to be zero initialised. Since this is an array, use kcalloc rather than kzalloc or kmalloc. Signed-off-by: Russell King --- arch/arm/oprofile/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'arch/arm/oprofile/common.c') diff --git a/arch/arm/oprofile/common.c b/arch/arm/oprofile/common.c index de72902ad0c..6f833358cd0 100644 --- a/arch/arm/oprofile/common.c +++ b/arch/arm/oprofile/common.c @@ -140,7 +140,7 @@ int __init oprofile_arch_init(struct oprofile_operations *ops) if (ret < 0) return ret; - counter_config = kmalloc(sizeof(struct op_counter_config) * spec->num_counters, + counter_config = kcalloc(spec->num_counters, sizeof(struct op_counter_config), GFP_KERNEL); if (!counter_config) return -ENOMEM; -- cgit v1.2.3-70-g09d2