Jan 27, 2012 - Waiting for UDev events to be processed


A couple of days ago my netbook started taking too long to start up and giving me timeouts while processing events from UDev.
This happened during the boot auto-detection of devices in my distro of choice, Arch Linux.
I found out that it was related to my wireless adapter, Broadcom BCM4313 and a recent commit to udev.

I will present the issue encountered and a possible solution for it. I will especifically show how to do it under Arch Linux and, finally, I will leave you some useful links.

During the boot I ran into the following bunch of lines:
Loading User-specified Modules                   [DONE]
Waiting for UDev uevents to be processed         [BUSY]udevd[131]: worker [138] timeout, kill it

udevd[132]: seq 1077 '/devices/pci0000:00/0000:00:1c.0/0000:05:00:0' killed

udevd[132]: worker [139] terminated by signal 9 (Killed)
In addition, the boot time was severely hit because the Waiting for UDev uevents to be processed part would take too long and timeout.

In my journey to fix this issue, I first ran lspci to check which device was causing this failure and found out it was my Broadcom BCM4313 wireless adapter:
$ lspci -s 0000:05:00.0
05:00.0 Network controller: Broadcom Corporation BCM4313 802.11b/g/n Wireless LAN Controller (rev 01)

Then, I got the name of the module loaded for my card:
$ lspci -vin -s 0000:05:00.0
05:00.0 Class 0280: Device 14e4:4727 (rev 01)
        Subsystem: Device 185f:051a
        Flags: bus master, fast devsel, latency 0, IRQ 16
        Memory at f0100000 (64-bit, non-prefetchable) [size=16K]
        Capabilities: < access denied >
        Kernel driver in use: brcmsmac

Now that I knew the module name was "brcmsmac", I decided to add it to my /etc/rc.conf MODULES section, thus making the adapter already available before the udev detection process.

It worked and my boot time got reduced and more elegant.

If you are having the same problem, you should add the module to your boot init script (/etc/rc.conf is one of the ways in Arch Linux), or you can build a cpio kernel image with the module already bundled (but make sure to, somehow, add the required firmware drivers or it won't work because the initial ramfs can't access the root file system).

I have also researched about this problem and it seems to affect many cards as this was generally caused by a recent commit in UDev. So, the solution is easily portable to other devices and kernel modules, you just need to know what those are first (for instance using lspci and the device ID reported by the boot errors and matching them with a kernel module, like I did above).

Now, in more detail, how to fix this problem in Arch Linux with /etc/rc.conf:
  1. Make sure you know the name of the module that is failing detection during the boot, as I explained in the paragraph above;
  2. Under root, edit /etc/rc.conf;
  3. Find a line stating MODULES=(module1 module2 etc);
  4. Inside these brackets put the kernel module of your device/adapter (that you found using lspci -vin -s) , like: MODULES=(mymodule) or MODULES=(othermodule mymodule), if you already have other modules manually declared;
  5. In my case, I ended up with: MODULES=(brcmsmac acpi-cpufreq coretemp), where brcmsmac is the module of my Broadcom BCM4313, which comes with the linux kernel since version 2.6.39;
  6. When you have edited rc.conf, quit and save it, restart the computer and you should now have a proper clean startup.

To complete, I'm leaving you some related links:

Update of 2012/03/15:

Dec 26, 2011 - Creating a search plugin for Firefox


You have probably used multiple search engines with Firefox's OpenSearch plugins. Many websites currently advertise their own search engines using the Autodiscovery method supported by Firefox. You can either add their search engines or you can find some custom ones on Add-ons for Mozilla.

However, sometimes you just need something different, something that fits your specific needs and can't be found anywhere else. In those cases, the best is to do it yourself.

Some browsers, like Chromium, provide an easy way for manually creating search plugins right in the user interface, but with a clean installation of Firefox it isn't that simple.
So, how to create a simple Firefox search plugin without wasting much time investigating? I'm gonna give you a hand for that:

You will need to create a little XML file for each search engine you want to add.

Let's take a look at an example that uses Google Translate:

<Description>Google Translate</Description>
<Image width="16" height="16">http://translate.google.com/favicon.ico</Image>
<Url type="text/html" method="GET" template="http://translate.google.com/#en|pt|{searchTerms}">

