Nov 3, 2015


I was a customer from November 2008 to November 2015. When I joined, they offered great service for the price, but the price is not interesting for at least two years now. Besides some minor technical issues, the company lost a lot when it was sold, maybe more than once. In 2008 there was a good feeling that they cared about me, and that they were always innovating. This has gone for a long time.

I've been avoiding to move to another provider because I was expecting a lot of pain. I don't have anything complex: 7 domains, and about 400 MB of static content. How to choose my next registrar and hosting provider?

Gandi SAS is a sponsor of the Kernel Recipes, a Linux kernel conference that happens every year in Paris. But, besides sponsoring the event, they go to the conference, which offers me the chance to meet people who works for Gandi, and I met them many times there.

About prices, was asking me € 157.54 ($ 172.66) to renew my hosting plan for one year. Gandi charged me € 57,60 for an equivalent plan. Saving € 100 is a nice way of starting the week. However I wasn't expecting to have to pay a to transfer the registrar of my domains to Gandi. The transfer added € 84.84 to the bill, with an average price of € 12.12 / domain. The good news is that the transfer adds one year to the period the domain is already registered which makes it a good deal as I would neet to pay € 13.68 ($ 14.99) per domain per year. So financially I saved € 15.16 immediately and an extra € 95.76 on the first year as my domains are renewed for one extra year.

Also Gandi registrar can handle all kind of top level domains(More than 500 now) while could not even register a .org when I needed one in 2012.

Comparing the interfaces, offers an icon based interface with one button for each action, while Gandi has a more efficient interface that allows you to do the same tasks in less steps.

It took me around 4 hours to have everything up and running at Gandi. Registrar and hosting problem solved until at least 2022.

Gandi efficient interface icon based interface

Mar 3, 2015

Making steam work with Ubuntu 14.04.2 with Kernel 3.16

I have Ubuntu 14.04 LTS for playing Steam. Steam stopped working after upgrading to the 3.16 Kernel with newer X. I've upgraded Ubuntu following:

To make Steam work again, I just:

$ sudo apt-get install --install-recommends
libgl1-mesa-glx-lts-utopic:i386 libegl1-mesa-drivers-lts-utopic:i386

And then rebooted.

Jun 8, 2014

Omron HBF-701 English Manual

I'm learning how my body works in terms of fat and muscle levels. My main tool is a body composition monitor from Omron. I just bought a version that is made for the Japanese market, with no manual available in English. I'm making one, and I'll be glad if you help me. You can fill issues on Github or send me pull requests.

The manual:

Github page:

HBF-701 at Amazon:

Oct 28, 2013

Fedora: Booting Fedora LIVE to RAM

Fedora live images do not include the "Boot to RAM" option any more. This is not a big problem as the scripts needed to boot to RAM are still there.

You just need to add as boot option.

To do that, highlight "Start Fedora Live" using the keyboard keys and press TAB to edit boot command line. Add and press Enter.

Press TAB to edit boot command line



Oct 20, 2013

Fedora: Creating Arch Linux chroot with ssh server

I made a fork of a clone detection tool named CCFinderX. Two days ago I got a message from an user telling that the compilation was not working on Arch Linux. As some Kernel developers, such as Greg KH, has mentioned Arch Linux as being nice, I decided to try it.

I prefer chroots over virtual machines due higher performance, and due the fact that I do not need insulation between my chroots. As for Debian, Fedora provides all tools needed to create chroots for Arch Linux. This is "very" nice, as one can setup the Arch Linux chroot in just a few minutes.

The steps will cover installing Arch Linux tools on Fedora, creating the Arch Linux chroot, and configuring it with a new user and ssh server.

Some data:
Target directory for the chroot: /opt/arch
Package groups to be installed: base base-devel (More groups available here)
User: peter
ssh server port of the chroot: 2227

Note that the text refers to "[fedora] $" and "[arch] $", but this strings will not show up. If you want it is possible to configure bash prompt for showing different strings. Here is guide on how to do it.

Installing Fedora packages:
[fedora] $ sudo yum install arch-install-scripts gpg

Setting up Arch Linux Keys:
[fedora] $ sudo pacman-key --init
[fedora] $ sudo pacman-key --populate archlinux
Create the target directory:
[fedora] $ sudo mkdir /opt/arch

Creating the Arch Linux chroot:
[fedora] $ sudo pacstrap -d -i /opt/arch base

Prepare chroot directory (Hint: Save this to a script, or check my start/stop chroot scripts). Note that lines with -o bind mount the host directory inside the chroot. So if you delete something there, it will affect the host:
[fedora] $ sudo mount /tmp /opt/arch/tmp -o bind
[fedora] $ sudo mount /lib/modules /opt/arch/lib/modules -o bind
[fedora] $ sudo mount proc /opt/arch/proc -t proc -o nosuid,noexec,nodev
[fedora] $ sudo mount sysfs /opt/arch/sys -t sysfs -o nosuid,noexec,nodev
[fedora] $ sudo mount devtmpfs /opt/arch/dev -t devtmpfs -o mode=0755,nosuid
[fedora] $ sudo mount devpts /opt/arch/dev/pts -t devpts -o gid=5,mode=620
[fedora] $ sudo cp -a /etc/resolv.conf /opt/arch/etc/resolv.conf

Entering the chroot:
[fedora] $ sudo chroot /opt/arch su -
[arch] #

Changing root password:
[arch] # passwd

Adding a new user:
[arch] # useradd -m -g users -G wheel,storage,power -s /bin/bash peter
[arch] # passwd peter

Installing base-devel group:
[arch] # pacman -Sy base-devel

