2007年3月31日星期六

Time to Wakeup a Thread in Linux

Abstract:
In multithreaded programming, it is sometimes desirable to have some process blocked for a specific event to happen. For better response time, there maybe two method to implement this, one approach is that the process spinned on a flag indicating the arrival of the event, and the other is the process blocked on a conditional variable and wakenup by another thread when the event happens. Here we compare the effectiveness of these two methods.

Test Platform:
OS: Linux 2.6.18-1.2798.fc6 #1 SMP x86_64 GNU/Linux
CC: gcc version 4.1.1 20061011 (Red Hat 4.1.1-30)
CFLAGS: -Wall -O2
LDFLAGS: -lrt -lpthread
CPU: Dual Core AMD Opteron(tm) Processor 270
System: 2 processors

Response Time(averaged among 500 run):
usleep(1): 39928260.000000 ns
clock_nanosleep(1): 39835940.000000 ns
pthread_cond_wait: 346940.000000 ns

Source Code for Test Program:
I can't find anywhere in this blog to upload files, so until I find it, the source code may not be publicly available. Maybe you can teach me howto upload files on blogger.com. Just drop me a email.

Conclusions:
Neither usleep(1) nor clock_nanosleep(1) is good for response time, use pthread_cond_wait() is a good choice with the additional advantage of releasing CPU time for other processes/threads.

2007年3月28日星期三

how to add a directory in cvs?

There are two circumstances:

(1) the directory is empty, then use

$ cvs add dir_name

(2) the directory is not empty, in such case, you use

$ cvs import dir_name path_in_repository vendor_tag release_tag

instead.

关于 make 的一些乱七八糟的东西

Abstract


(1) How to make the output of 'make' more readable(.SILENT)?
(2) Why can't I understand some strange makefiles(Multiple Rules for One Target)?
(3) How to boost make performance(-j nr_jobs)?

4.9 Special Built-in Target Names

Certain names have special meanings if they appear as targets.

.PHONY
The prerequisites of the special target .PHONY are considered to be phony targets. When it is time to consider such a target, make will run its commands unconditionally, regardless of whether a file with that name exists or what its last-modification time is. See Phony Targets.


.SUFFIXES
The prerequisites of the special target .SUFFIXES are the list of suffixes to be used in checking for suffix rules. See Old-Fashioned Suffix Rules.


.DEFAULT
The commands specified for .DEFAULT are used for any target for which no rules are found (either explicit rules or implicit rules). See Last Resort. If .DEFAULT commands are specified, every file mentioned as a prerequisite, but not as a target in a rule, will have these commands executed on its behalf. See Implicit Rule Search Algorithm.


.SILENT
If you specify prerequisites for .SILENT, then make will not print the commands to remake those particular files before executing them. The commands for .SILENT are not meaningful.

If mentioned as a target with no prerequisites, .SILENT says not to print any commands before executing them. This usage of `.SILENT' is supported only for historical compatibility. We recommend you use the more selective ways to silence specific commands. See Command Echoing. If you want to silence all commands for a particular run of make, use the `-s' or `--silent' option (see Options Summary).


.EXPORT_ALL_VARIABLES
Simply by being mentioned as a target, this tells make to export all variables to child processes by default. See Communicating Variables to a Sub-make.


.NOTPARALLEL
If .NOTPARALLEL is mentioned as a target, then this invocation of make will be run serially, even if the `-j' option is given. Any recursively invoked make command will still be run in parallel (unless its makefile contains this target). Any prerequisites on this target are ignored.

Any defined implicit rule suffix also counts as a special target if it appears as a target, and so does the concatenation of two suffixes, such as `.c.o'. These targets are suffix rules, an obsolete way of defining implicit rules (but a way still widely used). In principle, any target name could be special in this way if you break it in two and add both pieces to the suffix list. In practice, suffixes normally begin with `.', so these special target names also begin with `.'. See Old-Fashioned Suffix Rules.


4.11 Multiple Rules for One Target

One file can be the target of several rules. All the prerequisites mentioned in all the rules are merged into one list of prerequisites for the target. If the target is older than any prerequisite from any rule, the commands are executed.

There can only be one set of commands to be executed for a file. If more than one rule gives commands for the same file, make uses the last set given and prints an error message. (As a special case, if the file's name begins with a dot, no error message is printed. This odd behavior is only for compatibility with other implementations of make... you should avoid using it). Occasionally it is useful to have the same target invoke multiple commands which are defined in different parts of your makefile; you can use double-colon rules (see Double-Colon) for this.

5.4 Parallel Execution

GNU make knows how to execute several commands at once. Normally, make will execute only one command at a time, waiting for it to finish before executing the next. However, the `-j' or `--jobs' option tells make to execute many commands simultaneously.


5.5 Errors in Commands

To ignore errors in a command line, write a `-' at the beginning of the line's text (after the initial tab). The `-' is discarded before the command is passed to the shell for execution.

For example,

     clean:
-rm -f *.o

This causes rm to continue even if it is unable to remove a file.

When you run make with the `-i' or `--ignore-errors' flag, errors are ignored in all commands of all rules. A rule in the makefile for the special target .IGNORE has the same effect, if there are no prerequisites. These ways of ignoring errors are obsolete because `-' is more flexible.

When errors are to be ignored, because of either a `-' or the `-i' flag, make treats an error return just like success, except that it prints out a message that tells you the status code the command exited with, and says that the error has been ignored.

When an error happens that make has not been told to ignore, it implies that the current target cannot be correctly remade, and neither can any other that depends on it either directly or indirectly. No further commands will be executed for these targets, since their preconditions have not been achieved.