My personal blog

Tag Archives for Embedded

This is a continuation of my previous post. Based on the feedback I decided to do two things; investigate the strange FLAC high CPU usage with FFmpeg, and get more accurate measurements.

GStreamer sucks

It turns out that GStreamer flac parser uses four times more CPU than FFmpeg’s decoder. Thanks to perf, I was able to quickly figure out the biggest offenders: GStreamer’s horrible bitstream reader (GST_BIT_READER_READ_BITS) was by far the worst.

This is on my laptop just running the parser (filesrc ! flacparse ! fakesink), in total it was taking 2.67s.

After reading the code and trying different things, I decided to go for something similar to what FFmpeg is doing, and I also borrowed pieces of the architecture-specific optimizations, now it even looks ok:

Smart battery script

I tried different ideas, and after refreshing myself on statistics I wrote this script in Ruby that runs all the tests, gathers the battery capacity in a separate thread, and finally generates a report per test. Much easier than before.

But how credible are these results? Well, judge by yourself, listed below are the raw measurements, the samples are the differences in capacity (mAh) measured each 10 minutes, from which the drain and battery life are calculated.

I’ve tried many different cross-compilation methods and so far scratchbox is the simplest and most effective. Here I’ll try to introduce the benefits of using it, and how to get started as simply as possible.

Intro

If you are not familiar with scratchbox; it’s a cross-compilation toolkit which allows you to use native tools (gcc, binutils, perl) when possible and emulate the target through qemu when needed.

It’s needed because of autotools; have you seen these checks?checking whether the C compiler works... yes

The configure script actually compiles a small program and then runs it to validate it’s working, and sometimes extract information, such a the size of certain structures which might be different depending on the platform. If you tell ‘configure’ that you are cross-compiling it will go through a different path (which is much less tested) and ultimately will end up with wrong information that you need to correct.

OpenEmbedded and other distributions go through each and every package, make sure cross-compilation works, sometimes patching configure.ac, and often providing some information that normally would be obtained by running some test program.

This is an example of a typical GLib cross-compilation./configure ---host=arm-linux --build=i386-linux

Welcome to Scratchbox, the cross-compilation toolkit!
Use 'sb-menu' to change your compilation target.
See /scratchbox/doc/ for documentation.
[sbox-armv7: ~] >

Now if you want to cross-compile GLib, you do it as in your PC:./configure && make install

Much easier, now scratchbox does all the magic 😉

Scratchbox 2

Scratchbox 1 serves it's purpose, but there are many corner-cases where things get overly complicated so people came up with a much more elegant approach: Scratchbox 2.

In sb1 you need to login to a target (e.g. armv7, armv6, fremantle, diablo, etc.) in order to do anything, you can use only one target at a time, and each target is independent, in order to share tools between targets you need a devkit. Also, toolchains must be packaged in a special way.

In sb2, you don't login, you can setup any toolchain easily, you can use multiple targets at the same time, and you can configure it to do pretty much anything you want.

QEMU

sb2 doesn't include QEMU, you must have it already, this is how I compile it:git clone git://git.savannah.nongnu.org/qemu.git
cd qemu
git checkout -b stable v0.10.5
./configure --prefix=/opt/qemu --target-list=arm-linux-user
make install

sbox2

target

Now it's time to configure a target, I have a CodeSourcery toolchain installed on /opt/arm-2008q3, so:cd /opt/arm-2008q3/arm-none-linux-gnueabi/libc/
sb2-init -c /opt/qemu/bin/qemu-arm armv7 /opt/arm-2008q3/bin/arm-none-linux-gnueabi-gcc

You don't need to log-in, just prefix your commands with sb2 to do the magic:sb2 ./configure --prefix=/opt/arm/

If you want to use a different target just use the -t option:sb2 -t armv8 ./configure --prefix=/opt/arm/

It looks like it has a lot of potential. They have just launched and they already have a very extensible platform, way beyond what we have in Maemo, and even in GNOME or any Linux DE. I give it a month before we have unbelievably-crazy, original and useful killer-applications.

I like to develop in Linux, with vim, in C or in Ruby, so I’m not so excited about their Eclipse based SDK, but I guess it makes it easier for a lot of people. I like Java, but I like to write stuff without any fancy IDE. Anyhow $25,000 looks like a pretty good motivation to try installing it 🙂