public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Greg KH <gregkh@suse.de>, LKML <linux-kernel@vger.kernel.org>,
	ACPI Devel Maling List <linux-acpi@vger.kernel.org>,
	"Linux-pm mailing list" <linux-pm@lists.linux-foundation.org>,
	Ingo Molnar <mingo@elte.hu>,
	Arjan van de Ven <arjan@infradead.org>
Subject: Re: [patch update] PM: Introduce core framework for run-time PM of I/O devices (rev. 6)
Date: Sun, 28 Jun 2009 12:25:26 +0200	[thread overview]
Message-ID: <200906281225.27596.rjw@sisk.pl> (raw)
In-Reply-To: <Pine.LNX.4.44L0.0906261707260.4155-100000@iolanthe.rowland.org>

On Friday 26 June 2009, Alan Stern wrote:
> On Fri, 26 Jun 2009, Rafael J. Wysocki wrote:
> 
> > > It occurs to me that the problem would be solved if were a cancel_work
> > > routine.  In the same vein, it ought to be possible for
> > > cancel_delayed_work to run in interrupt context.  I'll see what can be
> > > done.
> > 
> > Having looked at the workqueue code I'm not sure if there's a way to implement
> > that in a non-racy way.  Which may be the reason why there are no such
> > functions already. :-)
> 
> Well, I'll give it a try.

I did that too. :-)

It seems that if we do something like in the appended patch, then
cancel_work() and cancel_delayed_work_dequeue() can be used to simplify the
$subject patch slightly.

Best,
Rafael

---
 include/linux/workqueue.h |    2 ++
 kernel/workqueue.c        |   40 ++++++++++++++++++++++++++++++++++++----
 2 files changed, 38 insertions(+), 4 deletions(-)

