]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
DecayCounter: removed unused velocity
authorPatrick Donnelly <pdonnell@redhat.com>
Sat, 9 Jun 2018 04:15:58 +0000 (21:15 -0700)
committerPatrick Donnelly <pdonnell@redhat.com>
Fri, 15 Jun 2018 14:04:42 +0000 (07:04 -0700)
It's not actually used anywhere and it's not accurate.

Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
src/common/DecayCounter.cc
src/common/DecayCounter.h

index 1144daaf068ec934c4eaa29e6610b1206ccbf8fd..cbf38d6b0754c9fab654435bf2edbc8182bbcd4f 100644 (file)
 
 void DecayCounter::encode(bufferlist& bl) const
 {
-  decay(rate);
+  decay();
   ENCODE_START(5, 4, bl);
   encode(val, bl);
-  encode(vel, bl);
   ENCODE_FINISH(bl);
 }
 
@@ -39,51 +38,43 @@ void DecayCounter::decode(bufferlist::const_iterator &p)
   }
   decode(val, p);
   if (struct_v < 5) {
-    double delta;
+    double delta, _;
     decode(delta, p);
     val += delta;
+    decode(_, p); /* velocity */
   }
-  decode(vel, p);
   last_decay = clock::now();
   DECODE_FINISH(p);
 }
 
 void DecayCounter::dump(Formatter *f) const
 {
-  decay(rate);
+  decay();
   f->dump_float("value", val);
-  f->dump_float("velocity", vel);
+  f->dump_float("halflife", rate.k);
 }
 
 void DecayCounter::generate_test_instances(std::list<DecayCounter*>& ls)
 {
   DecayCounter *counter = new DecayCounter();
   counter->val = 3.0;
-  counter->vel = 1.0;
+  counter->rate = DecayRate(2.0);
   ls.push_back(counter);
   counter = new DecayCounter();
   ls.push_back(counter);
 }
 
-void DecayCounter::decay(const DecayRate &rate) const
+void DecayCounter::decay(double delta) const
 {
   auto now = clock::now();
-  if (now > last_decay) {
-    double el = std::chrono::duration<double>(now - last_decay).count();
-    if (el <= 0.1)
-      return; /* no need to decay for small differences */
+  double el = std::chrono::duration<double>(now - last_decay).count();
 
-    // calculate new value
-    double newval = val * exp(el * rate.k);
-    if (newval < .01) {
-      newval = 0.0;
-    }
-
-    // calculate velocity approx
-    vel += (newval - val) * el;
-    vel *= exp(el * rate.k);
-
-    val = newval;
-    last_decay = now;
+  // calculate new value
+  double newval = val * exp(el * rate.k) + delta;
+  if (newval < .01) {
+    newval = 0.0;
   }
+
+  val = newval;
+  last_decay = now;
 }
index 47ec0670118be76ee8b2dab37b5d022c4ff19fa3..33d400e1d83355bab33ea7de8dd51a74c58dc981 100644 (file)
@@ -67,7 +67,7 @@ public:
    */
 
   double get() const {
-    decay(rate);
+    decay();
     return val;
   }
 
@@ -75,10 +75,6 @@ public:
     return val;
   }
   
-  double get_last_vel() const {
-    return vel;
-  }
-
   time get_last_decay() const {
     return last_decay; 
   }
@@ -88,21 +84,15 @@ public:
    */
 
   double hit(double v = 1.0) {
-    decay(rate);
-    val += v;
+    decay(v);
     return val;
   }
-
-  void adjust(double a) {
-    decay(rate);
-    val += a;
-    if (val < 0)
-      val = 0;
+  void adjust(double v = 1.0) {
+    decay(v);
   }
 
   void scale(double f) {
     val *= f;
-    vel *= f;
   }
 
   /**
@@ -111,15 +101,15 @@ public:
 
   void reset() {
     last_decay = clock::now();
-    val = vel = 0;
+    val = 0;
   }
 
 protected:
-  void decay(const DecayRate &rate) const;
+  void decay(double delta) const;
+  void decay() const {decay(0.0);}
 
 private:
   mutable double val = 0.0;           // value
-  mutable double vel = 0.0;           // recent velocity
   mutable time last_decay = clock::zero();   // time of last decay
   DecayRate rate;
 };