mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: [patch] del_timer_sync scalability patch
@ 2005-03-11 18:54 Oleg Nesterov
  2005-03-11 20:57 ` Christoph Lameter
  2005-03-13 13:13 ` [patch] del_timer_sync scalability patch Oleg Nesterov
  0 siblings, 2 replies; 30+ messages in thread
From: Oleg Nesterov @ 2005-03-11 18:54 UTC (permalink / raw)
  To: linux-kernel; +Cc: Shai Fultheim, Christoph Lameter, Andrew Morton, Ingo Molnar

Hello.

I am not sure, but I think this patch incorrect.

> @@ -466,6 +482,7 @@ repeat:
>  			set_running_timer(base, timer);
>  			smp_wmb();
>  			timer->base = NULL;
------>	WINDOW <------
> +			set_last_running(timer, base);
>  			spin_unlock_irq(&base->lock);

Suppose it is the first invocation of timer, so
timer->last_running == NULL.

What if del_timer_sync() happens in that window?

del_timer_sync:
	del_timer();	// timer->base == NULL, returns

	base = timer->last_running;
	if (base)	// no, it is still NULL
		...

	if (timer->base != NULL || timer->last_running != base)
		goto del_again;	// not taken

	return;

I think it is not enough to exchange these 2 lines in
__run_timers, we also need barriers.

Oleg.

^ permalink raw reply	[flat|nested] 30+ messages in thread
* RE: [patch] del_timer_sync scalability patch
@ 2005-03-20 23:19 Chen, Kenneth W
  2005-03-20 23:34 ` Andrew Morton
  0 siblings, 1 reply; 30+ messages in thread
From: Chen, Kenneth W @ 2005-03-20 23:19 UTC (permalink / raw)
  To: linux-kernel; +Cc: 'Andrew Morton', christoph

We did exactly the same thing about 10 months back.  Nice to
see that independent people came up with exactly the same
solution that we proposed 10 months back.  In fact, this patch
is line-by-line identical to the one we post.

Hope Andrew is going to take the patch this time.

See our original posting:
http://marc.theaimsgroup.com/?l=linux-kernel&m=108422767319822&w=2

- Ken



^ permalink raw reply	[flat|nested] 30+ messages in thread
* [patch] del_timer_sync scalability patch
@ 2005-03-08  6:47 Christoph Lameter
  2005-03-08  7:32 ` Andrew Morton
  0 siblings, 1 reply; 30+ messages in thread
From: Christoph Lameter @ 2005-03-08  6:47 UTC (permalink / raw)
  To: akpm; +Cc: roland, shai, linux-kernel

When a potential periodic timer is deleted through timer_del_sync, all
cpus are scanned to determine if the timer is running on that cpu. In a
NUMA configuration doing so will cause NUMA interlink traffic which limits
the scalability of timers.

The following patch makes the timer remember where the timer was last
started. It is then possible to only wait for the completion of the timer
on that specific cpu.

Signed-off-by: Shai Fultheim <Shai@Scalex86.org>
Signed-off-by: Christoph Lameter <christoph@lameter.com>

Index: linux-2.6.11/include/linux/timer.h
===================================================================
--- linux-2.6.11.orig/include/linux/timer.h	2005-03-07 21:42:43.539328640 -0800
+++ linux-2.6.11/include/linux/timer.h	2005-03-07 21:42:50.993195480 -0800
@@ -19,10 +19,19 @@ struct timer_list {
 	unsigned long data;

 	struct tvec_t_base_s *base;
+#ifdef CONFIG_SMP
+	struct tvec_t_base_s *last_running;
+#endif
 };

 #define TIMER_MAGIC	0x4b87ad6e

+#ifdef CONFIG_SMP
+#define TIMER_INIT_LASTRUNNING .last_running = NULL,
+#else
+#define TIMER_INIT_LASTRUNNING
+#endif
+
 #define TIMER_INITIALIZER(_function, _expires, _data) {		\
 		.function = (_function),			\
 		.expires = (_expires),				\
