master
h 65 lines 2.28 KB
Raw
1 /*
2 * QEMU timed average computation
3 *
4 * Copyright (C) Nodalink, EURL. 2014
5 * Copyright (C) Igalia, S.L. 2015
6 *
7 * Authors:
8 * Benoît Canet <benoit.canet@nodalink.com>
9 * Alberto Garcia <berto@igalia.com>
10 *
11 * SPDX-License-Identifier: GPL-2.0-or-later
12 *
13 * This program is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 */
26
27 #ifndef TIMED_AVERAGE_H
28 #define TIMED_AVERAGE_H
29
30
31 #include "qemu/timer.h"
32
33 typedef struct TimedAverageWindow TimedAverageWindow;
34 typedef struct TimedAverage TimedAverage;
35
36 /* All fields of both structures are private */
37
38 struct TimedAverageWindow {
39 uint64_t min; /* minimum value accounted in the window */
40 uint64_t max; /* maximum value accounted in the window */
41 uint64_t sum; /* sum of all values */
42 uint64_t count; /* number of values */
43 int64_t expiration; /* the end of the current window in ns */
44 };
45
46 struct TimedAverage {
47 uint64_t period; /* period in nanoseconds */
48 TimedAverageWindow windows[2]; /* two overlapping windows of with
49 * an offset of period / 2 between them */
50 unsigned current; /* the current window index: it's also the
51 * oldest window index */
52 QEMUClockType clock_type; /* the clock used */
53 };
54
55 void timed_average_init(TimedAverage *ta, QEMUClockType clock_type,
56 uint64_t period);
57
58 void timed_average_account(TimedAverage *ta, uint64_t value);
59
60 uint64_t timed_average_min(TimedAverage *ta);
61 uint64_t timed_average_avg(TimedAverage *ta);
62 uint64_t timed_average_max(TimedAverage *ta);
63 uint64_t timed_average_sum(TimedAverage *ta, uint64_t *elapsed);
64
65 #endif