From 81195954986697d4e7007e3116c04ef0450da7be Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Wed, 31 Aug 2011 10:25:28 +1000 Subject: [PATCH] Fix the bouncing short term value by allowing it to change dynamically when the latest value is very different from the rolling value, but damp the change when it gets close. --- main.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 4d01a49b..77ac515c 100644 --- a/main.c +++ b/main.c @@ -1355,10 +1355,24 @@ static inline int dev_from_id(int thr_id) return thr_info[thr_id].cgpu->cpu_gpu; } -/* Simulate a rolling average by faking an exponential decay over 5 * log */ -static inline void decay_time(double *f, double fadd) +/* Make the change in the recent value adjust dynamically when the difference + * is large, but damp it when the values are closer together. This allows the + * value to change quickly, but not fluctuate too dramatically when it has + * stabilised. */ +static void decay_time(double *f, double fadd) { - *f = (fadd * .37 + *f) / 1.37; + double ratio = 0; + + if (likely(*f > 0)) { + ratio = fadd / *f; + if (ratio > 1) + ratio = 1 / ratio; + } + + if (ratio > 0.9) + *f = (fadd * 0.1 + *f) / 1.1; + else + *f = (fadd + *f * 0.1) / 1.1; } static int requests_staged(void)