Add the infrastructure that will be used to compute I/O accouting averages
cover Add the infrastructure that will be used to compute I/O accouting averages
Tiny module of code to maintain and compute timed average on a given period. It comes with unit tests so we are sure the code will not bitrot while waiting for the accouting code to use it.
Best regards
Benoît
Benoît Canet (2):
timers: Move NANOSECONDS_PER_SECONDS to timer.h for future reuse
util: Add an utility infrastructure used to compute an average on a
time slice
include/qemu/throttle.h | 2 - include/qemu/timed-average.h | 45 +++++++++++++++++++ include/qemu/timer.h | 2 + tests/Makefile | 2 + tests/test-timed-average.c | 53 ++++++++++++++++++++++ util/Makefile.objs | 1 + util/timed-average.c | 102 +++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 205 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.0
PATCH 1/2 timers: Move NANOSECONDS_PER_SECONDS to timer.h for future reuse
--- 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.0 - 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.0 +/* timers */ #define SCALE_MS 1000000
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH 1/2] timers: Move NANOSECONDS_PER_SECONDS to timer.h for future reuse
Quoted 24 lines · Benoît Canet
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.0 - typedef enum { THROTTLE_BPS_TOTAL, THROTTLE_BPS_READ,include/qemu/timer.h +0
-0
include/qemu/timer.h line 8
Quoted 4 lines
include/qemu/timer.h +1
-0@@ -5,6 +5,8 @@#include "qemu-common.h" #include "qemu/notify.h" +#define NANOSECONDS_PER_SECOND 1000000000.0
I was slightly surprised to see this was a floating point constant rather than an integer. I wonder if we'll get bitten by that in future...
-- PMM
Re: [Qemu-devel] [PATCH 1/2] timers: Move NANOSECONDS_PER_SECONDS to timer.h for future reuse
Quoted 28 lines · Peter Maydell
Quoted 27 lines · Benoît Canet
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.0 - typedef enum { THROTTLE_BPS_TOTAL, THROTTLE_BPS_READ,include/qemu/timer.h +0
-0@@ -5,6 +5,8 @@#include "qemu-common.h" #include "qemu/notify.h"
Quoted 5 lines
include/qemu/timer.h line 8
Quoted 1 line
include/qemu/timer.h +1
-0+#define NANOSECONDS_PER_SECOND 1000000000.0I was slightly surprised to see this was a floating point constant rather than an integer. I wonder if we'll get bitten by that in future...
The origin is the throttle code which does a lot of computation on double. I'll check if throttle works fine with this constants as an integer.
Best regards
Benoît
Quoted 2 lines
-- PMM
PATCH 2/2 util: Add an utility infrastructure used to compute an average on a time slice
In reply to Benoît CanetThe algorithm used was defined on the list while discussing the new IO accounting overhaul.
See http://lists.nongnu.org/archive/html/qemu-devel/2014-08/msg04954.html
--- include/qemu/timed-average.h | 45 +++++++++++++++++++ tests/Makefile | 2 + tests/test-timed-average.c | 53 ++++++++++++++++++++++ util/Makefile.objs | 1 + util/timed-average.c | 102 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 203 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 +45 -0
@@ -0,0 +1,45 @@ +/* +* 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 or +* (at your option) version 3 of the License. +* +* 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 TimedAverage { +uint64_t sum;/* sum of the discrete values */ +uint64_t count;/* number of values */ +uint64_t period;/* period in seconds */ +int64_t expiration;/* the end of the current period slice in ns */ +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_get (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 libqemustub.a 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 +53 -0
53 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 +102 -0
102 lines not on this page · raw message
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH 2/2] util: Add an utility infrastructure used to compute an average on a time slice
Quoted 11 lines · Benoît Canet
The algorithm used was defined on the list while discussing the new IO accounting overhaul.
See http://lists.nongnu.org/archive/html/qemu-devel/2014-08/msg04954.htmlSigned-off-by 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 or
+ * (at your option) version 3 of the License.
GPLv2/3 is not as nice as GPLv2+. It prohibits your code from being used in GPLv4 if that turns out to be incompatible with both earlier versions (the way GPLv3 cannot be used with GPLv2-only). Any chance you can relax this?
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 2/2] util: Add an utility infrastructure used to compute an average on a time slice
Quoted 13 lines · Eric Blake
Quoted 11 lines · Benoît Canet
The algorithm used was defined on the list while discussing the new IO accounting overhaul.
See http://lists.nongnu.org/archive/html/qemu-devel/2014-08/msg04954.htmlSigned-off-by 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 or
+ * (at your option) version 3 of the License.
Quoted 4 lines
GPLv2/3 is not as nice as GPLv2+. It prohibits your code from being used in GPLv4 if that turns out to be incompatible with both earlier versions (the way GPLv3 cannot be used with GPLv2-only). Any chance you can relax this?
Sure.
Quoted 5 lines
Signature · 3 lines
-- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org