Using Linux RT Kernel

It’s taken me a while to mess around with the Linux RT system, so here’s a somewhat full documentation of what I did. I assume some Linux compiling knowledge and a safe environment to actually do this, such as a chroot environment or a virtual machine or your roommate’s computer who isn’t going to know what happened.

I’ll start with a simple program in C to test the RT Kernel. Get it here, adapted from the official docs’ provided example. You can compile it on your regular stock kernel as such:
$ gcc -o test_rt test_rt.c -lrt
You can then run the program a number of times to see what the minimum run time is.
$ time sudo ./test_rt
My personal record is about 10 seconds on a stock kernel on VirtualBox running a single CPU. However, we know that testing this program on a standard machine with low load is not indicative of a `real` real time system. So we now run our program under high load. But first, we need to simulate that high load:
$ sudo stress -c 1000 -i 100 -m 2 --vm-keep -t 120
(note that the -m 2 uses (2 * 256)MB of memory, so make sure you have enough!)
And then, we’ll run the test_rt program again.

Patching the Kernel

In this example I’m working with kernel 3.8.4. You may want to use a different version of the kernel, in which case look for the highest version of the patch available here: https://www.kernel.org/pub/linux/kernel/projects/rt/
And download the corresponding vanilla kernel here: https://www.kernel.org/pub/linux/kernel/v3.x/

And moving along, here’s how we patch:

  1. In your home directory go to the Download folder and download the patch file in bz2 format (mandatory for this exercise) and the vanilla kernel.
  2. Unpack the kernel, and go into the directory
    $ tar -xjvf linux-3.8.4
    $ cd linux-3.8.4
  3. Apply the patch
    $ patch -p1 < <(bunzip2 -c ../patches-3.8.4-rt2.tar.bz2)
  4. Configure the kernel using the config file from your existing kernel
    $ cp /boot/config-$(uname -r) .config
    $ make oldconfig

    IMPORTANT:
    1. when prompted for preemption model, select option 5 – Fully Preemptible.
    2. When prompted for debug options do not select it. Turning on the debug flags (which is the default option) will decrease performance.
    3. For every other prompt you can just press which selects the default
  5. Build the kernel
    $ make-kpkg clean
    $ CONCURRENCY_LEVEL=$(getconf _NPROCESSORS_ONLN) fakeroot make-kpkg --initrd --revision=0 kernel_image kernel_headers
  6. Install the .deb files
    $ cd ../
    $ sudo dpkg -i linux-headers-3.8.4-rt2_0_i386.deb linux-image-3.8.4-rt2_0_i386.deb
  7. Reboot into your new kernel. Note: the steps above do not make this kernel your default. You will need to select the appropriate kernel from your grub menu

At this point you can try running the benchmarking script again. My record was under 2 seconds, down from the 10 seconds mentioned above.

Note: If your performance actually decreases, you may want to check to make sure your debugging flags were turned off during compile.

Using the Nokia N900 as a modem

For those of you who don’t know, I was lucky enough to be selected to receive a Nokia N900 for trial courtesy of WOMworld Nokia. I will write about my experience using the phone as a first-time smartphone user soon enough; I don’t think I’ve had enough time to build a first impression :)

For now though, here’s a howto on the first thing anyone would want to do with a 3G phone: turning it into a modem. This applies to someone in my scenario who is connecting a Nokia N900 to a Linux machine (also known as tethering). However it should apply the same to any other machine using the same concepts. Which is that you can plug the phone in, expect it to register as a USB modem, and use a dialer to dial out.

Step 1: Connect Your Phone
Make sure your phone is connected to the machine via the US cable that comes packaged with the phone. Upon connecting your phone to the machine you will see a pop-up on the phone that asks how you would like to connect this device, with the options being “Mass Storage mode” or “PC Suite Mode”. Technically you should be able to use the phone as a modem even without making a choice here, but if you can’t connect without choosing, choose “PC Suite Mode”.

Step 2: Make sure the phone is recognised as a USB modem
Make sure the phone (Nokia N900 in this case) is recognised as a USB modem by the machine. To do so run lsusb from the terminal. Which should give you something along the lines of
Bus 002 Device 007: ID 0421:01c8 Nokia Mobile Phones Next run ifconfig from the terminal, you should see a new device “usb0″. This is where you know you’re good to go. If you don’t get this, well, unplug the phone from the machine and try again.

