]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/Finisher: No waite_for_empty no signal. 14363/head
authorJianpeng Ma <jianpeng.ma@intel.com>
Wed, 3 May 2017 15:37:52 +0000 (23:37 +0800)
committerJianpeng Ma <jianpeng.ma@intel.com>
Wed, 3 May 2017 15:37:52 +0000 (23:37 +0800)
Avoid every time to send a signal because wait_for_empty is rare event.

Signed-off-by: Jianpeng Ma <jianpeng.ma@intel.com>
src/common/Finisher.cc
src/common/Finisher.h

index 2f98fe289d51c059239575f01da81b3ad2ab3d21..18a423d6af99589aeaef8f4c95b233ebc510214b 100644 (file)
@@ -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;
     
index 045b8e47a5a5c4e103304a783d1b9a98fd27c550..1629d915d638d4e66982435fb21f0c740010fafb 100644 (file)
@@ -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,