linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] powerpc: eeh_event: convert semaphore to completion
@ 2018-12-10 21:51 Arnd Bergmann
  2018-12-10 23:18 ` Oliver
  2018-12-22  9:54 ` Michael Ellerman
  0 siblings, 2 replies; 4+ messages in thread
From: Arnd Bergmann @ 2018-12-10 21:51 UTC (permalink / raw)
  To: Russell Currey, Sam Bobroff, Oliver O'Halloran,
	Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman
  Cc: Arnd Bergmann, Alexey Kardashevskiy, linuxppc-dev, linux-kernel

For this use case, completions and semaphores are equivalent,
but semaphores are an awkward interface that should generally
be avoided, so use the completion instead.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 arch/powerpc/kernel/eeh_event.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/kernel/eeh_event.c b/arch/powerpc/kernel/eeh_event.c
index 61c9356bf9c9..227e57f980df 100644
--- a/arch/powerpc/kernel/eeh_event.c
+++ b/arch/powerpc/kernel/eeh_event.c
@@ -35,7 +35,7 @@
  */
 
 static DEFINE_SPINLOCK(eeh_eventlist_lock);
-static struct semaphore eeh_eventlist_sem;
+static DECLARE_COMPLETION(eeh_eventlist_event);
 static LIST_HEAD(eeh_eventlist);
 
 /**
@@ -55,7 +55,7 @@ static int eeh_event_handler(void * dummy)
 	struct eeh_pe *pe;
 
 	while (!kthread_should_stop()) {
-		if (down_interruptible(&eeh_eventlist_sem))
+		if (wait_for_completion_interruptible(&eeh_eventlist_event))
 			break;
 
 		/* Fetch EEH event from the queue */
@@ -102,9 +102,6 @@ int eeh_event_init(void)
 	struct task_struct *t;
 	int ret = 0;
 
-	/* Initialize semaphore */
-	sema_init(&eeh_eventlist_sem, 0);
-
 	t = kthread_run(eeh_event_handler, NULL, "eehd");
 	if (IS_ERR(t)) {
 		ret = PTR_ERR(t);
@@ -142,7 +139,7 @@ int eeh_send_failure_event(struct eeh_pe *pe)
 	spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
 
 	/* For EEH deamon to knick in */
-	up(&eeh_eventlist_sem);
+	complete(&eeh_eventlist_event);
 
 	return 0;
 }
-- 
2.20.0


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

* Re: [PATCH] powerpc: eeh_event: convert semaphore to completion
  2018-12-10 21:51 [PATCH] powerpc: eeh_event: convert semaphore to completion Arnd Bergmann
@ 2018-12-10 23:18 ` Oliver
  2018-12-10 23:33   ` Sam Bobroff
  2018-12-22  9:54 ` Michael Ellerman
  1 sibling, 1 reply; 4+ messages in thread
From: Oliver @ 2018-12-10 23:18 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Russell Currey, Sam Bobroff, Benjamin Herrenschmidt,
	Paul Mackerras, Michael Ellerman, aik, linuxppc-dev,
	Linux Kernel Mailing List

On Tue, Dec 11, 2018 at 8:52 AM Arnd Bergmann <arnd@arndb.de> wrote:
>
> For this use case, completions and semaphores are equivalent,
> but semaphores are an awkward interface that should generally
> be avoided, so use the completion instead.

IIRC Sam has been reworking the locking used inside of EEH so this is
probably going to clash with his changes. Converting to a completion
is probably a good idea, but we might want to do it as a part of his
series since it's going to collide with this anyway.

Sam, what do you think?

>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  arch/powerpc/kernel/eeh_event.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/arch/powerpc/kernel/eeh_event.c b/arch/powerpc/kernel/eeh_event.c
> index 61c9356bf9c9..227e57f980df 100644
> --- a/arch/powerpc/kernel/eeh_event.c
> +++ b/arch/powerpc/kernel/eeh_event.c
> @@ -35,7 +35,7 @@
>   */
>
>  static DEFINE_SPINLOCK(eeh_eventlist_lock);
> -static struct semaphore eeh_eventlist_sem;
> +static DECLARE_COMPLETION(eeh_eventlist_event);
>  static LIST_HEAD(eeh_eventlist);
>
>  /**
> @@ -55,7 +55,7 @@ static int eeh_event_handler(void * dummy)
>         struct eeh_pe *pe;
>
>         while (!kthread_should_stop()) {
> -               if (down_interruptible(&eeh_eventlist_sem))
> +               if (wait_for_completion_interruptible(&eeh_eventlist_event))
>                         break;
>
>                 /* Fetch EEH event from the queue */
> @@ -102,9 +102,6 @@ int eeh_event_init(void)
>         struct task_struct *t;
>         int ret = 0;
>
> -       /* Initialize semaphore */
> -       sema_init(&eeh_eventlist_sem, 0);
> -
>         t = kthread_run(eeh_event_handler, NULL, "eehd");
>         if (IS_ERR(t)) {
>                 ret = PTR_ERR(t);
> @@ -142,7 +139,7 @@ int eeh_send_failure_event(struct eeh_pe *pe)
>         spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
>
>         /* For EEH deamon to knick in */
> -       up(&eeh_eventlist_sem);
> +       complete(&eeh_eventlist_event);
>
>         return 0;
>  }
> --
> 2.20.0
>

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

* Re: [PATCH] powerpc: eeh_event: convert semaphore to completion
  2018-12-10 23:18 ` Oliver
