diff mbox

[1/2] infiniband: Help gcc generate better code for ocrdma_srq_toggle_bit

Message ID 1421419196-4659-1-git-send-email-linux@rasmusvillemoes.dk (mailing list archive)
State Accepted, archived
Headers show

Commit Message

Rasmus Villemoes Jan. 16, 2015, 2:39 p.m. UTC
gcc emits a surprising amount of code in order to flip a bit. One
would think that a single instruction is enough.

$ scripts/bloat-o-meter /tmp/ocrdma_verbs.o drivers/infiniband/hw/ocrdma/ocrdma_verbs.o
add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-142 (-142)
function                                     old     new   delta
ocrdma_post_srq_recv                         498     460     -38
ocrdma_poll_cq                              2010    1962     -48
ocrdma_discard_cqes                          495     439     -56

All three calls of ocrdma_srq_toggle_bit happen within spinlocks, so
saving a few useless instructions might be worthwhile.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

Comments

Rasmus Villemoes Jan. 30, 2015, 11 p.m. UTC | #1
ping

On Fri, Jan 16 2015, Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote:

> gcc emits a surprising amount of code in order to flip a bit. One
> would think that a single instruction is enough.
>
> $ scripts/bloat-o-meter /tmp/ocrdma_verbs.o drivers/infiniband/hw/ocrdma/ocrdma_verbs.o
> add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-142 (-142)
> function                                     old     new   delta
> ocrdma_post_srq_recv                         498     460     -38
> ocrdma_poll_cq                              2010    1962     -48
> ocrdma_discard_cqes                          495     439     -56
>
> All three calls of ocrdma_srq_toggle_bit happen within spinlocks, so
> saving a few useless instructions might be worthwhile.
>
> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> ---
>  drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
> index fb8d8c4dfbb9..eff11e6c6183 100644
> --- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
> +++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
> @@ -1484,10 +1484,7 @@ static void ocrdma_srq_toggle_bit(struct ocrdma_srq *srq, int idx)
>  	int i = idx / 32;
>  	unsigned int mask = (1 << (idx % 32));
>  
> -	if (srq->idx_bit_fields[i] & mask)
> -		srq->idx_bit_fields[i] &= ~mask;
> -	else
> -		srq->idx_bit_fields[i] |= mask;
> +	srq->idx_bit_fields[i] ^= mask;
>  }
>  
>  static int ocrdma_hwq_free_cnt(struct ocrdma_qp_hwq_info *q)
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Yann Droneaud Jan. 31, 2015, 11:07 a.m. UTC | #2
Hi,

Le samedi 31 janvier 2015 à 00:00 +0100, Rasmus Villemoes a écrit :
> ping
> 

As you're fixing ocrdma driver, I think you might want to find people
@emulex.com to review your patches.

BTW, there's no MAINTAINERS entry for ocrdma driver ... which is a pity.

> On Fri, Jan 16 2015, Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote:
> 
> > gcc emits a surprising amount of code in order to flip a bit. One
> > would think that a single instruction is enough.
> >
> > $ scripts/bloat-o-meter /tmp/ocrdma_verbs.o drivers/infiniband/hw/ocrdma/ocrdma_verbs.o
> > add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-142 (-142)
> > function                                     old     new   delta
> > ocrdma_post_srq_recv                         498     460     -38
> > ocrdma_poll_cq                              2010    1962     -48
> > ocrdma_discard_cqes                          495     439     -56
> >
> > All three calls of ocrdma_srq_toggle_bit happen within spinlocks, so
> > saving a few useless instructions might be worthwhile.
> >
> > Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> > ---
> >  drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 5 +----
> >  1 file changed, 1 insertion(+), 4 deletions(-)
> >
> > diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
> > index fb8d8c4dfbb9..eff11e6c6183 100644
> > --- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
> > +++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
> > @@ -1484,10 +1484,7 @@ static void ocrdma_srq_toggle_bit(struct ocrdma_srq *srq, int idx)
> >  	int i = idx / 32;
> >  	unsigned int mask = (1 << (idx % 32));
> >  
> > -	if (srq->idx_bit_fields[i] & mask)
> > -		srq->idx_bit_fields[i] &= ~mask;
> > -	else
> > -		srq->idx_bit_fields[i] |= mask;
> > +	srq->idx_bit_fields[i] ^= mask;
> >  }
> >  
> >  static int ocrdma_hwq_free_cnt(struct ocrdma_qp_hwq_info *q)
> --

Regards.
Selvin Xavier Feb. 2, 2015, 12:04 p.m. UTC | #3
Acked-by: Selvin Xavier <selvin.xavier@emulex.com>

Thanks!

