mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christoph Lameter <christoph@graphe.net>
To: akpm@osdl.org
Cc: roland@redhat.com, shai@scalex86.org, linux-kernel@vger.kernel.org
Subject: [patch] del_timer_sync scalability patch
Date: Mon, 7 Mar 2005 22:47:27 -0800 (PST)	[thread overview]
Message-ID: <Pine.LNX.4.58.0503072244270.20044@server.graphe.net> (raw)

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();

             reply	other threads:[~2005-03-08  7:12 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-08  6:47 Christoph Lameter [this message]
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
2005-03-11 18:54 Oleg Nesterov
2005-03-11 20:57 ` Christoph Lameter
2005-03-13 13:13 ` 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
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.58.0503072244270.20044@server.graphe.net \
    --to=christoph@graphe.net \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=roland@redhat.com \
    --cc=shai@scalex86.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®