mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lai Jiangshan <laijs@cn.fujitsu.com>
To: <linux-kernel@vger.kernel.org>
Cc: Tejun Heo <tj@kernel.org>, Lai Jiangshan <laijs@cn.fujitsu.com>
Subject: [PATCH 1/1 V2] workqueue: remove the del_timer_sync()s in maybe_create_worker()
Date: Mon, 14 Jul 2014 16:13:21 +0800	[thread overview]
Message-ID: <1405325601-12437-2-git-send-email-laijs@cn.fujitsu.com> (raw)
In-Reply-To: <1405325601-12437-1-git-send-email-laijs@cn.fujitsu.com>

It is said in the document that the timer which is being
deleted by del_timer_sync() should not be restarted:
  Synchronization rules: Callers must prevent restarting of
  the timer, otherwise this function is meaningless.

Repeating timer may cause the del_timer_sync() spin longer,
or even spin forever in very very very very extreme condition.

It is not considered a bug for me, but it disobeys the document.

To fix it, we need:
  1) don't requeue the mayday timer unless the manager is working
       it is a preparation/cleanup step for the fix. Otherwise the timer
       will repeat forever if we only do the 2).
  2) remove the del_timer_sync()s in maybe_create_worker()
       the timer is still repeating, we should not use del_timer_sync(),
       let the timer dismiss itself.

Change from V1:
  V1 incorrectly stops the timer when !need_to_create_worker(),
  but no one can restart it when needed. In V2, we stops the
  timer only when manager is not working.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
 kernel/workqueue.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 338d418..9c86a64 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -1864,10 +1864,11 @@ static void pool_mayday_timeout(unsigned long __pool)
 			send_mayday(work);
 	}
 
+	if (mutex_is_locked(&pool->manager_arb))
+		mod_timer(&pool->mayday_timer, jiffies + MAYDAY_INTERVAL);
+
 	spin_unlock(&pool->lock);
 	spin_unlock_irq(&wq_mayday_lock);
-
-	mod_timer(&pool->mayday_timer, jiffies + MAYDAY_INTERVAL);
 }
 
 /**
@@ -1909,7 +1910,6 @@ restart:
 
 		worker = create_worker(pool);
 		if (worker) {
-			del_timer_sync(&pool->mayday_timer);
 			spin_lock_irq(&pool->lock);
 			start_worker(worker);
 			if (WARN_ON_ONCE(need_to_create_worker(pool)))
@@ -1926,7 +1926,6 @@ restart:
 			break;
 	}
 
-	del_timer_sync(&pool->mayday_timer);
 	spin_lock_irq(&pool->lock);
 	if (need_to_create_worker(pool))
 		goto restart;
-- 
1.7.4.4


  reply	other threads:[~2014-07-14  8:12 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-13 15:31 [PATCH] " Lai Jiangshan
2014-07-14  8:13 ` [PATCH 0/1 V2] workqueue: a tiny fix for the mayday timer Lai Jiangshan
2014-07-14  8:13   ` Lai Jiangshan [this message]
2014-07-14 14:27     ` [PATCH 1/1 V2] workqueue: remove the del_timer_sync()s in maybe_create_worker() Tejun Heo
2014-07-14 15:33       ` Thomas Gleixner
2014-07-14 21:18         ` Lai Jiangshan
2014-07-14 21:42           ` Thomas Gleixner
2014-07-15  0:22             ` Lai Jiangshan
2014-07-16  1:24             ` Lai Jiangshan

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=1405325601-12437-2-git-send-email-laijs@cn.fujitsu.com \
    --to=laijs@cn.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tj@kernel.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®