[ofa-general] Re: multiple threads posting to the same QP

Roland Dreier rdreier at cisco.com
Tue Oct 2 10:53:04 PDT 2007


 > Looking on the mthca and mlx4 low-level libraries I realize that you
 > use pthread_spin_lock/unlock for thread safeness.
 > 
 > Can you spare few words on why spinning is used rather then sleeping
 > (eg pthread_mutex_lock/unlock) - is it since you assume that:
 > 
 > A) if the lock is not contended - both calls have the same efficiency
 > B) if the lock is contended - it would be such for --short-- time and
 > hence spinning is more efficient then sleeping (no context-switch etc)

Pretty much, although the main reason is really that pthread spinlocks
are actually measurably faster than mutexes in the uncontended case.

 > > (And BTW, yes, it is possible to call send(2) in any racy way you want
 > > on the same FD, and the kernel's internal state will not get messed
 > > up)
 > 
 > is it documented any where? other then the kernel state, what happens
 > if send(2) is called from two threads on a datagram socket? will the
 > two datagrams be accepted in the remote side uncorrupted? as for
 > stream socket, since the bits order in the stream is not defined in
 > the sender
 > side, I "corruption" would surely be experienced by the remote side.

I don't know what documentation has written explicitly.  I guess you
could read the POSIX or SUS standards to see.

 - R.



More information about the general mailing list