blob: e2fd0513c4bc189d0b7771c4424ac2e4347c9580 [file] [log] [blame]
Alberto Garcia2ff1f2e2015-06-08 18:17:42 +02001/*
2 * QEMU block throttling group infrastructure
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 * 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_GROUPS_H
26#define THROTTLE_GROUPS_H
27
28#include "qemu/throttle.h"
29#include "block/block_int.h"
30
Manos Pitsidianakis022cdc92017-08-25 16:20:23 +030031/* The ThrottleGroupMember structure indicates membership in a ThrottleGroup
32 * and holds related data.
33 */
34
35typedef struct ThrottleGroupMember {
Manos Pitsidianakisc61791f2017-08-25 16:20:24 +030036 AioContext *aio_context;
Manos Pitsidianakis022cdc92017-08-25 16:20:23 +030037 /* throttled_reqs_lock protects the CoQueues for throttled requests. */
38 CoMutex throttled_reqs_lock;
39 CoQueue throttled_reqs[2];
40
41 /* Nonzero if the I/O limits are currently being ignored; generally
42 * it is zero. Accessed with atomic operations.
43 */
44 unsigned int io_limits_disabled;
45
46 /* The following fields are protected by the ThrottleGroup lock.
47 * See the ThrottleGroup documentation for details.
48 * throttle_state tells us if I/O limits are configured. */
49 ThrottleState *throttle_state;
50 ThrottleTimers throttle_timers;
51 unsigned pending_reqs[2];
52 QLIST_ENTRY(ThrottleGroupMember) round_robin;
53
54} ThrottleGroupMember;
55
Manos Pitsidianakis432d8892017-08-25 16:20:26 +030056#define TYPE_THROTTLE_GROUP "throttle-group"
57#define THROTTLE_GROUP(obj) OBJECT_CHECK(ThrottleGroup, (obj), TYPE_THROTTLE_GROUP)
58
Manos Pitsidianakis022cdc92017-08-25 16:20:23 +030059const char *throttle_group_get_name(ThrottleGroupMember *tgm);
Alberto Garcia2ff1f2e2015-06-08 18:17:42 +020060
Max Reitz973f2dd2015-10-19 17:53:23 +020061ThrottleState *throttle_group_incref(const char *name);
62void throttle_group_unref(ThrottleState *ts);
63
Manos Pitsidianakis022cdc92017-08-25 16:20:23 +030064void throttle_group_config(ThrottleGroupMember *tgm, ThrottleConfig *cfg);
65void throttle_group_get_config(ThrottleGroupMember *tgm, ThrottleConfig *cfg);
Alberto Garcia2ff1f2e2015-06-08 18:17:42 +020066
Manos Pitsidianakis022cdc92017-08-25 16:20:23 +030067void throttle_group_register_tgm(ThrottleGroupMember *tgm,
Manos Pitsidianakisc61791f2017-08-25 16:20:24 +030068 const char *groupname,
69 AioContext *ctx);
Manos Pitsidianakis022cdc92017-08-25 16:20:23 +030070void throttle_group_unregister_tgm(ThrottleGroupMember *tgm);
71void throttle_group_restart_tgm(ThrottleGroupMember *tgm);
Alberto Garcia2ff1f2e2015-06-08 18:17:42 +020072
Manos Pitsidianakis022cdc92017-08-25 16:20:23 +030073void coroutine_fn throttle_group_co_io_limits_intercept(ThrottleGroupMember *tgm,
Alberto Garcia76f4afb2015-06-08 18:17:44 +020074 unsigned int bytes,
75 bool is_write);
Manos Pitsidianakisc61791f2017-08-25 16:20:24 +030076void throttle_group_attach_aio_context(ThrottleGroupMember *tgm,
77 AioContext *new_context);
78void throttle_group_detach_aio_context(ThrottleGroupMember *tgm);
Manos Pitsidianakisd8e7d872017-08-25 16:20:27 +030079/*
80 * throttle_group_exists() must be called under the global
81 * mutex.
82 */
83bool throttle_group_exists(const char *name);
Alberto Garcia76f4afb2015-06-08 18:17:44 +020084
Alberto Garcia2ff1f2e2015-06-08 18:17:42 +020085#endif