Index: linux-2.6/include/linux/workqueue.h
===================================================================
--- linux-2.6.orig/include/linux/workqueue.h
+++ linux-2.6/include/linux/workqueue.h
@@ -223,6 +223,7 @@ int execute_in_process_context(work_func
 extern int flush_work(struct work_struct *work);
 
 extern int cancel_work_sync(struct work_struct *work);
+extern int cancel_work(struct work_struct *work);
 
 /*
  * Kill off a pending schedule_delayed_work().  Note that the work callback
@@ -241,6 +242,7 @@ static inline int cancel_delayed_work(st
 }
 
 extern int cancel_delayed_work_sync(struct delayed_work *work);
+extern int cancel_delayed_work_dequeue(struct delayed_work *dwork);
 
 /* Obsolete. use cancel_delayed_work_sync() */
 static inline
Index: linux-2.6/kernel/workqueue.c
===================================================================
--- linux-2.6.orig/kernel/workqueue.c
+++ linux-2.6/kernel/workqueue.c
@@ -536,7 +536,7 @@ static void wait_on_work(struct work_str
 		wait_on_cpu_work(per_cpu_ptr(wq->cpu_wq, cpu), work);
 }
 
-static int __cancel_work_timer(struct work_struct *work,
+static int __cancel_work_timer(struct work_struct *work, bool wait,
 				struct timer_list* timer)
 {
 	int ret;
@@ -545,7 +545,8 @@ static int __cancel_work_timer(struct wo
 		ret = (timer && likely(del_timer(timer)));
 		if (!ret)
 			ret = try_to_grab_pending(work);
-		wait_on_work(work);
+		if (wait)
+			wait_on_work(work);
 	} while (unlikely(ret < 0));
 
 	work_clear_pending(work);
@@ -575,11 +576,27 @@ static int __cancel_work_timer(struct wo
  */
 int cancel_work_sync(struct work_struct *work)
 {
-	return __cancel_work_timer(work, NULL);
+	return __cancel_work_timer(work, true, NULL);
 }
 EXPORT_SYMBOL_GPL(cancel_work_sync);
 
 /**
+ * cancel_work - kill off a work without waiting for its callback to terminate
+ * @work: the work which is to be canceled
+ *
+ * Returns true if @work was pending.
+ *
+ * cancel_work() will cancel the work if it is queued, but it will not block
+ * until the works callback completes.  Apart from this, it works like
+ * cancel_work_sync().
+ */
+int cancel_work(struct work_struct *work)
+{
+	return __cancel_work_timer(work, false, NULL);
+}
+EXPORT_SYMBOL_GPL(cancel_work);
+
+/**
  * cancel_delayed_work_sync - reliably kill off a delayed work.
  * @dwork: the delayed work struct
  *
@@ -590,10 +607,25 @@ EXPORT_SYMBOL_GPL(cancel_work_sync);
  */
 int cancel_delayed_work_sync(struct delayed_work *dwork)
 {
-	return __cancel_work_timer(&dwork->work, &dwork->timer);
+	return __cancel_work_timer(&dwork->work, true, &dwork->timer);
 }
 EXPORT_SYMBOL(cancel_delayed_work_sync);
 
+/**
+ * cancel_delayed_work_dequeue - kill off a delayed work.
+ * @dwork: the delayed work struct
+ *
+ * Returns true if @dwork was pending.
+ *
+ * cancel_delayed_work_dequeue() will not wait for the work's callback to
+ * terminate.  Apart from this it works like cancel_delayed_work_sync().
+ */
+int cancel_delayed_work_dequeue(struct delayed_work *dwork)
+{
+	return __cancel_work_timer(&dwork->work, false, &dwork->timer);
+}
+EXPORT_SYMBOL(cancel_delayed_work_dequeue);
+
 static struct workqueue_struct *keventd_wq __read_mostly;
 
 /**

  parent reply	other threads:[~2009-06-28 10:25 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-22 23:21 [PATCH] PM: Introduce core framework for run-time PM of I/O devices (rev. 3) Rafael J. Wysocki
2009-06-23 17:00 ` Rafael J. Wysocki
2009-06-23 17:10 ` Alan Stern
2009-06-24  0:08   ` Rafael J. Wysocki
2009-06-24  0:36     ` [patch update] PM: Introduce core framework for run-time PM of I/O devices (rev. 4) Rafael J. Wysocki
2009-06-24 19:24       ` [patch update] PM: Introduce core framework for run-time PM of I/O devices (rev. 5) Rafael J. Wysocki
2009-06-24 21:30         ` Alan Stern
2009-06-25 16:49           ` [linux-pm] " Alan Stern
2009-06-25 21:58             ` Rafael J. Wysocki
2009-06-25 23:17               ` Rafael J. Wysocki
2009-06-26 18:06               ` Alan Stern
2009-06-26 20:46                 ` [patch update] PM: Introduce core framework for run-time PM of I/O devices (rev. 6) Rafael J. Wysocki
2009-06-26 21:13                   ` Alan Stern
2009-06-26 22:32                     ` Rafael J. Wysocki
2009-06-27  1:25                       ` Alan Stern
2009-06-27 14:51                       ` Alan Stern
2009-06-27 21:51                         ` [patch update] PM: Introduce core framework for run-time PM of I/O devices (rev. 7) Rafael J. Wysocki
2009-06-28 10:25                     ` Rafael J. Wysocki [this message]
2009-06-28 21:07                       ` [patch update] PM: Introduce core framework for run-time PM of I/O devices (rev. 6) Alan Stern
2009-06-29  0:15                         ` Rafael J. Wysocki
2009-06-29  3:05                           ` Alan Stern
2009-06-29 14:09                             ` Rafael J. Wysocki
2009-06-29 14:29                               ` Alan Stern
2009-06-29 14:54                                 ` Rafael J. Wysocki
2009-06-29 15:27                                   ` Alan Stern
2009-06-29 15:55                                     ` Rafael J. Wysocki
2009-06-29 16:10                                       ` Alan Stern
2009-06-29 16:39                                         ` Rafael J. Wysocki
2009-06-29 17:29                                           ` Alan Stern
2009-06-29 18:25                                             ` Rafael J. Wysocki
2009-06-29 19:25                                               ` Alan Stern
2009-06-29 21:04                                                 ` Rafael J. Wysocki
2009-06-29 22:00                                                   ` Alan Stern
2009-06-29 22:50                                                     ` Rafael J. Wysocki
2009-06-30 15:10                                                       ` Alan Stern
2009-06-30 22:30                                                         ` [RFC] Run-time PM framework (was: Re: [patch update] PM: Introduce core framework for run-time PM of I/O devices (rev. 6)) Rafael J. Wysocki
2009-07-01 15:35                                                           ` Alan Stern
2009-07-01 22:19                                                             ` Rafael J. Wysocki
2009-07-02 15:42                                                               ` Rafael J. Wysocki
2009-07-02 15:55                                                               ` Alan Stern
2009-07-02 17:50                                                                 ` Rafael J. Wysocki
2009-07-02 19:53                                                                   ` Alan Stern
2009-07-02 23:05                                                                     ` Rafael J. Wysocki
2009-07-03 20:58                                                                       ` Alan Stern
2009-07-03 23:57                                                                         ` Rafael J. Wysocki
2009-07-04  3:12                                                                           ` Alan Stern
2009-07-04 21:27                                                                             ` Rafael J. Wysocki
2009-07-05 14:50                                                                               ` Alan Stern
2009-07-05 21:47                                                                                 ` Rafael J. Wysocki
2009-06-26 21:49           ` [patch update] PM: Introduce core framework for run-time PM of I/O devices (rev. 5) Rafael J. Wysocki
2009-06-25 14:57         ` Magnus Damm
2009-06-26 22:02           ` Rafael J. Wysocki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200906281225.27596.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=arjan@infradead.org \
    --cc=gregkh@suse.de \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=mingo@elte.hu \
    --cc=stern@rowland.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox