SMP and too Optimistic Compiler Optimization

In a nowadays common SMP/CMP environment with more then one CPU it is necessary to protect global/shared data in the kernel. One prominent example are sysctl_ variables. Sysctl variables are protected via a spin lock (sysctl_lock). This look protect the /proc/sysctl interface path, the look itself does not protect the usage path itself. Consider the following example: int global\_val; int foo(void) { if (global\_val != 0) { int res = bar(); return res / global\_val; } return -1; } Here global_val is a global accessible variable....

December 7, 2010 · 2 min · Hagen Paul Pfeifer

Hoist Function Subexpression Elimination

Function calls embedded in loop constructs are a area of optimization. As a general statement: it is clever to hoist any method calls from loop statments like for, while and the like where the result is constant (eliminating redundant computation is a standard optimization mechanism). For example, often you will see constructs like for (i = 0; i < strlen(str); i++) { whatever }. strlen() is evaluated every time, although str does never change....

December 5, 2010 · 2 min · Hagen Paul Pfeifer

Jump Table Optimization For If Else Constructs

This blog post is not about micro-optimization nor about what you have to use. Neither, it is about how compilers can optimize two common flow constructs. The knowledge may provide enough background information to sharpen the view and provides enough insights what construct to use for which usage. The following if-else statement is compiled on x86_64 with -O6 into the following ASM sequence: int main(int ac, char \*\*av) { if (a == 0) foo(); else if (a == 1) bar(); else if (a == 2) shu(); } [....

December 4, 2010 · 3 min · Hagen Paul Pfeifer

My Baby Is Gone

My baby was my lovely Canon EOS 7D. And I lost the camera during the flight back from the IETF meeting in Beijing/China to Frankfurt/Germany. It is a story about how scatterbrained a man can be. ;-) I deposited the camera under the seat in front of me. After the plane landed and all passengers surrounding me left the plane I left the plane too - without the camera …...

December 4, 2010 · 2 min · Hagen Paul Pfeifer

KVM QEMU Kernel Debugging

Sometimes it is unavoidable to single step through the kernel because the code flow is complicated and systemtap and other tools are not helpful. This comes true when a lot of code must be conditionally analysed, without any prior knowledge. KVM and GDB provides a nice combination for this. I use my standard qemu setup with two additional qemu flags: -s and -S. Both flags instrument qemu to start a qemu gdb server and to break at the beginning....

December 4, 2010 · 1 min · Hagen Paul Pfeifer

Implicit Type Conversions and Bitwise Shift Operators

A error source for ANSI C (ISO/IEC 9899:TC2; 6.3 Conversions) is the implicit type conversion mechanism. The following code fragment illustrates a bogus usage of the shift operation in realtion with the type of the operands: void bit\_mark(unsigned long \*seq\_bits, int32\_t n) { int32\_t word\_offset, word\_num; word\_num = n / sizeof(unsigned long) \* 8; word\_offset = n % sizeof(unsigned long) \* 8; seq\_bits[word\_num] |= 1 << word\_offset; } The error source is the type of “1” which is implicit casted to an integer (Section: 6....

December 2, 2010 · 2 min · Hagen Paul Pfeifer

Libhashish Release

New are pleased to announce realease version 1.1 of “libhashish”:http://libhashish.sf.net. Major features are, … no new features. The release includes bugfixes for (u)int{8,16,32}_t hash key collision, a memory leak fix for the collision array implementation - thanks to Emmanuel Roullit, CFLAGS adjustments from Florian Westpahl, and “Debian”:http://www.debian.org packageizing fixes from Michael Stapelberg.

December 2, 2010 · 1 min · Hagen Paul Pfeifer

Genetic Algorithm Search Algorithm for Complex Problems

Several month ago I spend some months to analyse the behaviour of Genetic Algorithms. The research focused on mutation, selection and crossover algorithms and their behaviour. Genetic Algorithms are probabilistic search heuristics that emulate the process of evolution. Problem domains for genetic algorithms are complex scheduling problems (e.g. flight scheduling at the airport), Protein structure prediction or academic problems like traveling salesman problem. Genetic algorithms are useful where other search algorithms collapse through an almost infinite solution space....

October 14, 2010 · 2 min · Hagen Paul Pfeifer

Advanced Encryption Standard Crypto Speed

Some time ago I benchmarked Rijndal at CPU Cycle Level. I held a small presentation where I presented the raw values. The presentation foils itself are a little bit sparse but the important value are cognizable.

October 14, 2010 · 1 min · Hagen Paul Pfeifer

A Group Mobility Model for MANETs Using Terrain Maps

Due to the lack of money some month ago - now sounds funny - I skipped a conference where I wanted to present an approach to model group mobility of nodes. The idea is to use a form of terrain map (normally used to generate landscape models) as a basis to emulate real world motion characteristics similar. The focus are groups and their motion characterstic within the group. The terrain map is interpreted as what I called penalty map: the object wish is to evade areas with higher penalties to move from start to end....

October 14, 2010 · 1 min · Hagen Paul Pfeifer