On Mon, 21 Jan 2013 19:16:47 +0530, Prashant Shah said: > There is a bitmap that needs to be locked across many threads for test > / set bit operations. Which one is faster - bitops or mutex ? > > 1. Bitops : > set_bit(5, (long unsigned *)&tmp); > > 2. Mutex : > mutex_lock(&m); > *tmp = (*tmp) | (1 << 5); > mutex_unlock(&m); Do you care about "faster" as in "less latency", or "less total cycles consumed"? The two can be quite different.... One uses a mutex, the other a spinlock and irq save/restore. "faster" will depend on the architecture (irqsave is more expensive on some archs than others) and how heavily the lock is contended. If the answer *really* matters, you better go ahead and instrument the code and actually time it and do the statistical analysis. Also, double-check that you don't require *additional* locking. It's pretty rare that the *entire* critical section is exactly one bit-set operation long
Attachment:
pgp8gxmyx3295.pgp
Description: PGP signature
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@xxxxxxxxxxxxxxxxx http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies