Skip to contentSkip to conversation

usb: f_ncm: only first packet of aggregate needs to start timer

PATCH In review Maciej Żenczykowski 2 participants 3 messages Jun 8, 2021 – Jun 9, 2021 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: f_ncm: only first packet of aggregate needs to start timer

From: Maciej Żenczykowski <[email protected]>

The reasoning for this change is that if we already had a packet pending, then we also already had a pending timer, and as such there is no need to reschedule it.

This also prevents packets getting delayed 60 ms worst case under a tiny packet every 290us transmit load, by keeping the timeout always relative to the first queued up packet. (300us delay * 16KB max aggregation / 80 byte packet =~ 60 ms)

As such the first packet is now at most delayed by 300us.

Under low transmit load, this will simply result in us sending a shorter aggregate, as originally intended.

This patch has the benefit of greatly reducing (by ~10 factor with 1500 byte frames aggregated into 16 kiB) the number of (potentially pretty costly) updates to the hrtimer.

Cc Brooke Basile <[email protected]>
Cc Bryan O'Donoghue <[email protected]>
Cc Felipe Balbi <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Lorenzo Colitti <[email protected]>
---
 drivers/usb/gadget/function/f_ncm.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/usb/gadget/function/f_ncm.c +4 -4
index 0d23c6c11a13..855127249f24 100644
@@ -1101,11 +1101,11 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port,
 			ncm->ndp_dgram_count = 1;
 
 			/* Note: we skip opts->next_ndp_index */
-		}
 
-		/* Delay the timer. */
-		hrtimer_start(&ncm->task_timer, TX_TIMEOUT_NSECS,
-			      HRTIMER_MODE_REL_SOFT);
+			/* Start the timer. */
+			hrtimer_start(&ncm->task_timer, TX_TIMEOUT_NSECS,
+				      HRTIMER_MODE_REL_SOFT);
+		}
 
 		/* Add the datagram position entries */
 		ntb_ndp = skb_put_zero(ncm->skb_tx_ndp, dgram_idx_len);
Signature · 1 line
2.32.0.rc1.229.g3e70b5a671-goog
#1 lore raw
Quoted 40 lines · Maciej Żenczykowski

From: Maciej Żenczykowski <[email protected]>

The reasoning for this change is that if we already had a packet pending, then we also already had a pending timer, and as such there is no need to reschedule it.

This also prevents packets getting delayed 60 ms worst case under a tiny packet every 290us transmit load, by keeping the timeout always relative to the first queued up packet. (300us delay * 16KB max aggregation / 80 byte packet =~ 60 ms)

As such the first packet is now at most delayed by 300us.

Under low transmit load, this will simply result in us sending a shorter aggregate, as originally intended.

This patch has the benefit of greatly reducing (by ~10 factor with 1500 byte frames aggregated into 16 kiB) the number of (potentially pretty costly) updates to the hrtimer.

Cc Brooke Basile <[email protected]>
Cc Bryan O'Donoghue <[email protected]>
Cc Felipe Balbi <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Lorenzo Colitti <[email protected]>
---
 drivers/usb/gadget/function/f_ncm.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/usb/gadget/function/f_ncm.c +0 -1
index 0d23c6c11a13..855127249f24 100644
@@ -1101,11 +1101,11 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port,
 			ncm->ndp_dgram_count = 1;
 
 			/* Note: we skip opts->next_ndp_index */
-		}
 

drivers/usb/gadget/function/f_ncm.c static struct sk_buff *ncm_wrap_ntb(struct gether *port, · line 1111

Quoted 10 lines
drivers/usb/gadget/function/f_ncm.c +4 -3
-		/* Delay the timer. */
-		hrtimer_start(&ncm->task_timer, TX_TIMEOUT_NSECS,
-			      HRTIMER_MODE_REL_SOFT);
+			/* Start the timer. */
+			hrtimer_start(&ncm->task_timer, TX_TIMEOUT_NSECS,
+				      HRTIMER_MODE_REL_SOFT);
+		}
 
 		/* Add the datagram position entries */
 		ntb_ndp = skb_put_zero(ncm->skb_tx_ndp, dgram_idx_len);

Nice, hopefully this helps out a lot on the systems where re-arming timers are slow.

greg k-h

#2 lore raw
Quoted 49 lines · Greg Kroah-Hartman
Quoted 48 lines · Maciej Żenczykowski

From: Maciej Żenczykowski <[email protected]>

The reasoning for this change is that if we already had a packet pending, then we also already had a pending timer, and as such there is no need to reschedule it.

This also prevents packets getting delayed 60 ms worst case under a tiny packet every 290us transmit load, by keeping the timeout always relative to the first queued up packet. (300us delay * 16KB max aggregation / 80 byte packet =~ 60 ms)

As such the first packet is now at most delayed by 300us.

Under low transmit load, this will simply result in us sending a shorter aggregate, as originally intended.

This patch has the benefit of greatly reducing (by ~10 factor with 1500 byte frames aggregated into 16 kiB) the number of (potentially pretty costly) updates to the hrtimer.

Cc Brooke Basile <[email protected]>
Cc Bryan O'Donoghue <[email protected]>
Cc Felipe Balbi <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Lorenzo Colitti <[email protected]>
---
 drivers/usb/gadget/function/f_ncm.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/usb/gadget/function/f_ncm.c +4 -4
index 0d23c6c11a13..855127249f24 100644
@@ -1101,11 +1101,11 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port,
 			ncm->ndp_dgram_count = 1;
 
 			/* Note: we skip opts->next_ndp_index */
-		}
 
-		/* Delay the timer. */
-		hrtimer_start(&ncm->task_timer, TX_TIMEOUT_NSECS,
-			      HRTIMER_MODE_REL_SOFT);
+			/* Start the timer. */
+			hrtimer_start(&ncm->task_timer, TX_TIMEOUT_NSECS,
+				      HRTIMER_MODE_REL_SOFT);
+		}
 
Quoted 5 lines

drivers/usb/gadget/function/f_ncm.c static struct sk_buff *ncm_wrap_ntb(struct gether *port, · line 1111

Quoted 2 lines
drivers/usb/gadget/function/f_ncm.c +0 -0
 		/* Add the datagram position entries */
 		ntb_ndp = skb_put_zero(ncm->skb_tx_ndp, dgram_idx_len);

Nice, hopefully this helps out a lot on the systems where re-arming timers are slow.

And that's what the changelog said, I need more coffee...