Tuesday, August 30, 2011

If you want a complete set of unix tools in your phone, here are the steps to cross-compile and install busybox from source (there's no need to root the phone and/or install everything using the busybox installer from the market).

[optional] Change the busybox config if you want by running:
$ make menuconfig

Cross-compile busybox:
$ make oldconfig && make

At the end of the build the busybox binary should be available as a statically linked ELF for ARM:
$ file busybox
busybox: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.16, stripped

If you have enabled the adb root shell access to your phone (i.e., by rooting the phone or by installing my custom kernel), you can also install busybox in the /system partition and have all the commands available in the $PATH.

Recently I've replaced my Bravo HTC Desire with a new Android phone: a Samsung Galaxy S II I-9100. I couldn't resist too much with the stock kernel, so finally I've found some spare time to cook a custom kernel starting from the original Samsung kernel source code GT-I9100_OpenSource_Update2.

In this post I report (for me to remember later and for those who are interested) all the steps that I did to setup the build environment, cross compile the custom kernel and flash it into the phone.

DISCLAIMER: I take no responsibility for anything that may go wrong by you following these instructions. Proceed at your own risk!

=== Requirements ===

- A Samsung Galaxy S II (not necessarily rooted! you'll get a root shell when you'll flash the new kernel)
- The latest android SDK
- The arm-none-eabi cross-compile toolchain (you can get it from the CodeSourcery website)

=== HOWTO ===

Download and install the arm toolchain from the CodeSourcery website: be sure that arm-none-eabi-gcc is in your $PATH.

At the end of the autobuild process the file kernel-gt-i9100-arighi.tar can be used to flash the new kernel to the phone using Odin (search on the web or in the xda-developers forum, there are tons of howtos/tutorials for this).

=== Results ===

The score with Quadrant benchmark is not bad at all, I got always > 4000, but remember that we're cheating during the IO test, due to the fsync-disable patch.

Anyway overall result looks good enough.

== Additional notes ===

- All the custom *.ko files are included into the initramfs to avoid potential errors/problems with the original kernel modules (so it is always possible to flash back the original kernel later, all the old kernel modules are still there, untouched).

- After you've flashed the -arighi kernel the first time you will also have root access to your device. The initramfs template enables adb root shell (ro.secure == 0), so an adb shell will immediately drop you to a root shell. This means you can also re-flash your device from Linux directly using the flash-kernel.sh script.

- For the complete list of all the patches applied to this kernel have a look at the git log here.

- IMPORTANT: the fsync-disable patch (enabled in the kernel by default) can increase performance and battery life, but it is dangerous, because it might eat your data!! It makes the software no longer crash safe, so if you start to randomly kill your apps you may lose some data

[UPDATE: the fsync-disable patch is no more enabled by default in the kernel, to enable it just set CONFIG_FILE_SYNC_DISABLE=y in the kernel .config)]

Thursday, January 20, 2011

Android is a privilege-separated operating system, in which each application runs with a distinct system identity: the Linux user ID (uid).

With this patch (sched-automated-per-uid-task-groups.patch) the kernel automatically creates a distinct task group for each uid (when a process calls set_user()) and places all the tasks that belong to a single uid into the same task group. In this way each application can get a fair amount of the CPU bandwidth (guaranteed by the CFS scheduler), independently by the number of task/threads spawned.

The patch is against the CyanogenMod's 6.1.1 kernel (2.6.35.10) and I tested it successfully on my HTC Desire (Bravo).

- run the Quadrant benchmark in parallel and measure the result with and without the patch applied

Without the patch (output of top):

PID PPID USER STAT VSZ %MEM CPU %CPU COMMAND

6533 123 10070 R 202m 48.6 0 20.0 com.aurorasoftworks.quadrant.ui.st

6506 1 10035 R 1128 0.2 0 20.0 yes

6507 1 10035 R 1128 0.2 0 20.0 yes

