Skip to content

Commit 59cc185

Browse files
Markus ArmbrusterLinus Torvalds
authored andcommitted
[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>
1 parent a2926b1 commit 59cc185

4 files changed

Lines changed: 25 additions & 25 deletions

File tree

‎drivers/oprofile/buffer_sync.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ static int module_load_notify(struct notifier_block * self, unsigned long val, v
108108
return 0;
109109

110110
/* FIXME: should we process all CPU buffers ? */
111-
down(&buffer_sem);
111+
mutex_lock(&buffer_mutex);
112112
add_event_entry(ESCAPE_CODE);
113113
add_event_entry(MODULE_LOADED_CODE);
114-
up(&buffer_sem);
114+
mutex_unlock(&buffer_mutex);
115115
#endif
116116
return 0;
117117
}
@@ -501,7 +501,7 @@ void sync_buffer(int cpu)
501501
sync_buffer_state state = sb_buffer_start;
502502
unsigned long available;
503503

504-
down(&buffer_sem);
504+
mutex_lock(&buffer_mutex);
505505

506506
add_cpu_switch(cpu);
507507

@@ -550,5 +550,5 @@ void sync_buffer(int cpu)
550550

551551
mark_done(cpu);
552552

553-
up(&buffer_sem);
553+
mutex_unlock(&buffer_mutex);
554554
}

‎drivers/oprofile/event_buffer.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424
#include "event_buffer.h"
2525
#include "oprofile_stats.h"
2626

27-
DECLARE_MUTEX(buffer_sem);
27+
DEFINE_MUTEX(buffer_mutex);
2828

2929
static unsigned long buffer_opened;
3030
static DECLARE_WAIT_QUEUE_HEAD(buffer_wait);
3131
static unsigned long * event_buffer;
3232
static unsigned long buffer_size;
3333
static unsigned long buffer_watershed;
3434
static size_t buffer_pos;
35-
/* atomic_t because wait_event checks it outside of buffer_sem */
35+
/* atomic_t because wait_event checks it outside of buffer_mutex */
3636
static atomic_t buffer_ready = ATOMIC_INIT(0);
3737

3838
/* Add an entry to the event buffer. When we
@@ -60,10 +60,10 @@ void add_event_entry(unsigned long value)
6060
*/
6161
void wake_up_buffer_waiter(void)
6262
{
63-
down(&buffer_sem);
63+
mutex_lock(&buffer_mutex);
6464
atomic_set(&buffer_ready, 1);
6565
wake_up(&buffer_wait);
66-
up(&buffer_sem);
66+
mutex_unlock(&buffer_mutex);
6767
}
6868

6969

@@ -162,7 +162,7 @@ static ssize_t event_buffer_read(struct file * file, char __user * buf,
162162
if (!atomic_read(&buffer_ready))
163163
return -EAGAIN;
164164

165-
down(&buffer_sem);
165+
mutex_lock(&buffer_mutex);
166166

167167
atomic_set(&buffer_ready, 0);
168168

@@ -177,7 +177,7 @@ static ssize_t event_buffer_read(struct file * file, char __user * buf,
177177
buffer_pos = 0;
178178

179179
out:
180-
up(&buffer_sem);
180+
mutex_unlock(&buffer_mutex);
181181
return retval;
182182
}
183183

‎drivers/oprofile/event_buffer.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#define EVENT_BUFFER_H
1212

1313
#include <linux/types.h>
14-
#include <asm/semaphore.h>
14+
#include <asm/mutex.h>
1515

1616
int alloc_event_buffer(void);
1717

@@ -46,6 +46,6 @@ extern struct file_operations event_buffer_fops;
4646
/* mutex between sync_cpu_buffers() and the
4747
* file reading code.
4848
*/
49-
extern struct semaphore buffer_sem;
49+
extern struct mutex buffer_mutex;
5050

5151
#endif /* EVENT_BUFFER_H */

‎drivers/oprofile/oprof.c‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <linux/init.h>
1313
#include <linux/oprofile.h>
1414
#include <linux/moduleparam.h>
15-
#include <asm/semaphore.h>
15+
#include <asm/mutex.h>
1616

1717
#include "oprof.h"
1818
#include "event_buffer.h"
@@ -25,7 +25,7 @@ struct oprofile_operations oprofile_ops;
2525
unsigned long oprofile_started;
2626
unsigned long backtrace_depth;
2727
static unsigned long is_setup;
28-
static DECLARE_MUTEX(start_sem);
28+
static DEFINE_MUTEX(start_mutex);
2929

3030
/* timer
3131
0 - use performance monitoring hardware if available
@@ -37,7 +37,7 @@ int oprofile_setup(void)
3737
{
3838
int err;
3939

40-
down(&start_sem);
40+
mutex_lock(&start_mutex);
4141

4242
if ((err = alloc_cpu_buffers()))
4343
goto out;
@@ -57,7 +57,7 @@ int oprofile_setup(void)
5757
goto out3;
5858

5959
is_setup = 1;
60-
up(&start_sem);
60+
mutex_unlock(&start_mutex);
6161
return 0;
6262

6363
out3:
@@ -68,7 +68,7 @@ int oprofile_setup(void)
6868
out1:
6969
free_cpu_buffers();
7070
out:
71-
up(&start_sem);
71+
mutex_unlock(&start_mutex);
7272
return err;
7373
}
7474

@@ -78,7 +78,7 @@ int oprofile_start(void)
7878
{
7979
int err = -EINVAL;
8080

81-
down(&start_sem);
81+
mutex_lock(&start_mutex);
8282

8383
if (!is_setup)
8484
goto out;
@@ -95,44 +95,44 @@ int oprofile_start(void)
9595

9696
oprofile_started = 1;
9797
out:
98-
up(&start_sem);
98+
mutex_unlock(&start_mutex);
9999
return err;
100100
}
101101

102102

103103
/* echo 0>/dev/oprofile/enable */
104104
void oprofile_stop(void)
105105
{
106-
down(&start_sem);
106+
mutex_lock(&start_mutex);
107107
if (!oprofile_started)
108108
goto out;
109109
oprofile_ops.stop();
110110
oprofile_started = 0;
111111
/* wake up the daemon to read what remains */
112112
wake_up_buffer_waiter();
113113
out:
114-
up(&start_sem);
114+
mutex_unlock(&start_mutex);
115115
}
116116

117117

118118
void oprofile_shutdown(void)
119119
{
120-
down(&start_sem);
120+
mutex_lock(&start_mutex);
121121
sync_stop();
122122
if (oprofile_ops.shutdown)
123123
oprofile_ops.shutdown();
124124
is_setup = 0;
125125
free_event_buffer();
126126
free_cpu_buffers();
127-
up(&start_sem);
127+
mutex_unlock(&start_mutex);
128128
}
129129

130130

131131
int oprofile_set_backtrace(unsigned long val)
132132
{
133133
int err = 0;
134134

135-
down(&start_sem);
135+
mutex_lock(&start_mutex);
136136

137137
if (oprofile_started) {
138138
err = -EBUSY;
@@ -147,7 +147,7 @@ int oprofile_set_backtrace(unsigned long val)
147147
backtrace_depth = val;
148148

149149
out:
150-
up(&start_sem);
150+
mutex_unlock(&start_mutex);
151151
return err;
152152
}
153153

0 commit comments

Comments
 (0)