Friday, November 09, 2007

Re: "C and multithreading"

On debian planet. I read the C and multithreading post of Miriam Ruiz, but I don't agree with some conclusions:

First of all, I don't agree with Linus. C standard doesn't allow such optimizations. One of the driving point of C standard (and thus C) is that compiler should do what a programmer write, without much optimization, i.e. C should remain a low level language. It was iterated also for the principles of new C1X standard.

Second point. Volatile is not the right solution. volatile means that a variable should be read every time it is accessed, so the variable should not be but in registers (remember the nearly obsolete register keyword).

The problem of multi threading is not only that variables could changes (but this is a fact also of
single thread programs, when you write a signal handler [which are specified in C standard and which are handled correctly]), but for semaphores there are "barriers", i.e. you should not move read or write across such barriers.

What do volatile have with barriers? Nothing. If you read the standard (you can check also only the one page C appendix), you see that C specify what are the "standard" barrier, and they are nearly in all obvious points (i.e. a ";" is also a barrier), so moving instructions is "illegal" for C.
Ok. volatile had few other barriers, but across ";" there is already a barrier, so volatile is not the solution of barrier problem (AB locking).

References: see C wiki and C standard.

Thursday, November 01, 2007

Linux Kernel Driver DataBase

This weekend I finally finished the Linux Kernel Driver DataBase . Really I started this project in 2000, but in 2001 after some flames in the LKML (for CML2, the configuration engine used by my project) I put the project in a long hibernation. Now I had some time to finish it.

LKDDb is a database of hardware (and protocols), kernel configuration items and associated kernel driver files. Actually it has nearly 6000 entries (see the statistics). The database is generated automagically, quite fast: it take 2 minutes to scan the whole kernel source, and to interpret it. Unfortunately it is not complete and not accurate (I'm not sure if there is some black-list in kernel, but my scanner cannot distinguish the black-list with the supported hardware list).

Now I'm looking for some application of the database. In 2001 it seemed that there was some interest, but let see.

As a prototype, I dis-hibernate also the AutoKernConf, an automagical kernel configuration. The old version was a more powerful, so I need to forward-port some old features. BTW I changed an other time the project name: autoconfig was too similar to existing projects, kautoconfig, kernfig, kernautoconf were other names, but I like better the new name, and I can use the automagical word in the description ;-)

Do you see other uses of the database?

Friday, March 09, 2007

ICANN Factsheet on last DNS root server attack

Yesterday ICANN published an interesting article about last attack of root servers (6 February 2007): see . The paper is not so detailed and technical as one should expect, anyway it is worth to read it.

It seems that also the remaining root servers should move to anycast. I think this is good, but it will works reliable with TCP? Do someone use TCP to query DNS servers? Why is it not disabled? It seems that all root servers accept TCP ( dig . NS +tcp).

A side note: as you can see, root servers don't give you yet the IPv6 addresses of root servers. Now they do some test, prior to broke the root server 512-bytes packet rule. We are still away to the full IPv4/IPv6 inter-operative nets.

The last recommendation is: "ISPs should only accept DNS queries from trusted sources (i.e., their own customers) rather than allow anyone to use their servers." . This rule (on recursive queries) is already a well know rule, and I I think it is less problematic of mail-rely (ev. with SPF), but on the other side, we are moving to the point that we should trust our ISP and our ISP will firewall "non-proxied" traffic.

As last point, the fact sheet cite two wikipedia articles. Wikipedia is so good, or there are not better (updated) documentation on the net?

Saturday, October 28, 2006

shell: parallel execution with timeouts

From time in time I was looking how to run a command with a timeout (in a shell script). I never put big efford to find the solution, because I always found a easyer (and probably better) workaround. But few days ago, in a discussion in the austing group (POSIX standardization), I found the solution, in an elegant manner, and it permit also to run commands in parallel.

The solution (it works on bash, dash, and it seems posix compatible, but you should test, because the discussion was about the different behaviours of $! in bash and kornshell):
 # run command1 in background, and the sleeping killer