Step 3: Make sure your phone is no longer connected to the internet.
edit: this step is dependent on your provider. You may not need this
That means shut down your Internet Connection (generally your 3G) on the N900. And on the N900 this was a little more difficult than I expected; because I did initially set my phone to connect whenever it can. Turning the 3G services off did nothing to override the previous settings, the phone just tries to reconnect again. That means you will have to first make sure you turn off the settings to “Always Connect” and only then turn the Internet Connection off.

Step 4: Configure your dialer
I use wvdial and i recommend you do too. If you don’t have it, install it (ie “sudo apt-get install wvdial). For this step there’s one really important detail that you will need to know which is your APN (Access Point Name). This differs across carriers so google for your carrier / ISP’s APN first. The next thing to know will be the credentials required to login. I’m using DiGi where the APN is “diginet”; the username “guest” and the password “guest”. The rest of the settings aren’t too different from my 3G broadband settings identified here.
Note: the modem in my case is registered as /dev/ttyACM0 which IIRC is a standard USB modem, but you will want to confirm the location of your modem before actually configuring your dialer

Step 5: Dial
As mentioned I use wvdial, so all I need to do is to ensure I have configure the config file at /etc/wvdial.conf and from terminal type sudo wvdial. I have included the wvdial config file below which of course works for me. Your own config file shouldn’t look that much different with the exception of the APN, the Username, the Password and maybe the Phone number.


[Dialer Defaults]
Modem = /dev/ttyACM0
Baud = 230400
Init1 = AT+CGDCONT=1,"IP","diginet"
Init3 =
Area Code =
Phone = *99***1#
Username = guest
Password = guest
Ask Password = 0
Dial Command = ATDT
Stupid Mode = 1
Compuserve = 0
Force Address =
Idle Seconds = 0
DialMessage1 =
DialMessage2 =
ISDN = 0
Auto DNS = 1
Check Def Route = 1

Huawei E620 and Linux

The modem used is Huawei E620 or E1550. I’m not sure why it has 2 names, but it’s the same thing as far as I can see.

This is specifically for DiGi, but anything else on the same modem would work as well

1. make sure the device registers as a 3g modem and not a storage device. lsusb and look for:

Bus 002 Device 005: ID 12d1:1001 Huawei Technologies Co., Ltd. E620 USB Modem
if you get that proceed to step 5. Else continue with step 2
2. Get usb_modswitch, install it as root. The default installation path is /usr/sbin.
You will not need to compile this, there is a binary prepackaged that you may use.
3. `vim /etc/usb_modeswitch.conf` and paste the following lines:
# Huawei E1550
DefaultVendor = 0x12d1
DefaultProduct = 0x1446
MessageEndpoint = 0x01
MessageContent = "55534243000000000000000000000011060000000000000000000000000000"

4. plug in the modem and run `sudo usb_modswitch`. do another `lsusb` to make sure the device is registered properly as in step 1. `vim /etc/udev/rules.d/45-huawei1550.rules` and paste the following line:

SUBSYSTEM=="usb", SYSFS{idProduct}=="1446", SYSFS{idVendor}=="12d1", RUN+="/usr/sbin/usb_modeswitch"
5. I use wvdial, if you do too then `vim /etc/wvdial.conf` and paste the following lines:
< == Leave This Line Empty ==>
Modem = /dev/ttyUSB0
Baud = 230400
Init1 = AT+CGDCONT=1,"IP","3gdgnet"
Init3 =
Area Code =
Phone = *99***1#
Username = digi
Password = digi
Ask Password = 0
Dial Command = ATDT
Stupid Mode = 1
Compuserve = 0
Force Address =
Idle Seconds = 0
DialMessage1 =
DialMessage2 =
ISDN = 0
Auto DNS = 1
Check Def Route = 1
Notice the empty first line. That makes a difference. Trust me.
6. run `sudo wvdial` and you should be good to go.
If you’re using kppp then just use the configuration from the top except the phone number is *99#
And who said linux was not ready for the desktop??

vim tips part 1.

Yes, A little bit of googling will give you good results but this is like most of all I have here: meant to be for beginners. so here goes.

Note my conventions
:w means type the phrase :w in normal mode (not insert mode)
`a` means hit the a key in normal mode

Tip #1 – Are you really using vim?
First off, you need to figure out if you’re using VI or VIM.
No  they are not the same and are not intended to be.
I believe ubuntu ships with vi and not vim so you do not get vim out of the box.
Some distros alias `vi` to `vim` but trust me, you will want to get used to typing `vim` not `vi`
This way you’re always sure you’re using vim and not vi

