Saturday, October 13, 2012

If OpenGL is limited to 10 FPS, check the video card interrupt

When using a VisionTek Radeon HD 2600 Pro AGP with open source Linux drivers in Ubuntu 12.04, I often found that OpenGL and VDPAU frame rates were limited to 10 FPS. It's as if the video card was synchronizing to a 10 Hz refresh rate, but the actual refresh rate was 60 Hz. According to xrandr, X knew the actual refresh rate.

For OpenGL programs, it was possible to override this using ~/.drirc or a vblank_mode=0 environment variable. It's easy to demonstrate this using glxgears, for example comparing "glxgears" to "vblank_mode=0 glxgears".  With mplayer, it can be overridden using "-vo gl:swapinterval=0", but there doesn't seem to be a way to override it for "-vo vdpau".

Driconf is a nice graphical tool for changing ~/.drirc settings. However, I needed to edit the resulting ~/.drirc, changing to driver="dri2".

These are just partial workarounds. The real problem is that unhandled interrupts cause the kernel to disable the radeon IRQ. This is the IRQ used for waiting for vertical retrace, and I guess that wait times out after 0.1s. When things work properly, I can see radeon interrupt count increasing in /proc/interrupts while running glxgears and for a few moments afterwards. When things don't work properly, that count is 200000 and this appears in dmesg:
 
[ 33.806034] irq 5: nobody cared (try booting with the "irqpoll" option)

followed by a long backtrace and

[ 33.806980] handlers:
[ 33.807173] [<e8a57cc0>] radeon_driver_irq_handler_kms
[ 33.807180] Disabling IRQ #5


This happened about 5 seconds after all the drm initialization messages. As you can see, the radeon irq handler was there. It just acted as if the interrupt was not from the video card. Earlier on there is:

[ 24.047694] ACPI: PCI Interrupt Link [LNKA] enabled at IRQ 5
[ 24.047707] PCI: setting IRQ 5 as level-triggered
[ 24.047723] radeon 0000:01:00.0: PCI INT A -> Link[LNKA] -> GSI 5 (level, low) -> IRQ 5


Since the interrupt is level triggered, I don't think it would be reasonable to use the noirqdebug kernel option to prevent the interrupt from being disabled. It would just keep interrupting and make everything slow or even unresponsive.

Wednesday, October 10, 2012

MythTV notes

I just installed Mythbuntu 12.04.1 and set up MythTV on an old computer. Here are some notes from the process.

plopKexec can boot Linux from USB when the BIOS can't

The computer has a floppy drive, a CD-ROM drive that can't read CD-RW discs, and USB 2.0 ports. USB seemed like the best way to install Linux.

I put the files on my Archos Recorder V2 using UNetbootin. The Windows version failed to detect the Archos Recorder V2. The Linux version hung for a while but otherwise worked properly. I successfully tested the result on a computer that supported booting from USB, but the computer I wanted to use didn't support it, so something else was needed. I first tried Plop Boot Manager, but it only sometimes detected the drive and every boot attempt hung. I was able to start the installation without problems using a plopKexec floppy.

Don't upgrade MythTV from the PPA

Mythbuntu has repositories with updated versions of MythTV. These can be enabled using Mythbuntu Control Center. I tried these when I encountered problems, and they did not make things any better. If you upgrade MythTV, it might upgrade the database schema. It's possible to downgrade MythTV via ppa-purge, but the old version will refuse to work with the upgraded database. You can restore the database from a backup.

Analog channel scanning does not work

I was trying to use the Hauppauge PVR-250 analog video capture board with hardware MPEG encoding. The channel scan always quickly finished and picked up no channels. However, ivtv-tune from ivtv-utils could tune to channels, and the video was available at /dev/video0. I guess analog channel scanning is broken in MythTV.

Channels can be input via the channel editor in backend setup. The important thing to set is the "Frequency or Channel" on the last page. I populated the channels using some SQL that I constructed using sed from my cable company's channel listing.

