locking: Optimize lock_bh functions
Currently all _bh_ lock functions do two preempt_count operations: local_bh_disable(); preempt_disable(); and for the unlock: preempt_enable_no_resched(); local_bh_enable(); Since its a waste of perfectly good cycles to modify the same variable twice when you can do it in one go; use the new __local_bh_{dis,en}able_ip() functions that allow us to provide a preempt_count value to add/sub. So define SOFTIRQ_LOCK_OFFSET as the offset a _bh_ lock needs to add/sub to be done in one go. As a bonus it gets rid of the preempt_enable_no_resched() usage. This reduces a 1000 loops of: spin_lock_bh(&bh_lock); spin_unlock_bh(&bh_lock); from 53596 cycles to 51995 cycles. I didn't do enough measurements to say for absolute sure that the result is significant but the the few runs I did for each suggest it is so. Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Peter Zijlstra <peterz@infradead.org> Cc: jacob.jun.pan@linux.intel.com Cc: Mike Galbraith <bitbucket@online.de> Cc: hpa@zytor.com Cc: Arjan van de Ven <arjan@linux.intel.com> Cc: lenb@kernel.org Cc: rjw@rjwysocki.net Cc: rui.zhang@intel.com Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Andrew Morton <akpm@linux-foundation.org> Link: http://lkml.kernel.org/r/20131119151338.GF3694@twins.programming.kicks-ass.net Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:

committed by
Ingo Molnar

parent
c726099ec2
commit
9ea4c38006
@@ -24,11 +24,14 @@
|
||||
* flags straight, to suppress compiler warnings of unused lock
|
||||
* variables, and to add the proper checker annotations:
|
||||
*/
|
||||
#define ___LOCK(lock) \
|
||||
do { __acquire(lock); (void)(lock); } while (0)
|
||||
|
||||
#define __LOCK(lock) \
|
||||
do { preempt_disable(); __acquire(lock); (void)(lock); } while (0)
|
||||
do { preempt_disable(); ___LOCK(lock); } while (0)
|
||||
|
||||
#define __LOCK_BH(lock) \
|
||||
do { local_bh_disable(); __LOCK(lock); } while (0)
|
||||
do { __local_bh_disable_ip(_THIS_IP_, SOFTIRQ_LOCK_OFFSET); ___LOCK(lock); } while (0)
|
||||
|
||||
#define __LOCK_IRQ(lock) \
|
||||
do { local_irq_disable(); __LOCK(lock); } while (0)
|
||||
@@ -36,12 +39,15 @@
|
||||
#define __LOCK_IRQSAVE(lock, flags) \
|
||||
do { local_irq_save(flags); __LOCK(lock); } while (0)
|
||||
|
||||
#define ___UNLOCK(lock) \
|
||||
do { __release(lock); (void)(lock); } while (0)
|
||||
|
||||
#define __UNLOCK(lock) \
|
||||
do { preempt_enable(); __release(lock); (void)(lock); } while (0)
|
||||
do { preempt_enable(); ___UNLOCK(lock); } while (0)
|
||||
|
||||
#define __UNLOCK_BH(lock) \
|
||||
do { preempt_enable_no_resched(); local_bh_enable(); \
|
||||
__release(lock); (void)(lock); } while (0)
|
||||
do { __local_bh_enable_ip(_THIS_IP_, SOFTIRQ_LOCK_OFFSET); \
|
||||
___UNLOCK(lock); } while (0)
|
||||
|
||||
#define __UNLOCK_IRQ(lock) \
|
||||
do { local_irq_enable(); __UNLOCK(lock); } while (0)
|
||||
|
Reference in New Issue
Block a user