AVR32 Arbitrary Width Fonts

I made some changes to the et024006dhu.c file today, to allow arbitrary sized fonts. The original driver in the Atmel Software Framework was not able to cleanly draw arbitrary sized fonts as it makes the assumption that there are only 8 columns in the font.

Edit the ASF file located in:
avr32/components/display/et024006dhu/et024006dhu.c

You need to change the two loops in the et024006_PrintString() function:

for (row = y; row < (y + yfont); row++)
{
mask = 0x80;
for (col = x; col < (x + xfont); col++)
{
if (*data & mask) // if pixel data then put dot
{
et024006_DrawQuickPixel( col, row, fcolor );
}
mask >>= 1;
}
// Next row data
data++;
}

Add in the couple of lines like this:

for (row = y; row < (y + yfont); row++)
{
mask = 0x80;
for (col = x; col < (x + xfont); col++)
{
if (mask == 0) { mask = 0x80; data++; }
if (*data & mask) // if pixel data then put dot
{
et024006_DrawQuickPixel( col, row, fcolor );
}
mask >>= 1;
}
// Next row data
data++;
}

That’s it. This will allow the function to be used to print any arbitrary sized fonts as long as the custom font header is configured correctly.

IE8 Development on Linux

As an open-source advocate and Linux developer, I sometimes face the problem on creating websites that do not work correctly in IE because it is a borked browser. While IE is fast losing its market share to other browsers, it is still the dominant PC desktop browser and needs to be supported by any web applications that I develop.

To that end, I need to make sure that my code works on IE and these are the two steps that I recommend.

Firstly, use the X-UA-Compatible meta tag to ensure that IE works in a more standards compliant mode. This meta tag can be set either by the web-server or it can be set in the HTML header section itself. It is simple, just stick the following code in the header section of any HTML page:

<meta http-equiv="X-UA-Compatible" content="IE=8">

There are a number of parameters that are possible and these are described in the appropriate knowledge base page. The important thing is to ensure that your site adheres to web standards and to set the compatibility mode to IE8, which is the most standards compliant IE browser at the moment.

The next gem that I recently discovered is the availability of IE8 testing images from Microsoft. Turns out that Microsoft provides VPC images that can be used to run special VMs that can be used to test websites under IE8 rendering. Since I do not use VPC, I had to tweak things a little and run things under VirtualBox instead.

Even then, there are a couple of gotchas to note:

First, it is essential that the network drivers be installed when the VM is first booted. This is to allow the VM to activate itself online. Otherwise, on a second bootup, the VM will not allow the user to login because it is not activated, and will not be able to activate itself because it is not online – an infinite loop.

To do this, once the VirtualBox machine is booted and the Guest Additions disc is inserted, run the following command:

D:\VBoxWindowsAdditions-x86.exe /extract /D=C:\Drivers

Immediately after that, use the Windows Add/Remove Hardware wizard to detect the new network card and specify the drivers manually. They will reside in the earlier subdirectory. Once this is done, bridge the VMs network to your existing Internet network and ensure that the network settings are all working. Launch an instance of IE8 to see if the site works correctly.

Then, after a reboot, the VM will insist on activating itself online. If the network was working correctly earlier, just proceed with the activation. It works after that like any normal Windows except that it will display an “evaluation” notice on the desktop.

This is a good solution to work with IE8 development on Linux.

Instruction vs Data

A software programme is made up of a bunch of things but the main ones are: instruction and data. Instructions tell the programme what to do and is usually stored in the .text portion of the binary. Data is what the programme works on and mainly consists of the heap and stack stored in different parts of the memory.

So, with all else being equal, what is the difference between these two parts of an application and should a programmer care?

Knuth claims that it is important to select an appropriate data structure for a programme and that the selection of the right data structure can make or break an application – or something to that affect. Therefore, it is obvious that the data portion of a programme is a very important consideration. However, the trick is to have a data structure that is small and fast for two reasons.

Firstly, small data structures can be held in cache memory, speeding up processing time by reducing the number of reads and writes between the processor and memory. Anyone who cares about writing good software should already know about this trade-off. So, this should not surprise most people. Unless there is good reason to use a large dynamic data structure, a small static one may produce better performance.

Secondly, small data structures use less memory. Instructions rarely change and can actually be stored in fixed memory on a chip such as flash memory or ROM. In the case of programmes actually embedded into on-chip hardware, it is very important to minimise the use of RAM and to maximise the use of ROM for one reason – cost. It costs six-times as much per bit of RAM than ROM on a chip. It’s because SRAM contains six times as many transistors per bit.

So, for code that is embedded on-chip, it is particularly important to write code that uses less RAM and uses more ROM. So, static look-up-tables in ROM is good, while dynamic pointer linked structures in RAM is not so good.

Vanishing Varnish

I was recently saddled with a bunch of cryptic Varnish errors. For some reason, the varnish daemon just kept dying on me. I have previously used varnish in many places and I have never had to face such problems before. Varnish would actually start up and die about 5 seconds later, as shown in the log message below, which was very weird.


Jun 17 15:39:11 earth varnishd[2771]: child (2772) Started
Jun 17 15:39:16 earth varnishd[2771]: Pushing vcls failed: CLI communication error

The first thing I did was to start varnish on the command line using a -d -d parameter, which started varnish in debug mode. Everything worked normally in debug mode and nothing was amiss. So, it really vexed me for a while, not able to figure out why my cache was dying mysteriously.

Then, after lots of digging, turns out that on slower machines, varnish can kill the processes due to heavy load or timeout.

So, I had to add a startup parameter to the configuration file: cli_timeout.


DAEMON_OPTS="-a :8080 \
-T localhost:6082 \
-b localhost:80 \
-u varnish -g varnish \
-p cli_timeout=10 \
-s file,/var/lib/varnish/$INSTANCE/varnish_storage.bin,1G"

That fixed it! It seems that the default timeout was 3 seconds and it took about 7 seconds to start up Varnish and it would saturate the 100% of my processor. So, increasing the timeout to 10 seconds did the trick. I think that I would probably need to increase the number of VCPUs tied to this VM as well to cope with the increased load.

Prefork vs Worker

Apache2 comes with several threading/process models to handle requests. The traditional method is maintained as prefork while the newer method is worker. The main difference is that the former relies on forking processes while the latter method uses multiple threads. The result is that worker is faster than prefork under load.

I tested this by setting up two servers, one with prefork and the other with worker. I used Apache Bench to hit both systems. At low concurrency of around 200 connections, both of them worked equally as well because in both cases, the main bottleneck was CPU. After I increased the CPU from single to six-cores, the load was handled equally well until I upped the ante to 500 concurrent connections.

At this point, the worker model would still run fine while the prefork model would start to fail periodically. It is like it has trouble handling the sudden spike. Once it has been hit a few times, it will also be able to handle the load but ramping up is less graceful. This is pretty obvious once you think about it a bit and preforking processes will have a larger overhead than spawning threads.

The only advantage of using preforking is when handling non-thread safe code. However, since my Apache serves only as a reverse proxy front-end, it does not need to handle any non-thread safe scripts. These are all handled at the back-end by other servers. So, there is really no necessity for the prefork model on my setup.