[PATCH] oprofile: convert from semaphores to mutexes
Signed-off-by: Markus Armbruster <armbru@redhat.com> Cc: Philippe Elie <phil.el@wanadoo.fr> Cc: John Levon <levon@movementarian.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
parent
a2926b1449
commit
59cc185ada
|
@ -108,10 +108,10 @@ static int module_load_notify(struct notifier_block * self, unsigned long val, v
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* FIXME: should we process all CPU buffers ? */
|
/* FIXME: should we process all CPU buffers ? */
|
||||||
down(&buffer_sem);
|
mutex_lock(&buffer_mutex);
|
||||||
add_event_entry(ESCAPE_CODE);
|
add_event_entry(ESCAPE_CODE);
|
||||||
add_event_entry(MODULE_LOADED_CODE);
|
add_event_entry(MODULE_LOADED_CODE);
|
||||||
up(&buffer_sem);
|
mutex_unlock(&buffer_mutex);
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -501,7 +501,7 @@ void sync_buffer(int cpu)
|
||||||
sync_buffer_state state = sb_buffer_start;
|
sync_buffer_state state = sb_buffer_start;
|
||||||
unsigned long available;
|
unsigned long available;
|
||||||
|
|
||||||
down(&buffer_sem);
|
mutex_lock(&buffer_mutex);
|
||||||
|
|
||||||
add_cpu_switch(cpu);
|
add_cpu_switch(cpu);
|
||||||
|
|
||||||
|
@ -550,5 +550,5 @@ void sync_buffer(int cpu)
|
||||||
|
|
||||||
mark_done(cpu);
|
mark_done(cpu);
|
||||||
|
|
||||||
up(&buffer_sem);
|
mutex_unlock(&buffer_mutex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include "event_buffer.h"
|
#include "event_buffer.h"
|
||||||
#include "oprofile_stats.h"
|
#include "oprofile_stats.h"
|
||||||
|
|
||||||
DECLARE_MUTEX(buffer_sem);
|
DEFINE_MUTEX(buffer_mutex);
|
||||||
|
|
||||||
static unsigned long buffer_opened;
|
static unsigned long buffer_opened;
|
||||||
static DECLARE_WAIT_QUEUE_HEAD(buffer_wait);
|
static DECLARE_WAIT_QUEUE_HEAD(buffer_wait);
|
||||||
|
@ -32,7 +32,7 @@ static unsigned long * event_buffer;
|
||||||
static unsigned long buffer_size;
|
static unsigned long buffer_size;
|
||||||
static unsigned long buffer_watershed;
|
static unsigned long buffer_watershed;
|
||||||
static size_t buffer_pos;
|
static size_t buffer_pos;
|
||||||
/* atomic_t because wait_event checks it outside of buffer_sem */
|
/* atomic_t because wait_event checks it outside of buffer_mutex */
|
||||||
static atomic_t buffer_ready = ATOMIC_INIT(0);
|
static atomic_t buffer_ready = ATOMIC_INIT(0);
|
||||||
|
|
||||||
/* Add an entry to the event buffer. When we
|
/* Add an entry to the event buffer. When we
|
||||||
|
@ -60,10 +60,10 @@ void add_event_entry(unsigned long value)
|
||||||
*/
|
*/
|
||||||
void wake_up_buffer_waiter(void)
|
void wake_up_buffer_waiter(void)
|
||||||
{
|
{
|
||||||
down(&buffer_sem);
|
mutex_lock(&buffer_mutex);
|
||||||
atomic_set(&buffer_ready, 1);
|
atomic_set(&buffer_ready, 1);
|
||||||
wake_up(&buffer_wait);
|
wake_up(&buffer_wait);
|
||||||
up(&buffer_sem);
|
mutex_unlock(&buffer_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ static ssize_t event_buffer_read(struct file * file, char __user * buf,
|
||||||
if (!atomic_read(&buffer_ready))
|
if (!atomic_read(&buffer_ready))
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
|
|
||||||
down(&buffer_sem);
|
mutex_lock(&buffer_mutex);
|
||||||
|
|
||||||
atomic_set(&buffer_ready, 0);
|
atomic_set(&buffer_ready, 0);
|
||||||
|
|
||||||
|
@ -177,7 +177,7 @@ static ssize_t event_buffer_read(struct file * file, char __user * buf,
|
||||||
buffer_pos = 0;
|
buffer_pos = 0;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
up(&buffer_sem);
|
mutex_unlock(&buffer_mutex);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#define EVENT_BUFFER_H
|
#define EVENT_BUFFER_H
|
||||||
|
|
||||||
#include <linux/types.h>
|
#include <linux/types.h>
|
||||||
#include <asm/semaphore.h>
|
#include <asm/mutex.h>
|
||||||
|
|
||||||
int alloc_event_buffer(void);
|
int alloc_event_buffer(void);
|
||||||
|
|
||||||
|
@ -46,6 +46,6 @@ extern struct file_operations event_buffer_fops;
|
||||||
/* mutex between sync_cpu_buffers() and the
|
/* mutex between sync_cpu_buffers() and the
|
||||||
* file reading code.
|
* file reading code.
|
||||||
*/
|
*/
|
||||||
extern struct semaphore buffer_sem;
|
extern struct mutex buffer_mutex;
|
||||||
|
|
||||||
#endif /* EVENT_BUFFER_H */
|
#endif /* EVENT_BUFFER_H */
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
#include <linux/oprofile.h>
|
#include <linux/oprofile.h>
|
||||||
#include <linux/moduleparam.h>
|
#include <linux/moduleparam.h>
|
||||||
#include <asm/semaphore.h>
|
#include <asm/mutex.h>
|
||||||
|
|
||||||
#include "oprof.h"
|
#include "oprof.h"
|
||||||
#include "event_buffer.h"
|
#include "event_buffer.h"
|
||||||
|
@ -25,7 +25,7 @@ struct oprofile_operations oprofile_ops;
|
||||||
unsigned long oprofile_started;
|
unsigned long oprofile_started;
|
||||||
unsigned long backtrace_depth;
|
unsigned long backtrace_depth;
|
||||||
static unsigned long is_setup;
|
static unsigned long is_setup;
|
||||||
static DECLARE_MUTEX(start_sem);
|
static DEFINE_MUTEX(start_mutex);
|
||||||
|
|
||||||
/* timer
|
/* timer
|
||||||
0 - use performance monitoring hardware if available
|
0 - use performance monitoring hardware if available
|
||||||
|
@ -37,7 +37,7 @@ int oprofile_setup(void)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
down(&start_sem);
|
mutex_lock(&start_mutex);
|
||||||
|
|
||||||
if ((err = alloc_cpu_buffers()))
|
if ((err = alloc_cpu_buffers()))
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -57,7 +57,7 @@ int oprofile_setup(void)
|
||||||
goto out3;
|
goto out3;
|
||||||
|
|
||||||
is_setup = 1;
|
is_setup = 1;
|
||||||
up(&start_sem);
|
mutex_unlock(&start_mutex);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
out3:
|
out3:
|
||||||
|
@ -68,7 +68,7 @@ out2:
|
||||||
out1:
|
out1:
|
||||||
free_cpu_buffers();
|
free_cpu_buffers();
|
||||||
out:
|
out:
|
||||||
up(&start_sem);
|
mutex_unlock(&start_mutex);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ int oprofile_start(void)
|
||||||
{
|
{
|
||||||
int err = -EINVAL;
|
int err = -EINVAL;
|
||||||
|
|
||||||
down(&start_sem);
|
mutex_lock(&start_mutex);
|
||||||
|
|
||||||
if (!is_setup)
|
if (!is_setup)
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -95,7 +95,7 @@ int oprofile_start(void)
|
||||||
|
|
||||||
oprofile_started = 1;
|
oprofile_started = 1;
|
||||||
out:
|
out:
|
||||||
up(&start_sem);
|
mutex_unlock(&start_mutex);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ out:
|
||||||
/* echo 0>/dev/oprofile/enable */
|
/* echo 0>/dev/oprofile/enable */
|
||||||
void oprofile_stop(void)
|
void oprofile_stop(void)
|
||||||
{
|
{
|
||||||
down(&start_sem);
|
mutex_lock(&start_mutex);
|
||||||
if (!oprofile_started)
|
if (!oprofile_started)
|
||||||
goto out;
|
goto out;
|
||||||
oprofile_ops.stop();
|
oprofile_ops.stop();
|
||||||
|
@ -111,20 +111,20 @@ void oprofile_stop(void)
|
||||||
/* wake up the daemon to read what remains */
|
/* wake up the daemon to read what remains */
|
||||||
wake_up_buffer_waiter();
|
wake_up_buffer_waiter();
|
||||||
out:
|
out:
|
||||||
up(&start_sem);
|
mutex_unlock(&start_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void oprofile_shutdown(void)
|
void oprofile_shutdown(void)
|
||||||
{
|
{
|
||||||
down(&start_sem);
|
mutex_lock(&start_mutex);
|
||||||
sync_stop();
|
sync_stop();
|
||||||
if (oprofile_ops.shutdown)
|
if (oprofile_ops.shutdown)
|
||||||
oprofile_ops.shutdown();
|
oprofile_ops.shutdown();
|
||||||
is_setup = 0;
|
is_setup = 0;
|
||||||
free_event_buffer();
|
free_event_buffer();
|
||||||
free_cpu_buffers();
|
free_cpu_buffers();
|
||||||
up(&start_sem);
|
mutex_unlock(&start_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ int oprofile_set_backtrace(unsigned long val)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
down(&start_sem);
|
mutex_lock(&start_mutex);
|
||||||
|
|
||||||
if (oprofile_started) {
|
if (oprofile_started) {
|
||||||
err = -EBUSY;
|
err = -EBUSY;
|
||||||
|
@ -147,7 +147,7 @@ int oprofile_set_backtrace(unsigned long val)
|
||||||
backtrace_depth = val;
|
backtrace_depth = val;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
up(&start_sem);
|
mutex_unlock(&start_mutex);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue