Skip to content

Commit fbb0e4d

Browse files
Sebastian Andrzej Siewioraegl
authored andcommitted
ia64: salinfo: use a waitqueue instead a sema down/up combo
The only purpose of down_try_lock() followed by up() seems to be to wake up a possible reader. This patch replaces it with a wake-queue. There is no locking around cpumask_empty() and the test is re-done in case there was no hit. With wait_event_interruptible_lock_irq(,&data_saved_lock) we would probably be able to get rid of the `retry` label. However we still can return CPU X which is valid now but later (after the lock dropped) the event may have been removed because the CPU went offline. Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Tony Luck <[email protected]>
1 parent 70f4f93 commit fbb0e4d

File tree

1 file changed

+10
-28
lines changed

1 file changed

+10
-28
lines changed

arch/ia64/kernel/salinfo.c

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ enum salinfo_state {
141141

142142
struct salinfo_data {
143143
cpumask_t cpu_event; /* which cpus have outstanding events */
144-
struct semaphore mutex;
144+
wait_queue_head_t read_wait;
145145
u8 *log_buffer;
146146
u64 log_size;
147147
u8 *oemdata; /* decoded oem data */
@@ -182,21 +182,6 @@ struct salinfo_platform_oemdata_parms {
182182
int ret;
183183
};
184184

185-
/* Kick the mutex that tells user space that there is work to do. Instead of
186-
* trying to track the state of the mutex across multiple cpus, in user
187-
* context, interrupt context, non-maskable interrupt context and hotplug cpu,
188-
* it is far easier just to grab the mutex if it is free then release it.
189-
*
190-
* This routine must be called with data_saved_lock held, to make the down/up
191-
* operation atomic.
192-
*/
193-
static void
194-
salinfo_work_to_do(struct salinfo_data *data)
195-
{
196-
(void)(down_trylock(&data->mutex) ?: 0);
197-
up(&data->mutex);
198-
}
199-
200185
static void
201186
salinfo_platform_oemdata_cpu(void *context)
202187
{
@@ -258,7 +243,7 @@ salinfo_log_wakeup(int type, u8 *buffer, u64 size, int irqsafe)
258243
}
259244
cpumask_set_cpu(smp_processor_id(), &data->cpu_event);
260245
if (irqsafe) {
261-
salinfo_work_to_do(data);
246+
wake_up_interruptible(&data->read_wait);
262247
spin_unlock_irqrestore(&data_saved_lock, flags);
263248
}
264249
}
@@ -271,14 +256,10 @@ extern void ia64_mlogbuf_dump(void);
271256
static void
272257
salinfo_timeout_check(struct salinfo_data *data)
273258
{
274-
unsigned long flags;
275259
if (!data->open)
276260
return;
277-
if (!cpumask_empty(&data->cpu_event)) {
278-
spin_lock_irqsave(&data_saved_lock, flags);
279-
salinfo_work_to_do(data);
280-
spin_unlock_irqrestore(&data_saved_lock, flags);
281-
}
261+
if (!cpumask_empty(&data->cpu_event))
262+
wake_up_interruptible(&data->read_wait);
282263
}
283264

284265
static void
@@ -308,10 +289,11 @@ salinfo_event_read(struct file *file, char __user *buffer, size_t count, loff_t
308289
int i, n, cpu = -1;
309290

310291
retry:
311-
if (cpumask_empty(&data->cpu_event) && down_trylock(&data->mutex)) {
292+
if (cpumask_empty(&data->cpu_event)) {
312293
if (file->f_flags & O_NONBLOCK)
313294
return -EAGAIN;
314-
if (down_interruptible(&data->mutex))
295+
if (wait_event_interruptible(data->read_wait,
296+
!cpumask_empty(&data->cpu_event)))
315297
return -EINTR;
316298
}
317299

@@ -510,7 +492,7 @@ salinfo_log_clear(struct salinfo_data *data, int cpu)
510492
if (data->state == STATE_LOG_RECORD) {
511493
spin_lock_irqsave(&data_saved_lock, flags);
512494
cpumask_set_cpu(cpu, &data->cpu_event);
513-
salinfo_work_to_do(data);
495+
wake_up_interruptible(&data->read_wait);
514496
spin_unlock_irqrestore(&data_saved_lock, flags);
515497
}
516498
return 0;
@@ -582,7 +564,7 @@ salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu
582564
i < ARRAY_SIZE(salinfo_data);
583565
++i, ++data) {
584566
cpumask_set_cpu(cpu, &data->cpu_event);
585-
salinfo_work_to_do(data);
567+
wake_up_interruptible(&data->read_wait);
586568
}
587569
spin_unlock_irqrestore(&data_saved_lock, flags);
588570
break;
@@ -640,7 +622,7 @@ salinfo_init(void)
640622
for (i = 0; i < ARRAY_SIZE(salinfo_log_name); i++) {
641623
data = salinfo_data + i;
642624
data->type = i;
643-
sema_init(&data->mutex, 1);
625+
init_waitqueue_head(&data->read_wait);
644626
dir = proc_mkdir(salinfo_log_name[i], salinfo_dir);
645627
if (!dir)
646628
continue;

0 commit comments

Comments
 (0)