2 * QEMU block throttling group infrastructure
4 * Copyright (C) Nodalink, EURL. 2014
5 * Copyright (C) Igalia, S.L. 2015
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.
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 THROTTLE_GROUPS_H
26 #define THROTTLE_GROUPS_H
28 #include "qemu/throttle.h"
29 #include "block/block_int.h"
31 /* The ThrottleGroupMember structure indicates membership in a ThrottleGroup
32 * and holds related data.
35 typedef struct ThrottleGroupMember {
36 AioContext *aio_context;
37 /* throttled_reqs_lock protects the CoQueues for throttled requests. */
38 CoMutex throttled_reqs_lock;
39 CoQueue throttled_reqs[2];
41 /* Nonzero if the I/O limits are currently being ignored; generally
42 * it is zero. Accessed with atomic operations.
44 unsigned int io_limits_disabled;
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;
54 } ThrottleGroupMember;
56 const char *throttle_group_get_name(ThrottleGroupMember *tgm);
58 ThrottleState *throttle_group_incref(const char *name);
59 void throttle_group_unref(ThrottleState *ts);
61 void throttle_group_config(ThrottleGroupMember *tgm, ThrottleConfig *cfg);
62 void throttle_group_get_config(ThrottleGroupMember *tgm, ThrottleConfig *cfg);
64 void throttle_group_register_tgm(ThrottleGroupMember *tgm,
65 const char *groupname,
67 void throttle_group_unregister_tgm(ThrottleGroupMember *tgm);
68 void throttle_group_restart_tgm(ThrottleGroupMember *tgm);
70 void coroutine_fn throttle_group_co_io_limits_intercept(ThrottleGroupMember *tgm,
73 void throttle_group_attach_aio_context(ThrottleGroupMember *tgm,
74 AioContext *new_context);
75 void throttle_group_detach_aio_context(ThrottleGroupMember *tgm);