mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFC PATCH] workqueue: introduce WORK_STRUCT_TIMER_PENDING_BIT.
@ 2024-12-30  6:45 Imran Khan
  2025-01-03 22:18 ` Tejun Heo
  0 siblings, 1 reply; 3+ messages in thread
From: Imran Khan @ 2024-12-30  6:45 UTC (permalink / raw)
  To: tj, jiangshanlai; +Cc: linux-kernel

Currently WORK_STRUCT_PENDING_BIT can indicate a work_struct that is
already made it to work list of a worker_pool or a work_struct that has
not yet made it there because it comes from a delayed_work whose timer
has not expired yet.

Use WORK_STRUCT_TIMER_PENDING_BIT to distinguish between these two
states of work_struct.

Signed-off-by: Imran Khan <imran.f.khan@oracle.com>
---
I have kept the patch as RFC, because this change is not fixing a bug.
It makes WORK_STRUCT_PENDING_BIT less ambiguous and helps in debugging,
by indicating where one should look for this pending work.

 include/linux/workqueue.h | 1 +
 kernel/workqueue.c        | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index b0dc957c3e560..2d327d9e9b53a 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -27,6 +27,7 @@ enum work_bits {
 	WORK_STRUCT_INACTIVE_BIT,	/* work item is inactive */
 	WORK_STRUCT_PWQ_BIT,		/* data points to pwq */
 	WORK_STRUCT_LINKED_BIT,		/* next work is linked to this one */
+	WORK_STRUCT_TIMER_PENDING_BIT,	/* timer pending for delayed work */
 #ifdef CONFIG_DEBUG_OBJECTS_WORK
 	WORK_STRUCT_STATIC_BIT,		/* static initializer (debugobjects) */
 #endif
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index eb71e3d9d16dd..454382a9a1585 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -2481,6 +2481,7 @@ void delayed_work_timer_fn(struct timer_list *t)
 {
 	struct delayed_work *dwork = from_timer(dwork, t, timer);
 
+	clear_bit(WORK_STRUCT_TIMER_PENDING_BIT, work_data_bits(&dwork->work));
 	/* should have been called from irqsafe timer with irq already off */
 	__queue_work(dwork->cpu, dwork->wq, &dwork->work);
 }
@@ -2511,6 +2512,7 @@ static void __queue_delayed_work(int cpu, struct workqueue_struct *wq,
 	dwork->wq = wq;
 	dwork->cpu = cpu;
 	timer->expires = jiffies + delay;
+	set_bit(WORK_STRUCT_TIMER_PENDING_BIT, work_data_bits(work));
 
 	if (housekeeping_enabled(HK_TYPE_TIMER)) {
 		/* If the current cpu is a housekeeping cpu, use it. */

base-commit: 8155b4ef3466f0e289e8fcc9e6e62f3f4dceeac2
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-01-06  2:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-30  6:45 [RFC PATCH] workqueue: introduce WORK_STRUCT_TIMER_PENDING_BIT Imran Khan
2025-01-03 22:18 ` Tejun Heo
2025-01-06  2:07   ` imran.f.khan

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®