Archive for May, 2008

I’ve spent more or less the last few days of spare time trying to figure out why gcc-4.3 built kernels were so unhappy on parisc. Basically the symptom was that any IPv4 networking operation would only complete once and a while, for example, ping would drop 90% of packets. This turned out to be a really troublesome bug to track down, and the fix was only 7 characters long.

gcc-4.2 wasn’t problematic, so that provided an interesting base. A bit of thinking ruled out some obvious parts of the kernel that would likely not be an issue. For instance, ARP appeared to be fine, so it likely wasn’t an issue at the network driver level. So rebuilding net/built-in.o on gcc-4.2, copying it to the gcc-4.3 tree, and rebuilding the tree using it resulted in a working kernel. Ok, excellent, we know it’s likely an issue in net/, what else can we rule out, and what do we know? ICMP is affected, so it’s probably not a TCP problem… Rebuilding the kernel with IPv6 enabled, and testing ping6? Ok, works. So it looks like an IPv4 issue. Test that assertion… yup, net/ipv4/built-in.o compiled with gcc-4.2 works.

Ok, peachy. What now? Bisecting the contents of the directory results in ip_output.c being the problematic file… Not all that helpfully, the differences between the code generated by 4.2 and 4.3 are extensive. Well, ok, let’s try turning off a variety of the added compiler options… nope, no luck, but the file works when compiled at -O0.

Next, I bisected the file until I found the problematic function (unfortunately for me starting in the middle, it ended up being the first function in the file.) Which was in a chain of inline functions, eventually calling some architecture specific inline assembly for ip_fast_csum. Ok, that looks like our canary in the coal mine… Look it up… SIGH. The routine touches memory, but didn’t have “memory” in the list of clobbers.

Adding the clobber and everything magically works again. Wasn’t that a party?

[ Of course, this makes things sound almost easy, except that at around 10 minutes to boot a test kernel, reboot, and boot a working kernel, this gets extremely tedious. I also didn't bother to talk about how many hours I probably wasted twiddling compiler flags trying to figure out which optimization pass might be broken... ]

This has probably been dugg before, but I've made a few unique observations in my article that I haven't seen anywhere else (namely the orangebox ps3 port).Enjoy. :)
You may remember the Elephants Dream, the open short movie. It was developed as project Orange at the Happy Blender Institute. Now, a new team working on project Peach at the Blender Institute has published their work: an open short movie Big Buck Bunny.

At LGM, I had the pleasure of watching this great movie on a big movie theatre screen.

Elephants Dream was a technical masterpiece, showing the quality of graphics that can be accomplished with open source programs, it was somewhat lacking in the area of storytelling. While I'm guessing this dreamlike drifting to different directions was intentional at least to some degree, it just felt somehow odd to me. Maybe I just don't understand the fine art ;)

Things look quite different in Big Buck Bunny. It's still a technical masterpiece, actually they've bumped the graphics quality up a notch or two with fur, grass and all such natural phenomena. But the bigger difference is in storytelling. This movie tells a simple story in easy to follow manner, with loads of humour. Some might think that it underestimates the mental capacity of viewers, but I digress. It's nice entertainment.

Other interesting thing from Blender Institute is the project Apricot, which is creating an open source game using Blender, CrystalSpace and several other related tools. I've tried the released versions of these tools, and from what I saw at LGM, this project has made huge improvements to them. Already with the release versions, you can edit stuff like models, textures and actions between the player and scenery in Blender and export all that to the game engine. With the development version project Apricot has, it's possible to actually have the game engine running in a blender window while you can edit game data in other windows.

In the Java API there are a number of APIs that rely on being able to walk up the call stack to determine certain properties of the immediate caller of the API. The most common scenario is determining the caller's class or class loader. This information is used to implement security checks or to use the right class loader.

Up until now IKVM used the System.Diagnostics.StackFrame .NET API to walk the stack. There are however two major issues with this API. The first issue is that it is unreliable and IKVM jumps through various hoops to make sure that the CLR doesn't inline methods it shouldn't inline or use tail call optimizations it shouldn't use. The second issue is that it is relatively slow.

I finally got around to implementing an alternative scheme that eliminates the usage of System.Diagnostics.StackFrame in most cases. In part 2 I'll describe the implementation, but for now let's just look at some performance numbers.

I've cooked up two microbenchmarks that clearly demonstrate the difference between the current approach and the new approach.

Class.forName()

In this microbenchmark we look at the Class.forName() API. It walks the call stack to determine the class loader of the immediate caller, because that is the class loader that it needs to use to load the class.

class ForName {
public static void main(String[] args) throwsException {
Class.forName("java.lang.Object");
long start = System.currentTimeMillis();
for (int i = 0; i < 100000; i++)
Class.forName("java.lang.Object");
long end = System.currentTimeMillis();
System.out.println(end - start);
}
}