command1 &
( sleep 60; kill $pid ) &
# other stuffs
# wait command1
wait $pid

Note: kill (the shell buildin) prints some error messages, which you should filter
Note: Security: the methods is not very clean and secure. If an user can force system to recycle the PID, the scripts could do unintended things.

I this trick can be used to parallel the init script (parallelize within the script, not "run scripts in parallel", as the current trend).
So another short tip: Debian sleep support "floating sleep", so use sleep .1 istead of sleep 1, to speed up the init scripts (module loading, waiting for devices, net,...). Unfortunately most of the debian scripts use integer sleeps.

Wednesday, October 18, 2006

ntp: keeping the right time

This is an other topic inspired by ;login: (usenix magazine). I think it is essential for a computer to have the clock showing the right time, and it is not hard! On my servers I use either ntpd (the daemon), or 4 time per day a ntpdate to a nearly ntp server. On my home desktop the ntpdate is run at every boot (because it is never on for long time), and on my ibook the same on linux boot and ntpd on MacOS (which is the default).
I don't know what is the better method. A drift of one second is mainly acceptable on my machines, so the ntpdate methond should be the better choice (if the hardware clock is not "broken"). [BTW the debian packages are: ntp and ntpdate]

Today I joined the ntp pool servers: a list of public (and unrestricted) ntp servers. For my configuration I choosed 6 ntp servers (stratum 2) located in Switzerland.

If you don't care to high precise timing, you can use ntp pool servers (check the references to choose the right servers). If you have not yet used ntp, it is the better start. For high precise timing, there are also Stratum 1 (but read the usage rules) and Stratum 2. Optionally you can also use a GPS clock.

References: ntp project home page. I've also heard that there is a project of one of the BSD to make an alternate (and lighter) implementation.

Tuesday, October 17, 2006


Yesterday I was looking for the changes between the ANSI/ISO C (1989) and the new C99 (ISO 1999). The best information are found in:
Summary of the main changes:
  • external identifier now are case sensitive and up 31 characters (in old standard a portable program should not rely on case sensitiveness nor to more of 6 chars)
  • variable argument on macros
  • from C++: // comment, inline, declaration and statement can mix, for allow declaration in first "argument"
  • compound literals
  • initializers: int a[10] = { [5] = 3}; struct {int a,b} c = { .b=3};
  • long long (64-bit or longer) with LL, ll, ULL and ull suffixes in costants
  • __func__ "automatic variable" : void f(int void) { fprint("me is %s\n", __func__); }
  • _Bool and if you #include you have bool, true and false
  • restrict keyword to optimize function: you tell compiler that pointers don't point overlapping regions.
  • variable-length arrays
The gcc has a page about what is implemented and what not.

In you see the complete standard with the two corrigenda, and the rationale about the new standard. It worth to browse it!

About me

As first post, I'll describe briefly me and my interest. I'm Swiss, I spoke Italian (mother tongue), French, German and English. Maybe this blog would improve my English skills.

I'm a Debian Developer (but few packages), I started with Debian in 1996 or 1997 (IIRC) with few floppies disks, than Mandrake (easier to handle packages with floppies), then someone burned my a RedHat, unfortunately with a non free X server, and than I compiled and installed a lot of program from sources (kernel, glibc, gcc...). Finally I used Debian for all home activities as only OS.
Recently with my new laptop (iBook), I use dual boot: MacOS and Linux/Debian.

I install nearly every kernel from "vanilla sources" since 2.0.28/2.1.8x. I read kernel mailing list
since 7-8 years, but I've contributed only with few and small patches.

I focus on kernel, security and standards, but I'm also interested in networks (IP, and the organizations behind Internet: IC, IAB, IETF, ICANN, IANA, RFC-editor,...), configuration and low level libraries.

I'm a wikipedian (now I think I have nearly 1200 edits in the English edition): anti vandalism, clean-up, swiss topics (mainly about Ticino), wine and filmmaking.

I own a small vineyard, and I make also some wine.

And a lot of other "minor" interests.