From: Patrick Donnelly Date: Sat, 9 Jun 2018 04:15:58 +0000 (-0700) Subject: DecayCounter: removed unused velocity X-Git-Tag: v14.0.1~1102^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=201cc8ea010ce5cef1a235976022c3eb48041417;p=ceph.git DecayCounter: removed unused velocity It's not actually used anywhere and it's not accurate. Signed-off-by: Patrick Donnelly --- diff --git a/src/common/DecayCounter.cc b/src/common/DecayCounter.cc index 1144daaf068ec..cbf38d6b0754c 100644 --- a/src/common/DecayCounter.cc +++ b/src/common/DecayCounter.cc @@ -19,10 +19,9 @@ 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& 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(now - last_decay).count(); - if (el <= 0.1) - return; /* no need to decay for small differences */ + double el = std::chrono::duration(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; } diff --git a/src/common/DecayCounter.h b/src/common/DecayCounter.h index 47ec0670118be..33d400e1d8335 100644 --- a/src/common/DecayCounter.h +++ b/src/common/DecayCounter.h @@ -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; };