Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 1 | /* |
| 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 | |
Peter Maydell | 80c71a2 | 2016-01-18 18:01:42 +0000 | [diff] [blame] | 25 | #include "qemu/osdep.h" |
Kevin Wolf | 31dce3c | 2016-03-21 11:30:57 +0100 | [diff] [blame] | 26 | #include "sysemu/block-backend.h" |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 27 | #include "block/throttle-groups.h" |
Manos Pitsidianakis | 432d889 | 2017-08-25 16:20:26 +0300 | [diff] [blame] | 28 | #include "qemu/throttle-options.h" |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 29 | #include "qemu/queue.h" |
| 30 | #include "qemu/thread.h" |
| 31 | #include "sysemu/qtest.h" |
Manos Pitsidianakis | 432d889 | 2017-08-25 16:20:26 +0300 | [diff] [blame] | 32 | #include "qapi/error.h" |
Markus Armbruster | 9af2398 | 2018-02-11 10:36:01 +0100 | [diff] [blame] | 33 | #include "qapi/qapi-visit-block-core.h" |
Manos Pitsidianakis | 432d889 | 2017-08-25 16:20:26 +0300 | [diff] [blame] | 34 | #include "qom/object.h" |
| 35 | #include "qom/object_interfaces.h" |
| 36 | |
| 37 | static void throttle_group_obj_init(Object *obj); |
| 38 | static void throttle_group_obj_complete(UserCreatable *obj, Error **errp); |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 39 | |
| 40 | /* The ThrottleGroup structure (with its ThrottleState) is shared |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 41 | * among different ThrottleGroupMembers and it's independent from |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 42 | * AioContext, so in order to use it from different threads it needs |
| 43 | * its own locking. |
| 44 | * |
| 45 | * This locking is however handled internally in this file, so it's |
Alberto Garcia | d87d01e | 2015-10-21 21:36:05 +0300 | [diff] [blame] | 46 | * transparent to outside users. |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 47 | * |
| 48 | * The whole ThrottleGroup structure is private and invisible to |
| 49 | * outside users, that only use it through its ThrottleState. |
| 50 | * |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 51 | * In addition to the ThrottleGroup structure, ThrottleGroupMember has |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 52 | * fields that need to be accessed by other members of the group and |
Kevin Wolf | 27ccdd5 | 2016-03-21 12:56:44 +0100 | [diff] [blame] | 53 | * therefore also need to be protected by this lock. Once a |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 54 | * ThrottleGroupMember is registered in a group those fields can be accessed |
Kevin Wolf | 27ccdd5 | 2016-03-21 12:56:44 +0100 | [diff] [blame] | 55 | * by other threads any time. |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 56 | * |
| 57 | * Again, all this is handled internally and is mostly transparent to |
| 58 | * the outside. The 'throttle_timers' field however has an additional |
| 59 | * constraint because it may be temporarily invalid (see for example |
Alberto Garcia | 0d2fac8 | 2017-06-14 00:16:12 +0300 | [diff] [blame] | 60 | * blk_set_aio_context()). Therefore in this file a thread will |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 61 | * access some other ThrottleGroupMember's timers only after verifying that |
| 62 | * that ThrottleGroupMember has throttled requests in the queue. |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 63 | */ |
| 64 | typedef struct ThrottleGroup { |
Manos Pitsidianakis | 432d889 | 2017-08-25 16:20:26 +0300 | [diff] [blame] | 65 | Object parent_obj; |
| 66 | |
| 67 | /* refuse individual property change if initialization is complete */ |
| 68 | bool is_initialized; |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 69 | char *name; /* This is constant during the lifetime of the group */ |
| 70 | |
| 71 | QemuMutex lock; /* This lock protects the following four fields */ |
| 72 | ThrottleState ts; |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 73 | QLIST_HEAD(, ThrottleGroupMember) head; |
| 74 | ThrottleGroupMember *tokens[2]; |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 75 | bool any_timer_armed[2]; |
Manos Pitsidianakis | dbe824c | 2017-07-02 13:06:45 +0300 | [diff] [blame] | 76 | QEMUClockType clock_type; |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 77 | |
Manos Pitsidianakis | 432d889 | 2017-08-25 16:20:26 +0300 | [diff] [blame] | 78 | /* This field is protected by the global QEMU mutex */ |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 79 | QTAILQ_ENTRY(ThrottleGroup) list; |
| 80 | } ThrottleGroup; |
| 81 | |
Manos Pitsidianakis | 432d889 | 2017-08-25 16:20:26 +0300 | [diff] [blame] | 82 | /* This is protected by the global QEMU mutex */ |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 83 | static QTAILQ_HEAD(, ThrottleGroup) throttle_groups = |
| 84 | QTAILQ_HEAD_INITIALIZER(throttle_groups); |
| 85 | |
Manos Pitsidianakis | 432d889 | 2017-08-25 16:20:26 +0300 | [diff] [blame] | 86 | |
| 87 | /* This function reads throttle_groups and must be called under the global |
| 88 | * mutex. |
| 89 | */ |
| 90 | static ThrottleGroup *throttle_group_by_name(const char *name) |
| 91 | { |
| 92 | ThrottleGroup *iter; |
| 93 | |
| 94 | /* Look for an existing group with that name */ |
| 95 | QTAILQ_FOREACH(iter, &throttle_groups, list) { |
| 96 | if (!g_strcmp0(name, iter->name)) { |
| 97 | return iter; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | return NULL; |
| 102 | } |
| 103 | |
Manos Pitsidianakis | d8e7d87 | 2017-08-25 16:20:27 +0300 | [diff] [blame] | 104 | /* This function reads throttle_groups and must be called under the global |
| 105 | * mutex. |
| 106 | */ |
| 107 | bool throttle_group_exists(const char *name) |
| 108 | { |
| 109 | return throttle_group_by_name(name) != NULL; |
| 110 | } |
| 111 | |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 112 | /* Increments the reference count of a ThrottleGroup given its name. |
| 113 | * |
| 114 | * If no ThrottleGroup is found with the given name a new one is |
| 115 | * created. |
| 116 | * |
Manos Pitsidianakis | 432d889 | 2017-08-25 16:20:26 +0300 | [diff] [blame] | 117 | * This function edits throttle_groups and must be called under the global |
| 118 | * mutex. |
| 119 | * |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 120 | * @name: the name of the ThrottleGroup |
Max Reitz | 973f2dd | 2015-10-19 17:53:23 +0200 | [diff] [blame] | 121 | * @ret: the ThrottleState member of the ThrottleGroup |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 122 | */ |
Max Reitz | 973f2dd | 2015-10-19 17:53:23 +0200 | [diff] [blame] | 123 | ThrottleState *throttle_group_incref(const char *name) |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 124 | { |
| 125 | ThrottleGroup *tg = NULL; |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 126 | |
| 127 | /* Look for an existing group with that name */ |
Manos Pitsidianakis | 432d889 | 2017-08-25 16:20:26 +0300 | [diff] [blame] | 128 | tg = throttle_group_by_name(name); |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 129 | |
Manos Pitsidianakis | 432d889 | 2017-08-25 16:20:26 +0300 | [diff] [blame] | 130 | if (tg) { |
| 131 | object_ref(OBJECT(tg)); |
| 132 | } else { |
| 133 | /* Create a new one if not found */ |
| 134 | /* new ThrottleGroup obj will have a refcnt = 1 */ |
| 135 | tg = THROTTLE_GROUP(object_new(TYPE_THROTTLE_GROUP)); |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 136 | tg->name = g_strdup(name); |
Manos Pitsidianakis | 432d889 | 2017-08-25 16:20:26 +0300 | [diff] [blame] | 137 | throttle_group_obj_complete(USER_CREATABLE(tg), &error_abort); |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 138 | } |
| 139 | |
Max Reitz | 973f2dd | 2015-10-19 17:53:23 +0200 | [diff] [blame] | 140 | return &tg->ts; |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /* Decrease the reference count of a ThrottleGroup. |
| 144 | * |
| 145 | * When the reference count reaches zero the ThrottleGroup is |
| 146 | * destroyed. |
| 147 | * |
Manos Pitsidianakis | 432d889 | 2017-08-25 16:20:26 +0300 | [diff] [blame] | 148 | * This function edits throttle_groups and must be called under the global |
| 149 | * mutex. |
| 150 | * |
Max Reitz | 973f2dd | 2015-10-19 17:53:23 +0200 | [diff] [blame] | 151 | * @ts: The ThrottleGroup to unref, given by its ThrottleState member |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 152 | */ |
Max Reitz | 973f2dd | 2015-10-19 17:53:23 +0200 | [diff] [blame] | 153 | void throttle_group_unref(ThrottleState *ts) |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 154 | { |
Max Reitz | 973f2dd | 2015-10-19 17:53:23 +0200 | [diff] [blame] | 155 | ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts); |
Manos Pitsidianakis | 432d889 | 2017-08-25 16:20:26 +0300 | [diff] [blame] | 156 | object_unref(OBJECT(tg)); |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 157 | } |
| 158 | |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 159 | /* Get the name from a ThrottleGroupMember's group. The name (and the pointer) |
Kevin Wolf | 49d2165 | 2016-03-21 11:58:21 +0100 | [diff] [blame] | 160 | * is guaranteed to remain constant during the lifetime of the group. |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 161 | * |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 162 | * @tgm: a ThrottleGroupMember |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 163 | * @ret: the name of the group. |
| 164 | */ |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 165 | const char *throttle_group_get_name(ThrottleGroupMember *tgm) |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 166 | { |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 167 | ThrottleGroup *tg = container_of(tgm->throttle_state, ThrottleGroup, ts); |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 168 | return tg->name; |
| 169 | } |
| 170 | |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 171 | /* Return the next ThrottleGroupMember in the round-robin sequence, simulating |
| 172 | * a circular list. |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 173 | * |
| 174 | * This assumes that tg->lock is held. |
| 175 | * |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 176 | * @tgm: the current ThrottleGroupMember |
| 177 | * @ret: the next ThrottleGroupMember in the sequence |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 178 | */ |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 179 | static ThrottleGroupMember *throttle_group_next_tgm(ThrottleGroupMember *tgm) |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 180 | { |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 181 | ThrottleState *ts = tgm->throttle_state; |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 182 | ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts); |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 183 | ThrottleGroupMember *next = QLIST_NEXT(tgm, round_robin); |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 184 | |
| 185 | if (!next) { |
Kevin Wolf | 31dce3c | 2016-03-21 11:30:57 +0100 | [diff] [blame] | 186 | next = QLIST_FIRST(&tg->head); |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 187 | } |
| 188 | |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 189 | return next; |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 190 | } |
| 191 | |
Alberto Garcia | 6bf77e1 | 2016-10-17 18:46:02 +0300 | [diff] [blame] | 192 | /* |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 193 | * Return whether a ThrottleGroupMember has pending requests. |
Alberto Garcia | 6bf77e1 | 2016-10-17 18:46:02 +0300 | [diff] [blame] | 194 | * |
| 195 | * This assumes that tg->lock is held. |
| 196 | * |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 197 | * @tgm: the ThrottleGroupMember |
| 198 | * @is_write: the type of operation (read/write) |
| 199 | * @ret: whether the ThrottleGroupMember has pending requests. |
Alberto Garcia | 6bf77e1 | 2016-10-17 18:46:02 +0300 | [diff] [blame] | 200 | */ |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 201 | static inline bool tgm_has_pending_reqs(ThrottleGroupMember *tgm, |
Alberto Garcia | 6bf77e1 | 2016-10-17 18:46:02 +0300 | [diff] [blame] | 202 | bool is_write) |
| 203 | { |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 204 | return tgm->pending_reqs[is_write]; |
Alberto Garcia | 6bf77e1 | 2016-10-17 18:46:02 +0300 | [diff] [blame] | 205 | } |
| 206 | |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 207 | /* Return the next ThrottleGroupMember in the round-robin sequence with pending |
| 208 | * I/O requests. |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 209 | * |
| 210 | * This assumes that tg->lock is held. |
| 211 | * |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 212 | * @tgm: the current ThrottleGroupMember |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 213 | * @is_write: the type of operation (read/write) |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 214 | * @ret: the next ThrottleGroupMember with pending requests, or tgm if |
| 215 | * there is none. |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 216 | */ |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 217 | static ThrottleGroupMember *next_throttle_token(ThrottleGroupMember *tgm, |
| 218 | bool is_write) |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 219 | { |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 220 | ThrottleState *ts = tgm->throttle_state; |
| 221 | ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts); |
| 222 | ThrottleGroupMember *token, *start; |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 223 | |
| 224 | start = token = tg->tokens[is_write]; |
| 225 | |
| 226 | /* get next bs round in round robin style */ |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 227 | token = throttle_group_next_tgm(token); |
| 228 | while (token != start && !tgm_has_pending_reqs(token, is_write)) { |
| 229 | token = throttle_group_next_tgm(token); |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | /* If no IO are queued for scheduling on the next round robin token |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 233 | * then decide the token is the current tgm because chances are |
| 234 | * the current tgm got the current request queued. |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 235 | */ |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 236 | if (token == start && !tgm_has_pending_reqs(token, is_write)) { |
| 237 | token = tgm; |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 238 | } |
| 239 | |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 240 | /* Either we return the original TGM, or one with pending requests */ |
| 241 | assert(token == tgm || tgm_has_pending_reqs(token, is_write)); |
Alberto Garcia | 6bf77e1 | 2016-10-17 18:46:02 +0300 | [diff] [blame] | 242 | |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 243 | return token; |
| 244 | } |
| 245 | |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 246 | /* Check if the next I/O request for a ThrottleGroupMember needs to be |
| 247 | * throttled or not. If there's no timer set in this group, set one and update |
| 248 | * the token accordingly. |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 249 | * |
| 250 | * This assumes that tg->lock is held. |
| 251 | * |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 252 | * @tgm: the current ThrottleGroupMember |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 253 | * @is_write: the type of operation (read/write) |
| 254 | * @ret: whether the I/O request needs to be throttled or not |
| 255 | */ |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 256 | static bool throttle_group_schedule_timer(ThrottleGroupMember *tgm, |
| 257 | bool is_write) |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 258 | { |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 259 | ThrottleState *ts = tgm->throttle_state; |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 260 | ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts); |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 261 | ThrottleTimers *tt = &tgm->throttle_timers; |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 262 | bool must_wait; |
| 263 | |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 264 | if (atomic_read(&tgm->io_limits_disabled)) { |
Paolo Bonzini | ce0f141 | 2016-04-07 18:33:33 +0200 | [diff] [blame] | 265 | return false; |
| 266 | } |
| 267 | |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 268 | /* Check if any of the timers in this group is already armed */ |
| 269 | if (tg->any_timer_armed[is_write]) { |
| 270 | return true; |
| 271 | } |
| 272 | |
| 273 | must_wait = throttle_schedule_timer(ts, tt, is_write); |
| 274 | |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 275 | /* If a timer just got armed, set tgm as the current token */ |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 276 | if (must_wait) { |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 277 | tg->tokens[is_write] = tgm; |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 278 | tg->any_timer_armed[is_write] = true; |
| 279 | } |
| 280 | |
| 281 | return must_wait; |
| 282 | } |
| 283 | |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 284 | /* Start the next pending I/O request for a ThrottleGroupMember. Return whether |
Paolo Bonzini | 3b170dc | 2017-06-05 14:38:57 +0200 | [diff] [blame] | 285 | * any request was actually pending. |
| 286 | * |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 287 | * @tgm: the current ThrottleGroupMember |
Paolo Bonzini | 3b170dc | 2017-06-05 14:38:57 +0200 | [diff] [blame] | 288 | * @is_write: the type of operation (read/write) |
| 289 | */ |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 290 | static bool coroutine_fn throttle_group_co_restart_queue(ThrottleGroupMember *tgm, |
Paolo Bonzini | 3b170dc | 2017-06-05 14:38:57 +0200 | [diff] [blame] | 291 | bool is_write) |
| 292 | { |
Paolo Bonzini | 93001e9 | 2017-06-05 14:38:58 +0200 | [diff] [blame] | 293 | bool ret; |
Paolo Bonzini | 3b170dc | 2017-06-05 14:38:57 +0200 | [diff] [blame] | 294 | |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 295 | qemu_co_mutex_lock(&tgm->throttled_reqs_lock); |
| 296 | ret = qemu_co_queue_next(&tgm->throttled_reqs[is_write]); |
| 297 | qemu_co_mutex_unlock(&tgm->throttled_reqs_lock); |
Paolo Bonzini | 93001e9 | 2017-06-05 14:38:58 +0200 | [diff] [blame] | 298 | |
| 299 | return ret; |
Paolo Bonzini | 3b170dc | 2017-06-05 14:38:57 +0200 | [diff] [blame] | 300 | } |
| 301 | |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 302 | /* Look for the next pending I/O request and schedule it. |
| 303 | * |
| 304 | * This assumes that tg->lock is held. |
| 305 | * |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 306 | * @tgm: the current ThrottleGroupMember |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 307 | * @is_write: the type of operation (read/write) |
| 308 | */ |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 309 | static void schedule_next_request(ThrottleGroupMember *tgm, bool is_write) |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 310 | { |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 311 | ThrottleState *ts = tgm->throttle_state; |
| 312 | ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts); |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 313 | bool must_wait; |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 314 | ThrottleGroupMember *token; |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 315 | |
| 316 | /* Check if there's any pending request to schedule next */ |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 317 | token = next_throttle_token(tgm, is_write); |
| 318 | if (!tgm_has_pending_reqs(token, is_write)) { |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 319 | return; |
| 320 | } |
| 321 | |
| 322 | /* Set a timer for the request if it needs to be throttled */ |
| 323 | must_wait = throttle_group_schedule_timer(token, is_write); |
| 324 | |
| 325 | /* If it doesn't have to wait, queue it for immediate execution */ |
| 326 | if (!must_wait) { |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 327 | /* Give preference to requests from the current tgm */ |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 328 | if (qemu_in_coroutine() && |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 329 | throttle_group_co_restart_queue(tgm, is_write)) { |
| 330 | token = tgm; |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 331 | } else { |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 332 | ThrottleTimers *tt = &token->throttle_timers; |
Manos Pitsidianakis | dbe824c | 2017-07-02 13:06:45 +0300 | [diff] [blame] | 333 | int64_t now = qemu_clock_get_ns(tg->clock_type); |
Paolo Bonzini | 7258ed9 | 2017-06-05 14:38:56 +0200 | [diff] [blame] | 334 | timer_mod(tt->timers[is_write], now); |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 335 | tg->any_timer_armed[is_write] = true; |
| 336 | } |
| 337 | tg->tokens[is_write] = token; |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | /* Check if an I/O request needs to be throttled, wait and set a timer |
| 342 | * if necessary, and schedule the next request using a round robin |
| 343 | * algorithm. |
| 344 | * |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 345 | * @tgm: the current ThrottleGroupMember |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 346 | * @bytes: the number of bytes for this I/O |
| 347 | * @is_write: the type of operation (read/write) |
| 348 | */ |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 349 | void coroutine_fn throttle_group_co_io_limits_intercept(ThrottleGroupMember *tgm, |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 350 | unsigned int bytes, |
| 351 | bool is_write) |
| 352 | { |
| 353 | bool must_wait; |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 354 | ThrottleGroupMember *token; |
| 355 | ThrottleGroup *tg = container_of(tgm->throttle_state, ThrottleGroup, ts); |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 356 | qemu_mutex_lock(&tg->lock); |
| 357 | |
| 358 | /* First we check if this I/O has to be throttled. */ |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 359 | token = next_throttle_token(tgm, is_write); |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 360 | must_wait = throttle_group_schedule_timer(token, is_write); |
| 361 | |
| 362 | /* Wait if there's a timer set or queued requests of this type */ |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 363 | if (must_wait || tgm->pending_reqs[is_write]) { |
| 364 | tgm->pending_reqs[is_write]++; |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 365 | qemu_mutex_unlock(&tg->lock); |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 366 | qemu_co_mutex_lock(&tgm->throttled_reqs_lock); |
| 367 | qemu_co_queue_wait(&tgm->throttled_reqs[is_write], |
| 368 | &tgm->throttled_reqs_lock); |
| 369 | qemu_co_mutex_unlock(&tgm->throttled_reqs_lock); |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 370 | qemu_mutex_lock(&tg->lock); |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 371 | tgm->pending_reqs[is_write]--; |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | /* The I/O will be executed, so do the accounting */ |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 375 | throttle_account(tgm->throttle_state, is_write, bytes); |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 376 | |
| 377 | /* Schedule the next request */ |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 378 | schedule_next_request(tgm, is_write); |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 379 | |
| 380 | qemu_mutex_unlock(&tg->lock); |
| 381 | } |
| 382 | |
Paolo Bonzini | 3b170dc | 2017-06-05 14:38:57 +0200 | [diff] [blame] | 383 | typedef struct { |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 384 | ThrottleGroupMember *tgm; |
Paolo Bonzini | 3b170dc | 2017-06-05 14:38:57 +0200 | [diff] [blame] | 385 | bool is_write; |
| 386 | } RestartData; |
| 387 | |
| 388 | static void coroutine_fn throttle_group_restart_queue_entry(void *opaque) |
Paolo Bonzini | 7258ed9 | 2017-06-05 14:38:56 +0200 | [diff] [blame] | 389 | { |
Paolo Bonzini | 3b170dc | 2017-06-05 14:38:57 +0200 | [diff] [blame] | 390 | RestartData *data = opaque; |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 391 | ThrottleGroupMember *tgm = data->tgm; |
| 392 | ThrottleState *ts = tgm->throttle_state; |
| 393 | ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts); |
Paolo Bonzini | 3b170dc | 2017-06-05 14:38:57 +0200 | [diff] [blame] | 394 | bool is_write = data->is_write; |
Paolo Bonzini | 7258ed9 | 2017-06-05 14:38:56 +0200 | [diff] [blame] | 395 | bool empty_queue; |
| 396 | |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 397 | empty_queue = !throttle_group_co_restart_queue(tgm, is_write); |
Paolo Bonzini | 7258ed9 | 2017-06-05 14:38:56 +0200 | [diff] [blame] | 398 | |
| 399 | /* If the request queue was empty then we have to take care of |
| 400 | * scheduling the next one */ |
| 401 | if (empty_queue) { |
| 402 | qemu_mutex_lock(&tg->lock); |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 403 | schedule_next_request(tgm, is_write); |
Paolo Bonzini | 7258ed9 | 2017-06-05 14:38:56 +0200 | [diff] [blame] | 404 | qemu_mutex_unlock(&tg->lock); |
| 405 | } |
Manos Pitsidianakis | 43a5dc0 | 2017-09-18 23:25:29 +0300 | [diff] [blame] | 406 | |
| 407 | g_free(data); |
Paolo Bonzini | 7258ed9 | 2017-06-05 14:38:56 +0200 | [diff] [blame] | 408 | } |
| 409 | |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 410 | static void throttle_group_restart_queue(ThrottleGroupMember *tgm, bool is_write) |
Paolo Bonzini | 3b170dc | 2017-06-05 14:38:57 +0200 | [diff] [blame] | 411 | { |
| 412 | Coroutine *co; |
Manos Pitsidianakis | 43a5dc0 | 2017-09-18 23:25:29 +0300 | [diff] [blame] | 413 | RestartData *rd = g_new0(RestartData, 1); |
Paolo Bonzini | 3b170dc | 2017-06-05 14:38:57 +0200 | [diff] [blame] | 414 | |
Manos Pitsidianakis | 43a5dc0 | 2017-09-18 23:25:29 +0300 | [diff] [blame] | 415 | rd->tgm = tgm; |
| 416 | rd->is_write = is_write; |
| 417 | |
| 418 | co = qemu_coroutine_create(throttle_group_restart_queue_entry, rd); |
Manos Pitsidianakis | c61791f | 2017-08-25 16:20:24 +0300 | [diff] [blame] | 419 | aio_co_enter(tgm->aio_context, co); |
Paolo Bonzini | 3b170dc | 2017-06-05 14:38:57 +0200 | [diff] [blame] | 420 | } |
| 421 | |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 422 | void throttle_group_restart_tgm(ThrottleGroupMember *tgm) |
Paolo Bonzini | a72f641 | 2016-04-07 18:33:31 +0200 | [diff] [blame] | 423 | { |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 424 | if (tgm->throttle_state) { |
| 425 | throttle_group_restart_queue(tgm, 0); |
| 426 | throttle_group_restart_queue(tgm, 1); |
Paolo Bonzini | a72f641 | 2016-04-07 18:33:31 +0200 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 430 | /* Update the throttle configuration for a particular group. Similar |
| 431 | * to throttle_config(), but guarantees atomicity within the |
| 432 | * throttling group. |
| 433 | * |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 434 | * @tgm: a ThrottleGroupMember that is a member of the group |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 435 | * @cfg: the configuration to set |
| 436 | */ |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 437 | void throttle_group_config(ThrottleGroupMember *tgm, ThrottleConfig *cfg) |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 438 | { |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 439 | ThrottleState *ts = tgm->throttle_state; |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 440 | ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts); |
| 441 | qemu_mutex_lock(&tg->lock); |
Manos Pitsidianakis | 27e4cf1 | 2017-07-02 13:06:46 +0300 | [diff] [blame] | 442 | throttle_config(ts, tg->clock_type, cfg); |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 443 | qemu_mutex_unlock(&tg->lock); |
Paolo Bonzini | a72f641 | 2016-04-07 18:33:31 +0200 | [diff] [blame] | 444 | |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 445 | throttle_group_restart_tgm(tgm); |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | /* Get the throttle configuration from a particular group. Similar to |
| 449 | * throttle_get_config(), but guarantees atomicity within the |
| 450 | * throttling group. |
| 451 | * |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 452 | * @tgm: a ThrottleGroupMember that is a member of the group |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 453 | * @cfg: the configuration will be written here |
| 454 | */ |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 455 | void throttle_group_get_config(ThrottleGroupMember *tgm, ThrottleConfig *cfg) |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 456 | { |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 457 | ThrottleState *ts = tgm->throttle_state; |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 458 | ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts); |
| 459 | qemu_mutex_lock(&tg->lock); |
| 460 | throttle_get_config(ts, cfg); |
| 461 | qemu_mutex_unlock(&tg->lock); |
| 462 | } |
| 463 | |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 464 | /* ThrottleTimers callback. This wakes up a request that was waiting |
| 465 | * because it had been throttled. |
| 466 | * |
Manos Pitsidianakis | c61791f | 2017-08-25 16:20:24 +0300 | [diff] [blame] | 467 | * @tgm: the ThrottleGroupMember whose request had been throttled |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 468 | * @is_write: the type of operation (read/write) |
| 469 | */ |
Manos Pitsidianakis | c61791f | 2017-08-25 16:20:24 +0300 | [diff] [blame] | 470 | static void timer_cb(ThrottleGroupMember *tgm, bool is_write) |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 471 | { |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 472 | ThrottleState *ts = tgm->throttle_state; |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 473 | ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts); |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 474 | |
| 475 | /* The timer has just been fired, so we can update the flag */ |
| 476 | qemu_mutex_lock(&tg->lock); |
| 477 | tg->any_timer_armed[is_write] = false; |
| 478 | qemu_mutex_unlock(&tg->lock); |
| 479 | |
| 480 | /* Run the request that was waiting for this timer */ |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 481 | throttle_group_restart_queue(tgm, is_write); |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | static void read_timer_cb(void *opaque) |
| 485 | { |
| 486 | timer_cb(opaque, false); |
| 487 | } |
| 488 | |
| 489 | static void write_timer_cb(void *opaque) |
| 490 | { |
| 491 | timer_cb(opaque, true); |
| 492 | } |
| 493 | |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 494 | /* Register a ThrottleGroupMember from the throttling group, also initializing |
| 495 | * its timers and updating its throttle_state pointer to point to it. If a |
Kevin Wolf | 31dce3c | 2016-03-21 11:30:57 +0100 | [diff] [blame] | 496 | * throttling group with that name does not exist yet, it will be created. |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 497 | * |
Manos Pitsidianakis | 432d889 | 2017-08-25 16:20:26 +0300 | [diff] [blame] | 498 | * This function edits throttle_groups and must be called under the global |
| 499 | * mutex. |
| 500 | * |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 501 | * @tgm: the ThrottleGroupMember to insert |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 502 | * @groupname: the name of the group |
Manos Pitsidianakis | c61791f | 2017-08-25 16:20:24 +0300 | [diff] [blame] | 503 | * @ctx: the AioContext to use |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 504 | */ |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 505 | void throttle_group_register_tgm(ThrottleGroupMember *tgm, |
Manos Pitsidianakis | c61791f | 2017-08-25 16:20:24 +0300 | [diff] [blame] | 506 | const char *groupname, |
| 507 | AioContext *ctx) |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 508 | { |
| 509 | int i; |
Max Reitz | 973f2dd | 2015-10-19 17:53:23 +0200 | [diff] [blame] | 510 | ThrottleState *ts = throttle_group_incref(groupname); |
| 511 | ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts); |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 512 | |
| 513 | tgm->throttle_state = ts; |
Manos Pitsidianakis | c61791f | 2017-08-25 16:20:24 +0300 | [diff] [blame] | 514 | tgm->aio_context = ctx; |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 515 | |
| 516 | qemu_mutex_lock(&tg->lock); |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 517 | /* If the ThrottleGroup is new set this ThrottleGroupMember as the token */ |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 518 | for (i = 0; i < 2; i++) { |
| 519 | if (!tg->tokens[i]) { |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 520 | tg->tokens[i] = tgm; |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 521 | } |
| 522 | } |
| 523 | |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 524 | QLIST_INSERT_HEAD(&tg->head, tgm, round_robin); |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 525 | |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 526 | throttle_timers_init(&tgm->throttle_timers, |
Manos Pitsidianakis | c61791f | 2017-08-25 16:20:24 +0300 | [diff] [blame] | 527 | tgm->aio_context, |
Manos Pitsidianakis | dbe824c | 2017-07-02 13:06:45 +0300 | [diff] [blame] | 528 | tg->clock_type, |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 529 | read_timer_cb, |
| 530 | write_timer_cb, |
Manos Pitsidianakis | c61791f | 2017-08-25 16:20:24 +0300 | [diff] [blame] | 531 | tgm); |
Manos Pitsidianakis | f738cfc | 2017-08-25 16:20:25 +0300 | [diff] [blame] | 532 | qemu_co_mutex_init(&tgm->throttled_reqs_lock); |
| 533 | qemu_co_queue_init(&tgm->throttled_reqs[0]); |
| 534 | qemu_co_queue_init(&tgm->throttled_reqs[1]); |
Alberto Garcia | 76f4afb | 2015-06-08 18:17:44 +0200 | [diff] [blame] | 535 | |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 536 | qemu_mutex_unlock(&tg->lock); |
| 537 | } |
| 538 | |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 539 | /* Unregister a ThrottleGroupMember from its group, removing it from the list, |
Kevin Wolf | 31dce3c | 2016-03-21 11:30:57 +0100 | [diff] [blame] | 540 | * destroying the timers and setting the throttle_state pointer to NULL. |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 541 | * |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 542 | * The ThrottleGroupMember must not have pending throttled requests, so the |
| 543 | * caller has to drain them first. |
Alberto Garcia | 5ac7241 | 2015-11-04 15:15:35 +0200 | [diff] [blame] | 544 | * |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 545 | * The group will be destroyed if it's empty after this operation. |
| 546 | * |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 547 | * @tgm the ThrottleGroupMember to remove |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 548 | */ |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 549 | void throttle_group_unregister_tgm(ThrottleGroupMember *tgm) |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 550 | { |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 551 | ThrottleState *ts = tgm->throttle_state; |
| 552 | ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts); |
| 553 | ThrottleGroupMember *token; |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 554 | int i; |
| 555 | |
Manos Pitsidianakis | d8e7d87 | 2017-08-25 16:20:27 +0300 | [diff] [blame] | 556 | if (!ts) { |
| 557 | /* Discard already unregistered tgm */ |
| 558 | return; |
| 559 | } |
| 560 | |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 561 | assert(tgm->pending_reqs[0] == 0 && tgm->pending_reqs[1] == 0); |
| 562 | assert(qemu_co_queue_empty(&tgm->throttled_reqs[0])); |
| 563 | assert(qemu_co_queue_empty(&tgm->throttled_reqs[1])); |
Alberto Garcia | 5ac7241 | 2015-11-04 15:15:35 +0200 | [diff] [blame] | 564 | |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 565 | qemu_mutex_lock(&tg->lock); |
| 566 | for (i = 0; i < 2; i++) { |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 567 | if (tg->tokens[i] == tgm) { |
| 568 | token = throttle_group_next_tgm(tgm); |
| 569 | /* Take care of the case where this is the last tgm in the group */ |
| 570 | if (token == tgm) { |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 571 | token = NULL; |
| 572 | } |
| 573 | tg->tokens[i] = token; |
| 574 | } |
| 575 | } |
| 576 | |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 577 | /* remove the current tgm from the list */ |
| 578 | QLIST_REMOVE(tgm, round_robin); |
| 579 | throttle_timers_destroy(&tgm->throttle_timers); |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 580 | qemu_mutex_unlock(&tg->lock); |
| 581 | |
Max Reitz | 973f2dd | 2015-10-19 17:53:23 +0200 | [diff] [blame] | 582 | throttle_group_unref(&tg->ts); |
Manos Pitsidianakis | 022cdc9 | 2017-08-25 16:20:23 +0300 | [diff] [blame] | 583 | tgm->throttle_state = NULL; |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 584 | } |
| 585 | |
Manos Pitsidianakis | c61791f | 2017-08-25 16:20:24 +0300 | [diff] [blame] | 586 | void throttle_group_attach_aio_context(ThrottleGroupMember *tgm, |
| 587 | AioContext *new_context) |
| 588 | { |
| 589 | ThrottleTimers *tt = &tgm->throttle_timers; |
| 590 | throttle_timers_attach_aio_context(tt, new_context); |
| 591 | tgm->aio_context = new_context; |
| 592 | } |
| 593 | |
| 594 | void throttle_group_detach_aio_context(ThrottleGroupMember *tgm) |
| 595 | { |
Stefan Hajnoczi | 341e0b5 | 2017-11-16 11:21:50 +0000 | [diff] [blame] | 596 | ThrottleGroup *tg = container_of(tgm->throttle_state, ThrottleGroup, ts); |
Manos Pitsidianakis | c61791f | 2017-08-25 16:20:24 +0300 | [diff] [blame] | 597 | ThrottleTimers *tt = &tgm->throttle_timers; |
Stefan Hajnoczi | 341e0b5 | 2017-11-16 11:21:50 +0000 | [diff] [blame] | 598 | int i; |
Stefan Hajnoczi | dc868fb | 2017-11-10 15:19:34 +0000 | [diff] [blame] | 599 | |
| 600 | /* Requests must have been drained */ |
| 601 | assert(tgm->pending_reqs[0] == 0 && tgm->pending_reqs[1] == 0); |
| 602 | assert(qemu_co_queue_empty(&tgm->throttled_reqs[0])); |
| 603 | assert(qemu_co_queue_empty(&tgm->throttled_reqs[1])); |
| 604 | |
Stefan Hajnoczi | 341e0b5 | 2017-11-16 11:21:50 +0000 | [diff] [blame] | 605 | /* Kick off next ThrottleGroupMember, if necessary */ |
| 606 | qemu_mutex_lock(&tg->lock); |
| 607 | for (i = 0; i < 2; i++) { |
| 608 | if (timer_pending(tt->timers[i])) { |
| 609 | tg->any_timer_armed[i] = false; |
| 610 | schedule_next_request(tgm, i); |
| 611 | } |
| 612 | } |
| 613 | qemu_mutex_unlock(&tg->lock); |
| 614 | |
Manos Pitsidianakis | c61791f | 2017-08-25 16:20:24 +0300 | [diff] [blame] | 615 | throttle_timers_detach_aio_context(tt); |
| 616 | tgm->aio_context = NULL; |
| 617 | } |
| 618 | |
Manos Pitsidianakis | 432d889 | 2017-08-25 16:20:26 +0300 | [diff] [blame] | 619 | #undef THROTTLE_OPT_PREFIX |
| 620 | #define THROTTLE_OPT_PREFIX "x-" |
| 621 | |
| 622 | /* Helper struct and array for QOM property setter/getter */ |
| 623 | typedef struct { |
| 624 | const char *name; |
| 625 | BucketType type; |
| 626 | enum { |
| 627 | AVG, |
| 628 | MAX, |
| 629 | BURST_LENGTH, |
| 630 | IOPS_SIZE, |
| 631 | } category; |
| 632 | } ThrottleParamInfo; |
| 633 | |
| 634 | static ThrottleParamInfo properties[] = { |
| 635 | { |
| 636 | THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_TOTAL, |
| 637 | THROTTLE_OPS_TOTAL, AVG, |
| 638 | }, |
| 639 | { |
| 640 | THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_TOTAL_MAX, |
| 641 | THROTTLE_OPS_TOTAL, MAX, |
| 642 | }, |
| 643 | { |
| 644 | THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_TOTAL_MAX_LENGTH, |
| 645 | THROTTLE_OPS_TOTAL, BURST_LENGTH, |
| 646 | }, |
| 647 | { |
| 648 | THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_READ, |
| 649 | THROTTLE_OPS_READ, AVG, |
| 650 | }, |
| 651 | { |
| 652 | THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_READ_MAX, |
| 653 | THROTTLE_OPS_READ, MAX, |
| 654 | }, |
| 655 | { |
| 656 | THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_READ_MAX_LENGTH, |
| 657 | THROTTLE_OPS_READ, BURST_LENGTH, |
| 658 | }, |
| 659 | { |
| 660 | THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_WRITE, |
| 661 | THROTTLE_OPS_WRITE, AVG, |
| 662 | }, |
| 663 | { |
| 664 | THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_WRITE_MAX, |
| 665 | THROTTLE_OPS_WRITE, MAX, |
| 666 | }, |
| 667 | { |
| 668 | THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_WRITE_MAX_LENGTH, |
| 669 | THROTTLE_OPS_WRITE, BURST_LENGTH, |
| 670 | }, |
| 671 | { |
| 672 | THROTTLE_OPT_PREFIX QEMU_OPT_BPS_TOTAL, |
| 673 | THROTTLE_BPS_TOTAL, AVG, |
| 674 | }, |
| 675 | { |
| 676 | THROTTLE_OPT_PREFIX QEMU_OPT_BPS_TOTAL_MAX, |
| 677 | THROTTLE_BPS_TOTAL, MAX, |
| 678 | }, |
| 679 | { |
| 680 | THROTTLE_OPT_PREFIX QEMU_OPT_BPS_TOTAL_MAX_LENGTH, |
| 681 | THROTTLE_BPS_TOTAL, BURST_LENGTH, |
| 682 | }, |
| 683 | { |
| 684 | THROTTLE_OPT_PREFIX QEMU_OPT_BPS_READ, |
| 685 | THROTTLE_BPS_READ, AVG, |
| 686 | }, |
| 687 | { |
| 688 | THROTTLE_OPT_PREFIX QEMU_OPT_BPS_READ_MAX, |
| 689 | THROTTLE_BPS_READ, MAX, |
| 690 | }, |
| 691 | { |
| 692 | THROTTLE_OPT_PREFIX QEMU_OPT_BPS_READ_MAX_LENGTH, |
| 693 | THROTTLE_BPS_READ, BURST_LENGTH, |
| 694 | }, |
| 695 | { |
| 696 | THROTTLE_OPT_PREFIX QEMU_OPT_BPS_WRITE, |
| 697 | THROTTLE_BPS_WRITE, AVG, |
| 698 | }, |
| 699 | { |
| 700 | THROTTLE_OPT_PREFIX QEMU_OPT_BPS_WRITE_MAX, |
| 701 | THROTTLE_BPS_WRITE, MAX, |
| 702 | }, |
| 703 | { |
| 704 | THROTTLE_OPT_PREFIX QEMU_OPT_BPS_WRITE_MAX_LENGTH, |
| 705 | THROTTLE_BPS_WRITE, BURST_LENGTH, |
| 706 | }, |
| 707 | { |
| 708 | THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_SIZE, |
| 709 | 0, IOPS_SIZE, |
| 710 | } |
| 711 | }; |
| 712 | |
| 713 | /* This function edits throttle_groups and must be called under the global |
| 714 | * mutex */ |
| 715 | static void throttle_group_obj_init(Object *obj) |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 716 | { |
Manos Pitsidianakis | 432d889 | 2017-08-25 16:20:26 +0300 | [diff] [blame] | 717 | ThrottleGroup *tg = THROTTLE_GROUP(obj); |
| 718 | |
| 719 | tg->clock_type = QEMU_CLOCK_REALTIME; |
| 720 | if (qtest_enabled()) { |
| 721 | /* For testing block IO throttling only */ |
| 722 | tg->clock_type = QEMU_CLOCK_VIRTUAL; |
| 723 | } |
| 724 | tg->is_initialized = false; |
| 725 | qemu_mutex_init(&tg->lock); |
| 726 | throttle_init(&tg->ts); |
| 727 | QLIST_INIT(&tg->head); |
Alberto Garcia | 2ff1f2e | 2015-06-08 18:17:42 +0200 | [diff] [blame] | 728 | } |
| 729 | |
Manos Pitsidianakis | 432d889 | 2017-08-25 16:20:26 +0300 | [diff] [blame] | 730 | /* This function edits throttle_groups and must be called under the global |
| 731 | * mutex */ |
| 732 | static void throttle_group_obj_complete(UserCreatable *obj, Error **errp) |
| 733 | { |
| 734 | ThrottleGroup *tg = THROTTLE_GROUP(obj); |
| 735 | ThrottleConfig cfg; |
| 736 | |
| 737 | /* set group name to object id if it exists */ |
| 738 | if (!tg->name && tg->parent_obj.parent) { |
| 739 | tg->name = object_get_canonical_path_component(OBJECT(obj)); |
| 740 | } |
| 741 | /* We must have a group name at this point */ |
| 742 | assert(tg->name); |
| 743 | |
| 744 | /* error if name is duplicate */ |
Manos Pitsidianakis | d8e7d87 | 2017-08-25 16:20:27 +0300 | [diff] [blame] | 745 | if (throttle_group_exists(tg->name)) { |
Manos Pitsidianakis | 432d889 | 2017-08-25 16:20:26 +0300 | [diff] [blame] | 746 | error_setg(errp, "A group with this name already exists"); |
| 747 | return; |
| 748 | } |
| 749 | |
| 750 | /* check validity */ |
| 751 | throttle_get_config(&tg->ts, &cfg); |
| 752 | if (!throttle_is_valid(&cfg, errp)) { |
| 753 | return; |
| 754 | } |
| 755 | throttle_config(&tg->ts, tg->clock_type, &cfg); |
| 756 | QTAILQ_INSERT_TAIL(&throttle_groups, tg, list); |
| 757 | tg->is_initialized = true; |
| 758 | } |
| 759 | |
| 760 | /* This function edits throttle_groups and must be called under the global |
| 761 | * mutex */ |
| 762 | static void throttle_group_obj_finalize(Object *obj) |
| 763 | { |
| 764 | ThrottleGroup *tg = THROTTLE_GROUP(obj); |
| 765 | if (tg->is_initialized) { |
| 766 | QTAILQ_REMOVE(&throttle_groups, tg, list); |
| 767 | } |
| 768 | qemu_mutex_destroy(&tg->lock); |
| 769 | g_free(tg->name); |
| 770 | } |
| 771 | |
| 772 | static void throttle_group_set(Object *obj, Visitor *v, const char * name, |
| 773 | void *opaque, Error **errp) |
| 774 | |
| 775 | { |
| 776 | ThrottleGroup *tg = THROTTLE_GROUP(obj); |
| 777 | ThrottleConfig *cfg; |
| 778 | ThrottleParamInfo *info = opaque; |
| 779 | Error *local_err = NULL; |
| 780 | int64_t value; |
| 781 | |
| 782 | /* If we have finished initialization, don't accept individual property |
| 783 | * changes through QOM. Throttle configuration limits must be set in one |
| 784 | * transaction, as certain combinations are invalid. |
| 785 | */ |
| 786 | if (tg->is_initialized) { |
| 787 | error_setg(&local_err, "Property cannot be set after initialization"); |
| 788 | goto ret; |
| 789 | } |
| 790 | |
| 791 | visit_type_int64(v, name, &value, &local_err); |
| 792 | if (local_err) { |
| 793 | goto ret; |
| 794 | } |
| 795 | if (value < 0) { |
| 796 | error_setg(&local_err, "Property values cannot be negative"); |
| 797 | goto ret; |
| 798 | } |
| 799 | |
| 800 | cfg = &tg->ts.cfg; |
| 801 | switch (info->category) { |
| 802 | case AVG: |
| 803 | cfg->buckets[info->type].avg = value; |
| 804 | break; |
| 805 | case MAX: |
| 806 | cfg->buckets[info->type].max = value; |
| 807 | break; |
| 808 | case BURST_LENGTH: |
| 809 | if (value > UINT_MAX) { |
| 810 | error_setg(&local_err, "%s value must be in the" |
| 811 | "range [0, %u]", info->name, UINT_MAX); |
| 812 | goto ret; |
| 813 | } |
| 814 | cfg->buckets[info->type].burst_length = value; |
| 815 | break; |
| 816 | case IOPS_SIZE: |
| 817 | cfg->op_size = value; |
| 818 | break; |
| 819 | } |
| 820 | |
| 821 | ret: |
| 822 | error_propagate(errp, local_err); |
| 823 | return; |
| 824 | |
| 825 | } |
| 826 | |
| 827 | static void throttle_group_get(Object *obj, Visitor *v, const char *name, |
| 828 | void *opaque, Error **errp) |
| 829 | { |
| 830 | ThrottleGroup *tg = THROTTLE_GROUP(obj); |
| 831 | ThrottleConfig cfg; |
| 832 | ThrottleParamInfo *info = opaque; |
| 833 | int64_t value; |
| 834 | |
| 835 | throttle_get_config(&tg->ts, &cfg); |
| 836 | switch (info->category) { |
| 837 | case AVG: |
| 838 | value = cfg.buckets[info->type].avg; |
| 839 | break; |
| 840 | case MAX: |
| 841 | value = cfg.buckets[info->type].max; |
| 842 | break; |
| 843 | case BURST_LENGTH: |
| 844 | value = cfg.buckets[info->type].burst_length; |
| 845 | break; |
| 846 | case IOPS_SIZE: |
| 847 | value = cfg.op_size; |
| 848 | break; |
| 849 | } |
| 850 | |
| 851 | visit_type_int64(v, name, &value, errp); |
| 852 | } |
| 853 | |
| 854 | static void throttle_group_set_limits(Object *obj, Visitor *v, |
| 855 | const char *name, void *opaque, |
| 856 | Error **errp) |
| 857 | |
| 858 | { |
| 859 | ThrottleGroup *tg = THROTTLE_GROUP(obj); |
| 860 | ThrottleConfig cfg; |
| 861 | ThrottleLimits arg = { 0 }; |
| 862 | ThrottleLimits *argp = &arg; |
| 863 | Error *local_err = NULL; |
| 864 | |
| 865 | visit_type_ThrottleLimits(v, name, &argp, &local_err); |
| 866 | if (local_err) { |
| 867 | goto ret; |
| 868 | } |
| 869 | qemu_mutex_lock(&tg->lock); |
| 870 | throttle_get_config(&tg->ts, &cfg); |
| 871 | throttle_limits_to_config(argp, &cfg, &local_err); |
| 872 | if (local_err) { |
| 873 | goto unlock; |
| 874 | } |
| 875 | throttle_config(&tg->ts, tg->clock_type, &cfg); |
| 876 | |
| 877 | unlock: |
| 878 | qemu_mutex_unlock(&tg->lock); |
| 879 | ret: |
| 880 | error_propagate(errp, local_err); |
| 881 | return; |
| 882 | } |
| 883 | |
| 884 | static void throttle_group_get_limits(Object *obj, Visitor *v, |
| 885 | const char *name, void *opaque, |
| 886 | Error **errp) |
| 887 | { |
| 888 | ThrottleGroup *tg = THROTTLE_GROUP(obj); |
| 889 | ThrottleConfig cfg; |
| 890 | ThrottleLimits arg = { 0 }; |
| 891 | ThrottleLimits *argp = &arg; |
| 892 | |
| 893 | qemu_mutex_lock(&tg->lock); |
| 894 | throttle_get_config(&tg->ts, &cfg); |
| 895 | qemu_mutex_unlock(&tg->lock); |
| 896 | |
| 897 | throttle_config_to_limits(&cfg, argp); |
| 898 | |
| 899 | visit_type_ThrottleLimits(v, name, &argp, errp); |
| 900 | } |
| 901 | |
| 902 | static bool throttle_group_can_be_deleted(UserCreatable *uc) |
| 903 | { |
| 904 | return OBJECT(uc)->ref == 1; |
| 905 | } |
| 906 | |
| 907 | static void throttle_group_obj_class_init(ObjectClass *klass, void *class_data) |
| 908 | { |
| 909 | size_t i = 0; |
| 910 | UserCreatableClass *ucc = USER_CREATABLE_CLASS(klass); |
| 911 | |
| 912 | ucc->complete = throttle_group_obj_complete; |
| 913 | ucc->can_be_deleted = throttle_group_can_be_deleted; |
| 914 | |
| 915 | /* individual properties */ |
| 916 | for (i = 0; i < sizeof(properties) / sizeof(ThrottleParamInfo); i++) { |
| 917 | object_class_property_add(klass, |
| 918 | properties[i].name, |
| 919 | "int", |
| 920 | throttle_group_get, |
| 921 | throttle_group_set, |
| 922 | NULL, &properties[i], |
| 923 | &error_abort); |
| 924 | } |
| 925 | |
| 926 | /* ThrottleLimits */ |
| 927 | object_class_property_add(klass, |
| 928 | "limits", "ThrottleLimits", |
| 929 | throttle_group_get_limits, |
| 930 | throttle_group_set_limits, |
| 931 | NULL, NULL, |
| 932 | &error_abort); |
| 933 | } |
| 934 | |
| 935 | static const TypeInfo throttle_group_info = { |
| 936 | .name = TYPE_THROTTLE_GROUP, |
| 937 | .parent = TYPE_OBJECT, |
| 938 | .class_init = throttle_group_obj_class_init, |
| 939 | .instance_size = sizeof(ThrottleGroup), |
| 940 | .instance_init = throttle_group_obj_init, |
| 941 | .instance_finalize = throttle_group_obj_finalize, |
| 942 | .interfaces = (InterfaceInfo[]) { |
| 943 | { TYPE_USER_CREATABLE }, |
| 944 | { } |
| 945 | }, |
| 946 | }; |
| 947 | |
| 948 | static void throttle_groups_init(void) |
| 949 | { |
| 950 | type_register_static(&throttle_group_info); |
| 951 | } |
| 952 | |
| 953 | type_init(throttle_groups_init); |