> -----Original Message-----
> From: linux-rdma-owner@vger.kernel.org [mailto:linux-rdma-
> owner@vger.kernel.org] On Behalf Of Rasmus Villemoes
> Sent: Friday, January 16, 2015 8:10 PM
> To: Roland Dreier; Sean Hefty; Hal Rosenstock
> Cc: Rasmus Villemoes; linux-rdma@vger.kernel.org; linux-
> kernel@vger.kernel.org
> Subject: [PATCH 1/2] infiniband: Help gcc generate better code for
> ocrdma_srq_toggle_bit
> 
> gcc emits a surprising amount of code in order to flip a bit. One would think
> that a single instruction is enough.
> 
> $ scripts/bloat-o-meter /tmp/ocrdma_verbs.o
> drivers/infiniband/hw/ocrdma/ocrdma_verbs.o
> add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-142 (-142)
> function                                     old     new   delta
> ocrdma_post_srq_recv                         498     460     -38
> ocrdma_poll_cq                              2010    1962     -48
> ocrdma_discard_cqes                          495     439     -56
> 
> All three calls of ocrdma_srq_toggle_bit happen within spinlocks, so saving a
> few useless instructions might be worthwhile.
> 
> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> ---
>  drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
> b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
> index fb8d8c4dfbb9..eff11e6c6183 100644
> --- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
> +++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
> @@ -1484,10 +1484,7 @@ static void ocrdma_srq_toggle_bit(struct
> ocrdma_srq *srq, int idx)
>  	int i = idx / 32;
>  	unsigned int mask = (1 << (idx % 32));
> 
> -	if (srq->idx_bit_fields[i] & mask)
> -		srq->idx_bit_fields[i] &= ~mask;
> -	else
> -		srq->idx_bit_fields[i] |= mask;
> +	srq->idx_bit_fields[i] ^= mask;
>  }
> 
>  static int ocrdma_hwq_free_cnt(struct ocrdma_qp_hwq_info *q)
> --
> 2.1.3
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the
> body of a message to majordomo@vger.kernel.org More majordomo info at
> http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Selvin Xavier Feb. 2, 2015, 12:58 p.m. UTC | #4
Thank you Yann Droneaud for forwarding this mail.

We will add  an entry for ocrdma driver in MAINTAINERS file.

Thanks,
Selvin Xavier

> -----Original Message-----

> From: Yann Droneaud [mailto:ydroneaud@opteya.com]

> Sent: Saturday, January 31, 2015 4:38 PM

> To: Rasmus Villemoes

> Cc: Roland Dreier; Sean Hefty; Hal Rosenstock; linux-rdma@vger.kernel.org;

> linux-kernel@vger.kernel.org; Devesh Sharma; Selvin Xavier; Mitesh Ahuja

> Subject: Re: [PATCH 1/2] infiniband: Help gcc generate better code for

> ocrdma_srq_toggle_bit

> 

> Hi,

> 

> Le samedi 31 janvier 2015 à 00:00 +0100, Rasmus Villemoes a écrit :

> > ping

> >

> 

> As you're fixing ocrdma driver, I think you might want to find people

> @emulex.com to review your patches.

> 

> BTW, there's no MAINTAINERS entry for ocrdma driver ... which is a pity.

> 

> > On Fri, Jan 16 2015, Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote:

> >

> > > gcc emits a surprising amount of code in order to flip a bit. One

> > > would think that a single instruction is enough.

> > >

> > > $ scripts/bloat-o-meter /tmp/ocrdma_verbs.o

> > > drivers/infiniband/hw/ocrdma/ocrdma_verbs.o

> > > add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-142 (-142)

> > > function                                     old     new   delta

> > > ocrdma_post_srq_recv                         498     460     -38

> > > ocrdma_poll_cq                              2010    1962     -48

> > > ocrdma_discard_cqes                          495     439     -56

> > >

> > > All three calls of ocrdma_srq_toggle_bit happen within spinlocks, so

> > > saving a few useless instructions might be worthwhile.

> > >

> > > Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>

> > > ---

> > >  drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 5 +----

> > >  1 file changed, 1 insertion(+), 4 deletions(-)

> > >

> > > diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c

> > > b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c

> > > index fb8d8c4dfbb9..eff11e6c6183 100644

> > > --- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c

> > > +++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c

> > > @@ -1484,10 +1484,7 @@ static void ocrdma_srq_toggle_bit(struct

> ocrdma_srq *srq, int idx)

> > >  	int i = idx / 32;

> > >  	unsigned int mask = (1 << (idx % 32));

> > >

> > > -	if (srq->idx_bit_fields[i] & mask)

> > > -		srq->idx_bit_fields[i] &= ~mask;

> > > -	else

> > > -		srq->idx_bit_fields[i] |= mask;

> > > +	srq->idx_bit_fields[i] ^= mask;

> > >  }

> > >

> > >  static int ocrdma_hwq_free_cnt(struct ocrdma_qp_hwq_info *q)

> > --

> 

> Regards.

> 

> --

> Yann Droneaud

> OPTEYA

> 

>
diff mbox

Patch

diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
index fb8d8c4dfbb9..eff11e6c6183 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
@@ -1484,10 +1484,7 @@  static void ocrdma_srq_toggle_bit(struct ocrdma_srq *srq, int idx)
 	int i = idx / 32;
 	unsigned int mask = (1 << (idx % 32));
 
-	if (srq->idx_bit_fields[i] & mask)
-		srq->idx_bit_fields[i] &= ~mask;
-	else
-		srq->idx_bit_fields[i] |= mask;
+	srq->idx_bit_fields[i] ^= mask;
 }
 
 static int ocrdma_hwq_free_cnt(struct ocrdma_qp_hwq_info *q)