ForName results:

x86 x64
IKVM 0.37.3063 4350 3959
IKVM 0.37.3073 45 49
JDK 1.6 138 97


(The difference between JDK 1.6 x86 and x64 is mostly due to x86 defaulting to HotSpot Client and x64 to HotSpot Server.)

Method.invoke()

The Method.invoke() API uses the caller class to perform the required access checks when you are calling a non-public method or a method in non-public class.

class Invoke {
public static void main(String[] args) throwsException {
java.lang.reflect.Method m = Invoke.class.getDeclaredMethod("foo");
long start = System.currentTimeMillis();
for (int i = 0; i < 100000; i++)
m.invoke(null);
long end = System.currentTimeMillis();
System.out.println(end - start);
}

private static void foo() { }
}

Invoke results:

x86 x64
IKVM 0.37.3063 6083 5572
IKVM 0.37.3073 14 16
JDK 1.6 82 39

To be continued in part 2...

Matthew Garrett

| May 31st, 2008
In other news, I am now in London and will be having a housewarming next Saturday (the 7th). whois will give you the address. Nearby stations include Battersea Park and Queenstown Road. Nearest tube is probably Clapham Common. 137, 156 and 452 buses stop at Priory Road, less than 5 minutes away. A bunch more stop at Wandsworth Road station, which is also a fairly short walk. It'll be an all day affair, so feel free to drop in at any time of the day assuming you don't fall into one of these categories:
  • I have expressed a deep and abiding hope that you die in a freak accident in the near future
  • I have threatened to stab you to death and you suspect I wasn't joking
  • You have OMG A GURLed in a sincere manner within the past 18 months
  • I hate you
  • I have absolutely no idea who you are and so am unable to determine whether or not I hate you in advance
Bring food/booze/entertaining people.

In shaving, nothing quite beats the feeling of having a fresh blade glide over your face.

I keep forgetting this as I blunt my blade through the weeks, and then I get surprised all over again when I change.

One of the downsides of writing my thesis last year was that focusing on a technical subject for approximately 16 hours a day left me almost entirely unable to relate to people. The irony in this is that losing the ability to socially relate tends to result in you assuming that you're fine and everyone else is just behaving bizarrely, which makes rectifying the situation rather difficult. In an attempt to avoid this I have written some software, because dealing with the symptoms of a problem is always better than dealing with the root cause and technology is always the appropriate solution to social issues.

The aim was to send myself an email once a week that I'd actually have to read. This is achieved by running the script with the generate argument. This sends an email with an appropriate reminder message (something along the lines of "Are you sucking? Really? Are you sure? Is everyone around you suddenly getting annoyed at you for no obvious reason?", and so on) and a bunch of embedded characters randomly spread throughout it. Running the script with the check argument will send the email again if a valid response hasn't been received. Those can be stuck in cron. The final part is to add a procmail or whatever rule that passes replies back to the script with the validate argument. These replies should include a line containing all the embedded characters (order doesn't matter, but if there are multiple occurances of a character than the reply must include that number of occurances). If a valid reply is received then no further emails will be sent until the script is run with the generate argument again.

Also: My perl sucks.
We went for a little afternoon walk at RSA yesterday. I was out of the car and waiting for Dave when I saw motion out of the corner of my eye and heard a thump! of something hitting the ground a few feet away. Maybe something fell out of that tree? It sounded like it fell right ... there ... what's that? It looks almost like ... a bird? But why would a bird fall out of a tree? Is it dead?

And then the bird came to life, stretched its wings, and turned into a kestrel that exploded off the ground and flew away. I never did see if it caught whatever it was after, but I'm happy to have had the chance to see the little falcon make a strike so close to me.

Later, on the trail, a spotted towhee burst out of a tree and flew past us. Then a small woodpecker emerged from the same cluster of branches the towhee had just left. As we drew nearer we could hear quite a commotion up in the branches ... a dozen or more small birds, mostly chickadees, chattering and darting in and out like bees around a hive. It seemed centered on ... that unmoving spot there ... wait, doesn't it look a bit owl-shaped to you?

I snapped a few pictures, but none of the small owls in the bird guides have a facial pattern like this. It was smaller than a screech owl, but young screech owl is still my best guess.

And as long as I'm posting nature pictures, the bullfrogs are back at the Walden West Scum Lake. Just floatin' there, though ... they weren't making any noise or moving around.

Wine 1.0 RC3 Released

| May 31st, 2008
This is release 1.0-rc3 of Wine, a free implementation of Windows on Unix.

Gibberish Or HTML Art?

| May 30th, 2008
I can't decide!