tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Contended locks - mutex vs spin lock



Hi, I was expecting for a contended lock, spin lock to be at
least as efficient as adaptive mutex. However a simple test program
seems to indicate quite a big difference:

atom$ gcc -O2 lock_test.c -DMUTEX_LOCK -lpthread
atom$ time ./a.out
        4.54 real        16.76 user         0.00 sys

atom$ gcc -O2 lock_test.c -DSPIN_LOCK -lpthread
atom$ time ./a.out
       14.04 real        51.83 user         0.00 sys

Any idea why pthreads spin lock is 3 times slower compared to pthreads
mutex?


PS. Some info about my hardware:

atom$ cpuctl list
Num  HwId Unbound LWPs Interrupts Last change              #Intr
---- ---- ------------ ---------- ------------------------ -----
0    0    online       intr       Sun Oct 30 08:05:54 2011 13
1    2    online       intr       Sun Oct 30 08:05:54 2011 0
2    1    online       intr       Sun Oct 30 08:05:54 2011 0
3    3    online       intr       Sun Oct 30 08:05:54 2011 0

atom$ cpuctl identify 0
Cannot bind to target CPU.  Output may not accurately describe the
target. Run as root to allow binding.

cpu0: Intel Atom (686-class), 1666.74 MHz, id 0x106ca
cpu0: features
0xbfebfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR> cpu0:
features  0xbfebfbff<PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR>
cpu0: features  0xbfebfbff<SSE,SSE2,SS,HTT,TM,SBF> cpu0: features2
0x40e31d<SSE3,DTES64,MONITOR,DS-CPL,TM2,SSSE3,CX16,xTPR> cpu0:
features2 0x40e31d<PDCM,MOVBE> cpu0: features3
0x20100800<SYSCALL/SYSRET,XD,EM64T> cpu0: features4 0x1<LAHF>
cpu0: "Intel(R) Atom(TM) CPU D510   @ 1.66GHz"
cpu0: I-cache 32KB 64B/line 8-way
cpu0: Initial APIC ID 0
cpu0: Cluster/Package ID 0
cpu0: Core ID 0
cpu0: SMT ID 0
cpu0: family 06 model 0c extfamily 00 extmodel 01

Attachment: lock_test.c
Description: Binary data



Home | Main Index | Thread Index | Old Index