From: Tejun Heo <tj@kernel.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Arjan van de Ven <arjan@linux.intel.com>,
Ming Lei <ming.lei@canonical.com>,
Alex Riesen <raa.lkml@gmail.com>,
Alan Stern <stern@rowland.harvard.edu>,
Jens Axboe <axboe@kernel.dk>,
USB list <linux-usb@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Rusty Russell <rusty@rustcorp.com.au>
Subject: [PATCH 2/3] workqueue, async: implement work/async_current_func()
Date: Thu, 17 Jan 2013 17:25:03 -0800 [thread overview]
Message-ID: <20130118012503.GH16568@mtj.dyndns.org> (raw)
In-Reply-To: <CA+55aFzdf44QOZn4KS6tT09COFsmCg80sTah1XpeoErJxAzbRQ@mail.gmail.com>
Implement work/async_current_func() which query whether the current
task is a workqueue or async worker respectively and, if so, return
the current function being executed along with work / async item
related information.
This will be used to implement warning on synchronous request_module()
from async workers.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Arjan van de Ven <arjan@linux.intel.com>
---
include/linux/async.h | 2 ++
include/linux/workqueue.h | 1 +
kernel/async.c | 25 +++++++++++++++++++++++++
kernel/workqueue.c | 22 ++++++++++++++++++++++
4 files changed, 50 insertions(+)
diff --git a/include/linux/async.h b/include/linux/async.h
index 7a24fe9..6c49157 100644
--- a/include/linux/async.h
+++ b/include/linux/async.h
@@ -52,4 +52,6 @@ extern void async_synchronize_full_domain(struct async_domain *domain);
extern void async_synchronize_cookie(async_cookie_t cookie);
extern void async_synchronize_cookie_domain(async_cookie_t cookie,
struct async_domain *domain);
+extern async_func_ptr *async_current_func(void **datap,
+ async_cookie_t *cookiep);
#endif
diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index 2b58905..984fbef 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -428,6 +428,7 @@ extern void workqueue_set_max_active(struct workqueue_struct *wq,
extern bool workqueue_congested(unsigned int cpu, struct workqueue_struct *wq);
extern unsigned int work_cpu(struct work_struct *work);
extern unsigned int work_busy(struct work_struct *work);
+extern work_func_t work_current_func(struct work_struct **workp);
/*
* Like above, but uses del_timer() instead of del_timer_sync(). This means,
diff --git a/kernel/async.c b/kernel/async.c
index 9d31183..ed1eda0 100644
--- a/kernel/async.c
+++ b/kernel/async.c
@@ -337,3 +337,28 @@ void async_synchronize_cookie(async_cookie_t cookie)
async_synchronize_cookie_domain(cookie, &async_running);
}
EXPORT_SYMBOL_GPL(async_synchronize_cookie);
+
+/**
+ * async_current_func - determine the async entry %current is executing
+ * @datap: optional out param for the data
+ * @cookiep: optional out param for the cookie
+ *
+ * Determine whether %current is an async worker executing an async_entry
+ * and if so return the async function and, if @cookiep is not %NULL, the
+ * cookie. If %current isn't executing an async_entry, %NULL is returned.
+ */
+async_func_ptr *async_current_func(void **datap, async_cookie_t *cookiep)
+{
+ struct work_struct *work;
+ struct async_entry *entry;
+
+ if (work_current_func(&work) != async_run_entry_fn)
+ return NULL;
+
+ entry = container_of(work, struct async_entry, work);
+ if (datap)
+ *datap = entry->data;
+ if (cookiep)
+ *cookiep = entry->cookie;
+ return entry->func;
+}
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 6b99ac7..9fc1549 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -3492,6 +3492,28 @@ unsigned int work_busy(struct work_struct *work)
}
EXPORT_SYMBOL_GPL(work_busy);
+/**
+ * work_current_func - determine the work fn and item %current is executing
+ * @workp: optional out param for the current work item
+ *
+ * Determine whether %current is a kworker executing a work item and if so
+ * return the work function and, if @workp is not %NULL, the work item. If
+ * %current isn't executing a work item, %NULL is returned.
+ */
+work_func_t work_current_func(struct work_struct **workp)
+{
+ struct worker *worker;
+
+ /* am I a kworker? */
+ if (!(current->flags & PF_WQ_WORKER))
+ return NULL;
+
+ worker = kthread_data(current);
+ if (workp)
+ *workp = worker->current_work;
+ return worker->current_func;
+}
+
/*
* CPU hotplug.
*
--
1.8.0.2
next prev parent reply other threads:[~2013-01-18 1:25 UTC|newest]
Thread overview: 93+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-11 21:04 USB device cannot be reconnected and khubd "blocked for more than 120 seconds" Alex Riesen
2013-01-12 7:48 ` Alex Riesen
2013-01-12 9:18 ` Lan Tianyu
2013-01-12 17:37 ` Alan Stern
2013-01-12 19:39 ` Alex Riesen
2013-01-12 20:33 ` Alex Riesen
2013-01-12 22:52 ` Alan Stern
2013-01-13 12:09 ` Alex Riesen
2013-01-13 16:56 ` Alan Stern
2013-01-13 17:42 ` Alex Riesen
2013-01-13 19:16 ` Oliver Neukum
2013-01-14 2:39 ` Alan Stern
2013-01-14 16:43 ` Alex Riesen
2013-01-14 3:47 ` Ming Lei
2013-01-14 7:15 ` Ming Lei
2013-01-14 17:30 ` Linus Torvalds
2013-01-14 18:04 ` Alan Stern
2013-01-14 18:34 ` Linus Torvalds
2013-01-15 1:53 ` Ming Lei
2013-01-15 6:23 ` Ming Lei
2013-01-15 17:36 ` Linus Torvalds
2013-01-15 18:18 ` Linus Torvalds
2013-01-15 23:17 ` Tejun Heo
2013-01-15 18:20 ` Alan Stern
2013-01-15 18:39 ` Tejun Heo
2013-01-15 18:32 ` Tejun Heo
2013-01-15 20:18 ` Linus Torvalds
2013-01-15 23:50 ` Tejun Heo
2013-01-16 0:25 ` Arjan van de Ven
2013-01-16 0:35 ` Tejun Heo
2013-01-16 4:01 ` Alan Stern
2013-01-16 16:12 ` Tejun Heo
2013-01-16 17:01 ` Alan Stern
2013-01-16 17:37 ` Tejun Heo
2013-01-16 17:51 ` Alan Stern
2013-01-16 0:36 ` Linus Torvalds
2013-01-16 0:40 ` Linus Torvalds
2013-01-16 2:52 ` [PATCH] module, async: async_synchronize_full() on module init iff async is used Tejun Heo
2013-01-16 3:00 ` Linus Torvalds
2013-01-16 3:25 ` Tejun Heo
2013-01-16 3:37 ` Linus Torvalds
2013-01-16 16:22 ` Arjan van de Ven
2013-01-16 16:48 ` Tejun Heo
2013-01-16 17:03 ` Arjan van de Ven
2013-01-16 17:06 ` Linus Torvalds
2013-01-16 21:30 ` [PATCH 1/2] init, block: try to load default elevator module early during boot Tejun Heo
2013-01-17 18:05 ` Linus Torvalds
2013-01-17 18:38 ` Tejun Heo
2013-01-17 18:46 ` Linus Torvalds
2013-01-17 18:59 ` Tejun Heo
2013-01-17 19:00 ` Linus Torvalds
2013-01-18 1:24 ` [PATCH 1/3] workqueue: set PF_WQ_WORKER on rescuers Tejun Heo
2013-01-18 1:25 ` Tejun Heo [this message]
2013-01-18 2:47 ` [PATCH 2/3] workqueue, async: implement work/async_current_func() Linus Torvalds
2013-01-18 2:59 ` Tejun Heo
2013-01-18 3:04 ` Tejun Heo
2013-01-18 3:18 ` Linus Torvalds
2013-01-18 3:47 ` Tejun Heo
2013-01-18 22:08 ` [PATCH 1/5] workqueue: set PF_WQ_WORKER on rescuers Tejun Heo
2013-01-18 22:10 ` [PATCH 2/5] workqueue: rename kernel/workqueue_sched.h to kernel/workqueue_internal.h Tejun Heo
2013-01-18 22:11 ` [PATCH 3/5] workqueue: move struct worker definition to workqueue_internal.h Tejun Heo
2013-01-18 22:11 ` [PATCH 4/5] workqueue: implement current_is_async() Tejun Heo
2013-01-18 22:12 ` [PATCH 5/5] async, kmod: warn on synchronous request_module() from async workers Tejun Heo
2022-06-23 5:25 ` Saravana Kannan
2013-01-18 1:27 ` [PATCH 3/3] " Tejun Heo
2013-01-23 0:53 ` [PATCH v2 1/2] init, block: try to load default elevator module early during boot Tejun Heo
2013-01-16 21:31 ` [PATCH 2/2] block: don't request module during elevator init Tejun Heo
2013-01-23 0:51 ` [PATCH v2 " Tejun Heo
2013-01-16 3:30 ` [PATCH] module, async: async_synchronize_full() on module init iff async is used Ming Lei
2013-01-16 4:24 ` Rusty Russell
2013-01-16 11:36 ` Alex Riesen
2013-08-12 7:04 ` [3.8-rc3 -> 3.8-rc4 regression] " Jonathan Nieder
2013-08-12 15:09 ` Tejun Heo
2013-11-26 21:29 ` Josh Hunt
2013-11-26 21:53 ` Linus Torvalds
2013-11-26 22:12 ` Josh Hunt
2013-11-26 22:29 ` Tejun Heo
2013-12-03 14:28 ` Josh Hunt
2013-12-03 15:19 ` Tejun Heo
2013-12-04 23:01 ` Josh Hunt
2013-12-04 23:12 ` Tejun Heo
2013-11-26 22:30 ` Linus Torvalds
2013-01-16 0:44 ` USB device cannot be reconnected and khubd "blocked for more than 120 seconds" Tejun Heo
2013-01-16 17:19 ` [PATCH] async: fix __lowest_in_progress() Tejun Heo
2013-01-17 18:16 ` Linus Torvalds
2013-01-17 18:50 ` Tejun Heo
2013-01-23 0:15 ` [PATCH v2] " Tejun Heo
2013-01-23 0:22 ` Linus Torvalds
2013-01-16 3:05 ` USB device cannot be reconnected and khubd "blocked for more than 120 seconds" Ming Lei
2013-01-16 4:14 ` Linus Torvalds
2013-01-14 8:22 ` Oliver Neukum
2013-01-14 8:40 ` Ming Lei
2013-01-12 19:56 ` Alex Riesen
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=20130118012503.GH16568@mtj.dyndns.org \
--to=tj@kernel.org \
--cc=arjan@linux.intel.com \
--cc=axboe@kernel.dk \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=ming.lei@canonical.com \
--cc=raa.lkml@gmail.com \
--cc=rusty@rustcorp.com.au \
--cc=stern@rowland.harvard.edu \
--cc=torvalds@linux-foundation.org \
/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
all inboxes | Powered by JetHome®