infiniband: Help gcc generate better code for ocrdma_srq_toggle_bit
Subsystems (2)
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.
--- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +1 -4
@@ -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)
Signature · 6 lines
2.1.3 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 2/2 infiniband: Use unsigned for bit index
In the expressions idx/32 and idx%32, both idx and 32 have signed type, and unfortunately the C standard prescribes rounding to 0, so unless gcc can prove that idx is non-negative, these cannot be implemented as simple shift respectively mask operations. Help gcc by changing the type of idx to unsigned - this cuts another few instructions from the generated code.
--- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +3 -3
@@ -1479,10 +1479,10 @@ mbx_err:return status; } -static void ocrdma_srq_toggle_bit (struct ocrdma_srq *srq,int idx) +static void ocrdma_srq_toggle_bit (struct ocrdma_srq *srq,unsigned int idx) { -int i = idx /32 ; -unsigned int mask = (1 << (idx %32 )); +unsigned int i = idx /32 ; +u32 mask = (1U << (idx %32 )); srq->idx_bit_fields[i] ^= mask; }
Signature · 1 line
2.1.3
ping
Quoted 24 lines · Rasmus Villemoes
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 -56All three calls of
ocrdma_srq_toggle_bithappen within spinlocks, so saving a few useless instructions might be worthwhile.--- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +0
-0@@ -1484,10 +1484,7 @@ static void ocrdma_srq_toggle_bit(struct ocrdma_srq *srq, int idx)int i = idx /32 ;
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c static void ocrdma_srq_toggle_bit(struct ocrdma_srq *srq, int idx) · line 1490
Quoted 10 lines
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +1
-4unsigned 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 [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi,
Quoted 2 lines · Rasmus Villemoes
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.
Quoted 35 lines · Rasmus Villemoes
Quoted 34 lines
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 -56All three calls of
ocrdma_srq_toggle_bithappen within spinlocks, so saving a few useless instructions might be worthwhile.--- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +1
-4@@ -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; }
Quoted 2 lines
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c static void ocrdma_srq_toggle_bit(struct ocrdma_srq *srq, int idx) · line 1490
Quoted 1 line
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +0
-0static int ocrdma_hwq_free_cnt (struct ocrdma_qp_hwq_info *q)--
Regards.
Signature · 9 lines
Yann Droneaud OPTEYA -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH 2/2] infiniband: Use unsigned for bit index
In reply to Rasmus VillemoesThanks!
Quoted 43 lines
-----Original Message-----
From: [email protected] [mailto:linux-rdma- [email protected]] On Behalf Of Rasmus Villemoes
Sent: Friday, January 16, 2015 8:10 PM
To: Roland Dreier; Sean Hefty; Hal Rosenstock
Cc: Rasmus Villemoes; [email protected]; linux- [email protected]
Subject: [PATCH 2/2] infiniband: Use unsigned for bit indexIn the expressions idx/32 and idx%32, both idx and 32 have signed type, and unfortunately the C standard prescribes rounding to 0, so unless gcc can prove that idx is non-negative, these cannot be implemented as simple shift respectively mask operations. Help gcc by changing the type of idx to unsigned - this cuts another few instructions from the generated code.
--- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +4
-4@@ -1479,10 +1479,10 @@ mbx_err:return status; } -static void ocrdma_srq_toggle_bit (struct ocrdma_srq *srq,int idx) +static void ocrdma_srq_toggle_bit (struct ocrdma_srq *srq,unsigned int +idx) { -int i = idx /32 ; -unsigned int mask = (1 << (idx %32 )); +unsigned int i = idx /32 ; +u32 mask = (1U << (idx %32 )); srq->idx_bit_fields[i] ^= mask; } --2.1.3
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] 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 [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Thanks!
Quoted 50 lines
-----Original Message-----
From: [email protected] [mailto:linux-rdma- [email protected]] On Behalf Of Rasmus Villemoes
Sent: Friday, January 16, 2015 8:10 PM
To: Roland Dreier; Sean Hefty; Hal Rosenstock
Cc: Rasmus Villemoes; [email protected]; linux- [email protected]
Subject: [PATCH 1/2] infiniband: Help gcc generate better code forocrdma_srq_toggle_bitgcc 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 -56All three calls of
ocrdma_srq_toggle_bithappen within spinlocks, so saving a few useless instructions might be worthwhile.--- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +1
-4@@ -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
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] 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 [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
VGhhbmsgeW91IFlhbm4gRHJvbmVhdWQgZm9yIGZvcndhcmRpbmcgdGhpcyBtYWlsLg0KDQpXZSB3 aWxsIGFkZCAgYW4gZW50cnkgZm9yIG9jcmRtYSBkcml2ZXIgaW4gTUFJTlRBSU5FUlMgZmlsZS4N Cg0KVGhhbmtzLA0KU2VsdmluIFhhdmllcg0KDQo+IC0tLS0tT3JpZ2luYWwgTWVzc2FnZS0tLS0t DQo+IEZyb206IFlhbm4gRHJvbmVhdWQgW21haWx0bzp5ZHJvbmVhdWRAb3B0ZXlhLmNvbV0NCj4g U2VudDogU2F0dXJkYXksIEphbnVhcnkgMzEsIDIwMTUgNDozOCBQTQ0KPiBUbzogUmFzbXVzIFZp bGxlbW9lcw0KPiBDYzogUm9sYW5kIERyZWllcjsgU2VhbiBIZWZ0eTsgSGFsIFJvc2Vuc3RvY2s7 IGxpbnV4LXJkbWFAdmdlci5rZXJuZWwub3JnOw0KPiBsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwu b3JnOyBEZXZlc2ggU2hhcm1hOyBTZWx2aW4gWGF2aWVyOyBNaXRlc2ggQWh1amENCj4gU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tLSBhL2Ry aXZlcnMvaW5maW5pYmFuZC9ody9vY3JkbWEvb2NyZG1hX3ZlcmJzLmMNCj4gPiA+ICsrKyBiL2Ry aXZlcnMvaW5maW5pYmFuZC9ody9vY3JkbWEvb2NyZG1hX3ZlcmJzLmMNCj4gPiA+IEBAIC0xNDg0 LDEwICsxNDg0LDcgQEAgc3RhdGljIHZvaWQgb2NyZG1hX3NycV90b2dnbGVfYml0KHN0cnVjdA0K PiBvY3JkbWFfc3JxICpzcnEsIGludCBpZHgpDQo+ID4gPiAgCWludCBpID0gaWR4IC8gMzI7DQo+ ID4gPiAgCXVuc2lnbmVkIGludCBtYXNrID0gKDEgPDwgKGlkeCAlIDMyKSk7DQo+ID4gPg0KPiA+ ID4gLQlpZiAoc3JxLT5pZHhfYml0X2ZpZWxkc1tpXSAmIG1hc2spDQo+ID4gPiAtCQlzcnEtPmlk eF9iaXRfZmllbGRzW2ldICY9IH5tYXNrOw0KPiA+ID4gLQllbHNlDQo+ID4gPiAtCQlzcnEtPmlk eF9iaXRfZmllbGRzW2ldIHw9IG1hc2s7DQo+ID4gPiArCXNycS0+aWR4X2JpdF9maWVsZHNbaV0g Xj0gbWFzazsNCj4gPiA+ICB9DQo+ID4gPg0KPiA+ID4gIHN0YXRpYyBpbnQgb2NyZG1hX2h3cV9m cmVlX2NudChzdHJ1Y3Qgb2NyZG1hX3FwX2h3cV9pbmZvICpxKQ0KPiA+IC0tDQo+IA0KPiBSZWdh cmRzLg0KPiANCj4gLS0NCj4gWWFubiBEcm9uZWF1ZA0KPiBPUFRFWUENCj4gDQo+IA0KDQo= --
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html