Skip to contentSkip to conversation

workqueue: Implement delayed_work_busy()

PATCH In review Alex Naidis 2 participants 7 messages May 23, 2017 – May 24, 2017 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 workqueue: Implement delayed_work_busy()

This implements a variant of work_busy() for
delayed work.

---
 include/linux/workqueue.h | 1 +
 kernel/workqueue.c        | 9 +++++++++
 2 files changed, 10 insertions(+)
include/linux/workqueue.h +1 -0
index c102ef6..32ab046 100644
@@ -467,6 +467,7 @@ extern void workqueue_set_max_active(struct workqueue_struct *wq,
 extern bool current_is_workqueue_rescuer(void);
 extern bool workqueue_congested(int cpu, struct workqueue_struct *wq);
 extern unsigned int work_busy(struct work_struct *work);
+extern unsigned int delayed_work_busy(struct delayed_work *dwork);
 extern __printf(1, 2) void set_worker_desc(const char *fmt, ...);
 extern void print_worker_info(const char *log_lvl, struct task_struct *task);
 extern void show_workqueue_state(void);
kernel/workqueue.c +9 -0
index c74bf39..658cc2e 100644
@@ -4224,6 +4224,15 @@ unsigned int work_busy(struct work_struct *work)
 }
 EXPORT_SYMBOL_GPL(work_busy);
 
+/*
+ * See work_busy()
+ */
+unsigned int delayed_work_busy(struct delayed_work *dwork)
+{
+	return work_busy(&dwork->work);
+}
+EXPORT_SYMBOL_GPL(delayed_work_busy);
+
 /**
  * set_worker_desc - set description for the current work item
  * @fmt: printf-style format string
Signature · 1 line
2.7.4
maintainer
#1 lore raw

Hello,

Quoted 28 lines · Alex Naidis

This implements a variant of work_busy() for
delayed work.

---
 include/linux/workqueue.h | 1 +
 kernel/workqueue.c        | 9 +++++++++
 2 files changed, 10 insertions(+)
include/linux/workqueue.h +1 -0
index c102ef6..32ab046 100644
@@ -467,6 +467,7 @@ extern void workqueue_set_max_active(struct workqueue_struct *wq,
 extern bool current_is_workqueue_rescuer(void);
 extern bool workqueue_congested(int cpu, struct workqueue_struct *wq);
 extern unsigned int work_busy(struct work_struct *work);
+extern unsigned int delayed_work_busy(struct delayed_work *dwork);
 extern __printf(1, 2) void set_worker_desc(const char *fmt, ...);
 extern void print_worker_info(const char *log_lvl, struct task_struct *task);
 extern void show_workqueue_state(void);
kernel/workqueue.c +0 -0
index c74bf39..658cc2e 100644
@@ -4224,6 +4224,15 @@ unsigned int work_busy(struct work_struct *work)
 }

kernel/workqueue.c unsigned int work_busy(struct work_struct *work) · line 4234

Quoted 10 lines
kernel/workqueue.c +8 -0
 EXPORT_SYMBOL_GPL(work_busy);
 
+/*
+ * See work_busy()
+ */
+unsigned int delayed_work_busy(struct delayed_work *dwork)
+{
+	return work_busy(&dwork->work);
+}
+EXPORT_SYMBOL_GPL(delayed_work_busy);

What's the use case? Some of existing work_busy() seem wrong already. Also, if we need this, let's make it an inline function.

Thanks.

Signature · 1 line
tejun

A message that is not in the archive (sent off-list or not yet received): CACuw83r65iSCQdV1WVR=wQqw0voJ_98HmsRF9XaAdeGtQ_daGQ@mail.gmail.com

#3 lore raw

PATCH 1/1 workqueue: Implement delayed_work_busy()

Hello,
thank you for your quick review!

2017-05-24 17:11 GMT+02:00 Tejun Heo <[email protected]>:

Quoted 34 lines

Hello,

Quoted 30 lines · Alex Naidis

This implements a variant of work_busy() for
delayed work.

---
 include/linux/workqueue.h | 1 +
 kernel/workqueue.c        | 9 +++++++++
 2 files changed, 10 insertions(+)
include/linux/workqueue.h +1 -0
index c102ef6..32ab046 100644
@@ -467,6 +467,7 @@ extern void workqueue_set_max_active(struct workqueue_struct *wq,
 extern bool current_is_workqueue_rescuer(void);
 extern bool workqueue_congested(int cpu, struct workqueue_struct *wq);
 extern unsigned int work_busy(struct work_struct *work);
+extern unsigned int delayed_work_busy(struct delayed_work *dwork);
 extern __printf(1, 2) void set_worker_desc(const char *fmt, ...);
 extern void print_worker_info(const char *log_lvl, struct task_struct *task);
 extern void show_workqueue_state(void);
kernel/workqueue.c +0 -0
index c74bf39..658cc2e 100644
@@ -4224,6 +4224,15 @@ unsigned int work_busy(struct work_struct *work)
 }
 EXPORT_SYMBOL_GPL(work_busy);
 
