How to get Shed Skin working on Maemo 5

Big fat warning: You only should install the below described packages,, if you know how to do it! It might break your phone. A backup might be very wise! Also your rootfs will get full, if you install to many development packages! I did it so see if it is possible. But to really work with it, I strongly suggest to install it in scratchbox! On http://wiki.maemo.org/ShedSkin I described how to install and use it in scratchbox.

Shed Skin is a tool to create python modules writen in c. This is usually used to speed up programm code which is time critial and where python is too slow. The authors of Shedskin say the following about it:

Shed Skin is an experimental compiler, that can translate pure, but implicitly statically typed Python programs into optimized C++. It can generate stand-alone programs or extension modules that can be imported and used in larger Python programs.

As I write some python software for my Maemo based phone N900, I started to look into speeding up some of the programm code.

I now got shedskin working on the phone. First of all you will have to install the gnu c compiler gcc on it. This website shows how to do it. Basically you will have to add this repository on your Maemo device:

deb http://repository.maemo.org/ fremantle/sdk free

Afterwards I had to install the needed packages with:

apt-get install build-essential

This should give you all needed packages to compile a c program.

I then downloaded the source code of Shedskin 0.6 from its project website and installed it on the phone (extract it and run “python setup.py install“). The source package has a readme file which shows you how to do it and how to create the example programs. To get them working, I also had to install the the following packages:

libgc-dev
libpcre3-dev
python-all-dev

When I tried to compile the examples, g++ did not understand the flag “-msse2″. I had to remove it in the Makefile . If you want to remove it permanently, you can do it in the file shedskin/FLAGS in the Shedskin source package before you install it.

Speed test

I made a simple speed test, to see how much faster it would be. The test might not be well chosen, but is close to what I need.

test.py:

#Speed test with shedskin 0.6

from module1 import func1

a=0
for i in range(0, 1000000):
 a=i+i*5
#a=func1(a)

print a

module1.py:

#Module for speed test with shedskin 0.6

def func1(a):
 for i in range(0, 1000000):
 a=i+i*5
 return a

if __name__ == '__main__':
 print func1(0)

To test it with the module, I commented out the for loop in test.py and enabled the function call func1. To measure the time I used “time python test.py”. The measurements gave the following (average results):

normal:

real    0m5.560s
user    0m4.797s
sys     0m0.172s

with c module:

real    0m0.294s
user    0m0.250s
sys     0m0.039s

We can see that the program is approx 18 times faster with the c module!
This for sure shows how useful it can be to use c for certain functions.
The disadvantage how ever is the size of the created module, it is 1.3 MB.

Posted in Maemo, Programming | Leave a comment

Kubuntu 10.10 and dual screen

Every time I reinstall a Linux distribution and try to use 2 screens (my laptop screen and an external one), I have to struggle with the Xorg configuration.