6508 1 10035 R 1128 0.2 0 20.0 yes

6509 1 10035 R 1128 0.2 0 20.0 yes

Benchmark result: 676

uid 10035 (cpu hog) : 60.0 % cpu quota

uid 10070 (benchmark): 20.0 % cpu quota

With automated per-uid task group (output of top):

PID PPID USER STAT VSZ %MEM CPU %CPU COMMAND

6784 123 10070 S 209m 51.4 0 50.0 com.aurorasoftworks.quadrant.ui.st

6852 1 10035 R 1128 0.2 0 12.5 yes

6853 1 10035 R 1128 0.2 0 12.5 yes

6854 1 10035 R 1128 0.2 0 12.5 yes

6855 1 10035 R 1128 0.2 0 12.5 yes

Benchmark result: 816

uid 10035 (cpu hog) : 50.0 % cpu quota

uid 10070 (benchmark): 50.0 % cpu quota

Total speedup: ~1.2 (the benchmark is about 20% faster in this case), because in the last case the benchmark gets ~50% of the CPU time and in the other case it gets only ~20%, despite the fact that there are 2 "pair" applications that should be correctly considered as equal from the user's perspective.

The bcm4329.ko module can't be properly overwritten in the /system partition without S-OFF the device and so give access in read-write to the /system partition. However, we can enforce the usage of our new module binding any other writable directory to /system/lib/modules (i.e., /data/local).

Prerequisites:
- the latest ARM toolchain downloadable from the CodeSourcery site

Download and install the ARM toolchain and be sure that arm-none-linux-gnueabi-gcc is in your $PATH.

- get the latest version of busybox from git (or download a recent stable version if you prefer):$ git clone git://busybox.net/busybox.git

Friday, June 26, 2009

I really enjoy the power of mutt, and I've to say that I've not too far from reaching the email Nirvana with it :). OK, it's not the email client for everybody, it's just for the people that prefer the keyboard to the mouse and love the command line interfaces.

There's only one missing feature in mutt: a nice way to notifiy new emails. The problem with mutt is that I need to periodically switch to the mutt shell to check for new emails. And I don't even like the crappy notification balloons that cover the useful part of the desktop (e.g., thunderbird). A small tray icon could be a solution (and I did it this way for a while, patching mutt), but with the icon I don't see immediately the message that I receive.

This led me to notice a large unused area in the gnome panel at the top (recently I moved from Fluxbox to Gnome, yeah! :) now I've a ultra-very-fast SSD I can also use a fancy desktop environment). So, why not to use the top panel to notify the subject of the last email I received in my mailbox? ta-da! the solution: a small python gnome applet that periodically fetches the last unread email from a generic IMAPS folder in gmail and prints the subject to the panel.

Here's the code: gmail-check, very minimalist and designed just for my particular desktop environment, so it may not work in some cases...

Monday, June 8, 2009

I just got one new SSD disk MTRON MOBI 3000 for my Dell Latitude D430 notebook. It's very small, only 32GB, but it definitely ROCKS!!! I can boot in about 12 seconds, without any deep tuning of the kernel and boot services, but the _responsiveness_ is the most relevant thing, apart the read/write 100MB/s throughput (that is not so important for a desktop system). The impressive part is the ~5500 iops (IO operations per second) obtained using a workload of 4KB random reads/writes!

Who am I?

Andrea Righi joined the BetterLinuxteam because of his pathological interest in kernel programming. Before joining BetterLinux he received the Laurea degree in Computer Engineering at the University of Siena, on 2004. He also worked as a GNU/Linux engineer in the "Systems and Technology Department" at the CINECA supercomputing center and as an embedded engineer at Develer. He started to learn kernel programming in the spare time, while studying the University of Siena, where he wrote his very first kernel from scratch, called MiniRighi. Then he moved to a real kernel, Linux, focusing on the block IO subsystem, VM, and cgroups / container technologies.