]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
DecayCounter: remove unnecessary delta member
authorPatrick Donnelly <pdonnell@redhat.com>
Fri, 8 Jun 2018 22:02:17 +0000 (15:02 -0700)
committerPatrick Donnelly <pdonnell@redhat.com>
Fri, 15 Jun 2018 14:04:42 +0000 (07:04 -0700)
We can just add/sub to val directly (especially now that decay can be called on
a const DecayCounter).

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

index b06267c11ed9912e27a9e47e236f7454b9d49866..1144daaf068ec934c4eaa29e6610b1206ccbf8fd 100644 (file)
 
 void DecayCounter::encode(bufferlist& bl) const
 {
-  ENCODE_START(4, 4, bl);
+  decay(rate);
+  ENCODE_START(5, 4, bl);
   encode(val, bl);
-  encode(delta, bl);
   encode(vel, bl);
   ENCODE_FINISH(bl);
 }
 
 void DecayCounter::decode(bufferlist::const_iterator &p)
 {
-  DECODE_START_LEGACY_COMPAT_LEN(4, 4, 4, p);
+  DECODE_START_LEGACY_COMPAT_LEN(5, 4, 4, p);
   if (struct_v < 2) {
     double half_life = 0.0;
     decode(half_life, p);
@@ -38,7 +38,11 @@ void DecayCounter::decode(bufferlist::const_iterator &p)
     decode(k, p);
   }
   decode(val, p);
-  decode(delta, p);
+  if (struct_v < 5) {
+    double delta;
+    decode(delta, p);
+    val += delta;
+  }
   decode(vel, p);
   last_decay = clock::now();
   DECODE_FINISH(p);
@@ -48,7 +52,6 @@ void DecayCounter::dump(Formatter *f) const
 {
   decay(rate);
   f->dump_float("value", val);
-  f->dump_float("delta", delta);
   f->dump_float("velocity", vel);
 }
 
@@ -56,7 +59,6 @@ void DecayCounter::generate_test_instances(std::list<DecayCounter*>& ls)
 {
   DecayCounter *counter = new DecayCounter();
   counter->val = 3.0;
-  counter->delta = 2.0;
   counter->vel = 1.0;
   ls.push_back(counter);
   counter = new DecayCounter();
@@ -72,7 +74,7 @@ void DecayCounter::decay(const DecayRate &rate) const
       return; /* no need to decay for small differences */
 
     // calculate new value
-    double newval = (val+delta) * exp(el * rate.k);
+    double newval = val * exp(el * rate.k);
     if (newval < .01) {
       newval = 0.0;
     }
@@ -82,7 +84,6 @@ void DecayCounter::decay(const DecayRate &rate) const
     vel *= exp(el * rate.k);
 
     val = newval;
-    delta = 0;
     last_decay = now;
   }
 }
index a3f47653fe0dae3b5f4bf0a715b40a424f4ff665..47ec0670118be76ee8b2dab37b5d022c4ff19fa3 100644 (file)
@@ -68,7 +68,7 @@ public:
 
   double get() const {
     decay(rate);
-    return val+delta;
+    return val;
   }
 
   double get_last() const {
@@ -89,8 +89,8 @@ public:
 
   double hit(double v = 1.0) {
     decay(rate);
-    delta += v;
-    return val+delta;
+    val += v;
+    return val;
   }
 
   void adjust(double a) {
@@ -102,7 +102,6 @@ public:
 
   void scale(double f) {
     val *= f;
-    delta *= f;    
     vel *= f;
   }
 
@@ -112,7 +111,7 @@ public:
 
   void reset() {
     last_decay = clock::now();
-    val = delta = 0;
+    val = vel = 0;
   }
 
 protected:
@@ -120,7 +119,6 @@ protected:
 
 private:
   mutable double val = 0.0;           // value
-  mutable double delta = 0.0;         // delta since last decay
   mutable double vel = 0.0;           // recent velocity
   mutable time last_decay = clock::zero();   // time of last decay
   DecayRate rate;