As I now installed Kubuntu 10.10, I was very pleased to see that I easily can change the configuration on the KDE System settings. But my joy was only a for short time as I figured out that Kubuntu 10.10 is not able to set the resolution of my external screen correctly. The desired resolution, 1280×1024 just is not listed. :(

As the file /etc/X11/xorg.conf is not existing anymore, there has to be another way. After a long search I found the tips for the solution on those 2 websites: http://reustle.tumblr.com/post/1607857706/force-screen-resolutions-on-ubuntu-10-10 and http://www.jejik.com/articles/2008/10/setting_up_dual_monitors_system-wide_with_xrandr_on_debian_lenny/

The solution is to use xrandr. A simple “xrandr” in the terminal shows you the available devices and their resolutions:

Screen 0: minimum 320 x 200, current 2720 x 1024, maximum 8192 x 8192
VGA-0 connected 1280x1024+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
 1360x768       59.8
 1024x768       60.0*
 800x600        60.3     56.2
 848x480        60.0
 640x480        59.9     59.9
 680x384       119.6    119.9
 512x384       120.0
 400x300       120.6    112.7
 320x240       120.1
LVDS connected 1440x900+1280+0 (normal left inverted right x axis y axis) 303mm x 190mm
 1440x900       60.0*+   50.0
 1280x854       59.9
 1280x800       59.8
 1280x720       59.9
 1152x768       59.8
 1024x768       60.0     59.9
 800x600        60.3     59.9
 848x480        59.7
 720x480        59.7
 640x480        60.0     59.4
DVI-0 disconnected (normal left inverted right x axis y axis)

As you can see, VGA-0 does not have the correct resolution of 1280×1024.
This can now be added with those commands:

xrandr --newmode "1280x1024"  109.00  1280 1368 1496 1712  1024 1027 1034 1063 -hsync +vsync
xrandr --addmode VGA-0 "1280x1024"

To get the values for the first line, you can use this command:

cvt 1280 1024 60

Which should return something like this:

# 1280x1024 59.89 Hz (CVT 1.31M4) hsync: 63.67 kHz; pclk: 109.00 MHz
Modeline "1280x1024_60.00"  109.00  1280 1368 1496 1712  1024 1027 1034 1063 -hsync +vsync

Just drop the first line and the “Modeline”. Also I renamed the label from “1280x1024_60.00″ to “1280×1024″.

Now you can tell the X server to use the new resolution:

xrandr --output VGA-0 --mode 1280x1024

I also had to do it for the internal screen:

xrandr --output LVDS --mode 1440x900

Now we can change to the dual screen:

xrandr --output VGA-0 --left-of LVDS

Sadly it always takes my external screen as primary. According to some websites, this can be solved when you swap the two “mode” commands listed above, how ever it did not work for me. After some more research I found this working solution to set the internal screen as primary:

xrandr --output LVDS --primary

Sadly those changes get lost every time you restart the X server.
I did not find a way to make them permanent, so I have to execute those commands after every restart. To make my life easier, I put them into a script which gets executed automatically after I log in.

As I not always have an external screen, I made the script detecting if I have an external screen is connected. If not, it switches the (not connected) external screen off.  On http://www.jejik.com/articles/2008/10/setting_up_dual_monitors_system-wide_with_xrandr_on_debian_lenny/ you can find an even better script. Mines looks like that:

#!/bin/sh
xrandr | grep VGA | grep " connected "
if [ $? -eq 0 ]; then
 # External monitor is connected
 xrandr --newmode "1280x1024"  109.00  1280 1368 1496 1712  1024 1027 1034 1063 -hsync +vsync
 xrandr --addmode VGA-0 "1280x1024"

 xrandr --output LVDS --mode 1440x900 --output VGA-0 --mode 1280x1024

 xrandr --output VGA-0 --left-of LVDS
 xrandr --output LVDS --primary

else
 # External monitor is not connected
 xrandr --output LVDS --mode 1440x900 --output VGA-0 --off
fi

Also when ever I plug in/out the external screen, I just run this script and my screens get set up as desired.

Posted in Linux | Tagged , , , , | 2 Comments

New SleepAnalyser version in Maemo extras

The latest version (1.6.53) of my SleepAnalyser software (application which records your movement during your sleep) just reached the extras repository on the maemo system. If you own a N900 or another phone with the Maemo OS, have a look on it!

You can learn more about it here.

Posted in Maemo, Programming | Leave a comment

How to install VMware 6.5.4 on a kernel 2.6.35 (Kubuntu 10.10)

As I recently moved from my old Debian installation to Kubuntu 10.10, I tried to get VMware (VMware-Workstation-6.5.4-246459.i386.bundle) to work.
As normal, it did not just work from beginning.

After starting the installation, it missed gcc and some other packages.
Well that was easy to fix with the package manager. Surprisingly, the installation then finished without errors.

Then I tried to start it for the first time. As usual, it has to to built the modules first. How ever, it missed some stuff and gave this error:

C header files matching your running kernel were not found.  Refer to your distribution’s documentation for installation instructions.

After some research I found a tip on https://bbs.archlinux.org/viewtopic.php?pid=816564#p816564 about some missing files.
I fixed it with those commands:

cd /usr/src/linux-headers-2.6.35-22-generic/include/linux
ln --symbolic ../generated/autoconf.h ./autoconf.h
ln --symbolic ../generated/utsrelease.h ./utsrelease.h

After that it starts to compile the modules.
All modules except the one for the network and VMCI Sockets can get build.

Then I found the next tip on http://blog.gnu-designs.com/solved-building-vmware-workstation-modules-on-linux-2-6-32. Some strings have to be replaced in the source files. It can be done with the following commands:

tar xvf /usr/lib/vmware/modules/source/vmnet.tar -C /tmp
tar xvf /usr/lib/vmware/modules/source/vmci.tar -C /tmp

cd /tmp

perl -pi -e 's,("vnetInt.h"),\1\n#include "compat_sched.h",' vmnet-only/vnetUserListener.c
perl -pi -e 's,("compat_page.h"),\1\n#include "compat_sched.h",' vmci-only/include/pgtbl.h

tar cvf /usr/lib/vmware/modules/source/vmnet.tar vmnet-only
tar cvf /usr/lib/vmware/modules/source/vmci.tar vmci-only

Now I was able to build the network module. the VMCI module still fails, but VMware starts and seems to work correctly.

According to http://www.vmware.com/support/developer/vmci-sdk/ the VMCI is used fore some fast communication between host and guest or different guests:

The Virtual Machine Communication Interface (VMCI) supports fast and efficient communication between a guest virtual machine and its host server, or between multiple virtual machines on the same host.

As for now, It tries to compile this module every time I start the VMware. Its a bit annoying, but I can live with it for now. I am sure somebody will find a solution soon.

Posted in Linux | Leave a comment