* [PATCH] usb: f_ncm: only first packet of aggregate needs to start timer
@ 2021-06-08 8:54 Maciej Żenczykowski
2021-06-09 8:27 ` Greg Kroah-Hartman
0 siblings, 1 reply; 3+ messages in thread
From: Maciej Żenczykowski @ 2021-06-08 8:54 UTC (permalink / raw)
To: Maciej Żenczykowski
Cc: Linux USB Mailing List, Brooke Basile, Bryan O'Donoghue,
Felipe Balbi, Greg Kroah-Hartman, Lorenzo Colitti
From: Maciej Żenczykowski <maze@google.com>
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 <brookebasile@gmail.com>
Cc: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Cc: Felipe Balbi <balbi@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Lorenzo Colitti <lorenzo@google.com>
Signed-off-by: Maciej Żenczykowski <maze@google.com>
---
drivers/usb/gadget/function/f_ncm.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/function/f_ncm.c
index 0d23c6c11a13..855127249f24 100644
--- a/drivers/usb/gadget/function/f_ncm.c
+++ b/drivers/usb/gadget/function/f_ncm.c
@@ -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);
--
2.32.0.rc1.229.g3e70b5a671-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] usb: f_ncm: only first packet of aggregate needs to start timer
2021-06-08 8:54 [PATCH] usb: f_ncm: only first packet of aggregate needs to start timer Maciej Żenczykowski
@ 2021-06-09 8:27 ` Greg Kroah-Hartman
2021-06-09 8:34 ` Greg Kroah-Hartman
0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2021-06-09 8:27 UTC (permalink / raw)
To: Maciej Żenczykowski
Cc: Maciej Żenczykowski, Linux USB Mailing List, Brooke Basile,
Bryan O'Donoghue, Felipe Balbi, Lorenzo Colitti
On Tue, Jun 08, 2021 at 01:54:38AM -0700, Maciej Żenczykowski wrote:
> From: Maciej Żenczykowski <maze@google.com>
>
> 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 <brookebasile@gmail.com>
> Cc: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> Cc: Felipe Balbi <balbi@kernel.org>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Lorenzo Colitti <lorenzo@google.com>
> Signed-off-by: Maciej Żenczykowski <maze@google.com>
> ---
> drivers/usb/gadget/function/f_ncm.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/function/f_ncm.c
> index 0d23c6c11a13..855127249f24 100644
> --- a/drivers/usb/gadget/function/f_ncm.c
> +++ b/drivers/usb/gadget/function/f_ncm.c
> @@ -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);
Nice, hopefully this helps out a lot on the systems where re-arming
timers are slow.
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] usb: f_ncm: only first packet of aggregate needs to start timer
2021-06-09 8:27 ` Greg Kroah-Hartman
@ 2021-06-09 8:34 ` Greg Kroah-Hartman
0 siblings, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2021-06-09 8:34 UTC (permalink / raw)
To: Maciej Żenczykowski
Cc: Maciej Żenczykowski, Linux USB Mailing List, Brooke Basile,
Bryan O'Donoghue, Felipe Balbi, Lorenzo Colitti
On Wed, Jun 09, 2021 at 10:27:48AM +0200, Greg Kroah-Hartman wrote:
> On Tue, Jun 08, 2021 at 01:54:38AM -0700, Maciej Żenczykowski wrote:
> > From: Maciej Żenczykowski <maze@google.com>
> >
> > 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 <brookebasile@gmail.com>
> > Cc: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> > Cc: Felipe Balbi <balbi@kernel.org>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: Lorenzo Colitti <lorenzo@google.com>
> > Signed-off-by: Maciej Żenczykowski <maze@google.com>
> > ---
> > drivers/usb/gadget/function/f_ncm.c | 8 ++++----
> > 1 file changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/function/f_ncm.c
> > index 0d23c6c11a13..855127249f24 100644
> > --- a/drivers/usb/gadget/function/f_ncm.c
> > +++ b/drivers/usb/gadget/function/f_ncm.c
> > @@ -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);
>
> 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...
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-06-09 8:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-08 8:54 [PATCH] usb: f_ncm: only first packet of aggregate needs to start timer Maciej Żenczykowski
2021-06-09 8:27 ` Greg Kroah-Hartman
2021-06-09 8:34 ` Greg Kroah-Hartman
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.