usb: gadget: aspeed: improve vhub port irq handling
Subsystems (2)
PATCH v3 1/1 usb: gadget: aspeed: improve vhub port irq handling
From: Tao Ren <[email protected]>
This patch evaluates vhub ports' irq mask before going through per-port irq handling one by one, which helps to speed up irq handling in case there is no port interrupt.
---
Changes in v3:
- assign istat to (unsigned long) bitmap before calling
"for_each_set_bit_from".
Changes in v2:
- use "for_each_set_bit" to speed up port irq handling.
drivers/usb/gadget/udc/aspeed-vhub/core.c | 12 +++++++++--- drivers/usb/gadget/udc/aspeed-vhub/vhub.h | 8 +++----- 2 files changed, 12 insertions(+), 8 deletions(-)
drivers/usb/gadget/udc/aspeed-vhub/core.c +9 -3
@@ -134,11 +134,15 @@ static irqreturn_t ast_vhub_irq(int irq, void *data) }/* Handle device interrupts */ -for (i =0 ; i < vhub->max_ports; i++) { -u32 dev_mask =VHUB_IRQ_DEVICE1 << i; +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; -if (istat & dev_mask) +for_each_set_bit_from (offset, &bitmap, size) { + i = offset -VHUB_IRQ_DEV1_BIT ;ast_vhub_dev_irq (&vhub->ports[i].dev); + } }/* Handle top-level vHub EP0 interrupts */
@@ -332,6 +336,8 @@ static int ast_vhub_probe(struct platform_device *pdev)spin_lock_init (&vhub->lock); vhub->pdev = pdev; + vhub->port_irq_mask =GENMASK (VHUB_IRQ_DEV1_BIT + vhub->max_ports -1 , +VHUB_IRQ_DEV1_BIT ); res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); vhub->regs =devm_ioremap_resource (&pdev->dev, res);
drivers/usb/gadget/udc/aspeed-vhub/vhub.h +3 -5
@@ -51,14 +51,11 @@#define VHUB_CTRL_UPSTREAM_CONNECT (1 << 0)/* IER & ISR */ +#define VHUB_IRQ_DEV1_BIT 9#define VHUB_IRQ_USB_CMD_DEADLOCK (1 << 18)#define VHUB_IRQ_EP_POOL_NAK (1 << 17)#define VHUB_IRQ_EP_POOL_ACK_STALL (1 << 16) -#define VHUB_IRQ_DEVICE5 (1 << 13) -#define VHUB_IRQ_DEVICE4 (1 << 12) -#define VHUB_IRQ_DEVICE3 (1 << 11) -#define VHUB_IRQ_DEVICE2 (1 << 10) -#define VHUB_IRQ_DEVICE1 (1 << 9) +#define VHUB_IRQ_DEVICE1 (1 << (VHUB_IRQ_DEV1_BIT))#define VHUB_IRQ_BUS_RESUME (1 << 8)#define VHUB_IRQ_BUS_SUSPEND (1 << 7)#define VHUB_IRQ_BUS_RESET (1 << 6)
@@ -402,6 +399,7 @@ struct ast_vhub {/* Per-port info */ struct ast_vhub_port *ports;u32 max_ports; +u32 port_irq_mask;/* Generic EP data structures */ struct ast_vhub_ep *epns;
Signature · 1 line
2.17.1
Hi Ben,
Any further comments on the patch?
Cheers,
Tao
Quoted 82 lines · rentao.bupt at gmail.com
From: Tao Ren <[email protected]>
This patch evaluates vhub ports' irq mask before going through per-port irq handling one by one, which helps to speed up irq handling in case there is no port interrupt.
Signed-off-by Tao Ren <[email protected]>---
Changes in v3:
- assign istat to (unsigned long) bitmap before calling"for_each_set_bit_from".Changes in v2:
- use "for_each_set_bit" to speed up port irq handling.drivers/usb/gadget/udc/aspeed-vhub/core.c | 12 +++++++++--- drivers/usb/gadget/udc/aspeed-vhub/vhub.h | 8 +++----- 2 files changed, 12 insertions(+), 8 deletions(-)drivers/usb/gadget/udc/aspeed-vhub/core.c +9
-3@@ -134,11 +134,15 @@ static irqreturn_t ast_vhub_irq(int irq, void *data) }/* Handle device interrupts */ -for (i =0 ; i < vhub->max_ports; i++) { -u32 dev_mask =VHUB_IRQ_DEVICE1 << i; +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; -if (istat & dev_mask) +for_each_set_bit_from (offset, &bitmap, size) { + i = offset -VHUB_IRQ_DEV1_BIT ;ast_vhub_dev_irq (&vhub->ports[i].dev); + } }/* Handle top-level vHub EP0 interrupts */ @@ -332,6 +336,8 @@ static int ast_vhub_probe(struct platform_device *pdev)spin_lock_init (&vhub->lock); vhub->pdev = pdev; + vhub->port_irq_mask =GENMASK (VHUB_IRQ_DEV1_BIT + vhub->max_ports -1 , +VHUB_IRQ_DEV1_BIT ); res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); vhub->regs =devm_ioremap_resource (&pdev->dev, res);drivers/usb/gadget/udc/aspeed-vhub/vhub.h +3
-5@@ -51,14 +51,11 @@#define VHUB_CTRL_UPSTREAM_CONNECT (1 << 0)/* IER & ISR */ +#define VHUB_IRQ_DEV1_BIT 9#define VHUB_IRQ_USB_CMD_DEADLOCK (1 << 18)#define VHUB_IRQ_EP_POOL_NAK (1 << 17)#define VHUB_IRQ_EP_POOL_ACK_STALL (1 << 16) -#define VHUB_IRQ_DEVICE5 (1 << 13) -#define VHUB_IRQ_DEVICE4 (1 << 12) -#define VHUB_IRQ_DEVICE3 (1 << 11) -#define VHUB_IRQ_DEVICE2 (1 << 10) -#define VHUB_IRQ_DEVICE1 (1 << 9) +#define VHUB_IRQ_DEVICE1 (1 << (VHUB_IRQ_DEV1_BIT))#define VHUB_IRQ_BUS_RESUME (1 << 8)#define VHUB_IRQ_BUS_SUSPEND (1 << 7)#define VHUB_IRQ_BUS_RESET (1 << 6)@@ -402,6 +399,7 @@ struct ast_vhub {/* Per-port info */ struct ast_vhub_port *ports;u32 max_ports; +u32 port_irq_mask;/* Generic EP data structures */ struct ast_vhub_ep *epns;Signature · 1 line
2.17.1
Benjamin Herrenschmidt
Acked-byQuoted 3 lines · Tao Ren
Hi Ben,
Any further comments on the patch?
Ah sorry, nope. Did you check the generated assembly to see if it looked any better ? :-)
Otherwise,
Quoted 97 lines
Cheers,
Tao
Quoted 90 lines · rentao.bupt at gmail.com
From: Tao Ren <[email protected]>
This patch evaluates vhub ports' irq mask before going through per- port
irq handling one by one, which helps to speed up irq handling in case
there is no port interrupt.Signed-off-by Tao Ren <[email protected]>---
Changes in v3:
- assign istat to (unsigned long) bitmap before calling"for_each_set_bit_from".Changes in v2:
- use "for_each_set_bit" to speed up port irq handling.drivers/usb/gadget/udc/aspeed-vhub/core.c | 12 +++++++++--- drivers/usb/gadget/udc/aspeed-vhub/vhub.h | 8 +++----- 2 files changed, 12 insertions(+), 8 deletions(-)drivers/usb/gadget/udc/aspeed-vhub/core.c +7
-3@@ -134,11 +134,15 @@ static irqreturn_t ast_vhub_irq(int irq, void *data) }/* Handle device interrupts */ -for (i =0 ; i < vhub->max_ports; i++) { -u32 dev_mask =VHUB_IRQ_DEVICE1 << i; +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; -if (istat & dev_mask) +for_each_set_bit_from (offset, &bitmap, size) { + i = offset -VHUB_IRQ_DEV1_BIT ;ast_vhub_dev_irq (&vhub->ports[i].dev); + } }drivers/usb/gadget/udc/aspeed-vhub/core.c +2
-0/* Handle top-level vHub EP0 interrupts */ @@ -332,6 +336,8 @@ static int ast_vhub_probe(struct platform_device *pdev) spin_lock_init(&vhub->lock); vhub->pdev = pdev; + vhub->port_irq_mask =GENMASK (VHUB_IRQ_DEV1_BIT + vhub- >max_ports - 1, +VHUB_IRQ_DEV1_BIT );drivers/usb/gadget/udc/aspeed-vhub/core.c +0
-0res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); vhub->regs =devm_ioremap_resource (&pdev->dev, res);drivers/usb/gadget/udc/aspeed-vhub/vhub.h +2
-5@@ -51,14 +51,11 @@#define VHUB_CTRL_UPSTREAM_CONNECT (1 << 0)/* IER & ISR */ +#define VHUB_IRQ_DEV1_BIT 9#define VHUB_IRQ_USB_CMD_DEADLOCK (1 << 18)#define VHUB_IRQ_EP_POOL_NAK (1 << 17)#define VHUB_IRQ_EP_POOL_ACK_STALL (1 << 16) -#define VHUB_IRQ_DEVICE5 (1 << 13) -#define VHUB_IRQ_DEVICE4 (1 << 12) -#define VHUB_IRQ_DEVICE3 (1 << 11) -#define VHUB_IRQ_DEVICE2 (1 << 10) -#define VHUB_IRQ_DEVICE1 (1 << 9) +#define VHUB_IRQ_DEVICE1 (1 << (VHUB_IRQ_DEV1_BIT))#define VHUB_IRQ_BUS_RESUME (1 << 8)#define VHUB_IRQ_BUS_SUSPEND (1 << 7)#define
VHUB_IRQ_BUS_RESET(1 << 6)drivers/usb/gadget/udc/aspeed-vhub/vhub.h +1
-0@@ -402,6 +399,7 @@ struct ast_vhub {/* Per-port info */ struct ast_vhub_port *ports;u32 max_ports; +u32 port_irq_mask;/* Generic EP data structures */ struct ast_vhub_ep *epns;Signature · 1 line
2.17.1
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 3 lines · Tao Ren
Hi Ben,
Any further comments on the patch?
Ah sorry, nope. Did you check the generated assembly to see if it looked any better ? :-)
Otherwise,
Thanks Ben for the review. Let me see if I can collect some runtime data on my ast2400 BMC platform. Will update back later.
Cheers,
Tao
Quoted 99 lines
Quoted 98 lines
Cheers,
Tao
Quoted 90 lines · rentao.bupt at gmail.com
From: Tao Ren <[email protected]>
This patch evaluates vhub ports' irq mask before going through per- port
irq handling one by one, which helps to speed up irq handling in case
there is no port interrupt.Signed-off-by Tao Ren <[email protected]>---
Changes in v3:
- assign istat to (unsigned long) bitmap before calling"for_each_set_bit_from".Changes in v2:
- use "for_each_set_bit" to speed up port irq handling.drivers/usb/gadget/udc/aspeed-vhub/core.c | 12 +++++++++--- drivers/usb/gadget/udc/aspeed-vhub/vhub.h | 8 +++----- 2 files changed, 12 insertions(+), 8 deletions(-)drivers/usb/gadget/udc/aspeed-vhub/core.c +7
-3@@ -134,11 +134,15 @@ static irqreturn_t ast_vhub_irq(int irq, void *data) }/* Handle device interrupts */ -for (i =0 ; i < vhub->max_ports; i++) { -u32 dev_mask =VHUB_IRQ_DEVICE1 << i; +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; -if (istat & dev_mask) +for_each_set_bit_from (offset, &bitmap, size) { + i = offset -VHUB_IRQ_DEV1_BIT ;ast_vhub_dev_irq (&vhub->ports[i].dev); + } }drivers/usb/gadget/udc/aspeed-vhub/core.c +2
-0/* Handle top-level vHub EP0 interrupts */ @@ -332,6 +336,8 @@ static int ast_vhub_probe(struct platform_device *pdev) spin_lock_init(&vhub->lock); vhub->pdev = pdev; + vhub->port_irq_mask =GENMASK (VHUB_IRQ_DEV1_BIT + vhub- >max_ports - 1, +VHUB_IRQ_DEV1_BIT );drivers/usb/gadget/udc/aspeed-vhub/core.c +0
-0res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); vhub->regs =devm_ioremap_resource (&pdev->dev, res);drivers/usb/gadget/udc/aspeed-vhub/vhub.h +2
-5@@ -51,14 +51,11 @@#define VHUB_CTRL_UPSTREAM_CONNECT (1 << 0)/* IER & ISR */ +#define VHUB_IRQ_DEV1_BIT 9#define VHUB_IRQ_USB_CMD_DEADLOCK (1 << 18)#define VHUB_IRQ_EP_POOL_NAK (1 << 17)#define VHUB_IRQ_EP_POOL_ACK_STALL (1 << 16) -#define VHUB_IRQ_DEVICE5 (1 << 13) -#define VHUB_IRQ_DEVICE4 (1 << 12) -#define VHUB_IRQ_DEVICE3 (1 << 11) -#define VHUB_IRQ_DEVICE2 (1 << 10) -#define VHUB_IRQ_DEVICE1 (1 << 9) +#define VHUB_IRQ_DEVICE1 (1 << (VHUB_IRQ_DEV1_BIT))#define VHUB_IRQ_BUS_RESUME (1 << 8)#define VHUB_IRQ_BUS_SUSPEND (1 << 7)#define
VHUB_IRQ_BUS_RESET(1 << 6)drivers/usb/gadget/udc/aspeed-vhub/vhub.h +1
-0@@ -402,6 +399,7 @@ struct ast_vhub {/* Per-port info */ struct ast_vhub_port *ports;u32 max_ports; +u32 port_irq_mask;/* Generic EP data structures */ struct ast_vhub_ep *epns;Signature · 1 line
2.17.1
Hi Ben,
Quoted 9 lines · Tao Ren
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 3 lines · Tao Ren
Hi Ben,
Any further comments on the patch?
Ah sorry, nope. Did you check the generated assembly to see if it looked any better ? :-)
Quoted 6 lines
Quoted 3 lines
Otherwise,
Thanks Ben for the review. Let me see if I can collect some runtime data on my ast2400 BMC platform. Will update back later.
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.
- 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
Quoted 95 lines
Quoted 95 lines
Quoted 94 lines
Quoted 90 lines · rentao.bupt at gmail.com
From: Tao Ren <[email protected]>
This patch evaluates vhub ports' irq mask before going through per- port
irq handling one by one, which helps to speed up irq handling in case
there is no port interrupt.Signed-off-by Tao Ren <[email protected]>---
Changes in v3:
- assign istat to (unsigned long) bitmap before calling"for_each_set_bit_from".Changes in v2:
- use "for_each_set_bit" to speed up port irq handling.drivers/usb/gadget/udc/aspeed-vhub/core.c | 12 +++++++++--- drivers/usb/gadget/udc/aspeed-vhub/vhub.h | 8 +++----- 2 files changed, 12 insertions(+), 8 deletions(-)drivers/usb/gadget/udc/aspeed-vhub/core.c +7
-3@@ -134,11 +134,15 @@ static irqreturn_t ast_vhub_irq(int irq, void *data) }/* Handle device interrupts */ -for (i =0 ; i < vhub->max_ports; i++) { -u32 dev_mask =VHUB_IRQ_DEVICE1 << i; +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; -if (istat & dev_mask) +for_each_set_bit_from (offset, &bitmap, size) { + i = offset -VHUB_IRQ_DEV1_BIT ;ast_vhub_dev_irq (&vhub->ports[i].dev); + } }drivers/usb/gadget/udc/aspeed-vhub/core.c +2
-0/* Handle top-level vHub EP0 interrupts */ @@ -332,6 +336,8 @@ static int ast_vhub_probe(struct platform_device *pdev) spin_lock_init(&vhub->lock); vhub->pdev = pdev; + vhub->port_irq_mask =GENMASK (VHUB_IRQ_DEV1_BIT + vhub- >max_ports - 1, +VHUB_IRQ_DEV1_BIT );drivers/usb/gadget/udc/aspeed-vhub/core.c +0
-0res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); vhub->regs =devm_ioremap_resource (&pdev->dev, res);drivers/usb/gadget/udc/aspeed-vhub/vhub.h +2
-5@@ -51,14 +51,11 @@#define VHUB_CTRL_UPSTREAM_CONNECT (1 << 0)/* IER & ISR */ +#define VHUB_IRQ_DEV1_BIT 9#define VHUB_IRQ_USB_CMD_DEADLOCK (1 << 18)#define VHUB_IRQ_EP_POOL_NAK (1 << 17)#define VHUB_IRQ_EP_POOL_ACK_STALL (1 << 16) -#define VHUB_IRQ_DEVICE5 (1 << 13) -#define VHUB_IRQ_DEVICE4 (1 << 12) -#define VHUB_IRQ_DEVICE3 (1 << 11) -#define VHUB_IRQ_DEVICE2 (1 << 10) -#define VHUB_IRQ_DEVICE1 (1 << 9) +#define VHUB_IRQ_DEVICE1 (1 << (VHUB_IRQ_DEV1_BIT))#define VHUB_IRQ_BUS_RESUME (1 << 8)#define VHUB_IRQ_BUS_SUSPEND (1 << 7)#define
VHUB_IRQ_BUS_RESET(1 << 6)drivers/usb/gadget/udc/aspeed-vhub/vhub.h +1
-0@@ -402,6 +399,7 @@ struct ast_vhub {/* Per-port info */ struct ast_vhub_port *ports;u32 max_ports; +u32 port_irq_mask;/* Generic EP data structures */ struct ast_vhub_ep *epns;Signature · 1 line
2.17.1
Quoted 17 lines · Tao Ren
I ran some testing on my ast2400 and ast2500 BMC and looks like the
for()loop runs faster thanfor_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, andast_vhub_dev_irq()is replaced withbarrier()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 thefor()loop.- if downstream port number is 5 and all 5 bits are set, then
for_each_set_bit()loop takes ~50 cycles andfor()loop takes ~25 cycles.
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 andfor()loop takes 25 cycles. It's a little surprise to me because I thoughtfor()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 andfor()loop takes 30+ cycles.
I suspect the CPU doesn't have an efficient find-zero-bit primitive, check the generated asm. In that case I would go back to the simple for loop.
Cheers,
Ben.
Quoted 27 lines · Benjamin Herrenschmidt
Quoted 17 lines · Tao Ren
I ran some testing on my ast2400 and ast2500 BMC and looks like the
for()loop runs faster thanfor_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, andast_vhub_dev_irq()is replaced withbarrier()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 thefor()loop.- if downstream port number is 5 and all 5 bits are set, then
for_each_set_bit()loop takes ~50 cycles andfor()loop takes ~25 cycles.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 andfor()loop takes 25 cycles. It's a little surprise to me because I thoughtfor()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 andfor()loop takes 30+ cycles.
Quoted 6 lines
I suspect the CPU doesn't have an efficient find-zero-bit primitive, check the generated asm. In that case I would go back to the simple for loop.
Cheers,
Ben.
_find_next_bit_le() function is defined in arch/arm/lib/findbit.S. I'm looking at the code: will run more tests and send out patch v4 with simple for loop later.
Cheers,
Tao