Allows waiting with a custom @state.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
include/linux/completion.h | 1 +
kernel/sched/completion.c | 9 +++++++++
2 files changed, 10 insertions(+)
--- a/include/linux/completion.h
+++ b/include/linux/completion.h
@@ -103,6 +103,7 @@ extern void wait_for_completion(struct c
extern void wait_for_completion_io(struct completion *);
extern int wait_for_completion_interruptible(struct completion *x);
extern int wait_for_completion_killable(struct completion *x);
+extern int wait_for_completion_state(struct completion *x, unsigned int state);
extern unsigned long wait_for_completion_timeout(struct completion *x,
unsigned long timeout);
extern unsigned long wait_for_completion_io_timeout(struct completion *x,
--- a/kernel/sched/completion.c
+++ b/kernel/sched/completion.c
@@ -247,6 +247,15 @@ int __sched wait_for_completion_killable
}
EXPORT_SYMBOL(wait_for_completion_killable);
+int __sched wait_for_completion_state(struct completion *x, unsigned int state)
+{
+ long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, state);
+ if (t == -ERESTARTSYS)
+ return t;
+ return 0;
+}
+EXPORT_SYMBOL(wait_for_completion_state);
+
/**
* wait_for_completion_killable_timeout: - waits for completion of a task (w/(to,killable))
* @x: holds the state of this particular completion
* Peter Zijlstra <peterz@infradead.org> wrote:
> Allows waiting with a custom @state.
>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> ---
> include/linux/completion.h | 1 +
> kernel/sched/completion.c | 9 +++++++++
> 2 files changed, 10 insertions(+)
>
> --- a/include/linux/completion.h
> +++ b/include/linux/completion.h
> @@ -103,6 +103,7 @@ extern void wait_for_completion(struct c
> extern void wait_for_completion_io(struct completion *);
> extern int wait_for_completion_interruptible(struct completion *x);
> extern int wait_for_completion_killable(struct completion *x);
> +extern int wait_for_completion_state(struct completion *x, unsigned int state);
> extern unsigned long wait_for_completion_timeout(struct completion *x,
> unsigned long timeout);
> extern unsigned long wait_for_completion_io_timeout(struct completion *x,
> --- a/kernel/sched/completion.c
> +++ b/kernel/sched/completion.c
> @@ -247,6 +247,15 @@ int __sched wait_for_completion_killable
> }
> EXPORT_SYMBOL(wait_for_completion_killable);
>
> +int __sched wait_for_completion_state(struct completion *x, unsigned int state)
> +{
> + long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, state);
> + if (t == -ERESTARTSYS)
> + return t;
> + return 0;
Nit: newline missing after local variable definition.
Other than that:
Reviewed-by: Ingo Molnar <mingo@kernel.org>
Thanks,
Ingo
On Sun, Sep 04, 2022 at 12:46:11PM +0200, Ingo Molnar wrote:
>
> * Peter Zijlstra <peterz@infradead.org> wrote:
>
> > Allows waiting with a custom @state.
> >
> > Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> > ---
> > include/linux/completion.h | 1 +
> > kernel/sched/completion.c | 9 +++++++++
> > 2 files changed, 10 insertions(+)
> >
> > --- a/include/linux/completion.h
> > +++ b/include/linux/completion.h
> > @@ -103,6 +103,7 @@ extern void wait_for_completion(struct c
> > extern void wait_for_completion_io(struct completion *);
> > extern int wait_for_completion_interruptible(struct completion *x);
> > extern int wait_for_completion_killable(struct completion *x);
> > +extern int wait_for_completion_state(struct completion *x, unsigned int state);
> > extern unsigned long wait_for_completion_timeout(struct completion *x,
> > unsigned long timeout);
> > extern unsigned long wait_for_completion_io_timeout(struct completion *x,
> > --- a/kernel/sched/completion.c
> > +++ b/kernel/sched/completion.c
> > @@ -247,6 +247,15 @@ int __sched wait_for_completion_killable
> > }
> > EXPORT_SYMBOL(wait_for_completion_killable);
> >
> > +int __sched wait_for_completion_state(struct completion *x, unsigned int state)
> > +{
> > + long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, state);
> > + if (t == -ERESTARTSYS)
> > + return t;
> > + return 0;
>
> Nit: newline missing after local variable definition.
Yah, I know, but all the other similar functions there have the same
defect. I don't much like whitespace patches, so I figured I'd be
consistent and let it all be for now.
* Peter Zijlstra <peterz@infradead.org> wrote:
> On Sun, Sep 04, 2022 at 12:46:11PM +0200, Ingo Molnar wrote:
> >
> > * Peter Zijlstra <peterz@infradead.org> wrote:
> >
> > > Allows waiting with a custom @state.
> > >
> > > Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> > > ---
> > > include/linux/completion.h | 1 +
> > > kernel/sched/completion.c | 9 +++++++++
> > > 2 files changed, 10 insertions(+)
> > >
> > > --- a/include/linux/completion.h
> > > +++ b/include/linux/completion.h
> > > @@ -103,6 +103,7 @@ extern void wait_for_completion(struct c
> > > extern void wait_for_completion_io(struct completion *);
> > > extern int wait_for_completion_interruptible(struct completion *x);
> > > extern int wait_for_completion_killable(struct completion *x);
> > > +extern int wait_for_completion_state(struct completion *x, unsigned int state);
> > > extern unsigned long wait_for_completion_timeout(struct completion *x,
> > > unsigned long timeout);
> > > extern unsigned long wait_for_completion_io_timeout(struct completion *x,
> > > --- a/kernel/sched/completion.c
> > > +++ b/kernel/sched/completion.c
> > > @@ -247,6 +247,15 @@ int __sched wait_for_completion_killable
> > > }
> > > EXPORT_SYMBOL(wait_for_completion_killable);
> > >
> > > +int __sched wait_for_completion_state(struct completion *x, unsigned int state)
> > > +{
> > > + long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, state);
> > > + if (t == -ERESTARTSYS)
> > > + return t;
> > > + return 0;
> >
> > Nit: newline missing after local variable definition.
>
> Yah, I know, but all the other similar functions there have the same
> defect. I don't much like whitespace patches, so I figured I'd be
> consistent and let it all be for now.
That's not actually true: there's ~7 functions in kernel/sched/completion.c
with local variables, and only ~2 have this minor stylistic inconsistency
right now AFAICS. Scheduler-wide the ratio is even lower.
So even if a patch doesn't entirely remove the residual noise, let's not
add to it, please?
Thanks,
Ingo
On Wed, Sep 07, 2022 at 09:35:20AM +0200, Ingo Molnar wrote:
> That's not actually true: there's ~7 functions in kernel/sched/completion.c
> with local variables, and only ~2 have this minor stylistic inconsistency
> right now AFAICS. Scheduler-wide the ratio is even lower.
>
> So even if a patch doesn't entirely remove the residual noise, let's not
> add to it, please?
--- a/kernel/sched/completion.c
+++ b/kernel/sched/completion.c
@@ -204,6 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_io_tim
int __sched wait_for_completion_interruptible(struct completion *x)
{
long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_INTERRUPTIBLE);
+
if (t == -ERESTARTSYS)
return t;
return 0;
@@ -241,6 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_interr
int __sched wait_for_completion_killable(struct completion *x)
{
long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
+
if (t == -ERESTARTSYS)
return t;
return 0;
@@ -250,6 +252,7 @@ EXPORT_SYMBOL(wait_for_completion_killab
int __sched wait_for_completion_state(struct completion *x, unsigned int state)
{
long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, state);
+
if (t == -ERESTARTSYS)
return t;
return 0;
On Mon, Aug 22, 2022 at 1:48 PM Peter Zijlstra <peterz@infradead.org> wrote:
>
> Allows waiting with a custom @state.
>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> ---
> include/linux/completion.h | 1 +
> kernel/sched/completion.c | 9 +++++++++
> 2 files changed, 10 insertions(+)
>
> --- a/include/linux/completion.h
> +++ b/include/linux/completion.h
> @@ -103,6 +103,7 @@ extern void wait_for_completion(struct c
> extern void wait_for_completion_io(struct completion *);
> extern int wait_for_completion_interruptible(struct completion *x);
> extern int wait_for_completion_killable(struct completion *x);
> +extern int wait_for_completion_state(struct completion *x, unsigned int state);
> extern unsigned long wait_for_completion_timeout(struct completion *x,
> unsigned long timeout);
> extern unsigned long wait_for_completion_io_timeout(struct completion *x,
> --- a/kernel/sched/completion.c
> +++ b/kernel/sched/completion.c
> @@ -247,6 +247,15 @@ int __sched wait_for_completion_killable
> }
> EXPORT_SYMBOL(wait_for_completion_killable);
>
> +int __sched wait_for_completion_state(struct completion *x, unsigned int state)
> +{
> + long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, state);
> + if (t == -ERESTARTSYS)
> + return t;
> + return 0;
> +}
> +EXPORT_SYMBOL(wait_for_completion_state);
Why not EXPORT_SYMBOL_GPL? I guess to match the above?
> +
> /**
> * wait_for_completion_killable_timeout: - waits for completion of a task (w/(to,killable))
> * @x: holds the state of this particular completion
>
>
On Tue, Aug 23, 2022 at 07:32:33PM +0200, Rafael J. Wysocki wrote:
> On Mon, Aug 22, 2022 at 1:48 PM Peter Zijlstra <peterz@infradead.org> wrote:
> >
> > Allows waiting with a custom @state.
> >
> > Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> > ---
> > include/linux/completion.h | 1 +
> > kernel/sched/completion.c | 9 +++++++++
> > 2 files changed, 10 insertions(+)
> >
> > --- a/include/linux/completion.h
> > +++ b/include/linux/completion.h
> > @@ -103,6 +103,7 @@ extern void wait_for_completion(struct c
> > extern void wait_for_completion_io(struct completion *);
> > extern int wait_for_completion_interruptible(struct completion *x);
> > extern int wait_for_completion_killable(struct completion *x);
> > +extern int wait_for_completion_state(struct completion *x, unsigned int state);
> > extern unsigned long wait_for_completion_timeout(struct completion *x,
> > unsigned long timeout);
> > extern unsigned long wait_for_completion_io_timeout(struct completion *x,
> > --- a/kernel/sched/completion.c
> > +++ b/kernel/sched/completion.c
> > @@ -247,6 +247,15 @@ int __sched wait_for_completion_killable
> > }
> > EXPORT_SYMBOL(wait_for_completion_killable);
> >
> > +int __sched wait_for_completion_state(struct completion *x, unsigned int state)
> > +{
> > + long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, state);
> > + if (t == -ERESTARTSYS)
> > + return t;
> > + return 0;
> > +}
> > +EXPORT_SYMBOL(wait_for_completion_state);
>
> Why not EXPORT_SYMBOL_GPL? I guess to match the above?
Yeah; I'm torn between preference and consistency here :-)
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 929659acea03db6411a32de9037abab9f856f586
Gitweb: https://git.kernel.org/tip/929659acea03db6411a32de9037abab9f856f586
Author: Peter Zijlstra <peterz@infradead.org>
AuthorDate: Mon, 22 Aug 2022 13:18:20 +02:00
Committer: Peter Zijlstra <peterz@infradead.org>
CommitterDate: Wed, 07 Sep 2022 21:53:49 +02:00
sched/completion: Add wait_for_completion_state()
Allows waiting with a custom @state.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20220822114648.922711674@infradead.org
---
include/linux/completion.h | 1 +
kernel/sched/completion.c | 12 ++++++++++++
2 files changed, 13 insertions(+)
diff --git a/include/linux/completion.h b/include/linux/completion.h
index 51d9ab0..62b32b1 100644
--- a/include/linux/completion.h
+++ b/include/linux/completion.h
@@ -103,6 +103,7 @@ extern void wait_for_completion(struct completion *);
extern void wait_for_completion_io(struct completion *);
extern int wait_for_completion_interruptible(struct completion *x);
extern int wait_for_completion_killable(struct completion *x);
+extern int wait_for_completion_state(struct completion *x, unsigned int state);
extern unsigned long wait_for_completion_timeout(struct completion *x,
unsigned long timeout);
extern unsigned long wait_for_completion_io_timeout(struct completion *x,
diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
index 35f15c2..d57a5c1 100644
--- a/kernel/sched/completion.c
+++ b/kernel/sched/completion.c
@@ -204,6 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_io_timeout);
int __sched wait_for_completion_interruptible(struct completion *x)
{
long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_INTERRUPTIBLE);
+
if (t == -ERESTARTSYS)
return t;
return 0;
@@ -241,12 +242,23 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
int __sched wait_for_completion_killable(struct completion *x)
{
long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
+
if (t == -ERESTARTSYS)
return t;
return 0;
}
EXPORT_SYMBOL(wait_for_completion_killable);
+int __sched wait_for_completion_state(struct completion *x, unsigned int state)
+{
+ long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, state);
+
+ if (t == -ERESTARTSYS)
+ return t;
+ return 0;
+}
+EXPORT_SYMBOL(wait_for_completion_state);
+
/**
* wait_for_completion_killable_timeout: - waits for completion of a task (w/(to,killable))
* @x: holds the state of this particular completion
© 2016 - 2025 Red Hat, Inc.