RE: Pthread performance

David Schwartz (davids@webmaster.com)
Sun, 13 Jul 2003 13:11:44 -0700


> I found a benchmark program for threads and found a major
> difference between a single CPU and dual CPU system.
> Here's the code:
> http://www-124.ibm.com/pipermail/pthreads-users/2002-April/000176.html
> Is this showing context switches going between CPUs??

No.

> Wouldn't one expect the dual CPU to run twice as fast instead of
> ten times slower?

Not necessarily. The code doesn't do much other than modified shared data
without a lock. Not only does this invoke undefined behavior, but it
penalizes SMP machines because only they are subject to cache ping-ponging.

> As you can see from the timing user time increases by a factor of
> 4 and system time by a factor of 10.
> I seem to remember something about gettimeofday() possibly being
> a problem but couldn't find a reference to it.
> Anybody have an explanation/fix for this?

The program doesn't seem to measure anything useful and invokes undefined
behavior.

If you would like a fix, try this:

#define sched_yield() while(false)

DS

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/