Quoted 10 lines

kernel/workqueue.c unsigned int work_busy(struct work_struct *work) · line 4234

Quoted 8 lines
kernel/workqueue.c +8 -0
+/*
+ * See work_busy()
+ */
+unsigned int delayed_work_busy(struct delayed_work *dwork)
+{
+     return work_busy(&dwork->work);
+}
+EXPORT_SYMBOL_GPL(delayed_work_busy);

What's the use case? Some of existing work_busy() seem wrong already.

Yeah, I agree, it is wrong to rely on work_busy() providing correct data. However sometimes it is useful to have an indicator like this to at least catch some cases where requeuing work would be obsolete.
This applies for delayed work too.

Quoted 2 lines

Also, if we need this, let's make it an inline function.

Alright, you should receive V2 of this patch right after this mail.

Quoted 6 lines

Thanks.

--
tejun

Thank you again!
Alex

maintainer
#4 lore raw
In reply to a message not in the archive

Hello, Alex.

Quoted 4 lines · Alex Naidis

Yeah, I agree, it is wrong to rely on work_busy() providing correct data. However sometimes it is useful to have an indicator like this to at least catch some cases where requeuing work would be obsolete.
This applies for delayed work too.

Can you elaborage on "requeueing work would be obsolate" a bit?

Thanks.

Signature · 1 line
tejun
#5 lore raw

Hello,

2017-05-24 22:01 GMT+02:00 Tejun Heo <[email protected]>:

Quoted 9 lines

Hello, Alex.

Quoted 4 lines · Alex Naidis

Yeah, I agree, it is wrong to rely on work_busy() providing correct data. However sometimes it is useful to have an indicator like this to at least catch some cases where requeuing work would be obsolete.
This applies for delayed work too.

Can you elaborage on "requeueing work would be obsolate" a bit?

Sure.
The case that I mean is represented well by the usage of work_busy here:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/acpi/bus.c#n534
It checks work_busy() before requeuing the work, since in some cases it is obsolete
to requeue the work if it is already pending or running.

Quoted 5 lines

Thanks.

--
tejun

Alex

maintainer
#6 lore raw

Hello,

cc'ing ACPI folks.

Quoted 9 lines · Alex Naidis

2017-05-24 22:01 GMT+02:00 Tejun Heo <[email protected]>:

Quoted 8 lines

Hello, Alex.

Quoted 4 lines · Alex Naidis

Yeah, I agree, it is wrong to rely on work_busy() providing correct data. However sometimes it is useful to have an indicator like this to at least catch some cases where requeuing work would be obsolete.
This applies for delayed work too.

Quoted 7 lines
Quoted 1 line

Can you elaborage on "requeueing work would be obsolate" a bit?

Sure.
The case that I mean is represented well by the usage of work_busy here:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/acpi/bus.c#n534
It checks work_busy() before requeuing the work, since in some cases it is obsolete
to requeue the work if it is already pending or running.

So, there is no point in testing whether a work item is pending before queeing it. It's completely spurious. The only part which makes sense is if it doesn't want to queue a work item if it's already running (but note that this isn't synchronized properly) for some reason, but given that it can race with workqueue operation and spuriously return false when the work item just started running, it can't be for correctness.

Rafael, Len, can you please explain why work_busy() test is there?

Thanks.

Signature · 1 line
tejun
#7 lore raw

Hello,

2017-05-24 22:21 GMT+02:00 Tejun Heo <[email protected]>:

Quoted 22 lines

Hello,

cc'ing ACPI folks.

Quoted 9 lines · Alex Naidis

2017-05-24 22:01 GMT+02:00 Tejun Heo <[email protected]>:

Quoted 8 lines

Hello, Alex.

Quoted 4 lines · Alex Naidis

Yeah, I agree, it is wrong to rely on work_busy() providing correct data. However sometimes it is useful to have an indicator like this to at least catch some cases where requeuing work would be obsolete.
This applies for delayed work too.

Quoted 7 lines
Quoted 1 line

Can you elaborage on "requeueing work would be obsolate" a bit?

Sure.
The case that I mean is represented well by the usage of work_busy here:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/acpi/bus.c#n534
It checks work_busy() before requeuing the work, since in some cases it is obsolete
to requeue the work if it is already pending or running.

Quoted 8 lines

So, there is no point in testing whether a work item is pending before queeing it. It's completely spurious. The only part which makes sense is if it doesn't want to queue a work item if it's already running (but note that this isn't synchronized properly) for some reason, but given that it can race with workqueue operation and spuriously return false when the work item just started running, it can't be for correctness.

what I thought is that might be a good idea to catch at least some cases where the work is already running. It is obviously wrong to rely on the corectness of the return value.

Do you agree here or would you suggest another
alternative here?

Quoted 6 lines

Rafael, Len, can you please explain why work_busy() test is there?

Thanks.

--
tejun

Thank you!
Alex