All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] workqueue: Implement delayed_work_busy()
@ 2017-05-23 23:34 Alex Naidis
  2017-05-24 15:11 ` Tejun Heo
  0 siblings, 1 reply; 7+ messages in thread
From: Alex Naidis @ 2017-05-23 23:34 UTC (permalink / raw)
  To: Tejun Heo; +Cc: Alex Naidis, linux-kernel

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

CC: linux-kernel@vger.kernel.org
Signed-off-by: Alex Naidis <alex.naidis@linux.com>
---
 include/linux/workqueue.h | 1 +
 kernel/workqueue.c        | 9 +++++++++
 2 files changed, 10 insertions(+)

diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index c102ef6..32ab046 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -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);
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index c74bf39..658cc2e 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -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
-- 
2.7.4

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

* Re: [PATCH] workqueue: Implement delayed_work_busy()
  2017-05-23 23:34 [PATCH] workqueue: Implement delayed_work_busy() Alex Naidis
@ 2017-05-24 15:11 ` Tejun Heo
       [not found]   ` <CACuw83r65iSCQdV1WVR=wQqw0voJ_98HmsRF9XaAdeGtQ_daGQ@mail.gmail.com>
  0 siblings, 1 reply; 7+ messages in thread
From: Tejun Heo @ 2017-05-24 15:11 UTC (permalink / raw)
  To: Alex Naidis; +Cc: linux-kernel

Hello,

On Wed, May 24, 2017 at 01:34:53AM +0200, Alex Naidis wrote:
> This implements a variant of work_busy() for
> delayed work.
> 
> CC: linux-kernel@vger.kernel.org
> Signed-off-by: Alex Naidis <alex.naidis@linux.com>
> ---
>  include/linux/workqueue.h | 1 +
>  kernel/workqueue.c        | 9 +++++++++
>  2 files changed, 10 insertions(+)
> 
> diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
> index c102ef6..32ab046 100644
> --- a/include/linux/workqueue.h
> +++ b/include/linux/workqueue.h
> @@ -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);
> diff --git a/kernel/workqueue.c b/kernel/workqueue.c
> index c74bf39..658cc2e 100644
> --- a/kernel/workqueue.c
> +++ b/kernel/workqueue.c
> @@ -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);

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.

-- 
tejun

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

* Fwd: [PATCH] workqueue: Implement delayed_work_busy()
       [not found]   ` <CACuw83r65iSCQdV1WVR=wQqw0voJ_98HmsRF9XaAdeGtQ_daGQ@mail.gmail.com>
@ 2017-05-24 20:01     ` Alex Naidis
  2017-05-24 20:01     ` Tejun Heo
  1 sibling, 0 replies; 7+ messages in thread
From: Alex Naidis @ 2017-05-24 20:01 UTC (permalink / raw)
  To: Alex NDS; +Cc: linux-kernel

Hello,
thank you for your quick review!

2017-05-24 17:11 GMT+02:00 Tejun Heo <tj@kernel.org>:
>
> Hello,
>
> On Wed, May 24, 2017 at 01:34:53AM +0200, Alex Naidis wrote:
> > This implements a variant of work_busy() for
> > delayed work.
> >
> > CC: linux-kernel@vger.kernel.org
> > Signed-off-by: Alex Naidis <alex.naidis@linux.com>
> > ---
> >  include/linux/workqueue.h | 1 +
> >  kernel/workqueue.c        | 9 +++++++++
> >  2 files changed, 10 insertions(+)
> >
> > diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
> > index c102ef6..32ab046 100644
> > --- a/include/linux/workqueue.h
> > +++ b/include/linux/workqueue.h
> > @@ -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);
> > diff --git a/kernel/workqueue.c b/kernel/workqueue.c
> > index c74bf39..658cc2e 100644
> > --- a/kernel/workqueue.c
> > +++ b/kernel/workqueue.c
> > @@ -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);
>
> 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.

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

Alright, you should receive V2 of this patch right after this mail.
>
>
> Thanks.
>
> --
> tejun


Thank you again!
Alex

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

