timers: rework del_timer_sync()
PATCH 2/5 timers: rework del_timer_sync()
New rules:
->_base & 1 : is timer pending ->_base & ~1 : where the timer was last scheduled
->_base == NULL means that this timer is not running on any cpu.
del_timer_sync() clears ->_base, it is merely an optimization, so that subsequent del_timer calls do not need locking.
del_timer_sync() assumes that the timer's base == (->_base & ~1) can't be changed during execution of timer->function. It is achieved by the next patch.
Signed-off-by Oleg Nesterov <[email protected]>
include/linux/timer.h renamed from include/linux/timer.h~2_SYNC +18 -1
@@ -21,9 +21,26 @@ struct timer_list {struct tvec_t_base_s *_base; }; +/* +* To save space, we play games with the least significant bit +* of timer_list->_base. +* +* If (_base & __TIMER_PENDING), the timer is pending. Implies +* (_base & ~__TIMER_PENDING) != NULL. +* +* (_base & ~__TIMER_PENDING), if != NULL, is the address of the +* timer's per-cpu tvec_t_base_s where it was last scheduled and +* where it may still be running. +* +* If (_base == NULL), the timer was not scheduled yet or it was +* cancelled by del_timer_sync(), so it is not running on any CPU. +*/ + +#define __TIMER_PENDING 1 +static inline int __timer_pending (struct tvec_t_base_s *base) { -return base !=NULL ; +return ((unsigned long )base & __TIMER_PENDING) !=0 ; }#define TIMER_MAGIC 0x4b87ad6e
kernel/timer.c renamed from kernel/timer.c~2_SYNC +42 -27
98 lines not on this page · raw message