From: Cyril Bur <cyrilbur@gmail.com>
To: Michael Ellerman <mpe@ellerman.id.au>,
linux-mtd@lists.infradead.org, linuxppc-dev@lists.ozlabs.org,
stewart@linux.vnet.ibm.com
Cc: boris.brezillon@free-electrons.com, computersforpeace@gmail.com,
dwmw2@infradead.org, sjitindarsingh@gmail.com
Subject: Re: [PATCH v5 06/10] powerpc/opal: Rework the opal-async interface
Date: Tue, 07 Nov 2017 10:38:28 +1100 [thread overview]
Message-ID: <1510011508.5618.0.camel@gmail.com> (raw)
In-Reply-To: <87h8u7bv7l.fsf@concordia.ellerman.id.au>
On Mon, 2017-11-06 at 20:41 +1100, Michael Ellerman wrote:
> Cyril Bur <cyrilbur@gmail.com> writes:
>
> > diff --git a/arch/powerpc/platforms/powernv/opal-async.c b/arch/powerpc/platforms/powernv/opal-async.c
> > index c43421ab2d2f..fbae8a37ce2c 100644
> > --- a/arch/powerpc/platforms/powernv/opal-async.c
> > +++ b/arch/powerpc/platforms/powernv/opal-async.c
> > @@ -23,40 +23,45 @@
> > #include <asm/machdep.h>
> > #include <asm/opal.h>
> >
> > -#define N_ASYNC_COMPLETIONS 64
> > +enum opal_async_token_state {
> > + ASYNC_TOKEN_UNALLOCATED = 0,
> > + ASYNC_TOKEN_ALLOCATED,
> > + ASYNC_TOKEN_COMPLETED
> > +};
> > +
> > +struct opal_async_token {
> > + enum opal_async_token_state state;
> > + struct opal_msg response;
> > +};
> >
> > -static DECLARE_BITMAP(opal_async_complete_map, N_ASYNC_COMPLETIONS) = {~0UL};
> > -static DECLARE_BITMAP(opal_async_token_map, N_ASYNC_COMPLETIONS);
> > static DECLARE_WAIT_QUEUE_HEAD(opal_async_wait);
> > static DEFINE_SPINLOCK(opal_async_comp_lock);
> > static struct semaphore opal_async_sem;
> > -static struct opal_msg *opal_async_responses;
> > static unsigned int opal_max_async_tokens;
> > +static struct opal_async_token *opal_async_tokens;
> >
> > static int __opal_async_get_token(void)
> > {
> > unsigned long flags;
> > - int token;
> > + int token = -EBUSY;
> >
> > spin_lock_irqsave(&opal_async_comp_lock, flags);
> > - token = find_first_bit(opal_async_complete_map, opal_max_async_tokens);
> > - if (token >= opal_max_async_tokens) {
> > - token = -EBUSY;
> > - goto out;
> > + for (token = 0; token < opal_max_async_tokens; token++) {
> > + if (opal_async_tokens[token].state == ASYNC_TOKEN_UNALLOCATED) {
> > + opal_async_tokens[token].state = ASYNC_TOKEN_ALLOCATED;
> > + goto out;
> > + }
> > }
> > -
> > - if (__test_and_set_bit(token, opal_async_token_map)) {
> > - token = -EBUSY;
> > - goto out;
> > - }
> > -
> > - __clear_bit(token, opal_async_complete_map);
> > -
> > out:
> > spin_unlock_irqrestore(&opal_async_comp_lock, flags);
> > return token;
> > }
>
> Resulting in:
>
> static int __opal_async_get_token(void)
> {
> unsigned long flags;
> + int token = -EBUSY;
>
> spin_lock_irqsave(&opal_async_comp_lock, flags);
> + for (token = 0; token < opal_max_async_tokens; token++) {
> + if (opal_async_tokens[token].state == ASYNC_TOKEN_UNALLOCATED) {
> + opal_async_tokens[token].state = ASYNC_TOKEN_ALLOCATED;
> + goto out;
> + }
> }
> out:
> spin_unlock_irqrestore(&opal_async_comp_lock, flags);
> return token;
> }
>
> So when no unallocated token is found we return opal_max_async_tokens :(
>
> I changed it to:
>
> static int __opal_async_get_token(void)
> {
> unsigned long flags;
> int i, token = -EBUSY;
>
> spin_lock_irqsave(&opal_async_comp_lock, flags);
>
> for (i = 0; i < opal_max_async_tokens; i++) {
> if (opal_async_tokens[i].state == ASYNC_TOKEN_UNALLOCATED) {
> opal_async_tokens[i].state = ASYNC_TOKEN_ALLOCATED;
> token = i;
> break;
> }
> }
>
> spin_unlock_irqrestore(&opal_async_comp_lock, flags);
> return token;
> }
>
>
Thanks!!
> >
> > +/*
> > + * Note: If the returned token is used in an opal call and opal returns
> > + * OPAL_ASYNC_COMPLETION you MUST opal_async_wait_response() before
>
> ^
> call
>
>
> cheers
next prev parent reply other threads:[~2017-11-06 23:38 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-03 2:41 [PATCH v5 00/10] Allow opal-async waiters to get interrupted Cyril Bur
2017-11-03 2:41 ` [PATCH v5 01/10] mtd: powernv_flash: Use WARN_ON_ONCE() rather than BUG_ON() Cyril Bur
2017-11-07 23:30 ` [v5, " Michael Ellerman
2017-11-03 2:41 ` [PATCH v5 02/10] mtd: powernv_flash: Don't treat OPAL_SUCCESS as an error Cyril Bur
2017-11-03 2:41 ` [PATCH v5 03/10] mtd: powernv_flash: Remove pointless goto in driver init Cyril Bur
2017-11-03 2:41 ` [PATCH v5 04/10] mtd: powernv_flash: Don't return -ERESTARTSYS on interrupted token acquisition Cyril Bur
2017-11-03 2:41 ` [PATCH v5 05/10] powerpc/opal: Make __opal_async_{get, release}_token() static Cyril Bur
2017-11-03 2:41 ` [PATCH v5 06/10] powerpc/opal: Rework the opal-async interface Cyril Bur
2017-11-06 9:41 ` Michael Ellerman
2017-11-06 23:38 ` Cyril Bur [this message]
2017-11-03 2:41 ` [PATCH v5 07/10] powernv/opal-sensor: remove not needed lock Cyril Bur
2017-11-03 2:41 ` [PATCH v5 08/10] powerpc/opal: Add opal_async_wait_response_interruptible() to opal-async Cyril Bur
2017-11-03 2:41 ` [PATCH v5 09/10] powerpc/powernv: Add OPAL_BUSY to opal_error_code() Cyril Bur
2017-11-03 2:41 ` [PATCH v5 10/10] mtd: powernv_flash: Use opal_async_wait_response_interruptible() Cyril Bur
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1510011508.5618.0.camel@gmail.com \
--to=cyrilbur@gmail.com \
--cc=boris.brezillon@free-electrons.com \
--cc=computersforpeace@gmail.com \
--cc=dwmw2@infradead.org \
--cc=linux-mtd@lists.infradead.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=sjitindarsingh@gmail.com \
--cc=stewart@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.