]> Git Repo - qemu.git/blame - include/qemu/throttle.h
throttle: Merge all functions that check the configuration into one
[qemu.git] / include / qemu / throttle.h
CommitLineData
5ddfffbd
BC
1/*
2 * QEMU throttling infrastructure
3 *
a291d5d9
AG
4 * Copyright (C) Nodalink, EURL. 2013-2014
5 * Copyright (C) Igalia, S.L. 2015
5ddfffbd 6 *
a291d5d9
AG
7 * Authors:
8 * Benoît Canet <[email protected]>
9 * Alberto Garcia <[email protected]>
5ddfffbd
BC
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 or
14 * (at your option) version 3 of the License.
15 *
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.
20 *
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/>.
23 */
24
25#ifndef THROTTLE_H
26#define THROTTLE_H
27
28#include <stdint.h>
29#include "qemu-common.h"
30#include "qemu/timer.h"
31
972606c4
FZ
32#define THROTTLE_VALUE_MAX 1000000000000000LL
33
5ddfffbd
BC
34typedef enum {
35 THROTTLE_BPS_TOTAL,
36 THROTTLE_BPS_READ,
37 THROTTLE_BPS_WRITE,
38 THROTTLE_OPS_TOTAL,
39 THROTTLE_OPS_READ,
40 THROTTLE_OPS_WRITE,
41 BUCKETS_COUNT,
42} BucketType;
43
44/*
45 * The max parameter of the leaky bucket throttling algorithm can be used to
46 * allow the guest to do bursts.
47 * The max value is a pool of I/O that the guest can use without being throttled
48 * at all. Throttling is triggered once this pool is empty.
49 */
50
51typedef struct LeakyBucket {
52 double avg; /* average goal in units per second */
53 double max; /* leaky bucket max burst in units */
54 double level; /* bucket level in units */
55} LeakyBucket;
56
57/* The following structure is used to configure a ThrottleState
58 * It contains a bit of state: the bucket field of the LeakyBucket structure.
59 * However it allows to keep the code clean and the bucket field is reset to
60 * zero at the right time.
61 */
62typedef struct ThrottleConfig {
63 LeakyBucket buckets[BUCKETS_COUNT]; /* leaky buckets */
64 uint64_t op_size; /* size of an operation in bytes */
65} ThrottleConfig;
66
67typedef struct ThrottleState {
68 ThrottleConfig cfg; /* configuration */
69 int64_t previous_leak; /* timestamp of the last leak done */
0e5b0a2d
BC
70} ThrottleState;
71
72typedef struct ThrottleTimers {
73 QEMUTimer *timers[2]; /* timers used to do the throttling */
5ddfffbd 74 QEMUClockType clock_type; /* the clock used */
13af91eb
SH
75
76 /* Callbacks */
77 QEMUTimerCB *read_timer_cb;
78 QEMUTimerCB *write_timer_cb;
79 void *timer_opaque;
0e5b0a2d 80} ThrottleTimers;
5ddfffbd
BC
81
82/* operations on single leaky buckets */
83void throttle_leak_bucket(LeakyBucket *bkt, int64_t delta);
84
85int64_t throttle_compute_wait(LeakyBucket *bkt);
86
5ddfffbd 87/* init/destroy cycle */
0e5b0a2d
BC
88void throttle_init(ThrottleState *ts);
89
90void throttle_timers_init(ThrottleTimers *tt,
91 AioContext *aio_context,
92 QEMUClockType clock_type,
93 QEMUTimerCB *read_timer_cb,
94 QEMUTimerCB *write_timer_cb,
95 void *timer_opaque);
5ddfffbd 96
0e5b0a2d 97void throttle_timers_destroy(ThrottleTimers *tt);
5ddfffbd 98
0e5b0a2d 99void throttle_timers_detach_aio_context(ThrottleTimers *tt);
13af91eb 100
0e5b0a2d
BC
101void throttle_timers_attach_aio_context(ThrottleTimers *tt,
102 AioContext *new_context);
13af91eb 103
0e5b0a2d 104bool throttle_timers_are_initialized(ThrottleTimers *tt);
5ddfffbd
BC
105
106/* configuration */
107bool throttle_enabled(ThrottleConfig *cfg);
108
03ba36c8 109bool throttle_is_valid(ThrottleConfig *cfg, Error **errp);
5ddfffbd 110
0e5b0a2d
BC
111void throttle_config(ThrottleState *ts,
112 ThrottleTimers *tt,
113 ThrottleConfig *cfg);
5ddfffbd
BC
114
115void throttle_get_config(ThrottleState *ts, ThrottleConfig *cfg);
116
117/* usage */
0e5b0a2d
BC
118bool throttle_schedule_timer(ThrottleState *ts,
119 ThrottleTimers *tt,
120 bool is_write);
5ddfffbd
BC
121
122void throttle_account(ThrottleState *ts, bool is_write, uint64_t size);
123
124#endif
This page took 0.167945 seconds and 4 git commands to generate.