From: Jianpeng Ma Date: Wed, 3 May 2017 15:37:52 +0000 (+0800) Subject: common/Finisher: No waite_for_empty no signal. X-Git-Tag: v12.0.3~105^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F14363%2Fhead;p=ceph.git 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 --- diff --git a/src/common/Finisher.cc b/src/common/Finisher.cc index 2f98fe289d5..18a423d6af9 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 045b8e47a5a..1629d915d63 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,