[Development] QMutex with pthread on Linux

Thiago Macieira thiago.macieira at intel.com
Wed Aug 22 19:06:23 CEST 2012


On quarta-feira, 22 de agosto de 2012 10.20.24, Thiago Macieira wrote:
> b) the locking and unlocking itself
>                         pthread                                 QMutex
> locking         pthread_mutex_lock              pthread_mutex_lock
>                                                                         pthr
> ead_cond_wait pthread_mutex_unlock
> 
> unlocking       pthread_mutex_unlock    pthread_mutex_lock
>                                                                         pthr
> ead_cond_signal pthread_mutex_unlock

I've just tested how much the impact of using pthread the way we use is.

Here's the best result (out of 6 runs):

RESULT : tst_QMutex::contendedNative():"no msleep, 1 mutex":
     29,604,816.135 CPU ticks per iteration
      51293.764061 task-clock                #    2.310 CPUs utilized          
   150,427,629,633 cycles                    #    2.933 GHz                    
    82,754,202,716 instructions              #    0.55  insns per cycle        
        42,545,258 raw_syscalls:sys_enter    #    0.829 M/sec                  
      22.207549096 seconds time elapsed

Compare to the "proper" use of pthread_mutex:
RESULT : tst_QMutex::contendedNative():"no msleep, 1 mutex":
     2,052,212.507 CPU ticks per iteration
       5814.825257 task-clock                #    3.797 CPUs utilized          
    18,513,286,444 cycles                    #    3.184 GHz                    
    13,801,932,519 instructions              #    0.75  insns per cycle        
         8,609,051 raw_syscalls:sys_enter    #    1.481 M/sec                  
       1.531495948 seconds time elapsed

In other words: the way we use pthreads for mutexes, we're imposing a 
performance penalty of 1350%. Then we have a bunch of code to improve on that 
and avoid pthread.

Note that we're talking about one of the best pthreads implementations 
available, that is NPTL using futexes on Linux. On other systems, NPTL 
performance may be worse, so our avoidance of them might be warranted.

On Linux, doing what we do is definitely not acceptable. But we don't use this 
code anyway, we use the futex-based mutex, which is much faster, better than 
pthreads.

This code is only used on non-Linux and non-Mac Unix systems (FreeBSD, QNX, 
etc.) as well as Linux with LSB. People interested in those systems need to 
quick benchmark soon and figure out whether the solution needs attention there.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
     Intel Sweden AB - Registration Number: 556189-6027
     Knarrarnäsgatan 15, 164 40 Kista, Stockholm, Sweden
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/development/attachments/20120822/5a10d450/attachment.sig>


More information about the Development mailing list