Installing openssh tools, configure server port:
[arch] # pacman -Sy openssh
[arch] # vi /etc/ssh/sshd_config
[arch] # cat /etc/ssh/sshd_config |grep 2227
Port 2227

Create ssh keys:
[arch] # /usr/bin/ssh-keygen -A

Start ssh server:
[arch] # /usr/bin/sshd -f /etc/ssh/sshd_config

Exit chroot
[arch] # exit
[fedora] $

ssh to chroot:
[fedora] $ ssh localhost -p 2227
[arch] $

Nice resources:
 - How to install Arch Linux, while keeping it simple
 - Arch Linux Website
 - My start/stop chroot scripts

Aug 17, 2013

Script to add custom display resolution on Linux / X / Gnome

Toshiba R830-10P is a nice notebook as it lightweight, and very powerful, but the Graphics are poor. The integrated LCD has miserable resolution of 1366 x 768, and as it uses Intel HD Graphics 3000 it do not officially support high resolution displays such as 2560 x 1440.

See the problems I've faced to use high-res monitor here.

I made a script to help people with similar problem. If you have a monitor that is not officially supported by your video card, you can try this approach. You need to tune the Hz parameter to find one value that is supported by the hardware, that is comfortable and stable. For comfort the higher the Hz the best.

Please note that there is no warranty that this script works for you, and there is no warranty that this script is safe for your hardware. I'm quite sure that playing with Modelines can burn some old CRT monitors. I've never heard that you can burn LCD / LED monitors, but I'm not sure.

The script is available at:

Jul 24, 2013

New monitor and old notebook

When I arrived at the office today there was a new monitor on my desk. Acer PB278Q 27” 16:9 2560 x 1440 WQHD LED-backlit Monitor. It is very nice monitor.

My notebook uses the second generation Core i7 processor i7-2620M. The embedded Intel HD Graphics 3000 officially has as maximum resolution 1900x1200 for 60 Hz refresh rate.

If using lower refresh rate, it is possible to use higher resolution. One good source of information is the page:

I was not able to use more than 40 Hz as refresh rate when they say 55 Hz worked with Intel HD Graphics 3000. I can set modes up to 44 Hz but then the image is not stable and goes black for one second some times.

What I did:

$ gtf 2560 1440 40

  # 2560x1440 @ 40.00 Hz (GTF) hsync: 58.92 kHz; pclk: 200.80 MHz
  Modeline "2560x1440_40.00"  200.80  2560 2712 2984 3408  1440 1441 1444 1473  -HSync +Vsync


$ xrandr --newmode "2560x1440_40.00"  200.80  2560 2712 2984 3408  1440 1441 1444 1473  -HSync +Vsync

$ xrandr --addmode HDMI3 "2560x1440_40.00"

$ xrandr --output HDMI3 --mode "2560x1440_40.00"

But I would like to increase the refresh rate. Do you have the 55Hz ModeLine for Acer PB278Q?

Also, how can I tell Gnome display settings about the new resolution? See my question here.

See how cool it is! :-)

Jul 23, 2013

CCFinderX, the new CCFinder

Finding code clones is far from trivial. For a nice explanation about the challenges of finding clones in source code, I suggest reading: "Comparison and evaluation of code clone detection techniques and tools: a qualitative approach". You can start by reading sections 2 and 6.

There are at least two tools with source code available under permissive free software licenses. Deckard and CCFinderX. CCFinderX is an evolution of CCFinder, made by the same author.

Deckard is easy to build and test, however CCFinder was not. For Linux users, I made a fork from gpoo/ccfinderx, and made some changes to simplify the build on Linux. The main change is to separate the core from the GUI. I have now two repositories:


Both are clones from gpoo/ccfinderx, but I've spited things. At the moment the GUI do not work but you can build CCFinderX-core without wired OpenJDK dependencies. And it works producing textual output. My goal with this repositories is provide source code that can be compiled, packed, and distributed.

Jun 14, 2013

Creating 32 bits chroot on 64 bits system

I use Fedora 64 bits on my workstation but I need 32 bits chroot of Debian. It is easy to do.

Create the chroot following the instructions from:

The first difference is that you need to add --arch=i386 to the debootstrap command.

Then for entering the chroot add linux32 as the first argument after sudo. Something like:

$ sudo linux32 chroot debian-wheezy

After that even uname -a will show 32 bits instead of 64. The linux32 tool is on the util-linux Fedora package.

Mar 27, 2013

Fedora: Creating Debian chroot with ssh server

I use Fedora on the Desktop but I need to do some development on Debian. chroots gives you no performance overhead, while virtual machines gives you CPU and memory insulation. Also the chroot is only a directory on my development tree.

I'm using Fedora 17 on my workstation and Debian 7 inside the chroot. The debootstrap command will save the files on the directory debian7-chroot/ under the current directory.

1 - Install debootstrap and dpkg on Fedora:
Fedora # yum install debootstrap dpkg

2 - Create the basic Debian:
Fedora # debootstrap wheezy debian7-chroot/

3 - Enter your new Debian:
Fedora # chroot /path/to/destdir

4 - Install additional useful packages:
debian-chroot: # apt-get install locales less vim openssh-server sudo aptitude

5 - Configure openssh server to start server on port 2222:
debian-chroot: # vi /etc/ssh/sshd_config

Port 22

Port 2222

6 - Change root password
debian-chroot: # passwd

7 - Return to your desktop distro:
debian-chroot: # exit

8 - Create start and stop script for your chrooted Debian:
Fedora # cat

umount debian7-chroot/tmp debian7-chroot/proc debian7-chroot/sys debian7-chroot/dev/pts debian7-chroot/dev
umount debian7-chroot/tmp debian7-chroot/proc debian7-chroot/sys debian7-chroot/dev/pts debian7-chroot/dev