Switch to the Slim profile to avoid hesitations on slow hardware

When I first watched TV, there were regular hesitations. It was at first disappointing how a 1 GHz Pentium III couldn't properly play SD MPEG2, and I wondered if MythTV became more demanding recently. However, everything worked perfectly after I switched to the Slim video playback profile.

ATI Remote Wonder works, but some keys need remapping

For the ATI Remote Wonder, I just had to put batteries in the remote and plug in the receiver. It worked, both as a keyboard device and as a mouse. However, some keys weren't mapped the right way for MythTV. Some even had key codes above 255, which meant they can't normally be remapped in X. I remapped them using a patched xf86-input-evdev driver.

The git pull fails because the changes can't merge cleanly with current code. It would probably be best to simply check out the branches instead, for example "git checkout code-remap-2.6.0". It's also possible to check out earlier versions and then pull the code remap.

It's not necessary to change udev rules anymore. InputClass matching can be used to apply the remapping to the desired device. You can create a new file in /usr/share/X11/xorg.conf.d/ for all of this stuff.

It's also possible to use the ATI Remote Wonder via LIRC. I could have avoided the evdev patching that way, but I liked how the mouse part works with the kernel driver.

LIRC works

Cogeco only makes a few channels available via analog signals. I wanted access to more, so I hooked up a Huawei DC730. I already had a LIRC configuration file for the remote from before. LIRC failed to learn it, but I was able to find a compatible configuration online. It's actually for Comcast Branded Motorola DTA100 and Pace DC50X, so it seems XMP-1 is standardized. I already knew LIRC can recognize the remote, and for sending, I just had to build the simple transmitter circuit and configure LIRC on that machine. There's no need for a stronger transmitter as long as the LED is close to the DC730's IR window and properly aligned.

First, I disabled the normal serial driver via "setserial /dev/ttyS0 uart none".  I placed this along with other customizations in /etc/rc.local. Then I copied the configuration file for the remote into /etc/lirc/ and added an include to /etc/lirc/lircd.conf, like the comments there say. Finally, I edited parts of /etc/lirc/hardware.conf to load the lirc_serial module and start lircd. After running /etc/init.d/lirc to perform those actions, it was possible to test the setup via irsend.

For automatically changing channels via MythTV, I created a shell script to send the channel digits followed by the enter key. The MythTV back end is set to use this via input source configuration. There's also a field for pre-setting the channel on the tuner, but I'm not sure if that works. Instead, I added "ivtv-tune -t us-cable -c 3" to /etc/rc.local.

Eventually I found that repeated keys were sometimes registering as just one keypress. For example, attempts to change to channel 22 would sometimes change to channel 2. I fixed this by increasing gap in the remote configuration file to 101698.

MythTV goes overboard with logging

After a short while, I couldn't watch video while recording anymore.  The problem was that mysqld was using too much CPU time. Restoring an old database fixed this, but I didn't want to lose the settings made since then, so I investigated further. The problem was all the verbose logging being stored into the database. I stopped both the front and back ends from storing logs into the database, and reduced the verbosity of the front end. This has to be done via command line arguments. For the backend, edit /etc/init/mythtv-backend.conf. The front end arguments are either set from MYTHFRONTEND_OPTS in /usr/bin/mythfrontend shell script or from Mythwelcome setup. Other components such as Mythwelcome also log the same way.

Use the RTC

It makes no sense to keep a computer on 24/7 just for occasional use. Even the more than 10 year old motherboard I'm using can power on from an RTC alarm. It seems I don't even need to disable hwclock updates. It makes sense to use Mythwelcome. If I set Mythwelcome to automatically start the front end when the computer is manually turned on, then I have to press alt-tab to show Mythwelcome after quitting the front end. For now, I'm forced to disable that option.

Don't buy ATI/AMD video cards

The most annoying part was dealing with ATI graphics cards. The free software drivers don't work well, and the proprietary drivers don't work. I may write about this in another blog post.

Wednesday, October 03, 2012