@@ -30,6 +39,7 @@ struct timer_list {
 		.base = NULL,					\
 		.magic = TIMER_MAGIC,				\
 		.lock = SPIN_LOCK_UNLOCKED,			\
+		TIMER_INIT_LASTRUNNING                          \
 	}

 /***
@@ -41,6 +51,9 @@ struct timer_list {
  */
 static inline void init_timer(struct timer_list * timer)
 {
+#ifdef CONFIG_SMP
+	timer->last_running = NULL;
+#endif
 	timer->base = NULL;
 	timer->magic = TIMER_MAGIC;
 	spin_lock_init(&timer->lock);
Index: linux-2.6.11/kernel/timer.c
===================================================================
--- linux-2.6.11.orig/kernel/timer.c	2005-03-07 21:42:43.539328640 -0800
+++ linux-2.6.11/kernel/timer.c	2005-03-07 22:01:27.733425160 -0800
@@ -84,6 +84,14 @@ static inline void set_running_timer(tve
 #endif
 }

+static inline void set_last_running(struct timer_list *timer,
+					tvec_base_t *base)
+{
+#ifdef CONFIG_SMP
+	timer->last_running = base;
+#endif
+}
+
 /* Fake initialization */
 static DEFINE_PER_CPU(tvec_base_t, tvec_bases) = { SPIN_LOCK_UNLOCKED };

@@ -335,33 +343,41 @@ EXPORT_SYMBOL(del_timer);
  *
  * The function returns whether it has deactivated a pending timer or not.
  *
- * del_timer_sync() is slow and complicated because it copes with timer
- * handlers which re-arm the timer (periodic timers).  If the timer handler
- * is known to not do this (a single shot timer) then use
- * del_singleshot_timer_sync() instead.
+ * del_timer_sync() copes with time handlers which re-arm the timer (periodic
+ * timers).  If the timer handler is known to not do this (a single shot
+ * timer) then use del_singleshot_timer_sync() instead.
  */
 int del_timer_sync(struct timer_list *timer)
 {
 	tvec_base_t *base;
-	int i, ret = 0;
+	int ret = 0;

 	check_timer(timer);

 del_again:
 	ret += del_timer(timer);

-	for_each_online_cpu(i) {
-		base = &per_cpu(tvec_bases, i);
-		if (base->running_timer == timer) {
-			while (base->running_timer == timer) {
-				cpu_relax();
-				preempt_check_resched();
-			}
-			break;
+	/* Get where the timer ran last */
+	base = timer->last_running;
+	if (base) {
+		/*
+		 * If the timer is still executing then wait until the
+		 * run is complete.
+		 */
+		while (base->running_timer == timer) {
+			cpu_relax();
+			preempt_check_resched();
 		}
 	}
 	smp_rmb();
-	if (timer_pending(timer))
+	/*
+	 * If the timer is no longer pending and its last run
+	 * was where we checked then the timer
+	 * is truly off. If the timer has been started on some other
+	 * cpu in the meantime (due to a race condition) then
+	 * we need to repeat what we have done.
+	 */
+	if (timer_pending(timer) || timer->last_running != base)
 		goto del_again;

 	return ret;
@@ -464,6 +480,7 @@ repeat:
 			set_running_timer(base, timer);
 			smp_wmb();
 			timer->base = NULL;
+			set_last_running(timer, base);
 			spin_unlock_irq(&base->lock);
 			{
 				u32 preempt_count = preempt_count();

^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2005-03-21  1:17 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-11 18:54 [patch] del_timer_sync scalability patch Oleg Nesterov
2005-03-11 20:57 ` Christoph Lameter
2005-03-15 17:19   ` [PATCH 0/2] del_timer_sync: proof of concept Oleg Nesterov
2005-03-15 18:15     ` Christoph Lameter
2005-03-15 19:41       ` Oleg Nesterov
2005-03-15 19:02         ` Christoph Lameter
2005-03-16 16:55     ` Oleg Nesterov
2005-03-15 17:19   ` [PATCH 1/2] " Oleg Nesterov
2005-03-15 17:20   ` [PATCH 2/2] " Oleg Nesterov
2005-03-16  9:00     ` Ingo Molnar
2005-03-16 12:09       ` Oleg Nesterov
2005-03-16 13:52         ` Ingo Molnar
2005-03-13 13:13 ` [patch] del_timer_sync scalability patch Oleg Nesterov
2005-03-14 19:40   ` Christoph Lameter
2005-03-15  9:12     ` Oleg Nesterov
2005-03-15  8:06   ` Christoph Lameter
2005-03-15  9:28     ` Ingo Molnar
2005-03-15 10:28     ` Oleg Nesterov
  -- strict thread matches above, loose matches on Subject: below --
2005-03-20 23:19 Chen, Kenneth W
2005-03-20 23:34 ` Andrew Morton
2005-03-21  0:47   ` Christoph Lameter
2005-03-21  1:00     ` Andrew Morton
2005-03-21  0:54   ` Christoph Lameter
2005-03-21  1:17     ` Andrew Morton
2005-03-08  6:47 Christoph Lameter
2005-03-08  7:32 ` Andrew Morton
2005-03-08  8:19   ` Ingo Molnar
2005-03-08  8:33     ` Andrew Morton
2005-03-08 20:05       ` Christoph Lameter
2005-03-08 19:44     ` Christoph Lameter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome