From nobody Wed Nov 5 14:08:31 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1498222243492495.3792316024684; Fri, 23 Jun 2017 05:50:43 -0700 (PDT) Received: from localhost ([::1]:35389 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dOO2s-0003Ij-0Z for importer@patchew.org; Fri, 23 Jun 2017 08:50:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60087) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dOO0q-0001eM-6n for qemu-devel@nongnu.org; Fri, 23 Jun 2017 08:48:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dOO0o-0004U6-37 for qemu-devel@nongnu.org; Fri, 23 Jun 2017 08:48:36 -0400 Received: from smtp1.ntua.gr ([2001:648:2000:de::183]:23052) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dOO0h-0004Ex-0v; Fri, 23 Jun 2017 08:48:27 -0400 Received: from mail.ntua.gr (ppp141255063244.access.hol.gr [141.255.63.244]) (authenticated bits=0) by smtp1.ntua.gr (8.15.2/8.15.2) with ESMTPSA id v5NCljBX058496 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 23 Jun 2017 15:47:45 +0300 (EEST) (envelope-from el13635@mail.ntua.gr) X-Authentication-Warning: smtp1.ntua.gr: Host ppp141255063244.access.hol.gr [141.255.63.244] claimed to be mail.ntua.gr From: Manos Pitsidianakis To: qemu-devel Date: Fri, 23 Jun 2017 15:46:56 +0300 Message-Id: <20170623124700.1389-5-el13635@mail.ntua.gr> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170623124700.1389-1-el13635@mail.ntua.gr> References: <20170623124700.1389-1-el13635@mail.ntua.gr> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:648:2000:de::183 Subject: [Qemu-devel] [PATCH RFC v3 4/8] block: convert ThrottleGroup to object with QOM X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , Stefan Hajnoczi , qemu-block Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" ThrottleGroup is converted to an object to allow easy runtime configuration of throttling filter nodes in the BDS graph using QOM. Signed-off-by: Manos Pitsidianakis --- block/throttle-groups.c | 351 ++++++++++++++++++++++++++++++++++++++++++++= ++++ include/qemu/throttle.h | 4 + 2 files changed, 355 insertions(+) diff --git a/block/throttle-groups.c b/block/throttle-groups.c index 7883cbb511..60079dc8ea 100644 --- a/block/throttle-groups.c +++ b/block/throttle-groups.c @@ -25,9 +25,11 @@ #include "qemu/osdep.h" #include "sysemu/block-backend.h" #include "block/throttle-groups.h" +#include "qemu/throttle-options.h" #include "qemu/queue.h" #include "qemu/thread.h" #include "sysemu/qtest.h" +#include "qapi/error.h" =20 /* The ThrottleGroup structure (with its ThrottleState) is shared * among different ThrottleGroupMembers and it's independent from @@ -54,6 +56,7 @@ * that BlockBackend has throttled requests in the queue. */ typedef struct ThrottleGroup { + Object parent_obj; char *name; /* This is constant during the lifetime of the group */ =20 QemuMutex lock; /* This lock protects the following four fields */ @@ -562,3 +565,351 @@ static void throttle_groups_init(void) } =20 block_init(throttle_groups_init); + + +static bool throttle_group_exists(const char *name) +{ + ThrottleGroup *iter; + bool ret =3D false; + + qemu_mutex_lock(&throttle_groups_lock); + /* Look for an existing group with that name */ + QTAILQ_FOREACH(iter, &throttle_groups, list) { + if (!strcmp(name, iter->name)) { + ret =3D true; + break; + } + } + + qemu_mutex_unlock(&throttle_groups_lock); + return ret; +} + +typedef struct ThrottleGroupClass { + /* private */ + ObjectClass parent_class; + /* public */ +} ThrottleGroupClass; + + +#define DOUBLE 0 +#define UINT64 1 +#define UNSIGNED 2 + +typedef struct { + BucketType type; + int size; /* field size */ + ptrdiff_t offset; /* offset in LeakyBucket struct. */ +} ThrottleParamInfo; + +static ThrottleParamInfo throttle_iops_total_info =3D { + THROTTLE_OPS_TOTAL, DOUBLE, offsetof(LeakyBucket, avg), +}; + +static ThrottleParamInfo throttle_iops_total_max_info =3D { + THROTTLE_OPS_TOTAL, DOUBLE, offsetof(LeakyBucket, max), +}; + +static ThrottleParamInfo throttle_iops_total_max_length_info =3D { + THROTTLE_OPS_TOTAL, UNSIGNED, offsetof(LeakyBucket, burst_length), +}; + +static ThrottleParamInfo throttle_iops_read_info =3D { + THROTTLE_OPS_READ, DOUBLE, offsetof(LeakyBucket, avg), +}; + +static ThrottleParamInfo throttle_iops_read_max_info =3D { + THROTTLE_OPS_READ, DOUBLE, offsetof(LeakyBucket, max), +}; + +static ThrottleParamInfo throttle_iops_read_max_length_info =3D { + THROTTLE_OPS_READ, UNSIGNED, offsetof(LeakyBucket, burst_length), +}; + +static ThrottleParamInfo throttle_iops_write_info =3D { + THROTTLE_OPS_WRITE, DOUBLE, offsetof(LeakyBucket, avg), +}; + +static ThrottleParamInfo throttle_iops_write_max_info =3D { + THROTTLE_OPS_WRITE, DOUBLE, offsetof(LeakyBucket, max), +}; + +static ThrottleParamInfo throttle_iops_write_max_length_info =3D { + THROTTLE_OPS_WRITE, UNSIGNED, offsetof(LeakyBucket, burst_length), +}; + +static ThrottleParamInfo throttle_bps_total_info =3D { + THROTTLE_BPS_TOTAL, DOUBLE, offsetof(LeakyBucket, avg), +}; + +static ThrottleParamInfo throttle_bps_total_max_info =3D { + THROTTLE_BPS_TOTAL, DOUBLE, offsetof(LeakyBucket, max), +}; + +static ThrottleParamInfo throttle_bps_total_max_length_info =3D { + THROTTLE_BPS_TOTAL, UNSIGNED, offsetof(LeakyBucket, burst_length), +}; + +static ThrottleParamInfo throttle_bps_read_info =3D { + THROTTLE_BPS_READ, DOUBLE, offsetof(LeakyBucket, avg), +}; + +static ThrottleParamInfo throttle_bps_read_max_info =3D { + THROTTLE_BPS_READ, DOUBLE, offsetof(LeakyBucket, max), +}; + +static ThrottleParamInfo throttle_bps_read_max_length_info =3D { + THROTTLE_BPS_READ, UNSIGNED, offsetof(LeakyBucket, burst_length), +}; + +static ThrottleParamInfo throttle_bps_write_info =3D { + THROTTLE_BPS_WRITE, DOUBLE, offsetof(LeakyBucket, avg), +}; + +static ThrottleParamInfo throttle_bps_write_max_info =3D { + THROTTLE_BPS_WRITE, DOUBLE, offsetof(LeakyBucket, max), +}; + +static ThrottleParamInfo throttle_bps_write_max_length_info =3D { + THROTTLE_BPS_WRITE, UNSIGNED, offsetof(LeakyBucket, burst_length), +}; + +static ThrottleParamInfo throttle_iops_size_info =3D { + 0, UINT64, offsetof(ThrottleConfig, op_size), +}; + + +static void throttle_group_obj_complete(UserCreatable *obj, Error **errp) +{ + char *name =3D NULL; + Error *local_error =3D NULL; + ThrottleGroup *tg =3D THROTTLE_GROUP(obj); + + name =3D object_get_canonical_path_component(OBJECT(obj)); + if (throttle_group_exists(name)) { + error_setg(&local_error, "A throttle group with this name already \ + exists."); + goto ret; + } + + qemu_mutex_lock(&throttle_groups_lock); + tg->name =3D name; + qemu_mutex_init(&tg->lock); + QLIST_INIT(&tg->head); + QTAILQ_INSERT_TAIL(&throttle_groups, tg, list); + tg->refcount++; + qemu_mutex_unlock(&throttle_groups_lock); + +ret: + error_propagate(errp, local_error); + return; + +} + +static void throttle_group_set(Object *obj, Visitor *v, const char * name, + void *opaque, Error **errp) + +{ + ThrottleGroup *tg =3D THROTTLE_GROUP(obj); + ThrottleConfig cfg =3D tg->ts.cfg; + Error *local_err =3D NULL; + ThrottleParamInfo *info =3D opaque; + int64_t value; + + visit_type_int64(v, name, &value, &local_err); + + if (local_err) { + goto out; + } + if (value < 0) { + error_setg(&local_err, "%s value must be in range [0, %"PRId64"]", + "iops-total", INT64_MAX); /* change option string */ + goto out; + } + + switch (info->size) { + case UINT64: + { + uint64_t *field =3D (void *)&cfg.buckets[info->type] + info->o= ffset; + *field =3D value; + } + break; + case DOUBLE: + { + double *field =3D (void *)&cfg.buckets[info->type] + info->off= set; + *field =3D value; + } + break; + case UNSIGNED: + { + unsigned *field =3D (void *)&cfg.buckets[info->type] + info->o= ffset; + *field =3D value; + } + } + + tg->ts.cfg =3D cfg; + +out: + error_propagate(errp, local_err); +} + +static void throttle_group_get(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + ThrottleGroup *tg =3D THROTTLE_GROUP(obj); + ThrottleConfig cfg =3D tg->ts.cfg; + ThrottleParamInfo *info =3D opaque; + int64_t value; + + switch (info->size) { + case UINT64: + { + uint64_t *field =3D (void *)&cfg.buckets[info->type] + info->o= ffset; + value =3D *field; + } + break; + case DOUBLE: + { + double *field =3D (void *)&cfg.buckets[info->type] + info->off= set; + value =3D *field; + } + break; + case UNSIGNED: + { + unsigned *field =3D (void *)&cfg.buckets[info->type] + info->o= ffset; + value =3D *field; + } + } + + visit_type_int64(v, name, &value, errp); + +} + +static void throttle_group_init(Object *obj) +{ + ThrottleGroup *tg =3D THROTTLE_GROUP(obj); + throttle_init(&tg->ts); +} + +static void throttle_group_class_init(ObjectClass *klass, void *class_data) +{ + UserCreatableClass *ucc =3D USER_CREATABLE_CLASS(klass); + + ucc->complete =3D throttle_group_obj_complete; + /* iops limits */ + object_class_property_add(klass, QEMU_OPT_IOPS_TOTAL, "int", + throttle_group_get, + throttle_group_set, + NULL, &throttle_iops_total_info, &error_abort); + object_class_property_add(klass, QEMU_OPT_IOPS_TOTAL_MAX, "int", + throttle_group_get, + throttle_group_set, + NULL, &throttle_iops_total_max_info, &error_abort); + object_class_property_add(klass, QEMU_OPT_IOPS_TOTAL_MAX_LENGTH, "int", + throttle_group_get, + throttle_group_set, + NULL, &throttle_iops_total_max_length_info, &error_abort); + object_class_property_add(klass, QEMU_OPT_IOPS_READ, "int", + throttle_group_get, + throttle_group_set, + NULL, &throttle_iops_read_info, &error_abort); + object_class_property_add(klass, QEMU_OPT_IOPS_READ_MAX, "int", + throttle_group_get, + throttle_group_set, + NULL, &throttle_iops_read_max_info, &error_abort); + object_class_property_add(klass, QEMU_OPT_IOPS_READ_MAX_LENGTH, "int", + throttle_group_get, + throttle_group_set, + NULL, &throttle_iops_read_max_length_info, &error_abort); + object_class_property_add(klass, QEMU_OPT_IOPS_WRITE, "int", + throttle_group_get, + throttle_group_set, + NULL, &throttle_iops_write_info, &error_abort); + object_class_property_add(klass, QEMU_OPT_IOPS_WRITE_MAX, "int", + throttle_group_get, + throttle_group_set, + NULL, &throttle_iops_write_max_info, &error_abort); + object_class_property_add(klass, QEMU_OPT_IOPS_WRITE_MAX_LENGTH, "int", + throttle_group_get, + throttle_group_set, + NULL, &throttle_iops_write_max_length_info, &error_abort); + /* bps limits */ + object_class_property_add(klass, QEMU_OPT_BPS_TOTAL, "int", + throttle_group_get, + throttle_group_set, + NULL, &throttle_bps_total_info, &error_abort); + object_class_property_add(klass, QEMU_OPT_BPS_TOTAL_MAX, "int", + throttle_group_get, + throttle_group_set, + NULL, &throttle_bps_total_max_info, &error_abort); + object_class_property_add(klass, QEMU_OPT_BPS_TOTAL_MAX_LENGTH, "int", + throttle_group_get, + throttle_group_set, + NULL, &throttle_bps_total_max_length_info, &error_abort); + object_class_property_add(klass, QEMU_OPT_BPS_READ, "int", + throttle_group_get, + throttle_group_set, + NULL, &throttle_bps_read_info, &error_abort); + object_class_property_add(klass, QEMU_OPT_BPS_READ_MAX, "int", + throttle_group_get, + throttle_group_set, + NULL, &throttle_bps_read_max_info, &error_abort); + object_class_property_add(klass, QEMU_OPT_BPS_READ_MAX_LENGTH, "int", + throttle_group_get, + throttle_group_set, + NULL, &throttle_bps_read_max_length_info, &error_abort); + object_class_property_add(klass, QEMU_OPT_BPS_WRITE, "int", + throttle_group_get, + throttle_group_set, + NULL, &throttle_bps_write_info, &error_abort); + object_class_property_add(klass, QEMU_OPT_BPS_WRITE_MAX, "int", + throttle_group_get, + throttle_group_set, + NULL, &throttle_bps_write_max_info, &error_abort); + object_class_property_add(klass, QEMU_OPT_BPS_WRITE_MAX_LENGTH, "int", + throttle_group_get, + throttle_group_set, + NULL, &throttle_bps_write_max_length_info, &error_abort); + /* rest */ + object_class_property_add(klass, QEMU_OPT_IOPS_SIZE, "int", + throttle_group_get, + throttle_group_set, + NULL, &throttle_iops_size_info, &error_abort); +} + + +static void throttle_group_finalize(Object *obj) +{ + ThrottleGroup *tg =3D THROTTLE_GROUP(obj); + + qemu_mutex_lock(&throttle_groups_lock); + if (--tg->refcount =3D=3D 0) { + QTAILQ_REMOVE(&throttle_groups, tg, list); + qemu_mutex_destroy(&tg->lock); + g_free(tg->name); + g_free(tg); + } + qemu_mutex_unlock(&throttle_groups_lock); + +} + +static const TypeInfo throttle_group_info =3D { + .name =3D TYPE_THROTTLE_GROUP, + .parent =3D TYPE_OBJECT, + .class_init =3D throttle_group_class_init, + .instance_size =3D sizeof(ThrottleGroup), + .instance_init =3D throttle_group_init, + .instance_finalize =3D throttle_group_finalize, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_USER_CREATABLE }, + { } + }, +}; + +static void throttle_group_register_types(void) +{ + qemu_mutex_init(&throttle_groups_lock); + type_register_static(&throttle_group_info); +} + +type_init(throttle_group_register_types); diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h index 3e92d4d4eb..dd56baeb35 100644 --- a/include/qemu/throttle.h +++ b/include/qemu/throttle.h @@ -28,6 +28,8 @@ #include "qemu-common.h" #include "qemu/timer.h" #include "qemu/coroutine.h" +#include "qom/object.h" +#include "qom/object_interfaces.h" =20 #define THROTTLE_VALUE_MAX 1000000000000000LL =20 @@ -180,4 +182,6 @@ typedef struct ThrottleGroupMember { =20 } ThrottleGroupMember; =20 +#define TYPE_THROTTLE_GROUP "throttling-group" +#define THROTTLE_GROUP(obj) OBJECT_CHECK(ThrottleGroup, (obj), TYPE_THROTT= LE_GROUP) #endif --=20 2.11.0