Here I am using Google Translate to always translate whatever text I put in the search box from english to portuguese. You can use it as a model for your own search plugins, it will fit most of the situations, as long as they use the GET method.

Me searching for the translation of "flotsam"

Now a look at each section:

Here we define the namespaces for this XMLfile. Just put it always like this and it will work unless the format changes in the future.

<Description>Google Translate</Description>
Give a name to your search engine, inside the ShortName tag, a description inside Description and what encoding to use when entering the text to be searched inside InputEncoding. I recommend UTF-8 unless you are into some heavy characters stuff.

<Image width="16" height="16">http://translate.google.com/favicon.ico</Image>
This defines the icon to use with your search engine. Find the URL of the favicon and put it inside the Image tag and Firefox will automatically download the icon.

<Url type="text/html" method="GET" template="http://translate.google.com/#en|pt|{searchTerms}">
This is the most important part of the file because it tells what the link is and where to put the your search terms. In the case of Google Translate there are the source language, destination language and search terms, all separated by a pipe (|). I have fixed the languages from "en" to "pt" and where the search terms should be I entered {searchTerms}, which will be parsed by Firefox and replaced by what I enter in Firefox's search box.

In order to create an Url tag for other search engine website, you should first make a few tries to see where the link changes (where your search terms are being written). When you find it, just replace the random search terms with {searchTerms}, copy the link and put it inside Url tag template attribute.

Well, we have created the XMLfile. Now we need to know where to put it:

On Windows, assuming it is installed on the C: drive, you should move the XML file to:
C:\Users\yourUsername\AppData\Roaming\Mozilla\Firefox\Profiles\<yourProfileID>.default\searchpluginsC:\Document and Settings\yourUsername\Application Data\Mozilla\Firefox\Profiles\<yourProfileID>.default\searchplugins (Windows XP/2000/2003)

On Linux, the same can be achieved by moving it to:

On Mac OS, you can move it to one of these folders:
~/Library/Application Support/Firefox/Profiles/<yourProfileID>.default\searchplugins

If the directory searchplugins directory does not exist, feel free to create it.

Attention: If you later change the search plugin file and there are no changes in Firefox (even after restarting it), try to move the file away from the searchplugins directory and close Firefox (thus forcing it to sync everything). Then, before opening it again, move the file back to the searchplugins directory. I have witnessed this behaviour with Firefox 9.0.1 on Windows 7, but not on Arch Linux.

Be aware that the XMLfile I described in here isn't the actual OpenSearch format but rather a Firefox variant for locally stored OpenSearch plugins. However, mostly everything is the same and you can find more information at MDN.
Also, Firefox may change your XML file once it gets loaded and alter things like the favicon URL (replacing it with base64 encoded data, for caching).

OpenSearch is supported in Firefox 2.0 and all versions above.

This plugin is also available for direct download: Here.

Dec 22, 2011 - Integrating WPF and Microsoft Kinect SDK with OpenTK


Well, this is my first post, so I'm gonna make it a simple (yet not so short) one.

If you have started messing around with OpenTK recently and also do not have much experience with .NET, this might help you. This is especially true if you want to use WPF (Windows Presentation Foundation) instead of Windows Forms for rendering OpenGL graphics through OpenTK. And if, on top of that, you also intend on using Microsoft Kinect SDK, then this is the right post.

Using Kinect and OpenGL simultaneously gives us a really wide range of possibilities, for instance real time rendering of the 3D space captured by Kinect (plus texture). One way of obtaining that is having access to both Kinect and OpenTK's data and events, in the same application.

For this post, I will just focus on how to have a simple application that can render OpenTK graphics and present video from Kinect, in the same window.

Well, let's start then:

1. Create a new WPF Application project and rename the MainWindow Grid to grid.

2. Add references in the project to:
  • System.Windows.Forms
  • WindowsFormsIntegration
  • OpenTK
  • OpenTK.GLControl
  • System.Drawing (to ease the use of colors in OpenTK)
  • Microsoft.Research.Kinect (to use the Kinect device)

3. Open the WPF Designer and add the following namespace mapping (in the source code area) to the Window element:

Then, add an Image element (just to show Kinect video stream) called image and a WindowsFormsHost element called host, both inside the Grid element, side by side. Set an event for when the Window element is Loaded. It should look something like this:
<Window x:Class="WpfApplication1.MainWindow"
Title="MainWindow" Height="375" Width="1000" Loaded="Window_Loaded">
<Grid Name="grid">
<Image Width="500" Height="375" Name="image" HorizontalAlignment="Left" />
<WindowsFormsHost Width="500" Height="375" Name="host" HorizontalAlignment="Right" />

4. In the .cs include the following types:

using System.Windows.Forms;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using Microsoft.Research.Kinect.Nui;

5. Make the Window element Loaded event handler look like this:
        private void Window_Loaded(object sender, RoutedEventArgs e)
// Create the GLControl.
glc = new GLControl();

// Assign the GLControl as the host control's child.
host.Child = glc;

You are now creating an instance of GLControl and associating it with host (the WindowsFormsHost element you added) by making glc its child.

6. Next is assigning events Load and Paint of GLControl to two new event handlers (you can double press Tab key to automatically create an event handler body, after the += sign):
        private void Window_Loaded(object sender, RoutedEventArgs e)
// Create the GLControl.
glc = new GLControl();

// Assign Load and Paint events of GLControl.
glc.Load += new EventHandler(glc_Load);
glc.Paint += new System.Windows.Forms.PaintEventHandler(glc_Paint);

// Assign the GLControl as the host control's child.
host.Child = glc;

void glc_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
throw new NotImplementedException();

void glc_Load(object sender, EventArgs e)
throw new NotImplementedException();

7. Now fill Load and Paint event handlers with an initial OpenGL configuration (viewport, etc) and what should be drawn every time the control needs a repaint, respectively. The result can be something like:
        void glc_Load(object sender, EventArgs e)
// Make background "chocolate"

int w = glc.Width;
int h = glc.Height;

// Set up initial modes
GL.Ortho(0, w, 0, h, -1, 1);
GL.Viewport(0, 0, w, h);
        void glc_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);


// Draw a little yellow triangle
GL.Vertex2(200, 50);
GL.Vertex2(200, 200);
GL.Vertex2(100, 50);


Build and run it. If you (or me) haven't forgot something, it should be working and showing a little yellow triangle inside the WPF Grid.

8. Now, we want to have access to Kinect data, in real time.
You added a reference to Microsoft.Research.Kinect and did using Microsoft.Research.Kinect.Nui; in the beginning of this post, like you'd do with a normal Kinect project (it's exactly the same, now that we have finished integrating OpenTK), so now it's time to get Kinect ready.
Create a Runtime instance in the class definition, initiate it and assign the required events in the Window Loaded event.
            // Initiate Kinect runtime and streams
nui = Runtime.Kinects[0];
nui.VideoStream.Open(ImageStreamType.Video, 2,
ImageResolution.Resolution640x480, ImageType.Color);
catch (InvalidOperationException)
// Assign stream events
nui.VideoFrameReady += new EventHandler(nui_VideoFrameReady);

9. Fill the video stream ready event handler to just dump the stream to the Image element we previously created.
        public void nui_VideoFrameReady(object sender, ImageFrameReadyEventArgs e)
PlanarImage Image = e.ImageFrame.Image;
image.Source = BitmapSource.Create(Image.Width, Image.Height, 96, 96,
PixelFormats.Bgr32, null, Image.Bits, Image.Width * Image.BytesPerPixel);
Build and run, hopefully you'll see a window showing the Kinect video stream and an OpenGL rendering via OpenTK, both throwing and handling whatever events you register to them.

Full source code: Download here.

Everything I explained here has already been done on other sources. I've just put things together for a simple way of integrating Kinect (and WPF) with OpenTK (OpenGL in .NET). All source code has been tested on OpenTK 1.0 and Microsoft Kinect SDK beta 2.

For more information, check the following references:
Building a Windows.Forms + GLControl based application
Hosting a Windows Forms Control in WPF by Using XAML
Add or Remove References in Visual Studio