From: James Bottomley <James.Bottomley@SteelEye.com>
To: Sergey Vlasov <vsu@altlinux.ru>
Cc: Jens Axboe <axboe@suse.de>,
Russell King <rmk+lkml@arm.linux.org.uk>,
Greg KH <greg@kroah.com>, Andrew Morton <akpm@osdl.org>,
Linus Torvalds <torvalds@osdl.org>,
linux-kernel@vger.kernel.org, "Brown, Len" <len.brown@intel.com>,
"David S. Miller" <davem@davemloft.net>,
linux-acpi@vger.kernel.org,
linux-usb-devel@lists.sourceforge.net, "Yu,
Luming" <luming.yu@intel.com>, Ben Castricum <lk@bencastricum.nl>,
sanjoy@mrao.cam.ac.uk, Helge Hafting <helgehaf@aitel.hist.no>,
"Carlo E. Prelz" <fluido@fluido.as>,
Gerrit Bruchh?user <gbruchhaeuser@gmx.de>,
Nicolas.Mailhot@LaPoste.net, Jaroslav Kysela <perex@suse.cz>,
Takashi Iwai <tiwai@suse.de>,
Patrizio Bassi <patrizio.bassi@gmail.com>,
Bj?rn Nilsson <bni.swe@gmail.com>,
Andrey Borzenkov <arvidjaar@mail.ru>,
"P. Christeas" <p_christ@hol.gr>, ghrt <ghrt@dial.kappa.ro>,
jinhong hu <jinhong.hu@gmail.com>, Andrew Vasquez <andre>
Subject: Re: [linux-usb-devel] Re: Linux 2.6.16-rc3
Date: Thu, 23 Feb 2006 12:43:43 -0600 [thread overview]
Message-ID: <1140720224.2809.10.camel@localhost.localdomain> (raw)
In-Reply-To: <1140359458.3103.11.camel@mulgrave.il.steeleye.com>
On Sun, 2006-02-19 at 08:30 -0600, James Bottomley wrote:
> Yes, thanks ... although I think there's still value to wrappering
> work_struct (a bit like kref wrappers atomic_t).
OK, so how about this?
James
[PATCH] add execute_in_process_context() API
We have several points in the SCSI stack (primarily for our device
functions) where we need to guarantee process context, but (given the
place where the last reference was released) we cannot guarantee this.
This API gets around the issue by executing the function directly if
the caller has process context, but scheduling a workqueue to execute
in process context if the caller doesn't have it.
Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
Index: BUILD-2.6/include/linux/workqueue.h
===================================================================
--- BUILD-2.6.orig/include/linux/workqueue.h 2006-02-20 08:57:43.000000000 -0600
+++ BUILD-2.6/include/linux/workqueue.h 2006-02-20 08:58:34.000000000 -0600
@@ -20,6 +20,10 @@
struct timer_list timer;
};
+struct execute_work {
+ struct work_struct work;
+};
+
#define __WORK_INITIALIZER(n, f, d) { \
.entry = { &(n).entry, &(n).entry }, \
.func = (f), \
@@ -74,6 +78,8 @@
void cancel_rearming_delayed_work(struct work_struct *work);
void cancel_rearming_delayed_workqueue(struct workqueue_struct *,
struct work_struct *);
+int execute_in_process_context(void (*fn)(void *), void *,
+ struct execute_work *);
/*
* Kill off a pending schedule_delayed_work(). Note that the work callback
Index: BUILD-2.6/kernel/workqueue.c
===================================================================
--- BUILD-2.6.orig/kernel/workqueue.c 2006-02-20 08:57:43.000000000 -0600
+++ BUILD-2.6/kernel/workqueue.c 2006-02-20 08:59:18.000000000 -0600
@@ -27,6 +27,7 @@
#include <linux/cpu.h>
#include <linux/notifier.h>
#include <linux/kthread.h>
+#include <linux/hardirq.h>
/*
* The per-CPU workqueue (if single thread, we always use the first
@@ -476,6 +477,34 @@
}
EXPORT_SYMBOL(cancel_rearming_delayed_work);
+/**
+ * execute_in_process_context - reliably execute the routine with user context
+ * @fn: the function to execute
+ * @data: data to pass to the function
+ * @ew: guaranteed storage for the execute work structure (must
+ * be available when the work executes)
+ *
+ * Executes the function immediately if process context is available,
+ * otherwise schedules the function for delayed execution.
+ *
+ * Returns: 0 - function was executed
+ * 1 - function was scheduled for execution
+ */
+int execute_in_process_context(void (*fn)(void *data), void *data,
+ struct execute_work *ew)
+{
+ if (!in_interrupt()) {
+ fn(data);
+ return 0;
+ }
+
+ INIT_WORK(&ew->work, fn, data);
+ schedule_work(&ew->work);
+
+ return 1;
+}
+EXPORT_SYMBOL_GPL(execute_in_process_context);
+
int keventd_up(void)
{
return keventd_wq != NULL;
next prev parent reply other threads:[~2006-02-23 18:43 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <Pine.LNX.4.64.0602121709240.3691@g5.osdl.org>
2006-02-13 3:05 ` Linux 2.6.16-rc3 Andrew Morton
2006-02-13 3:22 ` Trond Myklebust
2006-02-13 3:28 ` Sanjoy Mahajan
2006-02-13 3:36 ` Jeff Garzik
2006-02-13 4:40 ` James Bottomley
2006-02-13 5:20 ` S3 sleep regression bisected (was Re: Linux 2.6.16-rc3) Sanjoy Mahajan
2006-02-13 7:04 ` Linux 2.6.16-rc3 Arjan van de Ven
2006-02-13 8:11 ` Jens Axboe
2006-02-13 9:22 ` Patrizio Bassi
2006-02-13 12:02 ` Takashi Iwai
2006-02-13 12:37 ` Patrizio Bassi
2006-02-13 13:13 ` Takashi Iwai
2006-02-13 13:31 ` Patrizio Bassi
2006-02-13 14:15 ` Takashi Iwai
2006-02-13 14:34 ` Patrizio Bassi
2006-02-13 14:39 ` Takashi Iwai
2006-02-13 13:09 ` Rafael J. Wysocki
2006-02-13 13:51 ` Takashi Iwai
2006-02-13 19:33 ` Rafael J. Wysocki
2006-02-13 20:38 ` Greg KH
2006-02-14 16:34 ` James Bottomley
2006-02-16 1:56 ` James Bottomley
2006-02-16 17:12 ` Russell King
2006-02-16 17:34 ` Stefan Richter
2006-02-16 17:57 ` James Bottomley
2006-02-16 18:09 ` Russell King
2006-02-16 18:14 ` James Bottomley
2006-02-16 18:18 ` Russell King
2006-02-16 19:09 ` James Bottomley
2006-02-16 20:01 ` Jens Axboe
2006-02-18 0:42 ` James Bottomley
2006-02-18 1:00 ` Greg KH
2006-02-18 2:12 ` Roland Dreier
2006-02-18 5:30 ` Matthew Wilcox
2006-02-18 10:03 ` [linux-usb-devel] " Sergey Vlasov
2006-02-19 14:30 ` James Bottomley
2006-02-23 18:43 ` James Bottomley [this message]
2006-02-18 20:16 ` Alan Stern
2006-02-19 13:51 ` James Bottomley
2006-02-18 21:06 ` Helge Hafting
2006-02-15 5:58 [linux-usb-devel] " Yu, Luming
2006-02-18 23:20 ` Sanjoy Mahajan
-- strict thread matches above, loose matches on Subject: below --
2006-02-20 8:07 Yu, Luming
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=1140720224.2809.10.camel@localhost.localdomain \
--to=james.bottomley@steeleye.com \
--cc=Nicolas.Mailhot@LaPoste.net \
--cc=akpm@osdl.org \
--cc=arvidjaar@mail.ru \
--cc=axboe@suse.de \
--cc=bni.swe@gmail.com \
--cc=davem@davemloft.net \
--cc=fluido@fluido.as \
--cc=gbruchhaeuser@gmx.de \
--cc=ghrt@dial.kappa.ro \
--cc=greg@kroah.com \
--cc=helgehaf@aitel.hist.no \
--cc=jinhong.hu@gmail.com \
--cc=len.brown@intel.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb-devel@lists.sourceforge.net \
--cc=lk@bencastricum.nl \
--cc=luming.yu@intel.com \
--cc=p_christ@hol.gr \
--cc=patrizio.bassi@gmail.com \
--cc=perex@suse.cz \
--cc=rmk+lkml@arm.linux.org.uk \
--cc=sanjoy@mrao.cam.ac.uk \
--cc=tiwai@suse.de \
--cc=torvalds@osdl.org \
--cc=vsu@altlinux.ru \
/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