diff mbox series

kernel: workqueue: clarify wq_worker_last_func() caller requirements

Message ID 20190206150528.31198-1-hannes@cmpxchg.org (mailing list archive)
State New, archived
Headers show
Series kernel: workqueue: clarify wq_worker_last_func() caller requirements | expand

Commit Message

Johannes Weiner Feb. 6, 2019, 3:05 p.m. UTC
This function can only be called safely from very specific scheduler
contexts. Document those.

Suggested-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
---
 kernel/workqueue.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Andrew suggested including the explanations that came up during the
code review in the function doc. As the function has since been
merged, sending as follow-up for 5.1. Thanks!

Comments

Tejun Heo Feb. 6, 2019, 4:31 p.m. UTC | #1
On Wed, Feb 06, 2019 at 04:05:28PM +0100, Johannes Weiner wrote:
> This function can only be called safely from very specific scheduler
> contexts. Document those.
> 
> Suggested-by: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>

Acked-by: Tejun Heo <tj@kernel.org>

Thanks.
diff mbox series

Patch

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index fc5d23d752a5..23a67b9430da 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -918,6 +918,16 @@  struct task_struct *wq_worker_sleeping(struct task_struct *task)
  * CONTEXT:
  * spin_lock_irq(rq->lock)
  *
+ * This function is called during schedule() when a kworker is going
+ * to sleep. It's used by psi to identify aggregation workers during
+ * dequeuing, to allow periodic aggregation to shut-off when that
+ * worker is the last task in the system or cgroup to go to sleep.
+ *
+ * As this function doesn't involve any workqueue-related locking, it
+ * only returns stable values when called from inside the scheduler's
+ * queuing and dequeuing paths, when @task, which must be a kworker,
+ * is guaranteed to not be processing any works.
+ *
  * Return:
  * The last work function %current executed as a worker, NULL if it
  * hasn't executed any work yet.