Skip to contentSkip to conversation

timers: kill timer_list->lock

PATCH New Oleg Nesterov 1 participant 1 message Mar 27, 2005 High-resolution timers, timer wheel, clockevents

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 timers: kill timer_list->lock

The timer->lock is needed in __mod_timer() because the freshly inited timer has base == NULL, so __mod_timer() can't use old_base for synchronization.

With this patch init_timer() sets ->_base = per_cpu(tvec_bases). This simplifies the code because we don't need to check that base != NULL, and slightly speedups __mod_timer(). And reduces the timer_list's size.

One problem. TIMER_INITIALIZER can't use per_cpu(tvec_bases). So this patch adds global

	struct {
		spinlock_t lock;
		struct timer_list *running_timer;
	} fake_timer_base;

which is used by TIMER_INITIALIZER.

It is indeed ugly. But this can't have scalability problems. The global fake_timer_base.lock is used only when __mod_timer() is called for the first time and the timer was compile time initialized. After that the timer migrates to the local CPU.

include/linux/timer.h renamed from include/linux/timer.h~ +8 -24
@@ -12,7 +12,6 @@ struct timer_list {
 	struct list_head entry;
 	unsigned long expires;
 
-	spinlock_t lock;
 	unsigned long magic;
 
 	void (*function)(unsigned long);
@@ -25,15 +24,11 @@ struct timer_list {
  * 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.
+ * If (_base & __TIMER_PENDING), the timer is pending.
  *
- * (_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.
+ * (_base & ~__TIMER_PENDING) is the address of the timer's
+ * per-cpu tvec_t_base_s where it was last registered and where
+ * it may still be running.
  */
 
 #define	__TIMER_PENDING	1
@@ -45,28 +40,17 @@ static inline int __timer_pending(struct
 
 #define TIMER_MAGIC	0x4b87ad6e
 
+extern struct fake_timer_base fake_timer_base;
+
 #define TIMER_INITIALIZER(_function, _expires, _data) {		\
 		.function = (_function),			\
 		.expires = (_expires),				\
 		.data = (_data),				\
-		._base = NULL,					\
+		._base = (void*)&fake_timer_base,		\
 		.magic = TIMER_MAGIC,				\
-		.lock = SPIN_LOCK_UNLOCKED,			\
 	}
 
-/***
- * init_timer - initialize a timer.
- * @timer: the timer to be initialized
- *
- * init_timer() must be done to a timer prior calling *any* of the
- * other timer functions.
- */
-static inline void init_timer(struct timer_list * timer)
-{
-	timer->_base = NULL;
-	timer->magic = TIMER_MAGIC;
-	spin_lock_init(&timer->lock);
-}
+void fastcall init_timer(struct timer_list * timer);
 
 /***
  * timer_pending - is a timer pending?
kernel/timer.c renamed from kernel/timer.c~ +65 -65

242 lines not on this page · raw message