@ 2018-12-10 23:33   ` Sam Bobroff
  0 siblings, 0 replies; 4+ messages in thread
From: Sam Bobroff @ 2018-12-10 23:33 UTC (permalink / raw)
  To: Oliver
  Cc: Arnd Bergmann, Russell Currey, Benjamin Herrenschmidt,
	Paul Mackerras, Michael Ellerman, aik, linuxppc-dev,
	Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 2508 bytes --]

On Tue, Dec 11, 2018 at 10:18:31AM +1100, Oliver wrote:
> On Tue, Dec 11, 2018 at 8:52 AM Arnd Bergmann <arnd@arndb.de> wrote:
> >
> > For this use case, completions and semaphores are equivalent,
> > but semaphores are an awkward interface that should generally
> > be avoided, so use the completion instead.
> 
> IIRC Sam has been reworking the locking used inside of EEH so this is
> probably going to clash with his changes. Converting to a completion
> is probably a good idea, but we might want to do it as a part of his
> series since it's going to collide with this anyway.
> 
> Sam, what do you think?

It's such a small change, I don't think it will cause any problems for
the rework. Anyway it seems like a good change, so I'd prefer to see it
go in :-)

Cheers,
Sam.

> >
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> > ---
> >  arch/powerpc/kernel/eeh_event.c | 9 +++------
> >  1 file changed, 3 insertions(+), 6 deletions(-)
> >
> > diff --git a/arch/powerpc/kernel/eeh_event.c b/arch/powerpc/kernel/eeh_event.c
> > index 61c9356bf9c9..227e57f980df 100644
> > --- a/arch/powerpc/kernel/eeh_event.c
> > +++ b/arch/powerpc/kernel/eeh_event.c
> > @@ -35,7 +35,7 @@
> >   */
> >
> >  static DEFINE_SPINLOCK(eeh_eventlist_lock);
> > -static struct semaphore eeh_eventlist_sem;
> > +static DECLARE_COMPLETION(eeh_eventlist_event);
> >  static LIST_HEAD(eeh_eventlist);
> >
> >  /**
> > @@ -55,7 +55,7 @@ static int eeh_event_handler(void * dummy)
> >         struct eeh_pe *pe;
> >
> >         while (!kthread_should_stop()) {
> > -               if (down_interruptible(&eeh_eventlist_sem))
> > +               if (wait_for_completion_interruptible(&eeh_eventlist_event))
> >                         break;
> >
> >                 /* Fetch EEH event from the queue */
> > @@ -102,9 +102,6 @@ int eeh_event_init(void)
> >         struct task_struct *t;
> >         int ret = 0;
> >
> > -       /* Initialize semaphore */
> > -       sema_init(&eeh_eventlist_sem, 0);
> > -
> >         t = kthread_run(eeh_event_handler, NULL, "eehd");
> >         if (IS_ERR(t)) {
> >                 ret = PTR_ERR(t);
> > @@ -142,7 +139,7 @@ int eeh_send_failure_event(struct eeh_pe *pe)
> >         spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
> >
> >         /* For EEH deamon to knick in */
> > -       up(&eeh_eventlist_sem);
> > +       complete(&eeh_eventlist_event);
> >
> >         return 0;
> >  }
> > --
> > 2.20.0
> >
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: powerpc: eeh_event: convert semaphore to completion
  2018-12-10 21:51 [PATCH] powerpc: eeh_event: convert semaphore to completion Arnd Bergmann
  2018-12-10 23:18 ` Oliver
@ 2018-12-22  9:54 ` Michael Ellerman
  1 sibling, 0 replies; 4+ messages in thread
From: Michael Ellerman @ 2018-12-22  9:54 UTC (permalink / raw)
  To: Arnd Bergmann, Russell Currey, Sam Bobroff,
	Oliver O'Halloran, Benjamin Herrenschmidt, Paul Mackerras
  Cc: Alexey Kardashevskiy, linuxppc-dev, linux-kernel, Arnd Bergmann

On Mon, 2018-12-10 at 21:51:57 UTC, Arnd Bergmann wrote:
> For this use case, completions and semaphores are equivalent,
> but semaphores are an awkward interface that should generally
> be avoided, so use the completion instead.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/2fea82db113e4422ef5c8e62099088

cheers

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

end of thread, other threads:[~2018-12-22 17:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-10 21:51 [PATCH] powerpc: eeh_event: convert semaphore to completion Arnd Bergmann
2018-12-10 23:18 ` Oliver
2018-12-10 23:33   ` Sam Bobroff
2018-12-22  9:54 ` Michael Ellerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).