Epoll versus Select

I finished the select() backend for libeve Thus libeve can be compiled under nearly every operating system in this solar system (I didn’t even tried it, but the functional components are ready). Primary focus was and is Linux, I am not necessarily interested in other systems. Under Linux epoll/timer_fd is the best what you can do if you want to do. Under {Free, Net, Open, …}BSD kqueue should be the most performant implementation, but doe to lack of time and interest it isn’t implemented and select() should be fine too....

January 19, 2011 · 1 min · Hagen Paul Pfeifer

IPv6 Address Assignment to End Sites

IAB/IESG Recommendations on IPv6 Address Allocations to Sites (“RFC 3177”:http://tools.ietf.org/html/rfc3177) provides recommendations that for end sites a @/48@ block should be provided in normal case. A @/64@ block when it is absolutely sure that only one subnet is needed and @/128@ for the case that only one device is connected. The requirements for IPv6 in 1993 included the plan that the next IP version should address approximately 2^40^ networks and 2^50^ hosts....

January 5, 2011 · 2 min · Hagen Paul Pfeifer

Chi Square Test and Cryptographic Hash Functions

The Chi-Square probe is a statistical hypothesis test. The here presented values show the distribution of several hash algorithms compared to the cryptographic SHA1. Currently I am too lazy to explain the algorithm in great detail. Wikipedia is a great source for an introduction. The analysis is part of libhashish and available in the analysis directory.

December 8, 2010 · 1 min · Hagen Paul Pfeifer

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