Using a DEC LK401 keyboard in Linux is easy

I just got my Stellaris Launchpad. When I examined the USB library in StellarisWare and the sample code, I saw it would be easy to create an adapter for using an old DEC or Sun keyboard as a USB keyboard. However, before I started on that project, I realized that Linux already has drivers in the kernel for Sun and DEC keyboards: sunkbd and lkkbd.

The lkkbd driver has very good documentation in the long comment at the start of the file. It gives you the pinout, tells you how to hook up the keyboard, and tells you about the DEC document which describes the LK201 keyboard. (The DEC document is unavailable at that link but can be downloaded here. It's a technical manual for a VAX graphics board set which uses these keyboards.)

The keyboard uses +12V power and communicates via RS-423 serial communication at 4800 baud. This is compatible with standard RS-232 serial ports in terms of both protocol and voltage level. All that needs to be done is to hook it up to a serial port and provide +12V power. The connector is a plug similar to a phone handset connector. It can fit into a standard RJ11 phone jack, but because it is narrower it can fit in two different ways, one of which would make wrong connections.

Ubuntu comes with an already compiled lkkbd kernel module. To enable, the keyboard, all that's needed is something  like:

sudo inputattach --daemon -lk /dev/ttyS0

This will load the module and make the keyboard usable, leaving inputattach running as a daemon. The last part of the command specifies the serial port; change it if necessary.

The LK401 is pretty good. The tactile feel is better than the LK201, and I can type quite fast with it. The driver is stable. It seems all keys except Select work. There are no X11 keysyms associated with F19 and F20. Most of the extra keys are reported as XF86Launch making them usable as programmable hotkeys.

Monday, October 01, 2012

Asus WL-500W router bad capacitors

My WL-500W wireless router recently became unstable. It was still perfectly fine for web browsing, but any large data transfers over wireless caused reboots. At first, I only noticed this with copies over the LAN, but a few days ago even a fast download from the Internet caused a reboot. At first I thought this was a bug with the firmware I use, but going back to a version that used to be perfectly stable did not help.

I found some info online about bad capacitors in Asus routers, so I decided to investigate. I chose to first look at the router, because it is easier to open. That just involves removing the glued on rubber feet, unscrewing the Phillips screws that were hidden by the feet, and lifting off the top. I immediately noticed a bulging capacitor near the toroidal inductor near the power input. It's used for filtering 3.3V power, so it's quite important.
This made me also wonder about the power supply wall wart. People were reporting bad capacitors there also. Since looking inside requires violent disassembly, I first measured the voltage to see if there might be a problem. Open circuit voltage was okay, but when the router was connected, the voltage drooped below 4V, which is obviously bad.

I opened up the wall wart by hammering a blade into the seam at various locations. This was much quicker and easier than sawing it apart. Then I had to yank out the circuit board, which was glued with silicone. The 1200µF 10V output filtering capacitor was bulging and leaking. After replacing it, the, voltage droop under load became much more reasonable.
After replacing both of these capacitors, the router was stable. As long as it's stable and the other capacitors don't look obviously bad, I don't feel like replacing them. This does however make me hesitant to glue the wall wart back together. For now I'm using a rubber band, and I guess I'll replace that with cable ties.

This wasn't too hard, but I shouldn't have to deal with bad capacitors in a product manufactured in 2008. I'm disappointed with Asus. By 2008 they should have learned how to avoid this problem. I guess the capacitor plague continues. Wikipedia even has an "after 2007" section in the article.

Finally, here are photos of markings on the two bad capacitors. The obscured number at the top is 8011D.


Thursday, August 16, 2012

When buying optical media, choose wisely

Yesterday I got a 50 pack of Memorex DVD+R discs at the Superstore. The first disc burned without any problems, but two different drives failed to read it. After that I checked the reviews on Amazon. The pack I got has only 3 stars, and it looks even worse if you examine the distribution of reviews. The Verbatim brand which I used before has much better reviews. The lesson here is that even though this is a small purchase, it's still necessary to check reviews and choose wisely, instead of picking up whatever is convenient.

The Memorex discs had a MID of "RITEK F16 001 (01h)". After returning those to the Superstore, I got a Verbatim 50-pack at Staples with a MID of "MCC 004 000 (00h)". My first Verbatim burn turned out great:


Thursday, July 26, 2012

Deconstructing Christianity, good and evil

Usually, when someone tries to control people via mass killings, collective punishment and torture, we call them evil. If one considers the Bible literally, as a true story, one finds that God is doing a lot of it. Here's an estimate of the number of people killed by God and on God's orders.

If one looks at the Bible without the bias that simply asserts that God is good, it seems like good and evil may be backwards there. It seems that Gnosticism has a more reasonable interpretation. The Bible makes a lot more sense if it is talking about a flawed and crazy Demiurge (creator), and not some ultimate supreme and good being.

However, even following Gnosticism does not seem right, because it's still just mythology without any proof. All of this makes the most sense if just thought of as mythology, instead of information about the nature of reality.

Even good and evil is mythology, and not something real. It is a particularly dangerous mythology because the idea that some group is evil has been used to justify some of the worst things people did to other people. Belief in good and evil is probably the root cause of why some religions have caused harm.

It's possible that if one digs even deeper, the root problem is the idea of absolutes. It leads people to not think or question, and instead stick with assumptions. That is why I do not like the idea of there being some absolute deity.

Friday, June 22, 2012

Playing AAC audio from FLV video in Rockbox

I wanted to have the audio from a guided meditation Flash video on my portable device running Rockbox. After downloading the video to an FLV file, I first tried using FLVExtract. This created an AAC file which was playable in Winamp, but Rockbox didn't recognize it. I had to put the file into an MPEG4 container. For that I used FFmpeg from the command line:

ffmpeg -i audio_from_flvextract.aac -absf aac_adtstoasc -acodec copy final_audio_file.m4a

It's also possible to skip the FLVExtract step:

ffmpeg -i video_file.flv -vn -absf aac_adtstoasc -acodec copy audio_file.m4a

For some reason, this M4A file was slightly larger.

Tuesday, June 12, 2012

Fixing a flash drive by reprogramming the controller

I recently started having problems with the Kingston DataTraveller 102 16GB flash drive (DT102/16GB) which I use on my Asus WL-500W router. It would disconnect as /dev/discs/disca and reconnect as /dev/discs/discb, and so on, making /opt inaccessible. I don't know if it was due to newer versions of the firmware I use or the drive itself. I first started having problems with r3702, and they continued with r4051. I wondered if the USB contacts got dirty, so I quickly plugged it in and unplugged it a bunch of times to try to clean them. That made the drive totally inaccessible. I now think I should only do something like that when power is off, although I'm not sure if it's responsible for the problem. The drive still registered as a USB device, but it couldn't be read or written. Both Windows and Linux reported it as a generic device (not Kingston as before) and Linux couldn't read the capacity.

There's a web site which shows which shows what controllers are used by various drives, and provides tools for reprogramming the controller. According to the site, the DT102 uses the SSS6990 controller, and the proper tool is SSS6690 USB Flash Sorting Ver 4.010. Other versions are available elsewhere, for example at this Russian site. I chose to use 4.010. The program immediately discovered the flash drive:

When I clicked start, it did some programming and then a large amount of testing. Eventually it failed, claiming there are too many bad blocks. I then changed some options via the setup button. Changing from "Downgrade Flash" to "Normal Flash" made the procedure work quickly, without any extended testing. However, the drive was ridiculously slow. I then changed the access time to 50ns, because the flash part number ended with 48 and I think that probably means 48ns. This gave good speed, I think like before. I also changed the LED, so it is normally off and on while the drive is accessed, like before. Here's the configuration dialog with the settings I changed:

The drive works now. I could fill it with data, read the data and verify hashes without any errors. It's also working fine so far with my router and firmware r3497. I wouldn't trust it for something very important though.