From: Mauro Carvalho Chehab <mchehab@s-opensource.com>
To: Linus Torvalds <torvalds@linux-foundation.org>,
Peter Zijlstra <peterz@infradead.org>
Cc: Alan Stern <stern@rowland.harvard.edu>,
Ingo Molnar <mingo@kernel.org>,
Josef Griebichler <griebichler.josef@gmx.at>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
USB list <linux-usb@vger.kernel.org>,
Eric Dumazet <edumazet@google.com>,
Rik van Riel <riel@redhat.com>, Paolo Abeni <pabeni@redhat.com>,
Hannes Frederic Sowa <hannes@redhat.com>,
Jesper Dangaard Brouer <jbrouer@redhat.com>,
linux-kernel <linux-kernel@vger.kernel.org>,
netdev <netdev@vger.kernel.org>, Jonathan Corbet <corbet@lwn.net>,
LMML <linux-media@vger.kernel.org>,
David Miller <davem@davemloft.net>
Subject: dvb usb issues since kernel 4.9
Date: Tue, 9 Jan 2018 15:42:35 -0200 [thread overview]
Message-ID: <20180109154235.2a42f0a0@vento.lan> (raw)
Em Mon, 8 Jan 2018 11:51:04 -0800
Linus Torvalds <torvalds@linux-foundation.org> escreveu:
> On Mon, Jan 8, 2018 at 11:15 AM, Alan Stern <stern@rowland.harvard.edu> wrote:
> >
> > Both dwc2_hsotg and ehci-hcd use the tasklets embedded in the
> > giveback_urb_bh member of struct usb_hcd. See usb_hcd_giveback_urb()
> > in drivers/usb/core/hcd.c; the calls are
> >
> > else if (high_prio_bh)
> > tasklet_hi_schedule(&bh->bh);
> > else
> > tasklet_schedule(&bh->bh);
> >
> > As it turns out, high_prio_bh gets set for interrupt and isochronous
> > URBs but not for bulk and control URBs. The DVB driver in question
> > uses bulk transfers.
>
> Ok, so we could try out something like the appended?
>
> NOTE! I have not tested this at all. It LooksObvious(tm), but...
>
> Linus
> kernel/softirq.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/softirq.c b/kernel/softirq.c
> index 2f5e87f1bae2..97b080956fea 100644
> --- a/kernel/softirq.c
> +++ b/kernel/softirq.c
> @@ -79,12 +79,16 @@ static void wakeup_softirqd(void)
>
> /*
> * If ksoftirqd is scheduled, we do not want to process pending softirqs
> - * right now. Let ksoftirqd handle this at its own rate, to get fairness.
> + * right now. Let ksoftirqd handle this at its own rate, to get fairness,
> + * unless we're doing some of the synchronous softirqs.
> */
> -static bool ksoftirqd_running(void)
> +#define SOFTIRQ_NOW_MASK ((1 << HI_SOFTIRQ) | (1 << TASKLET_SOFTIRQ))
> +static bool ksoftirqd_running(unsigned long pending)
> {
> struct task_struct *tsk = __this_cpu_read(ksoftirqd);
>
> + if (pending & SOFTIRQ_NOW_MASK)
> + return false;
> return tsk && (tsk->state == TASK_RUNNING);
> }
>
> @@ -325,7 +329,7 @@ asmlinkage __visible void do_softirq(void)
>
> pending = local_softirq_pending();
>
> - if (pending && !ksoftirqd_running())
> + if (pending && !ksoftirqd_running(pending))
> do_softirq_own_stack();
>
> local_irq_restore(flags);
> @@ -352,7 +356,7 @@ void irq_enter(void)
>
> static inline void invoke_softirq(void)
> {
> - if (ksoftirqd_running())
> + if (ksoftirqd_running(local_softirq_pending()))
> return;
>
> if (!force_irqthreads) {
Hi Linus,
Patch makes sense to me, although I was not able to test it myself.
I set a RPi3 machine here with vanilla Kernel 4.14.11 running a standard
raspbian distribution (with elevator=deadline). Right now, I'm trying to
reproduce the bug with dvbv5-zap. I may eventually do more tests on
some other slow machines.
Usually, applications like tvheadend records just one channel. So, instead
of a ~58 Mbits/s payload, it uses, typically, ~11 Mbits/s for a HD channel.
This is usually filtered by hardware. Here, I'm forcing to record the
entire TS, in order to make easier to reproduce the issue. So, I'm forcing
a condition that it is usually worse than real usecases (at last for HD - I
I don't have any DVB stream here with a 4K channel).
From what I checked so far, with vanila upstream Kernel on RPi3, just
receiving a DVB stream - or receiving it and writing to /dev/null works
with or without your patch.
The problem starts to happen when there are concurrency with writes.
On my preliminar tests, writing to a file on an ext4 partition at a
USB stick loses data up to the point to make it useless (1/4 of the data
is lost!). However, writing to a class 10 microSD card is doable.
If you're curious enough, this is what I'm doing (that are the results
while using class 10 microSD card):
$ FILE=/tmp/out.ts; for i in $(seq 1 6); do echo "step $i"; rm $FILE 2>/dev/null; dvbv5-zap -l universal -c ~/vivo-channels.conf NBR -o $FILE -P -t60 2>&1|grep -E "(buffer|received)"; du $FILE 2>/dev/null; done
step 1
Setting buffer length to 7250000
buffer overrun
buffer overrun
buffer overrun
buffer overrun
buffer overrun
buffer overrun
buffer overrun
received 347504652 bytes (5656 Kbytes/sec)
339368 /tmp/out.ts
step 2
Setting buffer length to 7250000
buffer overrun
received 408995880 bytes (6656 Kbytes/sec)
399416 /tmp/out.ts
step 3
Setting buffer length to 7250000
received 412999716 bytes (6722 Kbytes/sec)
403328 /tmp/out.ts
step 4
Setting buffer length to 7250000
buffer overrun
received 415564788 bytes (6763 Kbytes/sec)
405832 /tmp/out.ts
step 5
Setting buffer length to 7250000
received 412999716 bytes (6722 Kbytes/sec)
403324 /tmp/out.ts
step 6
Setting buffer length to 7250000
received 408366080 bytes (6646 Kbytes/sec)
398796 /tmp/out.ts
My plan is to do more tests along this week, and try to tweak a little
bit both userspace and kernelspace, in order to see if I can get better
results.
Thanks,
Mauro
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
WARNING: multiple messages have this Message-ID (diff)
From: Mauro Carvalho Chehab <mchehab@s-opensource.com>
To: Linus Torvalds <torvalds@linux-foundation.org>,
Peter Zijlstra <peterz@infradead.org>
Cc: Alan Stern <stern@rowland.harvard.edu>,
Ingo Molnar <mingo@kernel.org>,
Josef Griebichler <griebichler.josef@gmx.at>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
USB list <linux-usb@vger.kernel.org>,
Eric Dumazet <edumazet@google.com>,
Rik van Riel <riel@redhat.com>, Paolo Abeni <pabeni@redhat.com>,
Hannes Frederic Sowa <hannes@redhat.com>,
Jesper Dangaard Brouer <jbrouer@redhat.com>,
linux-kernel <linux-kernel@vger.kernel.org>,
netdev <netdev@vger.kernel.org>, Jonathan Corbet <corbet@lwn.net>,
LMML <linux-media@vger.kernel.org>,
David Miller <davem@davemloft.net>
Subject: Re: dvb usb issues since kernel 4.9
Date: Tue, 9 Jan 2018 15:42:35 -0200 [thread overview]
Message-ID: <20180109154235.2a42f0a0@vento.lan> (raw)
In-Reply-To: <CA+55aFwuAojr7vAfiRO-2je-wDs7pu+avQZNhX_k9NN=D7_zVQ@mail.gmail.com>
Em Mon, 8 Jan 2018 11:51:04 -0800
Linus Torvalds <torvalds@linux-foundation.org> escreveu:
> On Mon, Jan 8, 2018 at 11:15 AM, Alan Stern <stern@rowland.harvard.edu> wrote:
> >
> > Both dwc2_hsotg and ehci-hcd use the tasklets embedded in the
> > giveback_urb_bh member of struct usb_hcd. See usb_hcd_giveback_urb()
> > in drivers/usb/core/hcd.c; the calls are
> >
> > else if (high_prio_bh)
> > tasklet_hi_schedule(&bh->bh);
> > else
> > tasklet_schedule(&bh->bh);
> >
> > As it turns out, high_prio_bh gets set for interrupt and isochronous
> > URBs but not for bulk and control URBs. The DVB driver in question
> > uses bulk transfers.
>
> Ok, so we could try out something like the appended?
>
> NOTE! I have not tested this at all. It LooksObvious(tm), but...
>
> Linus
> kernel/softirq.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/softirq.c b/kernel/softirq.c
> index 2f5e87f1bae2..97b080956fea 100644
> --- a/kernel/softirq.c
> +++ b/kernel/softirq.c
> @@ -79,12 +79,16 @@ static void wakeup_softirqd(void)
>
> /*
> * If ksoftirqd is scheduled, we do not want to process pending softirqs
> - * right now. Let ksoftirqd handle this at its own rate, to get fairness.
> + * right now. Let ksoftirqd handle this at its own rate, to get fairness,
> + * unless we're doing some of the synchronous softirqs.
> */
> -static bool ksoftirqd_running(void)
> +#define SOFTIRQ_NOW_MASK ((1 << HI_SOFTIRQ) | (1 << TASKLET_SOFTIRQ))
> +static bool ksoftirqd_running(unsigned long pending)
> {
> struct task_struct *tsk = __this_cpu_read(ksoftirqd);
>
> + if (pending & SOFTIRQ_NOW_MASK)
> + return false;
> return tsk && (tsk->state == TASK_RUNNING);
> }
>
> @@ -325,7 +329,7 @@ asmlinkage __visible void do_softirq(void)
>
> pending = local_softirq_pending();
>
> - if (pending && !ksoftirqd_running())
> + if (pending && !ksoftirqd_running(pending))
> do_softirq_own_stack();
>
> local_irq_restore(flags);
> @@ -352,7 +356,7 @@ void irq_enter(void)
>
> static inline void invoke_softirq(void)
> {
> - if (ksoftirqd_running())
> + if (ksoftirqd_running(local_softirq_pending()))
> return;
>
> if (!force_irqthreads) {
Hi Linus,
Patch makes sense to me, although I was not able to test it myself.
I set a RPi3 machine here with vanilla Kernel 4.14.11 running a standard
raspbian distribution (with elevator=deadline). Right now, I'm trying to
reproduce the bug with dvbv5-zap. I may eventually do more tests on
some other slow machines.
Usually, applications like tvheadend records just one channel. So, instead
of a ~58 Mbits/s payload, it uses, typically, ~11 Mbits/s for a HD channel.
This is usually filtered by hardware. Here, I'm forcing to record the
entire TS, in order to make easier to reproduce the issue. So, I'm forcing
a condition that it is usually worse than real usecases (at last for HD - I
I don't have any DVB stream here with a 4K channel).
>From what I checked so far, with vanila upstream Kernel on RPi3, just
receiving a DVB stream - or receiving it and writing to /dev/null works
with or without your patch.
The problem starts to happen when there are concurrency with writes.
On my preliminar tests, writing to a file on an ext4 partition at a
USB stick loses data up to the point to make it useless (1/4 of the data
is lost!). However, writing to a class 10 microSD card is doable.
If you're curious enough, this is what I'm doing (that are the results
while using class 10 microSD card):
$ FILE=/tmp/out.ts; for i in $(seq 1 6); do echo "step $i"; rm $FILE 2>/dev/null; dvbv5-zap -l universal -c ~/vivo-channels.conf NBR -o $FILE -P -t60 2>&1|grep -E "(buffer|received)"; du $FILE 2>/dev/null; done
step 1
Setting buffer length to 7250000
buffer overrun
buffer overrun
buffer overrun
buffer overrun
buffer overrun
buffer overrun
buffer overrun
received 347504652 bytes (5656 Kbytes/sec)
339368 /tmp/out.ts
step 2
Setting buffer length to 7250000
buffer overrun
received 408995880 bytes (6656 Kbytes/sec)
399416 /tmp/out.ts
step 3
Setting buffer length to 7250000
received 412999716 bytes (6722 Kbytes/sec)
403328 /tmp/out.ts
step 4
Setting buffer length to 7250000
buffer overrun
received 415564788 bytes (6763 Kbytes/sec)
405832 /tmp/out.ts
step 5
Setting buffer length to 7250000
received 412999716 bytes (6722 Kbytes/sec)
403324 /tmp/out.ts
step 6
Setting buffer length to 7250000
received 408366080 bytes (6646 Kbytes/sec)
398796 /tmp/out.ts
My plan is to do more tests along this week, and try to tweak a little
bit both userspace and kernelspace, in order to see if I can get better
results.
Thanks,
Mauro
next reply other threads:[~2018-01-09 17:42 UTC|newest]
Thread overview: 82+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-09 17:42 Mauro Carvalho Chehab [this message]
2018-01-09 17:42 ` dvb usb issues since kernel 4.9 Mauro Carvalho Chehab
-- strict thread matches above, loose matches on Subject: below --
2018-07-17 22:21 Mauro Carvalho Chehab
2018-07-17 22:21 ` Mauro Carvalho Chehab
2018-07-17 22:21 ` Mauro Carvalho Chehab
2018-07-17 18:07 hannah
2018-07-17 18:07 ` Hanna Hawa
2018-07-17 18:07 ` Hanna Hawa
2018-07-17 17:09 Linus Torvalds
2018-07-17 17:09 ` Linus Torvalds
2018-07-17 17:09 ` Linus Torvalds
2018-07-17 11:54 hannah
2018-07-17 11:54 ` Hanna Hawa
2018-01-13 10:46 Aw: " Mauro Carvalho Chehab
2018-01-13 10:46 ` Mauro Carvalho Chehab
2018-01-13 9:09 Aw: " Mauro Carvalho Chehab
2018-01-13 9:09 ` Mauro Carvalho Chehab
2018-01-12 21:48 Aw: " Eric Dumazet
2018-01-12 21:48 ` Eric Dumazet
2018-01-12 21:13 Aw: " Mauro Carvalho Chehab
2018-01-12 21:13 ` Mauro Carvalho Chehab
2018-01-10 9:45 Aw: " Jesper Dangaard Brouer
2018-01-10 9:45 ` Jesper Dangaard Brouer
2018-01-10 3:02 Mike Galbraith
2018-01-10 3:02 ` Mike Galbraith
2018-01-09 21:48 Aw: " Eric Dumazet
2018-01-09 21:48 ` Eric Dumazet
2018-01-09 21:26 Jesper Dangaard Brouer
2018-01-09 21:26 ` Jesper Dangaard Brouer
2018-01-09 18:58 Aw: " Linus Torvalds
2018-01-09 18:58 ` Linus Torvalds
2018-01-09 17:57 Aw: " Eric Dumazet
2018-01-09 17:57 ` Eric Dumazet
2018-01-09 17:55 Linus Torvalds
2018-01-09 17:55 ` Linus Torvalds
2018-01-09 17:48 Aw: " Linus Torvalds
2018-01-09 17:48 ` Linus Torvalds
2018-01-09 17:27 Aw: " Eric Dumazet
2018-01-09 17:27 ` Eric Dumazet
2018-01-09 16:51 Aw: " Josef Griebichler
2018-01-09 16:51 ` Josef Griebichler
2018-01-08 22:16 Jesper Dangaard Brouer
2018-01-08 22:16 ` Jesper Dangaard Brouer
2018-01-08 21:44 Aw: " Peter Zijlstra
2018-01-08 21:44 ` Peter Zijlstra
2018-01-08 21:31 Aw: " Jesper Dangaard Brouer
2018-01-08 21:31 ` Jesper Dangaard Brouer
2018-01-08 20:40 Aw: " Jesper Dangaard Brouer
2018-01-08 20:40 ` Jesper Dangaard Brouer
2018-01-08 19:51 Linus Torvalds
2018-01-08 19:51 ` Linus Torvalds
2018-01-08 17:35 Aw: " Alan Stern
2018-01-08 17:35 ` Aw: " Alan Stern
2018-01-08 17:15 Aw: " Josef Griebichler
2018-01-08 17:15 ` Aw: " Josef Griebichler
2018-01-08 16:31 Aw: " Alan Stern
2018-01-08 16:31 ` Alan Stern
2018-01-08 16:26 Josef Griebichler
2018-01-08 16:26 ` Josef Griebichler
2018-01-08 16:10 Alan Stern
2018-01-08 16:10 ` Alan Stern
2018-01-08 9:43 Mauro Carvalho Chehab
2018-01-08 9:43 ` Mauro Carvalho Chehab
[not found] <trinity-35b3a044-b548-4a31-9646-ed9bc83e6846-1513505978471@3c-app-gmx-bs03>
[not found] ` <20171217120634.pmmuhdqyqmbkxrvl@gofer.mess.org>
2017-12-17 13:27 ` Mauro Carvalho Chehab
[not found] ` <trinity-1fa14556-8596-44b1-95cb-b8919d94d2d4-1515251056328@3c-app-gmx-bs15>
2018-01-06 19:54 ` Mauro Carvalho Chehab
2018-01-06 21:07 ` Aw: " Josef Griebichler
2018-01-06 21:44 ` Alan Stern
2018-01-07 11:03 ` Mauro Carvalho Chehab
2018-01-07 15:41 ` Alan Stern
2018-01-07 17:01 ` Aw: " Josef Griebichler
2018-01-07 17:01 ` Josef Griebichler
2018-01-07 21:23 ` Linus Torvalds
2018-01-08 10:02 ` Mauro Carvalho Chehab
2018-01-08 11:59 ` Jesper Dangaard Brouer
2018-01-08 12:53 ` Mauro Carvalho Chehab
2018-01-08 16:25 ` Alan Stern
2018-01-08 17:55 ` Ingo Molnar
2018-01-08 18:32 ` Linus Torvalds
2018-01-08 19:15 ` Alan Stern
2018-01-26 14:17 ` Mauro Carvalho Chehab
2018-01-26 19:37 ` Mauro Carvalho Chehab
2018-01-29 13:51 ` Mauro Carvalho Chehab
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180109154235.2a42f0a0@vento.lan \
--to=mchehab@s-opensource.com \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=griebichler.josef@gmx.at \
--cc=hannes@redhat.com \
--cc=jbrouer@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=peterz@infradead.org \
--cc=riel@redhat.com \
--cc=stern@rowland.harvard.edu \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.