[mythtv-users] mythbackend Start-up issue - possible race with dvb device firmware loading

Stephen Worthington stephen_agent at jsw.gen.nz
Thu Nov 19 16:13:04 UTC 2020

On Thu, 19 Nov 2020 14:55:27 +0000, you wrote:

>On 19/11/2020 13:17, Stephen Worthington wrote:
>> On Thu, 19 Nov 2020 12:28:14 +0000, you wrote:
>>> I'm running FC32 and, as far as I can tell, the device firmware is only
>>> being loaded at startup.  It's possible that it's loaded again whenever a
>>> recording is started.  It's hard to tell because that tuner is the second
>>> in the list and is rarely used.
>> I have never heard of a tuner where the firmware is ever reloaded.  It
>> will likely be loading when mythbackend tests the tuner as it starts
>> up.  If the firmware is actually being loaded more than once, that is
>> an indication that the tuner reset itself and is probably faulty -
>> check dmesg or kern.log and you will probably find messages about the
>> USB device disconnecting and reconnecting.  Given that this is a USB
>> tuner, the usual rule applies - suspect the cable first.  Make sure it
>> fits tightly in the PC socket - loose fit means that the slightest
>> jiggle on the cable (even a gust of air caused by the door being
>> opened) can be enough to cause the tuner to fault.  Change to cable to
>> a better fitting one if necessary.  Cats, kids and vacuuming are all
>> very hazardous to USB cables too, and bumping the aerial cable can
>> move the USB cable and cause trouble.  One useful trick is to use a
>> longer cable and lay the tuner flat on a surface at the back of the PC
>> and tape it down over the cables on both sides to that surface, so
>> that the USB and aerial cables are not able to move the tuner around
>> and jiggle things.
>> I used to have one USB DVB-T tuner that caused me endless problems
>> like that, and I finally managed to make it reasonably reliable by
>> using a different cable that was a very tight fit.  But even then, it
>> would still fail every few months, and just unplugging it an plugging
>> it in again made it start working again.  So eventually, because of
>> that and also because I wanted more tuners, I bought an 8 tuner DVB-T2
>> PCIe card (TBS6209).  That solved the problem!
>Actually, there is a possible circumstance to the OP's problem. That occurs when, I forget the exact 
>wording, but the tuner is not exclusively dedicated to myth but can be used by other programs, or 
>hosts in the case of a network tuner.
>If that happens, when myth comes to take control of the tuner to make a recording, it has no way of 
>knowing what state it has been left in by <something else>. Is it possible it then does a re-initialise?
>Is it possible that flag has been inadvertantly set?

No. MythTV does not reinitialise tuners - as far as I know, the Linux
DVBAPI has no call that allows you to reinitialise or reset a tuner.
When you open or close a tuner, you are just opening or closing access
to the existing tuner created by the driver.  Initialisation of a
tuner is up to the driver, and happens at boot or when the tuner is
plugged into the PC.  Firmware load happens when the driver decides it
happens.  What they mostly seem to do is to wait until the tuner is
opened or even later when it is tuned to a channel.  Getting an open
call tells the driver that the filesystems must be ready by then, as
the open call is the same one that is used by the filesystems.  So
getting it means that the driver will be able to access the firmware
file and download it.

When you do the DVBAPI open call, you can select exclusive use, or
permit simultaneous use.  When you open a tuner for exclusive use (as
MythTV does), nothing else can open it until you do a close call.  The
close call puts the tuner back into a state where it is idle and able
to be opened by any program again.  It clears the state of the tuner
so that it is ready to be opened.  But it does not reset the hardware
or unload the firmware.  So if there is a bug in the firmware which
has made the tuner unusable, unfortunately there is no way to reset
the tuner from software to work around the bug, except by rebooting or
unplugging it and plugging it in again.  If a stray cosmic ray has
come along and temporarily messed up the tuner, you can not reset it
to fix that either.  Hence the reason why it is a good idea to
occasionally power off a PC and do a full cold boot - that will
normally clear circuit lockups caused by stray radiation.  If you just
do warm boots all the time, often tuner drivers do not bother to
reload the firmware as the CPU in the tuner has been running that
firmware right through the warm boot and the driver sees that when it
tries to talk to the tuner after the driver is loaded.  But it depends
on the particular tuner - some get a hardware reset from a warm boot
and will be fully reset and have to load the firmware again.

Network tuners are completely different however - they do not have
kernel drivers, and there is no generic API like DVBAPI for running
them.  Each manufacturer has their own network API.  Some network
tuners may well have the ability to be reset by one of their API

More information about the mythtv-users mailing list