Skip to content

Commit 7c9cb38

Browse files
Tom ZanussiLinus Torvalds
Tom Zanussi
authored and
Linus Torvalds
committed
relay: use plain timer instead of delayed work
relay doesn't need to use schedule_delayed_work() for waking readers when a simple timer will do. Signed-off-by: Tom Zanussi <[email protected]> Cc: Satyam Sharma <[email protected]> Cc: Oleg Nesterov <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent d0758bc commit 7c9cb38

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

include/linux/relay.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include <linux/types.h>
1414
#include <linux/sched.h>
15+
#include <linux/timer.h>
1516
#include <linux/wait.h>
1617
#include <linux/list.h>
1718
#include <linux/fs.h>
@@ -38,7 +39,7 @@ struct rchan_buf
3839
size_t subbufs_consumed; /* count of sub-buffers consumed */
3940
struct rchan *chan; /* associated channel */
4041
wait_queue_head_t read_wait; /* reader wait queue */
41-
struct delayed_work wake_readers; /* reader wake-up work struct */
42+
struct timer_list timer; /* reader wake-up timer */
4243
struct dentry *dentry; /* channel file dentry */
4344
struct kref kref; /* channel buffer refcount */
4445
struct page **page_array; /* array of current buffer pages */

kernel/relay.c

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -310,16 +310,13 @@ static struct rchan_callbacks default_channel_callbacks = {
310310

311311
/**
312312
* wakeup_readers - wake up readers waiting on a channel
313-
* @work: work struct that contains the the channel buffer
313+
* @data: contains the the channel buffer
314314
*
315-
* This is the work function used to defer reader waking. The
316-
* reason waking is deferred is that calling directly from write
317-
* causes problems if you're writing from say the scheduler.
315+
* This is the timer function used to defer reader waking.
318316
*/
319-
static void wakeup_readers(struct work_struct *work)
317+
static void wakeup_readers(unsigned long data)
320318
{
321-
struct rchan_buf *buf =
322-
container_of(work, struct rchan_buf, wake_readers.work);
319+
struct rchan_buf *buf = (struct rchan_buf *)data;
323320
wake_up_interruptible(&buf->read_wait);
324321
}
325322

@@ -337,11 +334,9 @@ static void __relay_reset(struct rchan_buf *buf, unsigned int init)
337334
if (init) {
338335
init_waitqueue_head(&buf->read_wait);
339336
kref_init(&buf->kref);
340-
INIT_DELAYED_WORK(&buf->wake_readers, NULL);
341-
} else {
342-
cancel_delayed_work(&buf->wake_readers);
343-
flush_scheduled_work();
344-
}
337+
setup_timer(&buf->timer, wakeup_readers, (unsigned long)buf);
338+
} else
339+
del_timer_sync(&buf->timer);
345340

346341
buf->subbufs_produced = 0;
347342
buf->subbufs_consumed = 0;
@@ -447,8 +442,7 @@ static struct rchan_buf *relay_open_buf(struct rchan *chan, unsigned int cpu)
447442
static void relay_close_buf(struct rchan_buf *buf)
448443
{
449444
buf->finalized = 1;
450-
cancel_delayed_work(&buf->wake_readers);
451-
flush_scheduled_work();
445+
del_timer_sync(&buf->timer);
452446
kref_put(&buf->kref, relay_remove_buf);
453447
}
454448

@@ -608,11 +602,14 @@ size_t relay_switch_subbuf(struct rchan_buf *buf, size_t length)
608602
buf->dentry->d_inode->i_size += buf->chan->subbuf_size -
609603
buf->padding[old_subbuf];
610604
smp_mb();
611-
if (waitqueue_active(&buf->read_wait)) {
612-
PREPARE_DELAYED_WORK(&buf->wake_readers,
613-
wakeup_readers);
614-
schedule_delayed_work(&buf->wake_readers, 1);
615-
}
605+
if (waitqueue_active(&buf->read_wait))
606+
/*
607+
* Calling wake_up_interruptible() from here
608+
* will deadlock if we happen to be logging
609+
* from the scheduler (trying to re-grab
610+
* rq->lock), so defer it.
611+
*/
612+
__mod_timer(&buf->timer, jiffies + 1);
616613
}
617614

618615
old = buf->data;

0 commit comments

Comments
 (0)