From fcc7799e0ae9aea22325ffda828f348a00a68b08 Mon Sep 17 00:00:00 2001 From: Jianpeng Ma Date: Wed, 3 May 2017 23:37:52 +0800 Subject: [PATCH] common/Finisher: No waite_for_empty no signal. Avoid every time to send a signal because wait_for_empty is rare event. Signed-off-by: Jianpeng Ma --- src/common/Finisher.cc | 5 ++++- src/common/Finisher.h | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/common/Finisher.cc b/src/common/Finisher.cc index 2f98fe289d51c..18a423d6af995 100644 --- a/src/common/Finisher.cc +++ b/src/common/Finisher.cc @@ -33,9 +33,11 @@ void Finisher::wait_for_empty() finisher_lock.Lock(); while (!finisher_queue.empty() || finisher_running) { ldout(cct, 10) << "wait_for_empty waiting" << dendl; + finisher_empty_wait = true; finisher_empty_cond.Wait(finisher_lock); } ldout(cct, 10) << "wait_for_empty empty" << dendl; + finisher_empty_wait = false; finisher_lock.Unlock(); } @@ -92,7 +94,8 @@ void *Finisher::finisher_thread_entry() finisher_running = false; } ldout(cct, 10) << "finisher_thread empty" << dendl; - finisher_empty_cond.Signal(); + if (unlikely(finisher_empty_wait)) + finisher_empty_cond.Signal(); if (finisher_stop) break; diff --git a/src/common/Finisher.h b/src/common/Finisher.h index 045b8e47a5a5c..1629d915d638d 100644 --- a/src/common/Finisher.h +++ b/src/common/Finisher.h @@ -43,6 +43,7 @@ class Finisher { Cond finisher_empty_cond; ///< Signaled when the finisher has nothing more to process. bool finisher_stop; ///< Set when the finisher should stop. bool finisher_running; ///< True when the finisher is currently executing contexts. + bool finisher_empty_wait; ///< True mean someone wait finisher empty. /// Queue for contexts for which complete(0) will be called. /// NULLs in this queue indicate that an item from finisher_queue_rval /// should be completed in that place instead. @@ -136,14 +137,14 @@ class Finisher { /// Anonymous finishers do not log their queue length. explicit Finisher(CephContext *cct_) : cct(cct_), finisher_lock("Finisher::finisher_lock"), - finisher_stop(false), finisher_running(false), + finisher_stop(false), finisher_running(false), finisher_empty_wait(false), thread_name("fn_anonymous"), logger(0), finisher_thread(this) {} /// Construct a named Finisher that logs its queue length. Finisher(CephContext *cct_, string name, string tn) : cct(cct_), finisher_lock("Finisher::" + name), - finisher_stop(false), finisher_running(false), + finisher_stop(false), finisher_running(false), finisher_empty_wait(false), thread_name(tn), logger(0), finisher_thread(this) { PerfCountersBuilder b(cct, string("finisher-") + name, -- 2.39.5