[PATCH] flush_work_sync vs. flush_scheduled_work Re: [PATCH] PHYLIB: IRQ event workqueue handling fixes

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Oleg Nesterov <oleg@...>
Cc: Maciej W. Rozycki <macro@...>, Andy Fleming <afleming@...>, Andrew Morton <akpm@...>, Jeff Garzik <jgarzik@...>, <netdev@...>, <linux-kernel@...>
Date: Thursday, October 18, 2007 - 3:05 am

After reading this and earlier threads about phylib's way of using
workqueue I think such a lighter and safer wrt. locking alternative
for flush_scheduled_work should be useful, but maybe it's only my
imagination.

So, let's ask Oleg Nesterov, whose solutions are here only
copy-cut-pasted & possibly abused by myslef.

--------->
Subject: flush_work_sync as an alternative for flush_scheduled_work

Similar to cancel_work_sync() but will only busy wait & block
(without cancel).

Signed-off-by: Jarek Poplawski <jarkao2@o2.pl>

---

 include/linux/workqueue.h |    1 +
 kernel/workqueue.c        |   24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+)

diff -Nurp 2.6.23-mm1-/include/linux/workqueue.h 2.6.23-mm1/include/linux/workqueue.h
--- 2.6.23-mm1-/include/linux/workqueue.h	2007-10-12 23:45:24.000000000 +0200
+++ 2.6.23-mm1/include/linux/workqueue.h	2007-10-17 20:55:26.000000000 +0200
@@ -192,6 +192,7 @@ extern void init_workqueues(void);
 int execute_in_process_context(work_func_t fn, struct execute_work *);
 
 extern int cancel_work_sync(struct work_struct *work);
+extern void flush_work_sync(struct work_struct *work);
 
 /*
  * Kill off a pending schedule_delayed_work().  Note that the work callback
diff -Nurp 2.6.23-mm1-/kernel/workqueue.c 2.6.23-mm1/kernel/workqueue.c
--- 2.6.23-mm1-/kernel/workqueue.c	2007-10-12 23:45:25.000000000 +0200
+++ 2.6.23-mm1/kernel/workqueue.c	2007-10-17 20:54:03.000000000 +0200
@@ -539,6 +539,30 @@ int cancel_delayed_work_sync(struct dela
 }
 EXPORT_SYMBOL(cancel_delayed_work_sync);
 
+/**
+ * flush_work_sync - block until a work_struct's callback has terminated
+ * @work: the work which is to be flushed
+ *
+ * Similar to cancel_work_sync() but will only busy wait (without cancel)
+ * if the work is queued. If the work's callback appears to be running,
+ * flush_work_sync() will block until it has completed (but doesn't block
+ * while other callbacks are running, like flush_scheduled_work() does).
+ *
+ * It is not allowed to use this function if the work re-queues itself.
+ */
+void flush_work_sync(struct work_struct *work)
+{
+	int ret;
+
+	do {
+		ret = work_pending(work);
+		wait_on_work(work);
+		if (ret)
+			cpu_relax();
+	} while (ret);
+}
+EXPORT_SYMBOL(flush_work_sync);
+
 static struct workqueue_struct *keventd_wq __read_mostly;
 
 /**
-
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] PHYLIB: IRQ event workqueue handling fixes, Maciej W. Rozycki, (Wed Sep 19, 10:38 am)
Re: [PATCH] PHYLIB: IRQ event workqueue handling fixes, Jarek Poplawski, (Mon Oct 15, 8:53 am)
Re: [PATCH] PHYLIB: IRQ event workqueue handling fixes, Maciej W. Rozycki, (Mon Oct 15, 1:03 pm)
Re: [PATCH] PHYLIB: IRQ event workqueue handling fixes, Jarek Poplawski, (Tue Oct 16, 2:21 am)
Re: [PATCH] PHYLIB: IRQ event workqueue handling fixes, Maciej W. Rozycki, (Tue Oct 16, 1:19 pm)
Re: [PATCH] PHYLIB: IRQ event workqueue handling fixes, Jarek Poplawski, (Wed Oct 17, 4:58 am)
Re: [PATCH] PHYLIB: IRQ event workqueue handling fixes, Maciej W. Rozycki, (Thu Oct 18, 7:30 am)
Re: [PATCH] PHYLIB: IRQ event workqueue handling fixes, Maciej W. Rozycki, (Fri Oct 19, 7:38 am)
Re: [PATCH] PHYLIB: IRQ event workqueue handling fixes, Jarek Poplawski, (Fri Oct 19, 10:39 am)
Re: [PATCH] PHYLIB: IRQ event workqueue handling fixes, Benjamin Herrenschmidt, (Fri Oct 19, 5:46 pm)
Re: [PATCH] PHYLIB: IRQ event workqueue handling fixes, Maciej W. Rozycki, (Fri Oct 19, 1:58 pm)
Re: [PATCH] PHYLIB: IRQ event workqueue handling fixes, Jarek Poplawski, (Fri Oct 19, 4:17 am)
Re: [PATCH] PHYLIB: IRQ event workqueue handling fixes, Maciej W. Rozycki, (Fri Oct 19, 8:57 am)
Re: [PATCH] PHYLIB: IRQ event workqueue handling fixes, Jarek Poplawski, (Thu Oct 18, 10:37 am)
Re: [PATCH] PHYLIB: IRQ event workqueue handling fixes, Maciej W. Rozycki, (Thu Oct 18, 11:31 am)
Re: [PATCH] PHYLIB: IRQ event workqueue handling fixes, Jarek Poplawski, (Thu Oct 18, 2:31 am)
Re: [PATCH] PHYLIB: IRQ event workqueue handling fixes, Maciej W. Rozycki, (Thu Oct 18, 7:37 am)
[PATCH] flush_work_sync vs. flush_scheduled_work Re: [PATCH]..., Jarek Poplawski, (Thu Oct 18, 3:05 am)
Re: [PATCH] flush_work_sync vs. flush_scheduled_work Re: [PA..., Maciej W. Rozycki, (Thu Oct 18, 11:58 am)
Re: [PATCH] PHYLIB: IRQ event workqueue handling fixes, Benjamin Herrenschmidt, (Wed Oct 17, 5:08 am)
Re: [PATCH] PHYLIB: IRQ event workqueue handling fixes, Jarek Poplawski, (Wed Oct 17, 5:09 am)
Re: [PATCH] PHYLIB: IRQ event workqueue handling fixes, Andrew Morton, (Thu Sep 20, 7:53 pm)
Re: [PATCH] PHYLIB: IRQ event workqueue handling fixes, Maciej W. Rozycki, (Fri Sep 21, 8:51 am)
Re: [PATCH] PHYLIB: IRQ event workqueue handling fixes, Andrew Morton, (Fri Sep 21, 2:42 pm)