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