All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] workqueue: remove the del_timer_sync()s in maybe_create_worker()
@ 2014-07-13 15:31 Lai Jiangshan
  2014-07-14  8:13 ` [PATCH 0/1 V2] workqueue: a tiny fix for the mayday timer Lai Jiangshan
  0 siblings, 1 reply; 9+ messages in thread
From: Lai Jiangshan @ 2014-07-13 15:31 UTC (permalink / raw)
  To: linux-kernel; +Cc: Tejun Heo, Lai Jiangshan

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 when !need_to_create_worker()
       it is a preparation/cleaup 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()
       Fix the problem. It is not enough if we only do the 1),
       need_to_create_worker() would be probably true when the time
       del_timer_sync() is called, the timer is still repeating.

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

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 35974ac..593b9bc 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -1866,12 +1866,12 @@ static void pool_mayday_timeout(unsigned long __pool)
 		 */
 		list_for_each_entry(work, &pool->worklist, entry)
 			send_mayday(work);
+
+		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);
 }
 
 /**
@@ -1913,7 +1913,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)))
@@ -1931,7 +1930,6 @@ restart:
 			break;
 	}
 
-	del_timer_sync(&pool->mayday_timer);
 	spin_lock_irq(&pool->lock);
 	if (need_to_create_worker(pool))
 		goto restart;
-- 
1.7.7.6


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

end of thread, other threads:[~2014-07-16  1:23 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-13 15:31 [PATCH] workqueue: remove the del_timer_sync()s in maybe_create_worker() 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   ` [PATCH 1/1 V2] workqueue: remove the del_timer_sync()s in maybe_create_worker() Lai Jiangshan
2014-07-14 14:27     ` 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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.