Skip to contentSkip to conversation

usb: gadget: aspeed: fixup vhub port irq handling

PATCH In review [email protected] 2 participants 8 messages May 28, 2020 – Aug 31, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: gadget: aspeed: fixup vhub port irq handling

From: Tao Ren <[email protected]>

This is a follow-on patch for commit a23be4ed8f48 ("usb: gadget: aspeed:
improve vhub port irq handling"): for_each_set_bit() is replaced with simple for() loop because for() loop runs faster on ASPEED BMC.

---
 drivers/usb/gadget/udc/aspeed-vhub/core.c | 10 +++-------
 drivers/usb/gadget/udc/aspeed-vhub/vhub.h |  3 +++
 2 files changed, 6 insertions(+), 7 deletions(-)
drivers/usb/gadget/udc/aspeed-vhub/core.c +3 -7
index cdf96911e4b1..be7bb64e3594 100644
@@ -135,13 +135,9 @@ static irqreturn_t ast_vhub_irq(int irq, void *data)
 
 	/* Handle device interrupts */
 	if (istat & vhub->port_irq_mask) {
-		unsigned long bitmap = istat;
-		int offset = VHUB_IRQ_DEV1_BIT;
-		int size = VHUB_IRQ_DEV1_BIT + vhub->max_ports;
-
-		for_each_set_bit_from(offset, &bitmap, size) {
-			i = offset - VHUB_IRQ_DEV1_BIT;
-			ast_vhub_dev_irq(&vhub->ports[i].dev);
+		for (i = 0; i < vhub->max_ports; i++) {
+			if (istat & VHUB_DEV_IRQ(i))
+				ast_vhub_dev_irq(&vhub->ports[i].dev);
 		}
 	}
 
drivers/usb/gadget/udc/aspeed-vhub/vhub.h +3 -0
index 2e5a1ef14a75..87a5dea12d3c 100644
@@ -67,6 +67,9 @@
 #define VHUB_IRQ_HUB_EP0_SETUP			(1 << 0)
 #define VHUB_IRQ_ACK_ALL			0x1ff
 
+/* Downstream device IRQ mask. */
+#define VHUB_DEV_IRQ(n)				(VHUB_IRQ_DEVICE1 << (n))
+
 /* SW reset reg */
 #define VHUB_SW_RESET_EP_POOL			(1 << 9)
 #define VHUB_SW_RESET_DMA_CONTROLLER		(1 << 8)
Signature · 1 line
2.17.1
author
#1 lore raw

Hi Ben,

I sent out the follow-on patch per Greg's suggestion, and the purpose is to include the latest version (v4) of the original commit. As v4 was already Acked-by you, can I add the tag for this patch? Or are you willing to Ack it again?

Cheers,

Tao

Quoted 50 lines · rentao.bupt at gmail.com

From: Tao Ren <[email protected]>

This is a follow-on patch for commit a23be4ed8f48 ("usb: gadget: aspeed:
improve vhub port irq handling"): for_each_set_bit() is replaced with simple for() loop because for() loop runs faster on ASPEED BMC.

---
 drivers/usb/gadget/udc/aspeed-vhub/core.c | 10 +++-------
 drivers/usb/gadget/udc/aspeed-vhub/vhub.h |  3 +++
 2 files changed, 6 insertions(+), 7 deletions(-)
drivers/usb/gadget/udc/aspeed-vhub/core.c +3 -7
index cdf96911e4b1..be7bb64e3594 100644
@@ -135,13 +135,9 @@ static irqreturn_t ast_vhub_irq(int irq, void *data)
 
 	/* Handle device interrupts */
 	if (istat & vhub->port_irq_mask) {
-		unsigned long bitmap = istat;
-		int offset = VHUB_IRQ_DEV1_BIT;
-		int size = VHUB_IRQ_DEV1_BIT + vhub->max_ports;
-
-		for_each_set_bit_from(offset, &bitmap, size) {
-			i = offset - VHUB_IRQ_DEV1_BIT;
-			ast_vhub_dev_irq(&vhub->ports[i].dev);
+		for (i = 0; i < vhub->max_ports; i++) {
+			if (istat & VHUB_DEV_IRQ(i))
+				ast_vhub_dev_irq(&vhub->ports[i].dev);
 		}
 	}
 
drivers/usb/gadget/udc/aspeed-vhub/vhub.h +3 -0
index 2e5a1ef14a75..87a5dea12d3c 100644
@@ -67,6 +67,9 @@
 #define VHUB_IRQ_HUB_EP0_SETUP			(1 << 0)
 #define VHUB_IRQ_ACK_ALL			0x1ff
 
+/* Downstream device IRQ mask. */
+#define VHUB_DEV_IRQ(n)				(VHUB_IRQ_DEVICE1 << (n))
+
 /* SW reset reg */
 #define VHUB_SW_RESET_EP_POOL			(1 << 9)
 #define VHUB_SW_RESET_DMA_CONTROLLER		(1 << 8)
Signature · 1 line
2.17.1
#2 lore raw
In reply to [email protected]

Hi,

Quoted 20 lines · rentao.bupt at gmail.com

From: Tao Ren <[email protected]>

This is a follow-on patch for commit a23be4ed8f48 ("usb: gadget: aspeed:
improve vhub port irq handling"): for_each_set_bit() is replaced with simple for() loop because for() loop runs faster on ASPEED BMC.

---
 drivers/usb/gadget/udc/aspeed-vhub/core.c | 10 +++-------
 drivers/usb/gadget/udc/aspeed-vhub/vhub.h |  3 +++
 2 files changed, 6 insertions(+), 7 deletions(-)
drivers/usb/gadget/udc/aspeed-vhub/core.c +0 -0
index cdf96911e4b1..be7bb64e3594 100644
@@ -135,13 +135,9 @@ static irqreturn_t ast_vhub_irq(int irq, void *data)
 
 	/* Handle device interrupts */
 	if (istat & vhub->port_irq_mask) {

drivers/usb/gadget/udc/aspeed-vhub/core.c static irqreturn_t ast_vhub_irq(int irq, void *data) · line 140

Quoted 10 lines
drivers/usb/gadget/udc/aspeed-vhub/core.c +3 -7
-		unsigned long bitmap = istat;
-		int offset = VHUB_IRQ_DEV1_BIT;
-		int size = VHUB_IRQ_DEV1_BIT + vhub->max_ports;
-
-		for_each_set_bit_from(offset, &bitmap, size) {
-			i = offset - VHUB_IRQ_DEV1_BIT;
-			ast_vhub_dev_irq(&vhub->ports[i].dev);
+		for (i = 0; i < vhub->max_ports; i++) {
+			if (istat & VHUB_DEV_IRQ(i))
+				ast_vhub_dev_irq(&vhub->ports[i].dev);

how have you measured your statement above? for_each_set_bit() does exactly what you did. Unless your architecture has an instruction which helps finds the next set bit (like cls on ARM), which, then, makes it much faster.

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 857 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/linux-aspeed/attachments/20200817/5793c222/attachment.sig>
author
#3 lore raw
Quoted 31 lines · Felipe Balbi

Hi,

Quoted 27 lines · rentao.bupt at gmail.com

From: Tao Ren <[email protected]>

This is a follow-on patch for commit a23be4ed8f48 ("usb: gadget: aspeed:
improve vhub port irq handling"): for_each_set_bit() is replaced with simple for() loop because for() loop runs faster on ASPEED BMC.

---
 drivers/usb/gadget/udc/aspeed-vhub/core.c | 10 +++-------
 drivers/usb/gadget/udc/aspeed-vhub/vhub.h |  3 +++
 2 files changed, 6 insertions(+), 7 deletions(-)
drivers/usb/gadget/udc/aspeed-vhub/core.c +0 -7
index cdf96911e4b1..be7bb64e3594 100644
@@ -135,13 +135,9 @@ static irqreturn_t ast_vhub_irq(int irq, void *data)
 
 	/* Handle device interrupts */
 	if (istat & vhub->port_irq_mask) {
-		unsigned long bitmap = istat;
-		int offset = VHUB_IRQ_DEV1_BIT;
-		int size = VHUB_IRQ_DEV1_BIT + vhub->max_ports;
-
-		for_each_set_bit_from(offset, &bitmap, size) {
-			i = offset - VHUB_IRQ_DEV1_BIT;
-			ast_vhub_dev_irq(&vhub->ports[i].dev);
Quoted 8 lines

drivers/usb/gadget/udc/aspeed-vhub/core.c static irqreturn_t ast_vhub_irq(int irq, void *data) · line 140

Quoted 3 lines
drivers/usb/gadget/udc/aspeed-vhub/core.c +3 -0
+		for (i = 0; i < vhub->max_ports; i++) {
+			if (istat & VHUB_DEV_IRQ(i))
+				ast_vhub_dev_irq(&vhub->ports[i].dev);

how have you measured your statement above? for_each_set_bit() does exactly what you did. Unless your architecture has an instruction which helps finds the next set bit (like cls on ARM), which, then, makes it much faster.

I did some testing and result shows for() loop runs faster than for_each_set_bit() loop. Please refer to details below (discussion with Benjamin in the original patch) and kindly let me know your suggestions.

Quoted 18 lines · Tao Ren
Quoted 17 lines

I ran some testing on my ast2400 and ast2500 BMC and looks like the for() loop runs faster than for_each_set_bit_from() loop in my environment. I'm not sure if something needs to be revised in my test code, but please kindly share your suggestions:

I use get_cycles() to calculate execution time of 2 different loops, and ast_vhub_dev_irq() is replaced with barrier() to avoid "noise"; below are the results:

- when downstream port number is 5 and only 1 irq bit is set, it takes ~30 cycles to finish for_each_set_bit() loop, and 20-25 cycles to finish the for() loop.

- if downstream port number is 5 and all 5 bits are set, then for_each_set_bit() loop takes ~50 cycles and for() loop takes ~25 cycles.

Quoted 8 lines
Quoted 8 lines

- when I increase downsteam port number to 16 and set 1 irq bit, the for_each_set_bit() loop takes ~30 cycles and for() loop takes 25 cycles. It's a little surprise to me because I thought for() loop would cost 60+ cycles (3 times of the value when port number is 5).

- if downstream port number is 16 and all irq status bits are set, then for_each_set_bit() loop takes 60-70 cycles and for() loop takes 30+ cycles.

Cheers,

Tao

#4 lore raw

Hi,

Quoted 41 lines · Tao Ren
Quoted 31 lines · Felipe Balbi

Hi,

Quoted 27 lines · rentao.bupt at gmail.com

From: Tao Ren <[email protected]>

This is a follow-on patch for commit a23be4ed8f48 ("usb: gadget: aspeed:
improve vhub port irq handling"): for_each_set_bit() is replaced with simple for() loop because for() loop runs faster on ASPEED BMC.

---
 drivers/usb/gadget/udc/aspeed-vhub/core.c | 10 +++-------
 drivers/usb/gadget/udc/aspeed-vhub/vhub.h |  3 +++
 2 files changed, 6 insertions(+), 7 deletions(-)
drivers/usb/gadget/udc/aspeed-vhub/core.c +0 -7
index cdf96911e4b1..be7bb64e3594 100644
@@ -135,13 +135,9 @@ static irqreturn_t ast_vhub_irq(int irq, void *data)
 
 	/* Handle device interrupts */
 	if (istat & vhub->port_irq_mask) {
-		unsigned long bitmap = istat;
-		int offset = VHUB_IRQ_DEV1_BIT;
-		int size = VHUB_IRQ_DEV1_BIT + vhub->max_ports;
-
-		for_each_set_bit_from(offset, &bitmap, size) {
-			i = offset - VHUB_IRQ_DEV1_BIT;
-			ast_vhub_dev_irq(&vhub->ports[i].dev);
Quoted 8 lines

drivers/usb/gadget/udc/aspeed-vhub/core.c static irqreturn_t ast_vhub_irq(int irq, void *data) · line 140

Quoted 3 lines
drivers/usb/gadget/udc/aspeed-vhub/core.c +3 -0
+		for (i = 0; i < vhub->max_ports; i++) {
+			if (istat & VHUB_DEV_IRQ(i))
+				ast_vhub_dev_irq(&vhub->ports[i].dev);

how have you measured your statement above? for_each_set_bit() does exactly what you did. Unless your architecture has an instruction which helps finds the next set bit (like cls on ARM), which, then, makes it much faster.

Quoted 3 lines

I did some testing and result shows for() loop runs faster than for_each_set_bit() loop. Please refer to details below (discussion with Benjamin in the original patch) and kindly let me know your suggestions.

no strong feelings, just surprised that you're already worried about 20~40 cycles of cpu time ;-)

Patch applied for next merge window

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 857 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/linux-aspeed/attachments/20200831/6f6ceba7/attachment.sig>
#5 lore raw
In reply to Tao Ren

Hi,

Quoted 41 lines · Tao Ren
Quoted 31 lines · Felipe Balbi

Hi,

Quoted 27 lines · rentao.bupt at gmail.com

From: Tao Ren <[email protected]>

This is a follow-on patch for commit a23be4ed8f48 ("usb: gadget: aspeed:
improve vhub port irq handling"): for_each_set_bit() is replaced with simple for() loop because for() loop runs faster on ASPEED BMC.

---
 drivers/usb/gadget/udc/aspeed-vhub/core.c | 10 +++-------
 drivers/usb/gadget/udc/aspeed-vhub/vhub.h |  3 +++
 2 files changed, 6 insertions(+), 7 deletions(-)
drivers/usb/gadget/udc/aspeed-vhub/core.c +0 -7
index cdf96911e4b1..be7bb64e3594 100644
@@ -135,13 +135,9 @@ static irqreturn_t ast_vhub_irq(int irq, void *data)
 
 	/* Handle device interrupts */
 	if (istat & vhub->port_irq_mask) {
-		unsigned long bitmap = istat;
-		int offset = VHUB_IRQ_DEV1_BIT;
-		int size = VHUB_IRQ_DEV1_BIT + vhub->max_ports;
-
-		for_each_set_bit_from(offset, &bitmap, size) {
-			i = offset - VHUB_IRQ_DEV1_BIT;
-			ast_vhub_dev_irq(&vhub->ports[i].dev);
Quoted 8 lines

drivers/usb/gadget/udc/aspeed-vhub/core.c static irqreturn_t ast_vhub_irq(int irq, void *data) · line 140

Quoted 3 lines
drivers/usb/gadget/udc/aspeed-vhub/core.c +3 -0
+		for (i = 0; i < vhub->max_ports; i++) {
+			if (istat & VHUB_DEV_IRQ(i))
+				ast_vhub_dev_irq(&vhub->ports[i].dev);

how have you measured your statement above? for_each_set_bit() does exactly what you did. Unless your architecture has an instruction which helps finds the next set bit (like cls on ARM), which, then, makes it much faster.

Quoted 3 lines

I did some testing and result shows for() loop runs faster than for_each_set_bit() loop. Please refer to details below (discussion with Benjamin in the original patch) and kindly let me know your suggestions.

no strong feelings, just surprised that you're already worried about 20~40 cycles of cpu time ;-)

Patch applied for next merge window

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 857 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/linux-aspeed/attachments/20200831/51107915/attachment.sig>
author
#6 lore raw
Quoted 45 lines · Felipe Balbi

Hi,

Quoted 41 lines · Tao Ren
Quoted 39 lines · Felipe Balbi

Hi,

Quoted 20 lines · rentao.bupt at gmail.com

From: Tao Ren <[email protected]>

This is a follow-on patch for commit a23be4ed8f48 ("usb: gadget: aspeed:
improve vhub port irq handling"): for_each_set_bit() is replaced with simple for() loop because for() loop runs faster on ASPEED BMC.

---
 drivers/usb/gadget/udc/aspeed-vhub/core.c | 10 +++-------
 drivers/usb/gadget/udc/aspeed-vhub/vhub.h |  3 +++
 2 files changed, 6 insertions(+), 7 deletions(-)
drivers/usb/gadget/udc/aspeed-vhub/core.c +0 -0
index cdf96911e4b1..be7bb64e3594 100644
@@ -135,13 +135,9 @@ static irqreturn_t ast_vhub_irq(int irq, void *data)
 
 	/* Handle device interrupts */
 	if (istat & vhub->port_irq_mask) {

drivers/usb/gadget/udc/aspeed-vhub/core.c static irqreturn_t ast_vhub_irq(int irq, void *data) · line 140

Quoted 10 lines
drivers/usb/gadget/udc/aspeed-vhub/core.c +3 -7
-		unsigned long bitmap = istat;
-		int offset = VHUB_IRQ_DEV1_BIT;
-		int size = VHUB_IRQ_DEV1_BIT + vhub->max_ports;
-
-		for_each_set_bit_from(offset, &bitmap, size) {
-			i = offset - VHUB_IRQ_DEV1_BIT;
-			ast_vhub_dev_irq(&vhub->ports[i].dev);
+		for (i = 0; i < vhub->max_ports; i++) {
+			if (istat & VHUB_DEV_IRQ(i))
+				ast_vhub_dev_irq(&vhub->ports[i].dev);

how have you measured your statement above? for_each_set_bit() does exactly what you did. Unless your architecture has an instruction which helps finds the next set bit (like cls on ARM), which, then, makes it much faster.

Quoted 8 lines
Quoted 3 lines

I did some testing and result shows for() loop runs faster than for_each_set_bit() loop. Please refer to details below (discussion with Benjamin in the original patch) and kindly let me know your suggestions.

no strong feelings, just surprised that you're already worried about 20~40 cycles of cpu time ;-)

Patch applied for next merge window

Thanks Felipe. Ben had some concerns about interrupt handling cost on AST2400 BMC (ARM9), hence we did the comparison and noticed the small difference :)

Cheers,

Tao

#7 lore raw
In reply to Tao Ren

Hi,

Quoted 24 lines · Tao Ren
Quoted 15 lines
Quoted 15 lines
drivers/usb/gadget/udc/aspeed-vhub/core.c +0 -7
index cdf96911e4b1..be7bb64e3594 100644
@@ -135,13 +135,9 @@ static irqreturn_t ast_vhub_irq(int irq, void *data)
 
 	/* Handle device interrupts */
 	if (istat & vhub->port_irq_mask) {
-		unsigned long bitmap = istat;
-		int offset = VHUB_IRQ_DEV1_BIT;
-		int size = VHUB_IRQ_DEV1_BIT + vhub->max_ports;
-
-		for_each_set_bit_from(offset, &bitmap, size) {
-			i = offset - VHUB_IRQ_DEV1_BIT;
-			ast_vhub_dev_irq(&vhub->ports[i].dev);
Quoted 8 lines

drivers/usb/gadget/udc/aspeed-vhub/core.c static irqreturn_t ast_vhub_irq(int irq, void *data) · line 140

Quoted 3 lines
drivers/usb/gadget/udc/aspeed-vhub/core.c +3 -0
+		for (i = 0; i < vhub->max_ports; i++) {
+			if (istat & VHUB_DEV_IRQ(i))
+				ast_vhub_dev_irq(&vhub->ports[i].dev);

how have you measured your statement above? for_each_set_bit() does exactly what you did. Unless your architecture has an instruction which helps finds the next set bit (like cls on ARM), which, then, makes it much faster.

Quoted 4 lines

I did some testing and result shows for() loop runs faster than for_each_set_bit() loop. Please refer to details below (discussion with Benjamin in the original patch) and kindly let me know your suggestions.

no strong feelings, just surprised you're already worried about 20~40 cycles of cpu time ;-)

patch queued for next merge window

Signature · 1 line
balbi