@@ -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)
447442static 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