Tip #2 – Cursor Navigation
:1 takes you to the first line
:122 takes you to the 122nd line
:$ take you to the last line
`a` moves the cursor one character forward and enables INSERT
`i` does not move the cursor, it sets the cursor to INSERT wherever it is.
`o` moves the cursor one line down and enables INSERT

Tip #3 – File / Edit Management
`u` undoes your last action
:w saves the file
:q quits whatever you’re doing provided there’s no change to the file
:wq saves the file and then exits
:q! quits vim without saving
Do Not make it a habbit of hitting :wq!
This forces a save without a warning if there’s supposed to be one.

So thats it for the ultimate basics. Get used to this, more to come.

HOWTO Open Kopete links in Swiftfox

This of course works if you want to open Kopete links in Firefox as well. Instead of the default Konqueror. Just replace my ‘swiftfox’ in the commands with ‘firefox’

This assumes that you are using the same environment as I am (KDE4.2, Ubuntu 9.04)

1. System Settings* -> Default Applications -> Web Browser
2. Set the value for “in the following browser” as ” /usr/bin/swiftfox -new-tab ”
3. Apply
4. You’re Done.

*If you’re not sure where “System Settings” is, press Alt + F2 and type “System Settings” (remove quotes)

Worms Clone on Linux

.. which is currently my fav game! Is Hedgewars

There’s a complete review written here, but in short : the gameplay is a lot like Worms Armegeddon, the sound effects are cool, and the controls are really intuative.

Plus the AI’s pretty good (dunno if that’s a good thing)

The other alternative is wormux which has a pretty good game engine, a lil more stable with lesser bugs, and nicer characters. But Hedgewars is without a doubt more addictive and more user-friendly and more intuative.

Plus hedgehogs are cute

Battery Capacity Details on a Linux Laptop

All laptop batteries are created equal by Their Maker. But even so, some last longer than others despite coming out of the same production lines. Why? Because although it is manufactured to last (say) 5 hours, sometimes you only get 2 hours before it dies. Usually that means that your actual capacity is lower than what it was manufactured to be.

Here’s how you can figure out how useful your battery really is:

install acpi if it’s not yet available

sudo aptitude install acpi

Open a terminal / console and type:

acpi -V

See those details? Thats some minimal details available. Now for a more detailed view do this:

cat /proc/acpi/battery/BAT0/info

Look at the design capacity and last full capacity:

If you’re last full capacity is under the design capacity, then your battery cannot store as much power as it should and will therefore die faster than it should.

If the last full capacity is under 50% of the design capacity, I’d consider getting a new one.

Alternative Browsers for linux

These are 13 alternatives for Linux. If you google around you’ll find other similar lists, but the ones on my list are actually working, are in relatively active development as of June 1st 2009 and / or has a future. I’m not going to bother arranging this in any particular order, so here it is, all in one go.

  1. Arora – Small, lightweight, buggy
  2. Swiftfox – Big, Bloated, but faster then it’s siblings. Has a cooler logo
  3. Flock – Social stuff which can be cool when you’re surfing youtube or facebook
  4. Chromium – Fast. Buggy. Google.
  5. Opera – Not open source but Free (as in beer), innovative, fast, killer looks
  6. Konqueror – neah~ fits in nicely with kde
  7. Epiphany – neah~ fits in nicely with gnome
  8. Galeon – neah~ fits in nicely with gnome. Pretty light.
  9. Seamonkey – Big Bloated web stuff. Not just a browser
  10. Kazehakase – lightweight, buggy, JS sucks, keeps segfaulting…. but I see hope.
  11. Amaya – The best tool I’ve found for debugging xhtml pages / and XML. I wouldn’t actually browse with this unless I’m debugging something.
  12. elinks – OH YEAH!!
  13. wget – Don’t gimme that crap about it not being a browser. Just try recursive mode, and THEN browse.

SSH Tunneling in one line

ssh username@servername -L <localport>:destinationserver:<destinationport> -N

if you have multiple local addresses, you will want to specify the bind address.followed by a colon. ie:

ssh username@servername -L localbindaddress:<localport>:destinationserver:<destinationport> -N

a ‘*’ is acceptable as the localbindaddress,
Also you will need this if you have a Virtual IP on your machine.