mount /tmp debian7-chroot/tmp -o bind
mount proc debian7-chroot/proc -t proc -o nosuid,noexec,nodev
mount sysfs debian7-chroot/sys -t sysfs -o nosuid,noexec,nodev
mount devtmpfs debian7-chroot/dev -t devtmpfs -o mode=0755,nosuid
mount devpts debian7-chroot/dev/pts -t devpts -o gid=5,mode=620

chroot debian7-chroot /etc/init.d/ssh stop
chroot debian7-chroot /etc/init.d/ssh start

Fedora # cat

chroot debian7-chroot /etc/init.d/ssh stop

umount debian7-chroot/tmp debian7-chroot/proc debian7-chroot/sys debian7-chroot/dev/pts debian7-chroot/dev
umount debian7-chroot/tmp debian7-chroot/proc debian7-chroot/sys debian7-chroot/dev/pts debian7-chroot/dev

9 - Start the ssh server inside the Debian chroot:
Fedora # ./

10 - Connect over ssh to Debian chroot:
Fedora # ssh root@localhost -p 2200

Jan 17, 2013

Toshiba R830 and 16GB of RAM

The datasheet of Toshiba R830-10P mentions that the maximum memory capacity is 8GB. See it here.

But Intel says that the i7-2620M supports up to 16GB of RAM. See it here.

I have asked for help on Toshiba Forums. Nothing useful from there. See it here.

I was curious as I have a very particular need for 16GB of RAM. Today I decided to give it a try. I bought two Patriot PSD38G13332S (8GB PC3 - 10600 1333MHz CL9 SoDimm) and installed it on the notebook. It just worked.

Bios screen showing 16384 MB of RAM.

Memtest86+ and some info about performance.

So if you have the need for 16GB of RAM and a similar notebook from Toshiba, you can install 16GB of RAM.

Dec 9, 2012

Coccinellery is a gallery of semantic patches made to inspire users of Coccinelle. Currently the semantic patches comes from patches we have submitted to the Linux Kernel. We are working on improving Coccinellery and your suggestions and contributions are welcome.

"Coccinelle is a program matching and transformation engine which provides the language SmPL (Semantic Patch Language) for specifying desired matches and transformations in C code. Coccinelle was initially targeted towards performing collateral evolutions in Linux. Such evolutions comprise the changes that are needed in client code in response to evolutions in library APIs, and may include modifications such as renaming a function, adding a function argument whose value is somehow context-dependent, and reorganizing a data structure. Beyond collateral evolutions, Coccinelle is successfully used (by us and others) for finding and fixing bugs in systems code."

Nov 4, 2012

Do you want to become a pilot? Read me first.

Fly by wire is a book written by William Langewiesche that has, as a central history, the successful landing of Airbus A320 on the Hudson river on January 15 2009.

But this is only the central history of the book. The author has a very funny way of writing, and shares details about many people involved, like bird strikes specialists, air traffic controllers, Airbus engineers and test pilots. There is a very interesting analysis about impact of Airbus fly by wire system and how turbulent, and boring, can be the career of commercial pilots.

If you are considering becoming a pilot, read this book first. It can direct you to the right kind of pilot, or convince you that there are better ways of living.

Sep 23, 2012

Free Mobile Wifi: FreeWifi_secure on Android

I'm on France and decided to give Free Mobile a try. They offer good pack of service for € 20 / month.


One important feature for me is having Internet at home, and the "Accès FreeWiFi illimité", or unlimited access to FreeWifi was what I was expecting to use at home.

The problem is that I bought my cell phone in Brazil and it was not working with FreeWifi. This is related to how the connection works. See the links:

But you may not need to do anything by hand on your phone. Just try FreeWifiConfig app:

It will automatically configure your phone for connecting on FreeWifi_secure.

1 - Requires Free Mobile GSM chip
2 - May not work with all phones

Sep 13, 2012

Winter of the World is on my Kindle!

Today Amazon sent the Winter of the World by Ken Follett to my Kindle! I think I'll not sleep for some nights. :-D

Aug 5, 2012

Benchmark: SanDisk Cruzer Blade USB Flash Drive 16GB

Both Kingston and SanDisk 16GB pendrive has the same price range. I was curious for comparing them. The overall performance is poor, but is a bit better than Kingston DT101.

Write performance: 4.2 MB/s
ReWrite performance: 3.5 MB/s
Read performance: 24.5 MB/s
Random Seeks: 657.4 / sec

Comparing to Samsung S2 Portable 500GB USB 2.0 External HD:
8.2 times slower for write
4.9 times slower for rewrite
1.8 times slower for reading
5.3 times more seeks / sec

Full performance output:

[root@ace ~]# bonnie++ -n 0 -u 0 -r 7000 -f -b -d /mnt
Using uid:0, gid:0.
Writing intelligently...done
Reading intelligently...done
start 'em...done...done...done...done...done...
Version 1.96 ------Sequential Output------ --Sequential Input- --Random-
Concurrency 1 -Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks--
Machine Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP /sec %CP
ace.home 14G 4265 0      3576 0                            24593 3                         657.4 23
Latency           5727ms     11334ms                         1788ms                          86612us


See: Benchmark: Samsung S2 Portable 500GB USB 2.0 External HD
See more benchmarks:

Aug 4, 2012

Benchmark: Kingston DataTraveler 101 DT101 G2 16GB

I was curious about Kingston USB flash performance. The overall performance is poor.

Write performance: 3.7 MB/s
ReWrite performance: 3.0 MB/s
Read performance: 22.5 MB/s
Random Seeks: 4.3 / sec

Comparing to Samsung S2 Portable 500GB USB 2.0 External HD:
9.4 times slower for write
5.7 times slower for rewrite
2.0 times slower for reading
28.79 times less seeks / sec