* Re: [PATCH] workqueue: Implement delayed_work_busy()
       [not found]   ` <CACuw83r65iSCQdV1WVR=wQqw0voJ_98HmsRF9XaAdeGtQ_daGQ@mail.gmail.com>
  2017-05-24 20:01     ` Fwd: " Alex Naidis
@ 2017-05-24 20:01     ` Tejun Heo
  2017-05-24 20:16       ` Alex Naidis
  1 sibling, 1 reply; 7+ messages in thread
From: Tejun Heo @ 2017-05-24 20:01 UTC (permalink / raw)
  To: Alex Naidis; +Cc: linux-kernel

Hello, Alex.

On Wed, May 24, 2017 at 09:58:19PM +0200, Alex Naidis wrote:
> 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.

-- 
tejun

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

* Re: [PATCH] workqueue: Implement delayed_work_busy()
  2017-05-24 20:01     ` Tejun Heo
@ 2017-05-24 20:16       ` Alex Naidis
  2017-05-24 20:21         ` Tejun Heo
  0 siblings, 1 reply; 7+ messages in thread
From: Alex Naidis @ 2017-05-24 20:16 UTC (permalink / raw)
  To: Tejun Heo; +Cc: linux-kernel

Hello,

2017-05-24 22:01 GMT+02:00 Tejun Heo <tj@kernel.org>:
> Hello, Alex.
>
> On Wed, May 24, 2017 at 09:58:19PM +0200, Alex Naidis wrote:
>> 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.
>
> Thanks.
>
> --
> tejun

Alex

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

* Re: [PATCH] workqueue: Implement delayed_work_busy()
  2017-05-24 20:16       ` Alex Naidis
@ 2017-05-24 20:21         ` Tejun Heo
  2017-05-24 20:32           ` Alex Naidis
  0 siblings, 1 reply; 7+ messages in thread
From: Tejun Heo @ 2017-05-24 20:21 UTC (permalink / raw)
  To: Alex Naidis; +Cc: linux-kernel, Rafael J. Wysocki, Len Brown, linux-acpi

Hello,

cc'ing ACPI folks.

On Wed, May 24, 2017 at 10:16:02PM +0200, Alex Naidis wrote:
> 2017-05-24 22:01 GMT+02:00 Tejun Heo <tj@kernel.org>:
> > Hello, Alex.
> >
> > On Wed, May 24, 2017 at 09:58:19PM +0200, Alex Naidis wrote:
> >> 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.

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.

-- 
tejun

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

* Re: [PATCH] workqueue: Implement delayed_work_busy()
  2017-05-24 20:21         ` Tejun Heo
@ 2017-05-24 20:32           ` Alex Naidis
  0 siblings, 0 replies; 7+ messages in thread
From: Alex Naidis @ 2017-05-24 20:32 UTC (permalink / raw)
  To: Tejun Heo; +Cc: linux-kernel, Rafael J. Wysocki, Len Brown, linux-acpi

Hello,

2017-05-24 22:21 GMT+02:00 Tejun Heo <tj@kernel.org>:
> Hello,
>
> cc'ing ACPI folks.
>
> On Wed, May 24, 2017 at 10:16:02PM +0200, Alex Naidis wrote:
>> 2017-05-24 22:01 GMT+02:00 Tejun Heo <tj@kernel.org>:
>> > Hello, Alex.
>> >
>> > On Wed, May 24, 2017 at 09:58:19PM +0200, Alex Naidis wrote:
>> >> 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.
>
> 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?

> Rafael, Len, can you please explain why work_busy() test is there?
>
> Thanks.
>
> --
> tejun

Thank you!
Alex

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

end of thread, other threads:[~2017-05-24 20:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-23 23:34 [PATCH] workqueue: Implement delayed_work_busy() Alex Naidis
2017-05-24 15:11 ` Tejun Heo
     [not found]   ` <CACuw83r65iSCQdV1WVR=wQqw0voJ_98HmsRF9XaAdeGtQ_daGQ@mail.gmail.com>
2017-05-24 20:01     ` Fwd: " Alex Naidis
2017-05-24 20:01     ` Tejun Heo
2017-05-24 20:16       ` Alex Naidis
2017-05-24 20:21         ` Tejun Heo
2017-05-24 20:32           ` Alex Naidis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.