xref: /openbmc/qemu/include/block/throttle-groups.h (revision db1015e92e04835c9eb50c29625fe566d1202dbd)
12ff1f2e3SAlberto Garcia /*
22ff1f2e3SAlberto Garcia  * QEMU block throttling group infrastructure
32ff1f2e3SAlberto Garcia  *
42ff1f2e3SAlberto Garcia  * Copyright (C) Nodalink, EURL. 2014
52ff1f2e3SAlberto Garcia  * Copyright (C) Igalia, S.L. 2015
62ff1f2e3SAlberto Garcia  *
72ff1f2e3SAlberto Garcia  * Authors:
82ff1f2e3SAlberto Garcia  *   Benoît Canet <benoit.canet@nodalink.com>
92ff1f2e3SAlberto Garcia  *   Alberto Garcia <berto@igalia.com>
102ff1f2e3SAlberto Garcia  *
112ff1f2e3SAlberto Garcia  * This program is free software; you can redistribute it and/or
122ff1f2e3SAlberto Garcia  * modify it under the terms of the GNU General Public License as
132ff1f2e3SAlberto Garcia  * published by the Free Software Foundation; either version 2 or
142ff1f2e3SAlberto Garcia  * (at your option) version 3 of the License.
152ff1f2e3SAlberto Garcia  *
162ff1f2e3SAlberto Garcia  * This program is distributed in the hope that it will be useful,
172ff1f2e3SAlberto Garcia  * but WITHOUT ANY WARRANTY; without even the implied warranty of
182ff1f2e3SAlberto Garcia  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
192ff1f2e3SAlberto Garcia  * GNU General Public License for more details.
202ff1f2e3SAlberto Garcia  *
212ff1f2e3SAlberto Garcia  * You should have received a copy of the GNU General Public License
222ff1f2e3SAlberto Garcia  * along with this program; if not, see <http://www.gnu.org/licenses/>.
232ff1f2e3SAlberto Garcia  */
242ff1f2e3SAlberto Garcia 
252ff1f2e3SAlberto Garcia #ifndef THROTTLE_GROUPS_H
262ff1f2e3SAlberto Garcia #define THROTTLE_GROUPS_H
272ff1f2e3SAlberto Garcia 
282ff1f2e3SAlberto Garcia #include "qemu/throttle.h"
292ff1f2e3SAlberto Garcia #include "block/block_int.h"
30*db1015e9SEduardo Habkost #include "qom/object.h"
312ff1f2e3SAlberto Garcia 
32022cdc9fSManos Pitsidianakis /* The ThrottleGroupMember structure indicates membership in a ThrottleGroup
33022cdc9fSManos Pitsidianakis  * and holds related data.
34022cdc9fSManos Pitsidianakis  */
35022cdc9fSManos Pitsidianakis 
36022cdc9fSManos Pitsidianakis typedef struct ThrottleGroupMember {
37c61791fcSManos Pitsidianakis     AioContext   *aio_context;
38022cdc9fSManos Pitsidianakis     /* throttled_reqs_lock protects the CoQueues for throttled requests.  */
39022cdc9fSManos Pitsidianakis     CoMutex      throttled_reqs_lock;
40022cdc9fSManos Pitsidianakis     CoQueue      throttled_reqs[2];
41022cdc9fSManos Pitsidianakis 
42022cdc9fSManos Pitsidianakis     /* Nonzero if the I/O limits are currently being ignored; generally
43022cdc9fSManos Pitsidianakis      * it is zero.  Accessed with atomic operations.
44022cdc9fSManos Pitsidianakis      */
45022cdc9fSManos Pitsidianakis     unsigned int io_limits_disabled;
46022cdc9fSManos Pitsidianakis 
47bc19a0a6SStefan Hajnoczi     /* Number of pending throttle_group_restart_queue_entry() coroutines.
48bc19a0a6SStefan Hajnoczi      * Accessed with atomic operations.
49bc19a0a6SStefan Hajnoczi      */
50bc19a0a6SStefan Hajnoczi     unsigned int restart_pending;
51bc19a0a6SStefan Hajnoczi 
52022cdc9fSManos Pitsidianakis     /* The following fields are protected by the ThrottleGroup lock.
53022cdc9fSManos Pitsidianakis      * See the ThrottleGroup documentation for details.
54022cdc9fSManos Pitsidianakis      * throttle_state tells us if I/O limits are configured. */
55022cdc9fSManos Pitsidianakis     ThrottleState *throttle_state;
56022cdc9fSManos Pitsidianakis     ThrottleTimers throttle_timers;
57022cdc9fSManos Pitsidianakis     unsigned       pending_reqs[2];
58022cdc9fSManos Pitsidianakis     QLIST_ENTRY(ThrottleGroupMember) round_robin;
59022cdc9fSManos Pitsidianakis 
60022cdc9fSManos Pitsidianakis } ThrottleGroupMember;
61022cdc9fSManos Pitsidianakis 
62432d889eSManos Pitsidianakis #define TYPE_THROTTLE_GROUP "throttle-group"
637c9dcd6cSEduardo Habkost typedef struct ThrottleGroup ThrottleGroup;
64432d889eSManos Pitsidianakis #define THROTTLE_GROUP(obj) OBJECT_CHECK(ThrottleGroup, (obj), TYPE_THROTTLE_GROUP)
65432d889eSManos Pitsidianakis 
66022cdc9fSManos Pitsidianakis const char *throttle_group_get_name(ThrottleGroupMember *tgm);
672ff1f2e3SAlberto Garcia 
68973f2ddfSMax Reitz ThrottleState *throttle_group_incref(const char *name);
69973f2ddfSMax Reitz void throttle_group_unref(ThrottleState *ts);
70973f2ddfSMax Reitz 
71022cdc9fSManos Pitsidianakis void throttle_group_config(ThrottleGroupMember *tgm, ThrottleConfig *cfg);
72022cdc9fSManos Pitsidianakis void throttle_group_get_config(ThrottleGroupMember *tgm, ThrottleConfig *cfg);
732ff1f2e3SAlberto Garcia 
74022cdc9fSManos Pitsidianakis void throttle_group_register_tgm(ThrottleGroupMember *tgm,
75c61791fcSManos Pitsidianakis                                 const char *groupname,
76c61791fcSManos Pitsidianakis                                 AioContext *ctx);
77022cdc9fSManos Pitsidianakis void throttle_group_unregister_tgm(ThrottleGroupMember *tgm);
78022cdc9fSManos Pitsidianakis void throttle_group_restart_tgm(ThrottleGroupMember *tgm);
792ff1f2e3SAlberto Garcia 
80022cdc9fSManos Pitsidianakis void coroutine_fn throttle_group_co_io_limits_intercept(ThrottleGroupMember *tgm,
8176f4afb4SAlberto Garcia                                                         unsigned int bytes,
8276f4afb4SAlberto Garcia                                                         bool is_write);
83c61791fcSManos Pitsidianakis void throttle_group_attach_aio_context(ThrottleGroupMember *tgm,
84c61791fcSManos Pitsidianakis                                        AioContext *new_context);
85c61791fcSManos Pitsidianakis void throttle_group_detach_aio_context(ThrottleGroupMember *tgm);
86d8e7d87eSManos Pitsidianakis /*
87d8e7d87eSManos Pitsidianakis  * throttle_group_exists() must be called under the global
88d8e7d87eSManos Pitsidianakis  * mutex.
89d8e7d87eSManos Pitsidianakis  */
90d8e7d87eSManos Pitsidianakis bool throttle_group_exists(const char *name);
9176f4afb4SAlberto Garcia 
922ff1f2e3SAlberto Garcia #endif
93