Full performance output:

[root@ace ~]# bonnie++ -n 0 -u 0 -r 7000 -f -b -d /mnt
Using uid:0, gid:0.
Writing intelligently...done
Reading intelligently...done
start 'em...done...done...done...done...done...
Version  1.96       ------Sequential Output------ --Sequential Input- --Random-
Concurrency   1     -Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks--
Machine        Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP  /sec %CP
ace.home        14G            3708   0  3063   0           22568   3   4.3   0
Latency                        6309ms   22399ms             11761us   29385ms


See: Benchmark: Samsung S2 Portable 500GB USB 2.0 External HD
See more benchmarks:

Jul 21, 2012

Mounting and converting vdi and qcow2 image files

1. Convert VirtualBox VDI disk file for use with KVM
$ qemu-img convert -O qcow2 diskname.vdi newdiskname.qcow2

2. Mounting raw disk images
losetup /dev/loop0 image.img
# kpartx -a /dev/loop0
# mount /dev/mapper/loop0p1 /mnt/image

3. Mount qcow2 disk images

# modprobe nbd max_part=63
# qemu-nbd -c /dev/nbd0 image.img
# mount /dev/nbd0p1 /mnt/image

Optional: LVM
Scaning for LVM on disk images:

# vgscan
# vgchange -ay VolGroupName
# mount /dev/VolGroupName/LogVolName /mnt/image


# umount /mnt/image
# vgchange -an VolGroupName
# killall qemu-nbd
# kpartx -d /dev/loop0
# losetup -d /dev/loop0


Jun 20, 2012

Caboooo! Cabooooo! Acabooooo!

Assim que fiquei sabendo a última nota que faltava, me lembrei do Galvão bueno comemorando alucinadamente a final da copa de 1994.

Finalmente me formei!

Caboooo! Caboooo! Acabooo!

Jun 9, 2012

Enable power button on minimal install of Fedora 17

After fresh Fedora 17 minimal install, pressing the physical power button has no effect. This is valid for both virtual machines and physical servers. To fix it, just:

# yum install acpid
# reboot

Jun 3, 2012

Communication between two MSP430

I like the LauchPad kit due its price under USD 5. But I also like it due its simplicity.

The Lauchpad kit includes two MSP-430 chips. It is very easy to make the second chip to work with just a few components.

Schematic used for the second MSP430

This schematic is from:

I made two simple programs that communicate with each other. The source code is at:

Lightning fast boot with Fedora17

See Harald Hoyer article: Fedora 17 Boot Optimization (from 15 to 2.5 seconds).

One of the boot steps that consumes about 3 seconds is the decompression and running of initrd. If you do not use LVM, software RAID or partition encryption you may not need initrd.

But Grub2 is configured to always use initrd for booting. If you modify by hand the file /etc/grub2.cfg, it will last until your next Kernel update. To avoid this, I made a grub configuration file that will generate entries without initrd even for new Kernels. Check it out at:

[peter@ace Fedora17-fastboot]$ systemd-analyze
Startup finished in 1433ms (kernel) + 2150ms (userspace) = 3584ms

3.5 seconds is good for me and I still have a fully operational Fedora 17. :-D

May 1, 2012

Nobreak SMS no Linux

O software que a SMS disponibiliza para comunicar com os nobreaks é no mínimo precário. Não é bem acabado e consome uma enormidade de recursos. É difícil de acreditar que eles distribuem um servidor de aplicação apenas para isso. Resolvi fazer o meu software para comunicar com o nobreak. Veja a saída da versão 0.1:

É apenas um executável simples que não precisa de nada complexo. O código fonte está diponível para download em:

Também tem alguns binários em:

Mar 18, 2012

Emdebian Grip 2.0

The Grip flavor of Emdebian project allows to create thinner Debian root file systems. I've created one that includes apt, vim-tiny, net-tools, iputils-ping, and isc-dhcp-client. Later I've added grub and Kernel 2.6.32-5-686. The total size of this Emdebian is about 66MB, which is 3.5 times smaller than the usual 230 MB required for regular Debian root file system.

Want to test it? I've created a 128MB bootable image file for x86 architecture. You will need at least 48MB of RAM to this image work. You can download it here. For testing use USB pen drive and a personal computer that allows booting from USB. The procedure:
1 - After downloading, uncompress using gzip:
# gzip -d peters-emdebian.img.gz

2 - Copy the image do destination pen drive using dd. Be careful to use correct destination as dd will overwrite it. Replace "X" with the correct drive letter. All data on destination storage will be lost.
# dd if=peters-emdebian.img of=/dev/sdX bs=8k

3 - Boot! Using the storage you've created. Don't tell anyone but the root password is: 3dp

You can use $ df -h and $ cat /proc/meminfo to check the resource consumption of this Emdebian install.

Generating the Emdebian root filesystem from a Debian Squeeze box is easy. Making a bootable image require a little bit more work but also works fine. To generate the rootfs, download this file and:
# multistrap -d grip-squeeze -f grip-squeeze.conf

The Emdebian root filesystem will be saved at the folder grip-squeeze.

More at Emdebian Grip web site.

Mar 7, 2012

Performance Overhead and Comparative Performance of 4 Virtualization Solutions

Virtualization is being sold as a solution for data center hardware idleness. Increasing the hardware usage level from less than 20% to more than 70% is possible with virtualization solutions. This may represent advantages like more available computing power and less servers consuming electricity, space and services. But at what cost? What is the price of virtualization solutions in terms of computing power and I/O consumption? What is the overhead of the virtualization layer? 

Sample graph showing read performance for Linux

Feb 4, 2012

GitHub Social Coding

