timed average infrastructure for use in block statistics
v3 cover timed average infrastructure for use in block statistics
Hi,
Here is the new iteration of the timed average module.
A better algorithm avoiding unwanted noise has been implemented and the test have been rewritten as suggested.
Best regards
in V3:
Add Eric rev by of patch 2
drop unneeded (double) casts [Eric]
Implement new algorithm [Paolo]
rewrite commit message [Markus]
stub cpu_get_clock in tests [Paolo]
Benoît
Benoît Canet (3):
throttle: Make NANOSECONDS_PER_SECOND an integer
timers: Move NANOSECONDS_PER_SECONDS to timer.h for future reuse
util: Infrastructure for computing recent averages
include/qemu/throttle.h | 2 - include/qemu/timed-average.h | 60 +++++++++++++ include/qemu/timer.h | 2 + tests/Makefile | 2 + tests/test-timed-average.c | 89 ++++++++++++++++++ util/Makefile.objs | 1 + util/timed-average.c | 208 +++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 362 insertions(+), 2 deletions(-) create mode 100644 include/qemu/timed-average.h create mode 100644 tests/test-timed-average.c create mode 100644 util/timed-average.c
Signature · 1 line
2.1.1
PATCH v3 1/3 throttle: Make NANOSECONDS_PER_SECOND an integer
We will want to reuse this define in the future by making it common to multiple QEMU modules.
It would be safer that this define be an integer so we avoid strange float rounding errors.
Do this conversion.
--- include/qemu/throttle.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/qemu/throttle.h +1 -1
@@ -27,7 +27,7 @@#include "qemu-common.h" #include "qemu/timer.h" -#define NANOSECONDS_PER_SECOND 1000000000.0 +#define NANOSECONDS_PER_SECOND 1000000000 typedef enum { THROTTLE_BPS_TOTAL,
Signature · 1 line
2.1.1
Re: [Qemu-devel] [PATCH v3 1/3] throttle: Make NANOSECONDS_PER_SECOND an integer
Quoted 10 lines · Benoît Canet
We will want to reuse this define in the future by making it common to multiple QEMU modules.
It would be safer that this define be an integer so we avoid strange float rounding errors.
Do this conversion.Signed-off-by Benoît Canet <[email protected]>--- include/qemu/throttle.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines
include/qemu/throttle.h +1
-1@@ -27,7 +27,7 @@#include "qemu-common.h" #include "qemu/timer.h" -#define NANOSECONDS_PER_SECOND 1000000000.0 +#define NANOSECONDS_PER_SECOND 1000000000 typedef enum { THROTTLE_BPS_TOTAL,
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v3 2/3 timers: Move NANOSECONDS_PER_SECONDS to timer.h for future reuse
In reply to Benoît Canet--- include/qemu/throttle.h | 2 -- include/qemu/timer.h | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-)
include/qemu/throttle.h +0 -2
@@ -27,8 +27,6 @@#include "qemu-common.h" #include "qemu/timer.h" -#define NANOSECONDS_PER_SECOND 1000000000 - typedef enum { THROTTLE_BPS_TOTAL, THROTTLE_BPS_READ,
include/qemu/timer.h +2 -0
@@ -5,6 +5,8 @@#include "qemu-common.h" #include "qemu/notify.h" +#define NANOSECONDS_PER_SECOND 1000000000 +/* timers */ #define SCALE_MS 1000000
Signature · 1 line
2.1.1
Re: [Qemu-devel] [PATCH v3 2/3] timers: Move NANOSECONDS_PER_SECONDS to timer.h for future reuse
Il 24/09/2014 17:21, Benoît Canet ha scritto:
Quoted 26 lines
Reviewed-by Eric Blake <[email protected]>Signed-off-by Benoît Canet <[email protected]>--- include/qemu/throttle.h | 2 -- include/qemu/timer.h | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-)include/qemu/throttle.h +0
-2@@ -27,8 +27,6 @@#include "qemu-common.h" #include "qemu/timer.h" -#define NANOSECONDS_PER_SECOND 1000000000 - typedef enum { THROTTLE_BPS_TOTAL, THROTTLE_BPS_READ,include/qemu/timer.h +0
-0
include/qemu/timer.h line 12
Quoted 8 lines
include/qemu/timer.h +2
-0@@ -5,6 +5,8 @@#include "qemu-common.h" #include "qemu/notify.h" +#define NANOSECONDS_PER_SECOND 1000000000 +/* timers */ #define SCALE_MS 1000000
Went through all uses, for the two that matter:
util/throttle.c: leak = (bkt->avg * (double) delta_ns) / NANOSECONDS_PER_SECOND; util/throttle.c: double wait = extra * NANOSECONDS_PER_SECOND;
the other operand is already double.
Re: [Qemu-devel] [PATCH v3 2/3] timers: Move NANOSECONDS_PER_SECONDS to timer.h for future reuse
In reply to Benoît CanetIl 24/09/2014 17:21, Benoît Canet ha scritto:
Quoted 26 lines
Reviewed-by Eric Blake <[email protected]>Signed-off-by Benoît Canet <[email protected]>--- include/qemu/throttle.h | 2 -- include/qemu/timer.h | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-)include/qemu/throttle.h +0
-2@@ -27,8 +27,6 @@#include "qemu-common.h" #include "qemu/timer.h" -#define NANOSECONDS_PER_SECOND 1000000000 - typedef enum { THROTTLE_BPS_TOTAL, THROTTLE_BPS_READ,include/qemu/timer.h +0
-0
include/qemu/timer.h line 12
Quoted 8 lines
include/qemu/timer.h +2
-0@@ -5,6 +5,8 @@#include "qemu-common.h" #include "qemu/notify.h" +#define NANOSECONDS_PER_SECOND 1000000000 +/* timers */ #define SCALE_MS 1000000
:)
Re: [Qemu-devel] [PATCH v3 2/3] timers: Move NANOSECONDS_PER_SECONDS to timer.h for future reuse
Quoted 33 lines · Paolo Bonzini
Il 24/09/2014 17:21, Benoît Canet ha scritto:
Quoted 32 lines
Reviewed-by Eric Blake <[email protected]>Signed-off-by Benoît Canet <[email protected]>--- include/qemu/throttle.h | 2 -- include/qemu/timer.h | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-)include/qemu/throttle.h +0
-2@@ -27,8 +27,6 @@#include "qemu-common.h" #include "qemu/timer.h" -#define NANOSECONDS_PER_SECOND 1000000000 - typedef enum { THROTTLE_BPS_TOTAL, THROTTLE_BPS_READ,include/qemu/timer.h +2
-0@@ -5,6 +5,8 @@#include "qemu-common.h" #include "qemu/notify.h" +#define NANOSECONDS_PER_SECOND 1000000000 +/* timers */
Quoted 6 lines
include/qemu/timer.h line 12
Quoted 2 lines
include/qemu/timer.h +0
-0#define SCALE_MS 1000000Reviewed-by Paolo Bonzini <[email protected]>:)
Two rev by for one commit are better than one but does this belong to the third commit ? :)
Best regards
Benoît
Re: [Qemu-devel] [PATCH v3 2/3] timers: Move NANOSECONDS_PER_SECONDS to timer.h for future reuse
Il 29/09/2014 18:04, Benoît Canet ha scritto:
Quoted 39 lines · Paolo Bonzini
Quoted 38 lines
Il 24/09/2014 17:21, Benoît Canet ha scritto:
Quoted 26 lines
Reviewed-by Eric Blake <[email protected]>Signed-off-by Benoît Canet <[email protected]>--- include/qemu/throttle.h | 2 -- include/qemu/timer.h | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-)include/qemu/throttle.h +0
-2@@ -27,8 +27,6 @@#include "qemu-common.h" #include "qemu/timer.h" -#define NANOSECONDS_PER_SECOND 1000000000 - typedef enum { THROTTLE_BPS_TOTAL, THROTTLE_BPS_READ,include/qemu/timer.h +0
-0include/qemu/timer.h line 12
Quoted 8 lines
include/qemu/timer.h +2
-0@@ -5,6 +5,8 @@#include "qemu-common.h" #include "qemu/notify.h" +#define NANOSECONDS_PER_SECOND 1000000000 +/* timers */ #define SCALE_MS 1000000Reviewed-by Paolo Bonzini <[email protected]>
Quoted 4 lines
Quoted 1 line
:)
Two rev by for one commit are better than one but does this belong to the third commit ? :)
The rev-bys belong to the first and second. The third's on my list...
Paolo
Re: [Qemu-devel] [PATCH v3 2/3] timers: Move NANOSECONDS_PER_SECONDS to timer.h for future reuse
Quoted 40 lines · Paolo Bonzini
Il 29/09/2014 18:04, Benoît Canet ha scritto:
Quoted 39 lines · Paolo Bonzini
Quoted 38 lines
Il 24/09/2014 17:21, Benoît Canet ha scritto:
Quoted 26 lines
Reviewed-by Eric Blake <[email protected]>Signed-off-by Benoît Canet <[email protected]>--- include/qemu/throttle.h | 2 -- include/qemu/timer.h | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-)include/qemu/throttle.h +0
-2@@ -27,8 +27,6 @@#include "qemu-common.h" #include "qemu/timer.h" -#define NANOSECONDS_PER_SECOND 1000000000 - typedef enum { THROTTLE_BPS_TOTAL, THROTTLE_BPS_READ,include/qemu/timer.h +0
-0include/qemu/timer.h line 12
Quoted 8 lines
include/qemu/timer.h +2
-0@@ -5,6 +5,8 @@#include "qemu-common.h" #include "qemu/notify.h" +#define NANOSECONDS_PER_SECOND 1000000000 +/* timers */ #define SCALE_MS 1000000Reviewed-by Paolo Bonzini <[email protected]>
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
:)
Two rev by for one commit are better than one but does this belong to the third commit ? :)
The rev-bys belong to the first and second. The third's on my list...
I misread (freudian slip) the 20 seconds delta between the two rev-by as 20 min. 20 min was credible but 20 seconds is not despite you being fast :)
Best regards
Benoît
Quoted 2 lines
Paolo
PATCH v3 3/3 util: Infrastructure for computing recent averages
In reply to Benoît CanetThe module takes care of computing minimal and maximal values over the time slice duration.
--- include/qemu/timed-average.h | 60 +++++++++++++ tests/Makefile | 2 + tests/test-timed-average.c | 89 ++++++++++++++++++ util/Makefile.objs | 1 + util/timed-average.c | 208 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 360 insertions(+) create mode 100644 include/qemu/timed-average.h create mode 100644 tests/test-timed-average.c create mode 100644 util/timed-average.c
include/qemu/timed-average.h new file +60 -0
@@ -0,0 +1,60 @@ +/* +* QEMU timed average computation +* +* Copyright (C) Nodalink, EURL. 2014 +* +* Author: +* Benoît Canet <[email protected]> +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) version 3 or any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef TIMED_AVERAGE_H +#define TIMED_AVERAGE_H + +#include <stdint.h> + +#include "qemu/timer.h" + +typedef struct Window { +uint64_t min;/* minimal value accounted in the window */ +uint64_t max;/* maximal value accounted in the window */ +uint64_t sum;/* sum of the discrete values */ +uint64_t count;/* number of values */ +int64_t expiration;/* the end of the current window in ns */ +}Window ; + +typedef struct TimedAverage { +Window windows[2 ];/* two overlapping windows of period +* nanoseconds with an offset of period / 2 +* between them +*/ + +uint64_t period;/* period in nanoseconds */ +uint64_t current;/* the current window index: it's also the +* oldest window index +*/ +QEMUClockType clock_type;/* the clock used */ +}TimedAverage ; + +void timed_average_init (TimedAverage *ta,QEMUClockType clock_type, +uint64_t period); + +void timed_average_account (TimedAverage *ta,uint64_t value); + +uint64_t timed_average_min (TimedAverage *ta); +uint64_t timed_average_avg (TimedAverage *ta); +uint64_t timed_average_max (TimedAverage *ta); + +#endif
tests/Makefile +2 -0
@@ -64,6 +64,7 @@ gcov-files-check-qom-interface-y = qom/object.c check-unit-$(CONFIG_POSIX) += tests/test-vmstate$(EXESUF) check-unit-y += tests/test-qemu-opts$(EXESUF) gcov-files-test-qemu-opts-y = qom/test-qemu-opts.c +check-unit-y += tests/test-timed-average$(EXESUF) check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
@@ -259,6 +260,7 @@ tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o \ tests/test-vmstate$(EXESUF): tests/test-vmstate.o \ vmstate.o qemu-file.o \ libqemuutil.a +tests/test-timed-average$(EXESUF): tests/test-timed-average.o qemu-timer.o libqemuutil.a stubs/clock-warp.o stubs/cpu-get-icount.o stubs/notify-event.o tests/test-qapi-types.c tests/test-qapi-types.h :\ $(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-types.py
tests/test-timed-average.c new file +89 -0
89 lines not on this page · raw message
util/Makefile.objs +1 -0
@@ -15,3 +15,4 @@ util-obj-y += throttle.o util-obj-y += getauxval.o util-obj-y += readline.o util-obj-y += rfifolock.o +util-obj-y += timed-average.o
util/timed-average.c new file +208 -0
208 lines not on this page · raw message
Signature · 1 line
2.1.1
Re: [Qemu-devel] [PATCH v3 3/3] util: Infrastructure for computing recent averages
Il 24/09/2014 17:21, Benoît Canet ha scritto:
Quoted 2 lines
The module takes care of computing minimal and maximal values over the time slice duration.
The code looks good, just two comments:
Quoted 4 lines
util/timed-average.c new file +4
-0+/* Get the average value +* +* @ta: the timed average structure used +* @ret: the average value
util/timed-average.c line 193
Quoted 10 lines
util/timed-average.c new file +10
-0+*/ +uint64_t timed_average_avg (TimedAverage *ta) +{ +Window *w; +check_expirations (ta); + + w =current_window (ta); + +if (w->count) { +return w->sum / w->count;
First, do we want this to return double?
Second, this will return the min/max/avg in an unknown amount of time between period/2 and period---on average period*3/4, e.g. 0.75 seconds for a period equal to one second.
Would it make sense to tweak the TimedAverage period to be higher, e.g. 1.33 seconds/80 seconds/80 minutes, so that the _average_ period is 1 second/1 minute/1 hour?
This only applies to how the code is used, not to TimedAverage itself; hence, feel free to post the patch with Reviewed-by once timed_average_avg's return type is changed to a double.
Paolo
Quoted 16 lines
util/timed-average.c new file +15
-0+ } + +return 0 ; +} + +/* Get the maximum value +* +* @ta: the timed average structure used +* @ret: the maximal value +*/ +uint64_t timed_average_max (TimedAverage *ta) +{ +check_expirations (ta); +return current_window (ta)->max; +}
Re: [Qemu-devel] [PATCH v3 3/3] util: Infrastructure for computing recent averages
Quoted 27 lines · Paolo Bonzini
Il 24/09/2014 17:21, Benoît Canet ha scritto:
Quoted 2 lines
The module takes care of computing minimal and maximal values over the time slice duration.
The code looks good, just two comments:
Quoted 4 lines
util/timed-average.c new file +4
-0+/* Get the average value +* +* @ta: the timed average structure used +* @ret: the average value util/timed-average.c line 193
Quoted 10 lines
util/timed-average.c new file +10
-0+*/ +uint64_t timed_average_avg (TimedAverage *ta) +{ +Window *w; +check_expirations (ta); + + w =current_window (ta); + +if (w->count) { +return w->sum / w->count;First, do we want this to return double?
Second, this will return the min/max/avg in an unknown amount of time between period/2 and period---on average period*3/4, e.g. 0.75 seconds for a period equal to one second.
Quoted 7 lines
Would it make sense to tweak the TimedAverage period to be higher, e.g. 1.33 seconds/80 seconds/80 minutes, so that the _average_ period is 1 second/1 minute/1 hour?
This only applies to how the code is used, not to TimedAverage itself; hence, feel free to post the patch with Reviewed-by once timed_average_avg's return type is changed to a double.
This would require either changing _init period units or making it a float or baking the 1.33 ratio in timed average.
Which one would you prefer ?
Best regards
Benoît
Thanks for reviewing.
Quoted 20 lines
Paolo
Quoted 16 lines
util/timed-average.c new file +15
-0+ } + +return 0 ; +} + +/* Get the maximum value +* +* @ta: the timed average structure used +* @ret: the maximal value +*/ +uint64_t timed_average_max (TimedAverage *ta) +{ +check_expirations (ta); +return current_window (ta)->max; +}