linux-rt-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Leon Woestenberg" <leon.woestenberg@gmail.com>
To: "Ingo Molnar" <mingo@elte.hu>,
	"Linux Kernel list" <linux-kernel@vger.kernel.org>,
	"Peter Zijlstra" <a.p.zijlstra@chello.nl>,
	RT <linux-rt-users@vger.kernel.org>,
	"Steven Rostedt" <r
Subject: [PATCH -rt] {queue,schedule}_work_prio() allowing work priorities other than caller's priority
Date: Mon, 30 Jun 2008 17:52:06 +0200	[thread overview]
Message-ID: <c384c5ea0806300852p517c769ga17f1583fc55ad2d@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 112 bytes --]

Hello,

proposed patch for the -rt tree. queue_work() might be made a static
inline instead.

Regards,
-- 
Leon

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: schedule_work_prio.patch --]
[-- Type: text/x-diff; name=schedule_work_prio.patch, Size: 4709 bytes --]

Against 2.6.24.7-rt14. Tested on IXP4xx platform.

Adds schedule_work_prio() and queue_work_prio() so that work can be
scheduled with a different priority than the caller.

Under PREEMPT RT, schedule_work() and therefore queue_work() makes
the work inherit the caller's priority.

However, if a real-time kernel interrupt handler thread defers work it may want
the deferred work have lower priority so it does not contend for the cpu with
succeeding interrupt handling.

The faulty case was a non-FIFO serial driver that deferred LED blinking to
a workqueue using schedule_work(). However, that work used GPIO bitbanged I2C,
which uses 50 usecs udelay()s. With the work inheriting the serial IRQ priority,
it easily missed the ~60 usec deadline of 115200 bps communications.

This patch solves the issue with the IRQ using schedule_work_prio().

Signed-off-by: Leon Woestenberg <leon@sidebranch.com>

Index: linux-2.6.24/kernel/workqueue.c
===================================================================
--- linux-2.6.24.orig/kernel/workqueue.c	2008-06-30 17:12:05.000000000 +0200
+++ linux-2.6.24/kernel/workqueue.c	2008-06-30 17:25:03.000000000 +0200
@@ -163,9 +163,10 @@
 }
 
 /**
- * queue_work - queue work on a workqueue
+ * queue_work_prio - queue work on a workqueue and set work priority
  * @wq: workqueue to use
  * @work: work to queue
+ * @prio: priority of work
  *
  * Returns 0 if @work was already on a queue, non-zero otherwise.
  *
@@ -174,17 +175,36 @@
  *
  * Especially no such guarantee on PREEMPT_RT.
  */
-int fastcall queue_work(struct workqueue_struct *wq, struct work_struct *work)
+int fastcall queue_work_prio(struct workqueue_struct *wq,
+  struct work_struct *work, int prio)
 {
 	int ret = 0, cpu = raw_smp_processor_id();
 
 	if (!test_and_set_bit(WORK_STRUCT_PENDING, work_data_bits(work))) {
 		BUG_ON(!plist_node_empty(&work->entry));
-		__queue_work(wq_per_cpu(wq, cpu), work, current->normal_prio);
+		__queue_work(wq_per_cpu(wq, cpu), work, prio);
 		ret = 1;
 	}
 	return ret;
 }
+EXPORT_SYMBOL_GPL(queue_work_prio);
+
+/**
+ * queue_work - queue work on a workqueue. work inherits caller's prio.
+ * @wq: workqueue to use
+ * @work: work to queue
+ *
+ * Returns 0 if @work was already on a queue, non-zero otherwise.
+ *
+ * We queue the work to the CPU it was submitted, but there is no
+ * guarantee that it will be processed by that CPU.
+ *
+ * Especially no such guarantee on PREEMPT_RT.
+ */
+int fastcall queue_work(struct workqueue_struct *wq, struct work_struct *work)
+{
+  return queue_work_prio(wq, work, current->normal_prio);
+}
 EXPORT_SYMBOL_GPL(queue_work);
 
 void delayed_work_timer_fn(unsigned long __data)
@@ -627,7 +647,8 @@
  * schedule_work - put work task in global workqueue
  * @work: job to be done
  *
- * This puts a job in the kernel-global workqueue.
+ * This puts a job in the kernel-global workqueue. The job inherits the
+ * caller's priority.
  */
 int fastcall schedule_work(struct work_struct *work)
 {
@@ -636,6 +657,19 @@
 EXPORT_SYMBOL(schedule_work);
 
 /**
+ * schedule_work_prio - put work task in global workqueue, set work prio
+ * @work: job to be done
+ *
+ * This puts a job in the kernel-global workqueue. The job gets the specified
+ * priority.
+ */
+int fastcall schedule_work_prio(struct work_struct *work, int prio)
+{
+	return queue_work_prio(keventd_wq, work, prio);
+}
+EXPORT_SYMBOL(schedule_work_prio);
+
+/**
  * schedule_delayed_work - put work task in global workqueue after delay
  * @dwork: job to be done
  * @delay: number of jiffies to wait or 0 for immediate execution
Index: linux-2.6.24/include/linux/workqueue.h
===================================================================
--- linux-2.6.24.orig/include/linux/workqueue.h	2008-06-30 17:12:57.000000000 +0200
+++ linux-2.6.24/include/linux/workqueue.h	2008-06-30 17:30:34.000000000 +0200
@@ -185,6 +185,7 @@
 extern void destroy_workqueue(struct workqueue_struct *wq);
 
 extern int FASTCALL(queue_work(struct workqueue_struct *wq, struct work_struct *work));
+extern int FASTCALL(queue_work_prio(struct workqueue_struct *wq, struct work_struct *work, int prio));
 extern int FASTCALL(queue_delayed_work(struct workqueue_struct *wq,
 			struct delayed_work *work, unsigned long delay));
 extern int queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
@@ -194,6 +195,7 @@
 extern void flush_scheduled_work(void);
 
 extern int FASTCALL(schedule_work(struct work_struct *work));
+extern int FASTCALL(schedule_work_prio(struct work_struct *work, int prio));
 extern int FASTCALL(schedule_delayed_work(struct delayed_work *work,
 					unsigned long delay));
 extern int schedule_delayed_work_on(int cpu, struct delayed_work *work,

                 reply	other threads:[~2008-06-30 15:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=c384c5ea0806300852p517c769ga17f1583fc55ad2d@mail.gmail.com \
    --to=leon.woestenberg@gmail.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=mingo@elte.hu \
    /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;
as well as URLs for NNTP newsgroup(s).