Github is simple to use and powerful git repository with great web interface. If your project is open source, there is no problem if your repository is also open, right? What could be better to open source projects than having free hosting on feature rich and reliable service?

But if you are not the good guy and want to have your git repositories private, looks fair to charge you little money to keep your code safe. 

This looks to be the basic business model do Github and the prices are attractive.

For those have never being in touch with versioning and code repositories, Github is also good place to start. The step-by-step documentation will guide you over the process of using git. It is really easy to start.

Github also encourages you to make friends and to grow your social network around the code you share. I would like to be your friend on GitHub, so you are invited to see my profile:

If you are looking for a job, Github can also help you. You can make your "Job Profile" and select: "Available for hire". The link to your code looks to be that your "open" code repositories are your portfolio.

Jan 31, 2012

C code optimization benchmark

Steve Oualline talks about C code optimization on his book: Practical C Programming. I was curious about the real performance gains. The benchmark test results are at the end of the post.

How can this C code be optimized?

#define X_SIZE 60
#define Y_SIZE 30
int matrix[X_SIZE][Y_SIZE];
void initmatrix(void)
int x,y;
for (x = 0; x < X_SIZE; ++x){
for (y = 0; y < Y_SIZE; ++y){
matrix[x][y] = -1;
void main()
The first suggested optimization is to use the "register" qualifier for the indexes variables x and y:

#define X_SIZE 60
#define Y_SIZE 30
int matrix[X_SIZE][Y_SIZE];
void initmatrix(void)
register int x,y;
for (x = 0; x < X_SIZE; ++x){
for (y = 0; y < Y_SIZE; ++y){
matrix[x][y] = -1;
void main()
 Then the optimization suggestion is to order the for loops so that the innermost for is the most complex:

#define X_SIZE 60
#define Y_SIZE 30
int matrix[X_SIZE][Y_SIZE];
void initmatrix(void)
register int x,y;
for (y = 0; y < Y_SIZE; ++y){
for (x = 0; x < X_SIZE; ++x){
matrix[x][y] = -1;
void main()
The most tricky to understand is changing Y_SIZE from 30 to 32. This will activate one feature of most C compilers that converts multiples by a power of  2 (2, 4, 8, ...) into shifts. This will result in performance gains when the computer is doing pointer arithmetic to access the correspondent memory address of matrix[x][y]. The compiler will change one multiplication operation into one shift operation which is cheaper.
#define X_SIZE 60
#define Y_SIZE 32
int matrix[X_SIZE][Y_SIZE];
void initmatrix(void)
register int x,y;
for (y = 0; y < Y_SIZE; ++y){
for (x = 0; x < X_SIZE; ++x){
matrix[x][y] = -1;
void main()
Reducing the number of loops and taking control of the pointer arithmetic is great performance optimization.

#define X_SIZE 60
#define Y_SIZE 30
int matrix[X_SIZE][Y_SIZE];
void initmatrix(void)
register int index;
register int *matrix_ptr;
matrix_ptr = &matrix[0][0];
for (index = 0; index < X_SIZE * Y_SIZE; ++index){
*matrix_ptr = -1;

void main()
Reducing the number of variables that are necessary to do the pointer arithmetic also improves performance:
#define X_SIZE 60
#define Y_SIZE 32
int matrix[X_SIZE][Y_SIZE];
void initmatrix(void)
register int *matrix_ptr;
for (matrix_ptr = &matrix[0][0];
matrix_ptr <= &matrix[X_SIZE - 1][Y_SIZE - 1];
*matrix_ptr = -1;

void main()
Looks like that there is nothing more to optimize. You can always write some assembly but it may not be good idea. The library function memset() can be used to fill a matrix. "Frequent used library subroutines like memset are often coded into assembly language and may make use of special processor-dependent tricks to do the job faster than could be done in C".
#define X_SIZE 60
#define Y_SIZE 30
int matrix[X_SIZE][Y_SIZE];
void initmatrix(){
memset (matrix, -1, sizeof(matrix));

void main()
There is overhead in function call. It is possible to do better with macros.
#define X_SIZE 60
#define Y_SIZE 30
int matrix[X_SIZE][Y_SIZE];
#define initmatrix() \
memset (matrix, -1, sizeof(matrix));

void main()
The improvements looks good, but how much efficient each optimizations are? I've measured it in clock cycles. And found that the optimization level is processor dependent.

For clock cycles, lower is better.

Results for: Intel(R) Core(TM) i7-2620M CPU @ 2.70GHz

clock cycles times faster
matrix1() 11102.151556 1
matrix2() 6400.36597 1.7346119906
matrix3() 6379.460394 1.740296337
matrix4() 5952.497506 1.8651249404
matrix5() 2154.262528 5.153574094
matrix6() 1907.350431 5.8207193474
matrix7() 792.123493 14.0156827239
matrix8() 780.254779 14.2288799182

Results for: Intel(R) Core(TM)2 Quad CPU    Q8400  @ 2.66GHz

clock cycles times faster
matrix1() 17175.114362 1
matrix2() 8153.467501 2.1064797719
matrix3() 8063.182452 2.1300664427
matrix4() 8497.82453 2.0211189701
matrix5() 4300.083046 3.9941355035
matrix6() 4321.695819 3.9741608575
matrix7() 1569.097383 10.945856228
matrix8() 1560.792718 11.0040969335

Results for: AMD Athlon(tm) 7750 Dual-Core Processor @ 2.7GHz

clock cycles times faster
matrix1() 25319.969906 1
matrix2() 10329.498185 2.4512294259
matrix3() 8558.934585 2.9583086136
matrix4() 9480.851235 2.6706430972
matrix5() 5544.608885 4.5665926003
matrix6() 5577.454075 4.5397002943
matrix7() 643.046753 39.3750062307
matrix8() 631.545791 40.0920570873

So, it is real! For Intel you can get 2 times faster performance by doing simple changes and not using pointer arithmetic. If you do take control of pointer arithmetic and trash some variables, the performance gain can go up to almost 6 times faster. The performance gain can reach 14 times faster by using ultra specialized subroutines. It is much better then I was expecting.

For AMD the use of the specialized functions can result in speedup of more than 40 times.

The clock cycle count is not an integer because the values shown are average mean of 256 measurements.

For the graphs that shows results in clock cycles, lower is better.
C code optimization benchmark: Core i7

C code optimization benchmark: Core 2 Quad

C code optimization benchmark: Athlon X2

rdtscbench was used to do the benchmark testing. The source code is available here. The command line for rdtscbench was: "# ./rdtscbench 256 8". It is also available at:

Jan 23, 2012

How to recompile software with hardware optimization?

This may be useful for compiling local applications that you want to run faster.

Try this on your computer:
$ echo "" | gcc -march=native -v -E - 2>&1 | grep cc1
On my computer it has returned:
 /usr/libexec/gcc/x86_64-redhat-linux/4.6.1/cc1 -E -quiet -v - -march=corei7-avx -mcx16 -msahf -mno-movbe -maes -mpclmul -mpopcnt -mno-abm -mno-lwp -mno-fma -mno-fma4 -mno-xop -mno-bmi -mno-tbm -mavx -msse4.2 -msse4.1 --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=4096 -mtune=corei7-avx
This command probes the local computer for optimization flags. To use it:
$ CFLAGS="[blue string from above]" ./configure
You may consider adding the "-O3" flag. The -O3 flag enables levels 1, 2 and 3 of compile time optimization. There are more information about -O3 on gcc man page. For doing it, instead of previous line, use:
$ CFLAGS="-O3 [blue string from above]" ./configure


Dec 2, 2011

Lego Mindstorm NXT - Programming Options

Option 1: Lego Mindstorms NXT Software version 2.0
The first and the official programming option for the NXT is Lego Mindstorms NXT software version 2.0 that is based on Labview from National Instruments. It is delivered with 8547 LEGO® MINDSTORMS® NXT 2.0.

Mindstorms software is a graphical programming environment. The programming is made connecting bricks and data lines. It is "a great tool" for learning and teaching programming, and it is also fun. It is possible to do non trivial tasks like multi-threading and functions. But for non-small programs it is not practical.

Mindstorms software is used to make programs, to send the compiled programs to the NXT, to remote control the NXT, and to update NXT firmware. Both USB and Bluetooth are supported. I've tested it under Windows but it is also supported under Mac. It does not work under Linux.

See my enhanced color sorter program:
The main program. Note the two threads. The bottom is for the dispenser and color sensor, while the top controls the tray.

Function: tray_next

Function: tray_previous

This robot is running the code shown above.

You can download my program here. You will need Mindstorms software to open the files.

Mindstorms software is the perfect development environment for starting playing with Lego. It is as intuitive as connecting lego bricks and it is also beautiful. But is not practical for non small programs. I would not recommend to implement large software using it. But I would recommend this visual language to introduction to robotics and to programming languages.

There is lots of information about LabView at:

Option 2: RobotC
LabView was successful on allowing me implementing the enhanced color sorter algorithm. But it becomes clear that LabView is not practical for complex and large programs.

I found Robotc and tried it. There is a 30 days trial version that I used for two weeks.

The first step is to upgrade the NXT firmware so it can support Robotc binaries. Do not worry about firmware upgrades. It is easy and safe on the NXT. You can always upgrade the firmware to the Lego Offical Firmware using the LabView.

RobotC offers complete development environment with functions similar to the LabView. But instead of connecting bricks and data lines you write C programs.

I found some limitations when I was using more than one thread simultaneously. I'm quite sure that those limitations are not insurmountable, but I did not like RobotC. For the basics there are good documentation and tutorials but I did not find free detailed information.

Like labview, RobotC works on Windows and does not works on Linux.

See RobotC web site.

Option 3: NXC

"Not eXactly C (NXC) is a high level language, similar to C, built on top of the NBC compiler. It can also be used to program the NXT brick. NXC is basically NQC for the NXT. To compile NXC programs just use the NBC compiler with source code files that have a .nxc file extension. A reference guide for NXC is available. You can also access online API help for NXC or download a compiled HTML help file. To take advantage of multi-dimensional array support and native shift operations be sure to download the enhanced NBC/NXC firmware and install it on your NXT."

I liked NXC. "To me", it feels more like C gcc than RobotC and it works on Linux. If you are Windows user, you should try Bricx Command Center that uses NXC/NQC, but if you are Linux user, NXC is great option. I'm using two tools that are official Fedora 15 packages: NQC and NXTRC. NQC is the compiler for the NXC while NXTRC is a tool for remote controlling the NXT and to send files to the Brick using bluetooth. I'm using the following packages:




Installing both on Fedora 15 is as hard as:
# yum install nxtrc nbc

To compile the color sorter on Fedora 15:
$  nbc dispenser4.nxc -O=dispenser4.rxe -sm-

Then, to send it to the NXT using bluetooth:
$ nxtrc -a 00:16:53:13:9A:70 -W dispenser4.rxe

The documentation for NXT is complete and freely available. Also, working on Linux is also very good to me. The binaries made by NXT works on Offical Lego Firmware but you can update to a firmware that is announced to offer better performance. I did not tried the high performance firmware yet.

The source code of the color sorter can be downloaded from: dispenser4.nxc

There is more information about NXC here.

I would start with LabView for initial fun and learning about sensors and motors, then switch to NXC for the complex tasks.
RobotC may have better processing performance and also richer debugging than Bricx Command Center. But for now, processing performance and richer debugging interface are not features that I'm looking for. If you need processing speed and/or rich debugging interface, give RobotC a try.

Dec 1, 2011

Lego Mindstorm NXT - Open Source Rules

The bad news: My NXT brick was not working properly when I took it from the box. The sensor port 2 was not working. I do not think that there is warranty coverage for Lego Mindstorms in Brazil. I had no better option than try to fix it.

The good news: Lego delivers all information about the NXT electronics and its embedded software. It is a true open source platform.

I've downloaded the schematics from:

And I've noticed a missing component near the port 2. R59 was not there. For lucky it is a common 1k resistor. Thanks to my father's SMD lab, we were able to solder a new resistor, and push hot air over port 2 components. After that port 2 started to work.

I'm deeply happy with Lego's open source policy for this product. I was wondering how happy I'll be when my car becomes open source. Lego gave us the power to fix the problem without any limitation. It is clear to me now that open source is great for hardware too. Is there open source tendencies for industry?

R59 was not there when I've opened my NXT for the first time. The schematics is from Lego web site.

What kind of information is freely and officially available about the Lego NXT:
- NXT Brick hardware schematics
- Sensors schematics
- I2C Communication protocol used for sensors
- Bluetooth interface specification
- Hardware Developer Kit
- Executable File Specification
- Mobile Application Software
- Mobile Application Documentation
- Open Source Firmware


Lego has supported the development of a remote control to the NXT that runs on Android. The source code is released under GPL3.

About my non-working brick, I'm quite sure that this kind of problem happens very few times. Lego Mindstorms NXT 2.0 is clearly a high quality product. I believe that I'm the only in many many many owners who had this kind of trouble. And I admit: It was fun to fix it! :-D

Lego Mindstorm NXT

Want to have some fun with Robotics? 8547 LEGO® MINDSTORMS® NXT 2.0 is the right kit for you!

Color Sorter with a bit more complex algorithm

 To me Lego Mindstorms NXT is a dream come true. Why? Robotics! Robotics! Robotics!

What's inside the box?
- The NXT programmable Brick with Bluetooth, USB, 7 I/O ports for sensors and motors, speaker, buttons, and LCD display.
- 4 Sensors: Ultrasonic, light and color, 2 touch sensors
- Some cables
- 600+ pieces for assembling machines animals and humanoids.
- Software for Windows and Mac for programming the NXT.

Nov 7, 2011

iSCSI and LVM: Boot problem

Both LVM and iSCSI are powerful and reliable. But there is an issue with the combination of both that made me fell completely lost more than once.

The Scenario:
iSCSI target / server is a Linux Box with LVM features
iSCSI target / server exports disk, partition or LVM LV
iSCSI initiator / client uses the exported volume as LVM PV
All works perfectly until rebooting the iSCSI target / server

The symptom:
After rebooting the iSCSI target / server, it becomes impossible for the initiator / client use the exported volume as if it were deleted. The iSCSI target / server service itself is working properly but the exported volume is not.

The cause:
During the boot of the iSCSI target / server, its LVM liked the new found PVs / VGs / LVs. The iSCSI target / server has no idea about those new found are not for the local machine and it "locks" the VGs and LVs for local use. When iSCSI exports the LV, it will contain locked LVM volumes. This is why it becomes impossible to use it on the iSCSI initiator / client.

The solution:
It is very easy. Edit /etc/lvm/lvm.conf and use "filters" to tell LVM what is not for local use. My filter is configured as:

filter = [ "a/sda/", "r/.*/" ]

For testing, just type pvscan after editing the file to see if the filter worked as expected. If so, just reboot and it will work.

Please note that using sda on the filter is not the safest solution as it is not impossible that sda becomes sdb for example. It will be safer to use UUIDs of something else.

Nov 3, 2011

Acer Iconia Tab W501P Review II

Fedora 16 Beta

Feroda 16 Beta runs on the W501P without any major concern. The only issue I found is the Gnome onscreen keyboard that does not work well. Despite the onscreen keyboard, I did not found any serious issue when using Fedora on Iconia Tab W501P.

I did no testing with ATI proprietary drivers on Fedora.

Ubuntu 11.10

Ubuntu 11.10 also runs on the W501P but there are some details:
1 - When I allowed the installer to download updates during installation, the X did not work very well after first boot. So I installed it again and it is working pretty well without allowing the packages to be updated. I'll wait untill ATI driver supports the C-60 GPU until allowing updates.

2 - The ATI proprietary driver does NOT work with C-60 GPU. I've tried Ubuntu's two packages, "AMD Catalyst™ 11.9 Proprietary Linux x86 Display Driver", and "AMD Catalyst™ 11.10 Proprietary Linux x86 Display Driver". When using Ubuntu's package, an stamp with AMD logo appears on the right bottom corner saying: "Unsupported Hardware". I would not recommend to try those drivers with Ubuntu 11.10. It may be necessary to re-install your Ubuntu.

After learning about updates and ATI proprietary driver, I'm happy with Ubuntu on W501p. I'm curious about the performance gain by using the proprietary graphics driver. Will it be possible to play HD flash movies on full screen?

The battery

I was curious about the sleep state power consumption. I've charged the battery, and asked Ubuntu to sleep the tablet. I removed the charged cord and waited exactly 12 hours. How many % of the battery power were consumed in 12 hours?

The result is that after 12 hours of sleep state the battery charge was informed to be 92% by Ubuntu. 8% every 12 hours means 16% every 24 hours. Looks like that the Iconia Tab W501P can stay sleeping for more than 6 days. This is good!

Not tested yet battery life for usage. I think that this will be improved when the proprietary graphics driver is available.

Battery charge after 12 hours of sleeping

Nov 2, 2011

Recording from webcam, saving to file, displaying locally, using VLC, under Linux

# Change /dev/video1 to your webcam device name
# Change plughw:1,0 to your audio capture device. (Check /proc/asound/devices)
# Change 1920 to the correct width of your webcam ( Check Cheese preferences )
# Change 1080 to the correct height of your webcam ( Check Cheese preferences )

$ vlc v4l2:///dev/video1 :input-slave=alsa://plughw:1,0 :v4l2-standard=0 :v4l2-aspect-ratio=16\:9 :v4l2-width=1920 :v4l2-height=1080 :v4l2-fps=30 :sout="#transcode{vcodec=mp4v,vb=5000,scale=1,fps=30,acodec=mpga,ab=128,channels=1,samplerate=44100}:duplicate{dst=std{access=file,mux=ts,dst=/tmp/video-output.mpg},dst=display}"

Oct 29, 2011

Acer Iconia Tab W501P Review

Model Acer Iconia Tab W501P C62GO3iss
P/N: LE.L0603.038
Model: EAB00
OS: Windows 7® Professional 32-bit
Processor: AMD Dual-Core C-60
LCD: 10.1" Multi-touch HD LED LCD
Memory: 2GB Memory
Storage: 32GB SSD
Card Reader: 2-in-1 card reader
WLAN: 802.11 b/g/n & BT 3.0 + HS
Webcam: 1.3 Megapixel
Battery: 3-cell Li-ion battery
Software: Microsoft Office 2010 preloaded (purchase a license key to activate)
Microsoft Office Starter 2010

I was tremendously curious about the performance of both AMD C-60 processor and it's ATI GPU. I was expecting that it would be possible to play Full-HD flash movies at 30 fps. I'm at Czech Republic, and I ran to the first Acer Iconia TAB W501P that was available at The main differences to W500 is that the W501P has 3G modem and is equipped with AMD C-60 instead of AMD C-50. According to, the C-60 can run up to 1333 MHz and it's GPU can run up to 400 MHz, while C-50 maximums are 1000MHz for the CPU and 276 MHz for the GPU.

First impression
As the box reached me, I realized that it is "too" heavy. The box itself is heavy, as the tablet and it's keyboard are very well packed but "light weight" is not a feature for the W501P.

The first boot
Even being a Linux guy, I do not hate Windows. I think that Microsoft does good software, with bad business model, but good software. Windows 7 is not bad software. But the ton of crap that came pre-installed with the tablet is not good. It took 40 minutes installing toolbars and other useless software.  After installing all the crap, Windows 7 were so slow that I felt I that I shouldn't have bought the tablet.

But I noticed that the screen and it's touch sensor are great. It has resolution of 1280x800 with great colors and bright. The touch precision is also great. It just works without needing calibrate anything. Image quality and touchscreen precision are qualities of this tablet. Fullscreen play of Full-HD youtube videos did not went as I was expecting. The frame rate is perfect for resolutions up to 480p. Above 480p it is not perfect any more.

It works on Fedora 16 Beta. 3G modem, wired and wireless devices, single touch screen, two web cams, sleep state, and speed step. Rotation sensor, bluetooth and muti-touch did not work out of the box. I'll check what can be done.

After tuning the Kernel to use noop scheduler for the SSD the overall performance is not bad. It is light year ahead of 2008 Aspire One with single core Atom. I would not use the tablet for compiling Kernels, but it fits for reading, writing and surfing. Comparing the Iconia tab W501P with Toshiba R830 Core i7 notebook is not fair. But the fast graphics of the tablet really helps on giving the "sensation" of high speed. The user interface is almost as fast as on Core i7 but tasks like starting Libreoffice are much, much slower.

I was surprised that Fedora 16 comes with on-screen keyboard that shows up only when typing is needed. Almost like it is on Android. The software keyboard itself is very immature and many times it does not appear when it is necessary. I'll try with Ubuntu.

I'm happy with Linux on Iconia Tab W501P.

The docking
It could be thinner and lighter but it is ok. The keys are delicious to press and are not noisy. The stick mouse is fun but sometimes it is easier to touch the screen. Having Ethernet connection is very good. The docking fits the tablet, looking like a closed notebook. It is practical for transporting.

The battery
I had no time for testing it, but I do not believe that it would reach 4 hours of non intensive use. I'm curious about sleep state power consumption.

Next comments
I'll write again when I have more experience with it. I used the tablet for one day only. I'm really not sure about how can a tablet help me. I'll figure it out, or not, soon. :-)

Toshiba R830-10P and Acer Iconia Tab W501P

On the docking station - Front

On the docking station - Back

Off the docking station - Front

Docking and tablet closed as notebook

Jul 15, 2011

Samsung Galaxy S GT-I9000B Firmware upgrade

Finally Kies gave me the option to update my phone to Android 2.3.3. :-)

Jul 2, 2011

System Monitor applet and other Gnome3 tips

Gnome3 is revolutionary. But to enjoy its benefits, I had to exercise my zen side and let many old habits behind. I decided to give it a try. I'm liking it.

But even liking Gnome3, I was missing System-Monitor applet. But now I have it. :-)

I followed Matthew Casperson's post and added just some little steps:

After following the steps described on Matthew Casperson's post:

$ mkdir ~/bin
$ cd ~/bin
$ ln -s ~/git_projects/gnome-shell-system-monitor-applet/ system-monitor-applet-config

Those steps will enable you to call "Preferences" on the applet icon.

I would also recommend reading other Matthew Casperson's post: Gnome 3 Tips and Tricks