From nobody Fri May 17 05:54:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1690193454; cv=none; d=zohomail.com; s=zohoarc; b=oGsB8tyQLvK/lDGvwX9JQZTJDxk+tUwrtsJxQInC2hO3qHu720ZwDAqSbze8mVq2ZiqaEaSGTB5fEgloxeRpOpR/zsJtbvKfnmza3N3KVP1xakbImmSi1qIsyh9OCDhgDfEiMAag5UTG5IrJ0DCA/ZBhHd8ycqlbKFRRVGJvFHM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690193454; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mq2kY4BOOQ8xYk3QtPY1kkHoxXQ+5tDDw4bi3Y5yR8Q=; b=KouORpV6Hta92i3LRfXJ9m5mcR9SrlpJS99vtbNSLC9AzYEztbxgnK2E3qrKMiF8DqfAytS1AF2ef/Ba/nGm6K6NTzj1kWFqmqz33dXKQBSnffJasjAoesmhuVUVa8Vkd0ykpP6OvNmHzXzi3/C+mqhJw0sCxbVjYRFr4KF3UV8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1690193454151508.29165109047574; Mon, 24 Jul 2023 03:10:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qNsWA-0007lc-21; Mon, 24 Jul 2023 06:10:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qNsW1-0007ir-MG for qemu-devel@nongnu.org; Mon, 24 Jul 2023 06:10:11 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qNsVl-0000Xu-F0 for qemu-devel@nongnu.org; Mon, 24 Jul 2023 06:10:08 -0400 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1bb775625e2so13587025ad.1 for ; Mon, 24 Jul 2023 03:09:51 -0700 (PDT) Received: from libai.bytedance.net ([61.213.176.11]) by smtp.gmail.com with ESMTPSA id je2-20020a170903264200b001bb9d6b1baasm2419124plb.198.2023.07.24.03.09.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 03:09:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690193390; x=1690798190; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mq2kY4BOOQ8xYk3QtPY1kkHoxXQ+5tDDw4bi3Y5yR8Q=; b=Ar3Su0aKRrEhtzRnZebXUFgIAXQTPpnLtXlPa9RBUjweTRERYBIUcNZ+re4t9lZ3Pj 15Y6BPDL+oFu7hF/Kd4pVHEICvJBUYKa/p1HoT/rvIwPAI605ZagQnlgSKHm2A4n0enV d/mWO08b7R1WLg6l/+t+bL7Z/yZUKd8bhfAp5lM5rJph9xJDCEhVE10V+acXMXkvXI9S eywmYy7GOy+/JddUTpzjn/HurYwRLdBPE4PGwnGVX2XD3ms/65Iet9IvRK+ZVaPBjMWY /1Aj+OsnZXKGMPO2hKPg/yBAkwj2BdD7KNpI8zGCp0OqWuAO7WL/CBbQDnMpoizFBJN2 81eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690193390; x=1690798190; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mq2kY4BOOQ8xYk3QtPY1kkHoxXQ+5tDDw4bi3Y5yR8Q=; b=RbsKFDzZpsdq0iJr1VqPxoa9VvEr5M0JzUX/v9gtqg9kynosgoA2mtMMdXlVJKTnJm 4yvkVPm+fZX0ymCVG42PhdC1n/vSvsfAqi/mZNviAmy5Jctujwb7iQQUnYRrXYsMlO2l h0kntG1lH03+5B8H/G5xixjcFAEEmNky4SNlWFNjG9uBtBb0NtXSV+axWb64S+/jsswN 46hwhLvBpZP+7A7ow7eXbold0hDTxTnfkDxEkO8qGVfDFk+c8Qaz5o6U4m8AJNMDpQGF TsSnleTiOncwdiq/kovIbDaTKZXlBneypPbH7bpJWBGLorir7Xuj4bIEHGAYw4Yn3li6 bl8Q== X-Gm-Message-State: ABy/qLa7ggVYgMlh0s9P0YOJHZDmhrP2SG57I/wQoD6Y/ai1wNQ74WRY eI8iHNg8w2kIdofOFsedYS/wSw== X-Google-Smtp-Source: APBJJlGtQjbtyEcrk5ObCtvBVaqka/oHEb620/0ZzSAT29SNAN/HkxktOMG9jOqBArAlrivHsumGVA== X-Received: by 2002:a17:902:d502:b0:1b8:417d:d042 with SMTP id b2-20020a170902d50200b001b8417dd042mr12271818plg.20.1690193390265; Mon, 24 Jul 2023 03:09:50 -0700 (PDT) From: zhenwei pi To: berto@igalia.com, kwolf@redhat.com, groug@kaod.org, qemu_oss@crudebyte.com, hreitz@redhat.com Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, berrange@redhat.com, zhenwei pi Subject: [PATCH v4 1/9] throttle: introduce enum ThrottleDirection Date: Mon, 24 Jul 2023 18:09:31 +0800 Message-Id: <20230724100939.1022984-2-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230724100939.1022984-1-pizhenwei@bytedance.com> References: <20230724100939.1022984-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x62f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1690193455070100001 Content-Type: text/plain; charset="utf-8" Use enum ThrottleDirection instead of number index. Reviewed-by: Alberto Garcia Reviewed-by: Hanna Czenczek Signed-off-by: zhenwei pi --- include/qemu/throttle.h | 11 ++++++++--- util/throttle.c | 16 +++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h index 05f6346137..9ca5ab8197 100644 --- a/include/qemu/throttle.h +++ b/include/qemu/throttle.h @@ -99,13 +99,18 @@ typedef struct ThrottleState { int64_t previous_leak; /* timestamp of the last leak done */ } ThrottleState; =20 +typedef enum { + THROTTLE_READ =3D 0, + THROTTLE_WRITE, + THROTTLE_MAX +} ThrottleDirection; + typedef struct ThrottleTimers { - QEMUTimer *timers[2]; /* timers used to do the throttling */ + QEMUTimer *timers[THROTTLE_MAX]; /* timers used to do the throttlin= g */ QEMUClockType clock_type; /* the clock used */ =20 /* Callbacks */ - QEMUTimerCB *read_timer_cb; - QEMUTimerCB *write_timer_cb; + QEMUTimerCB *timer_cb[THROTTLE_MAX]; void *timer_opaque; } ThrottleTimers; =20 diff --git a/util/throttle.c b/util/throttle.c index 81f247a8d1..5642e61763 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -199,10 +199,12 @@ static bool throttle_compute_timer(ThrottleState *ts, void throttle_timers_attach_aio_context(ThrottleTimers *tt, AioContext *new_context) { - tt->timers[0] =3D aio_timer_new(new_context, tt->clock_type, SCALE_NS, - tt->read_timer_cb, tt->timer_opaque); - tt->timers[1] =3D aio_timer_new(new_context, tt->clock_type, SCALE_NS, - tt->write_timer_cb, tt->timer_opaque); + tt->timers[THROTTLE_READ] =3D + aio_timer_new(new_context, tt->clock_type, SCALE_NS, + tt->timer_cb[THROTTLE_READ], tt->timer_opaque); + tt->timers[THROTTLE_WRITE] =3D + aio_timer_new(new_context, tt->clock_type, SCALE_NS, + tt->timer_cb[THROTTLE_WRITE], tt->timer_opaque); } =20 /* @@ -236,8 +238,8 @@ void throttle_timers_init(ThrottleTimers *tt, memset(tt, 0, sizeof(ThrottleTimers)); =20 tt->clock_type =3D clock_type; - tt->read_timer_cb =3D read_timer_cb; - tt->write_timer_cb =3D write_timer_cb; + tt->timer_cb[THROTTLE_READ] =3D read_timer_cb; + tt->timer_cb[THROTTLE_WRITE] =3D write_timer_cb; tt->timer_opaque =3D timer_opaque; throttle_timers_attach_aio_context(tt, aio_context); } @@ -256,7 +258,7 @@ void throttle_timers_detach_aio_context(ThrottleTimers = *tt) { int i; =20 - for (i =3D 0; i < 2; i++) { + for (i =3D 0; i < THROTTLE_MAX; i++) { throttle_timer_destroy(&tt->timers[i]); } } --=20 2.34.1 From nobody Fri May 17 05:54:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1690193447; cv=none; d=zohomail.com; s=zohoarc; b=P93sZb20+z5o1+lIm0kapJrHAM4l5KCA2dMhjRMZzBl4ajJAwWo87JN0U53rby+AtCYpsnXQ7tOm6TUjPi7RB/KDTIHOUlRINm6FC4MilaS5ikbWMUBUR7ViTVaZH3+DYarv520huC8irWzrn+gz/OHED9IFU9DD8Gj3cbb6V54= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690193447; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Po0gAxAU3dnysaVx2B26/6HXOapX1SQhA8vH8XAjSZc=; b=i7wegabKtdcSX8uEhDYfio8XaS3EmB+Mrwjm/k8r/yrTsI+q7hdaAMXjWZeCx7P1VPBEaKYkGHp5kPI+GdIm+HtB7eKjBQn4F7AJxbO9OUMtOULmqLRthaU4Fkr0T8gHjZVSzhVah+im3XZclf8VS9Emso50sYzbYnrVSYtGs/8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1690193447883431.72619452533786; Mon, 24 Jul 2023 03:10:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qNsWG-0007qP-RL; Mon, 24 Jul 2023 06:10:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qNsW3-0007it-A7 for qemu-devel@nongnu.org; Mon, 24 Jul 2023 06:10:11 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qNsVn-0000YK-7F for qemu-devel@nongnu.org; Mon, 24 Jul 2023 06:10:10 -0400 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-666eb03457cso2207144b3a.1 for ; Mon, 24 Jul 2023 03:09:54 -0700 (PDT) Received: from libai.bytedance.net ([61.213.176.11]) by smtp.gmail.com with ESMTPSA id je2-20020a170903264200b001bb9d6b1baasm2419124plb.198.2023.07.24.03.09.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 03:09:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690193394; x=1690798194; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Po0gAxAU3dnysaVx2B26/6HXOapX1SQhA8vH8XAjSZc=; b=O4ObM1YqaLRcqgXMsAk/mPWpxMJ9/kFTFN54qK71rgylAkjTJHc9PeRKZyGRWvWjdN qFpxW3EEFGOeUW0xKxhcqioycyNGW1ZxNgGlHE41Crm1drAHbyGlOMxANmhM4LCdTKf/ Uh+hYV7XNdcep9bqnMd25eNItVUkjQ7fjleq9aaOdgO79YTVGLnCiboopYne/Q2gvUxy xOyy953jxDZpUttE7B6ZKt9U8251w5juZEuOpIPi6Wc3axCmMuSzqqexni0I8MGwFy8Q iy9RmpPqYD9eurtS2g/cxdobwVKAdSoXBBJgIsByxYqzdO2f2MAHhBFModHakm/yp5fQ UeDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690193394; x=1690798194; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Po0gAxAU3dnysaVx2B26/6HXOapX1SQhA8vH8XAjSZc=; b=Nj5iAQqx4Z3FipUceY91ElYYbf9rRVD4jR7M7B25xe5MUT2zBrrE6biDHPSgzvd0yc OI0YKJxEC/I8wiMdqF3rukTeMJmhp+3eps0+dgUC1WJJyK8BFcnHGnRL2Bi8L7etQrsM gquMauEZhr9fYp5UqTHeD24DoBe8devbSub3PMcyFHbZcH0fOTetjzeEHN3kancTf3+J 1x6hrrWPzuxn/U9/60RQydtAKz0M8PzEW2XA0GLrqjmnBqyisclLbQzw9BQ7freYYobE WCUUVx+IXmhw8knY9f9hohJjt4DtkhOkpfFc+y95zBKYnTzyC6+HrWoLXaV+G+VovGvX RqwA== X-Gm-Message-State: ABy/qLYdbHACcfKPMFpX8L70Mk0Uk6iDwnDMuGZtXgPgVek6g0T9e+q3 ND3HiZrWS6qDw69uY+oSORhG9Q== X-Google-Smtp-Source: APBJJlF94MaBNI26y7tn+/z6NVOjE+maGZ1sU09y1mozRAuBKdbXUA0hv8ccufWGuOaHxwOf8ouRvA== X-Received: by 2002:a17:903:190:b0:1b8:7618:5414 with SMTP id z16-20020a170903019000b001b876185414mr7008517plg.60.1690193393770; Mon, 24 Jul 2023 03:09:53 -0700 (PDT) From: zhenwei pi To: berto@igalia.com, kwolf@redhat.com, groug@kaod.org, qemu_oss@crudebyte.com, hreitz@redhat.com Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, berrange@redhat.com, zhenwei pi Subject: [PATCH v4 2/9] test-throttle: use enum ThrottleDirection Date: Mon, 24 Jul 2023 18:09:32 +0800 Message-Id: <20230724100939.1022984-3-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230724100939.1022984-1-pizhenwei@bytedance.com> References: <20230724100939.1022984-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=pizhenwei@bytedance.com; helo=mail-pf1-x430.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1690193449160100005 Content-Type: text/plain; charset="utf-8" Use enum ThrottleDirection instead in the throttle test codes. Reviewed-by: Alberto Garcia Reviewed-by: Hanna Czenczek Signed-off-by: zhenwei pi --- tests/unit/test-throttle.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/test-throttle.c b/tests/unit/test-throttle.c index 7adb5e6652..a60b5fe22e 100644 --- a/tests/unit/test-throttle.c +++ b/tests/unit/test-throttle.c @@ -169,8 +169,8 @@ static void test_init(void) =20 /* check initialized fields */ g_assert(tt->clock_type =3D=3D QEMU_CLOCK_VIRTUAL); - g_assert(tt->timers[0]); - g_assert(tt->timers[1]); + g_assert(tt->timers[THROTTLE_READ]); + g_assert(tt->timers[THROTTLE_WRITE]); =20 /* check other fields where cleared */ g_assert(!ts.previous_leak); @@ -191,7 +191,7 @@ static void test_destroy(void) throttle_timers_init(tt, ctx, QEMU_CLOCK_VIRTUAL, read_timer_cb, write_timer_cb, &ts); throttle_timers_destroy(tt); - for (i =3D 0; i < 2; i++) { + for (i =3D 0; i < THROTTLE_MAX; i++) { g_assert(!tt->timers[i]); } } --=20 2.34.1 From nobody Fri May 17 05:54:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1690193446; cv=none; d=zohomail.com; s=zohoarc; b=DS4s+EWpgTx6AUWeSdkI0WA7sRNHAMXB5ssykM1z7BjG60/2JRW6E6+YjOYjXbgXZSAzfIH986qzc863CgVdOYVD7k4Y9UNj6vZbKUYbulJ/iDKdkBtiobDYQOahDo5QK2VyRTChnBVg4kLEGDw+ldx52yoL7Jm5ME5oVwhEH4o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690193446; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6y39WsGI6ZaymBhC0tayr2DVImGPxd/56ERoZgkjVfM=; b=TTFBq5+Ts8ryE9ao2yzNXw2+3hNq5lEiu9Q1Bb9qKhXVcaDcxSaakb7Cno/e2Ox6+ZJIx0z7FECk9YrwI6pQEhgZ9QkeZNvLPq+Td6D2P8j+GKQCMtrWf4pkGPCFk0GTHWvFj/v6uGXeHCD5Bw/TsvLSPNsjHeIMUX53tL5bKCE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1690193446618521.5510404242553; Mon, 24 Jul 2023 03:10:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qNsWB-0007nj-Ub; Mon, 24 Jul 2023 06:10:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qNsVx-0007hl-Aq for qemu-devel@nongnu.org; Mon, 24 Jul 2023 06:10:05 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qNsVu-0000Yt-U4 for qemu-devel@nongnu.org; Mon, 24 Jul 2023 06:10:05 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6686ef86110so2212874b3a.2 for ; Mon, 24 Jul 2023 03:09:58 -0700 (PDT) Received: from libai.bytedance.net ([61.213.176.11]) by smtp.gmail.com with ESMTPSA id je2-20020a170903264200b001bb9d6b1baasm2419124plb.198.2023.07.24.03.09.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 03:09:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690193397; x=1690798197; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6y39WsGI6ZaymBhC0tayr2DVImGPxd/56ERoZgkjVfM=; b=Fqs2hvnwuP6PRjyoFYbTqejwA3fyTXgXwkp7qPoiUgbN/iOlgk07+6RHxdJwKczmqe yxVDzqS9z5SYyE/Q9fS6gtM1hTxK/3sBdDzc+Qo4WPRQM3leyLVAiB3PyLPGuEXizZ30 /RJaiqZuEtLOCBLH6PC1E69PiG0PhjS0Mnf8COjrM/ibm3KadoDeZu/skh1EE1qWaS2/ CbqXXMnJplYeBt8u9JGJ43o4gTxNmLzO6ij/103LRIUafG4McW7ZYEIYPTIdRFCsBv/Y DV5TI8epw+DjpsMr1k8KnQsYdDB+vyfaHp1uY35dyPBGzDfGmLSl9uh9VzP9hy5IL2Mk mpPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690193397; x=1690798197; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6y39WsGI6ZaymBhC0tayr2DVImGPxd/56ERoZgkjVfM=; b=QISJkIhyWV1muPDjCYpBA7WeX86PrHwRVd6gxOt+T6EOKXGAqm51MtPzCP1NeQg5/z aFXQhFOe+deJBJ41VH1/o5kwe8Hv6XP2pvk4Fx8LPrhEGgSqDHOtMxMDSwndhuBnxLd9 qe66RCac+T7yCfG5bC5RU6HbnIUL8BZXOTb7feBPniOqRkNMgsa5UUukM3uwHABQ100+ hPU6oOqWx3BdvYsr7xjrzzhE7h468bp99+P85/SSOLV5z1v+5pbHZ8HDSWiMhERMwVs7 HFl2iWBmefj3AlkRkEwFePud254a4WaCXG0vRYZ7Y4GHMIcdwSxe4I1pFVEUoo05ax+n DMyg== X-Gm-Message-State: ABy/qLaTAZ03XxU0L9p5RNbj6+Tq4cQ4YzKwmZGLOBZKpUMpVSuseBva ZQBlM66Z66G6gQGNzq3uwlYdug== X-Google-Smtp-Source: APBJJlGmcInRLpSEc4uFLn0OSWHE/uUQOLMmjcsUCX7sB0zn1d78pemg7ujnJOU6Kvk6O92qdmxhPA== X-Received: by 2002:a05:6a20:7f93:b0:133:8229:196e with SMTP id d19-20020a056a207f9300b001338229196emr9695590pzj.35.1690193397260; Mon, 24 Jul 2023 03:09:57 -0700 (PDT) From: zhenwei pi To: berto@igalia.com, kwolf@redhat.com, groug@kaod.org, qemu_oss@crudebyte.com, hreitz@redhat.com Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, berrange@redhat.com, zhenwei pi Subject: [PATCH v4 3/9] throttle: support read-only and write-only Date: Mon, 24 Jul 2023 18:09:33 +0800 Message-Id: <20230724100939.1022984-4-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230724100939.1022984-1-pizhenwei@bytedance.com> References: <20230724100939.1022984-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=pizhenwei@bytedance.com; helo=mail-pf1-x433.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1690193448257100003 Content-Type: text/plain; charset="utf-8" Only one direction is necessary in several scenarios: - a read-only disk - operations on a device are considered as *write* only. For example, encrypt/decrypt/sign/verify operations on a cryptodev use a single *write* timer(read timer callback is defined, but never invoked). Allow a single direction in throttle, this reduces memory, and uplayer does not need a dummy callback any more. Reviewed-by: Alberto Garcia Reviewed-by: Hanna Czenczek Signed-off-by: zhenwei pi --- util/throttle.c | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/util/throttle.c b/util/throttle.c index 5642e61763..0439028d21 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -199,12 +199,15 @@ static bool throttle_compute_timer(ThrottleState *ts, void throttle_timers_attach_aio_context(ThrottleTimers *tt, AioContext *new_context) { - tt->timers[THROTTLE_READ] =3D - aio_timer_new(new_context, tt->clock_type, SCALE_NS, - tt->timer_cb[THROTTLE_READ], tt->timer_opaque); - tt->timers[THROTTLE_WRITE] =3D - aio_timer_new(new_context, tt->clock_type, SCALE_NS, - tt->timer_cb[THROTTLE_WRITE], tt->timer_opaque); + ThrottleDirection dir; + + for (dir =3D THROTTLE_READ; dir < THROTTLE_MAX; dir++) { + if (tt->timer_cb[dir]) { + tt->timers[dir] =3D + aio_timer_new(new_context, tt->clock_type, SCALE_NS, + tt->timer_cb[dir], tt->timer_opaque); + } + } } =20 /* @@ -235,6 +238,7 @@ void throttle_timers_init(ThrottleTimers *tt, QEMUTimerCB *write_timer_cb, void *timer_opaque) { + assert(read_timer_cb || write_timer_cb); memset(tt, 0, sizeof(ThrottleTimers)); =20 tt->clock_type =3D clock_type; @@ -247,7 +251,9 @@ void throttle_timers_init(ThrottleTimers *tt, /* destroy a timer */ static void throttle_timer_destroy(QEMUTimer **timer) { - assert(*timer !=3D NULL); + if (*timer =3D=3D NULL) { + return; + } =20 timer_free(*timer); *timer =3D NULL; @@ -256,10 +262,10 @@ static void throttle_timer_destroy(QEMUTimer **timer) /* Remove timers from event loop */ void throttle_timers_detach_aio_context(ThrottleTimers *tt) { - int i; + ThrottleDirection dir; =20 - for (i =3D 0; i < THROTTLE_MAX; i++) { - throttle_timer_destroy(&tt->timers[i]); + for (dir =3D THROTTLE_READ; dir < THROTTLE_MAX; dir++) { + throttle_timer_destroy(&tt->timers[dir]); } } =20 @@ -272,8 +278,12 @@ void throttle_timers_destroy(ThrottleTimers *tt) /* is any throttling timer configured */ bool throttle_timers_are_initialized(ThrottleTimers *tt) { - if (tt->timers[0]) { - return true; + ThrottleDirection dir; + + for (dir =3D THROTTLE_READ; dir < THROTTLE_MAX; dir++) { + if (tt->timers[dir]) { + return true; + } } =20 return false; @@ -424,8 +434,12 @@ bool throttle_schedule_timer(ThrottleState *ts, { int64_t now =3D qemu_clock_get_ns(tt->clock_type); int64_t next_timestamp; + QEMUTimer *timer; bool must_wait; =20 + timer =3D is_write ? tt->timers[THROTTLE_WRITE] : tt->timers[THROTTLE_= READ]; + assert(timer); + must_wait =3D throttle_compute_timer(ts, is_write, now, @@ -437,12 +451,12 @@ bool throttle_schedule_timer(ThrottleState *ts, } =20 /* request throttled and timer pending -> do nothing */ - if (timer_pending(tt->timers[is_write])) { + if (timer_pending(timer)) { return true; } =20 /* request throttled and timer not pending -> arm timer */ - timer_mod(tt->timers[is_write], next_timestamp); + timer_mod(timer, next_timestamp); return true; } =20 --=20 2.34.1 From nobody Fri May 17 05:54:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1690193543; cv=none; d=zohomail.com; s=zohoarc; b=KNLMS/APlCWuCeYFzDmobbE6uubKywQokGhyso/USj0JZWq74cNak06AGv9/3nQaBpXSp/KXyKuOUJTrtmQWOYfgKwIKxYzKZdVnXtV2wvG7oHh8AN+q2vEDfUDUZaikMHw5igmXkKFRXT/ZMx7Zo1Jg//TQVt832kwKg49ugQw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690193543; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wg78UB7cYAokVViU4U5tFWb/GJUMtPAxxn2JcC2wYiI=; b=Tnd5/hfLbbys20RRl7+PlSomeAkAz+aayDNc1OQrIcjrsl+/Mq6fOSO4oehGBn3pmp+79HYGEm/IjI9bnNrERkhVg8frBRURakYUq9hx9z6ubDI14kpEQjOYHtvgcCYJFPtvZFpkUvtAjQTse1xvR4RDzb6tVbiO0J46v7XVBr8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169019354396247.81298017714255; Mon, 24 Jul 2023 03:12:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qNsWN-0007vE-FE; Mon, 24 Jul 2023 06:10:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qNsWB-0007nO-Gm for qemu-devel@nongnu.org; Mon, 24 Jul 2023 06:10:19 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qNsVu-0000ZG-W3 for qemu-devel@nongnu.org; Mon, 24 Jul 2023 06:10:18 -0400 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1bb775625e2so13588225ad.1 for ; Mon, 24 Jul 2023 03:10:02 -0700 (PDT) Received: from libai.bytedance.net ([61.213.176.11]) by smtp.gmail.com with ESMTPSA id je2-20020a170903264200b001bb9d6b1baasm2419124plb.198.2023.07.24.03.09.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 03:10:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690193401; x=1690798201; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wg78UB7cYAokVViU4U5tFWb/GJUMtPAxxn2JcC2wYiI=; b=bnel0JMx0K8UiW/pkkPT4kkVAYPoy1yUJcc6zzF64JEaMfqrJR70uN99/XGfIltBC4 DD7nJxMfG3JWXf0t9cMLSUM/eH9TQv/TNHPCZtiDDALZG4bvSAMOYFD97pbZYTt95h7T reQf2LIZeG1nJEL9GRVNY+3uN0mvZgI9fkiHcVRVnsVl7CTrm+g4zjHV4fKqSDyRbUsS y/qPgRzvf86PkOL0bndS5RwO5FhcVMxefbJf1qe7GTOknEd7olF7cSd+m6PcOuP3wJW3 d51fvO+xQ+kHLkg6T5/D/1lZWHbQKd2l7lLmglU4cEDguBVzyV44xmtukiQvDTC0FXMn BXOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690193401; x=1690798201; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wg78UB7cYAokVViU4U5tFWb/GJUMtPAxxn2JcC2wYiI=; b=PwlsGB3E1bZPhsO96J1qoexeAjNqx2tVDc7S/QBlGChzFZaftcuXNFe0z67B2X9Enb pHrTPiGMMS1LmQsgvg3SvpGrWCkSoCp/3pdIxnfOpyT99yCLqUurfYy5Xejmh2FHhz38 oC8uwCMsR/mHZJOeoMQlFxfWvfhqvxaMKbYkMekUE/jdUaSBxiauAlXm7tB9wJNsiwdX NNvpJ+MevFSKSBJcrnEcS/5AaU9zKh6si2L4ZXjNKHgEgYD6BCXY1en5+SQYfpSgkZtd 3xFSdqOiDInRWfpms4DHDADl40hqHAUM7fm65ML18oyiJp7huINK7Mw/+U2ugOHwMvGv R/ig== X-Gm-Message-State: ABy/qLahmW0ObjvQgtNvr3e7PP8waumr4ac50B5hi2I12a6rTWFnVko8 vZf3Om5TIN6IA39JRW6sdoIqQQ== X-Google-Smtp-Source: APBJJlEG04Zi9RrWWoYE9MgktvWKa+xPsNq2dbTEsMIt6urB9Udt25OlHwR1qNZTKj8Z/YbsSD610g== X-Received: by 2002:a17:902:d2cd:b0:1b0:3ab6:5140 with SMTP id n13-20020a170902d2cd00b001b03ab65140mr13738594plc.4.1690193401139; Mon, 24 Jul 2023 03:10:01 -0700 (PDT) From: zhenwei pi To: berto@igalia.com, kwolf@redhat.com, groug@kaod.org, qemu_oss@crudebyte.com, hreitz@redhat.com Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, berrange@redhat.com, zhenwei pi Subject: [PATCH v4 4/9] test-throttle: test read only and write only Date: Mon, 24 Jul 2023 18:09:34 +0800 Message-Id: <20230724100939.1022984-5-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230724100939.1022984-1-pizhenwei@bytedance.com> References: <20230724100939.1022984-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62a; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x62a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1690193545946100003 Content-Type: text/plain; charset="utf-8" Reviewed-by: Alberto Garcia Reviewed-by: Hanna Czenczek Signed-off-by: zhenwei pi --- tests/unit/test-throttle.c | 66 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tests/unit/test-throttle.c b/tests/unit/test-throttle.c index a60b5fe22e..5547837a58 100644 --- a/tests/unit/test-throttle.c +++ b/tests/unit/test-throttle.c @@ -184,6 +184,70 @@ static void test_init(void) throttle_timers_destroy(tt); } =20 +static void test_init_readonly(void) +{ + int i; + + tt =3D &tgm.throttle_timers; + + /* fill the structures with crap */ + memset(&ts, 1, sizeof(ts)); + memset(tt, 1, sizeof(*tt)); + + /* init structures */ + throttle_init(&ts); + throttle_timers_init(tt, ctx, QEMU_CLOCK_VIRTUAL, + read_timer_cb, NULL, &ts); + + /* check initialized fields */ + g_assert(tt->clock_type =3D=3D QEMU_CLOCK_VIRTUAL); + g_assert(tt->timers[THROTTLE_READ]); + g_assert(!tt->timers[THROTTLE_WRITE]); + + /* check other fields where cleared */ + g_assert(!ts.previous_leak); + g_assert(!ts.cfg.op_size); + for (i =3D 0; i < BUCKETS_COUNT; i++) { + g_assert(!ts.cfg.buckets[i].avg); + g_assert(!ts.cfg.buckets[i].max); + g_assert(!ts.cfg.buckets[i].level); + } + + throttle_timers_destroy(tt); +} + +static void test_init_writeonly(void) +{ + int i; + + tt =3D &tgm.throttle_timers; + + /* fill the structures with crap */ + memset(&ts, 1, sizeof(ts)); + memset(tt, 1, sizeof(*tt)); + + /* init structures */ + throttle_init(&ts); + throttle_timers_init(tt, ctx, QEMU_CLOCK_VIRTUAL, + NULL, write_timer_cb, &ts); + + /* check initialized fields */ + g_assert(tt->clock_type =3D=3D QEMU_CLOCK_VIRTUAL); + g_assert(!tt->timers[THROTTLE_READ]); + g_assert(tt->timers[THROTTLE_WRITE]); + + /* check other fields where cleared */ + g_assert(!ts.previous_leak); + g_assert(!ts.cfg.op_size); + for (i =3D 0; i < BUCKETS_COUNT; i++) { + g_assert(!ts.cfg.buckets[i].avg); + g_assert(!ts.cfg.buckets[i].max); + g_assert(!ts.cfg.buckets[i].level); + } + + throttle_timers_destroy(tt); +} + static void test_destroy(void) { int i; @@ -752,6 +816,8 @@ int main(int argc, char **argv) g_test_add_func("/throttle/leak_bucket", test_leak_bucket); g_test_add_func("/throttle/compute_wait", test_compute_wait); g_test_add_func("/throttle/init", test_init); + g_test_add_func("/throttle/init_readonly", test_init_readonly); + g_test_add_func("/throttle/init_writeonly", test_init_writeonly); g_test_add_func("/throttle/destroy", test_destroy); g_test_add_func("/throttle/have_timer", test_have_timer); g_test_add_func("/throttle/detach_attach", test_detach_attach); --=20 2.34.1 From nobody Fri May 17 05:54:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1690193514; cv=none; d=zohomail.com; s=zohoarc; b=O2AK2rahkS0iy7sbH0fRCC/iiPboDkYeawhExXFCWhWJN0Epm+JW1GurSO/BmbS+hHhk5u4KA3UyJFAr/v7zGNG8SfTjgKejgyvO1g1/SmjuoZ8ukmh9nDONWaJB1k7SlC0lHdSSCYbQ8Wf44LMwv9UAtVON45sKTE/zXsluoIA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690193514; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=48meBdD6mTHtH2x/RIoONhW/lCpA4vlss4RgaZN1ubw=; b=RucGMMIE+juHvm6FS3baGHJqlL9HHz8u2lgvRrgSA19MuvbGdLK/7YAq5j18usuxre3Fv3p+Gd1P0vXT0S1WWaNgh9e1zpdBD2AJ+zDX60zzojHSg97d3Lns9japGSGx9i2V/D0x41Jg/1NDmL76ZX/C91fytC/oQHwweQ3Cr84= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1690193514309809.7985181861234; Mon, 24 Jul 2023 03:11:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qNsWC-0007nq-71; Mon, 24 Jul 2023 06:10:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qNsW3-0007iu-AT for qemu-devel@nongnu.org; Mon, 24 Jul 2023 06:10:11 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qNsVy-0000ay-9M for qemu-devel@nongnu.org; Mon, 24 Jul 2023 06:10:10 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1b89d47ffb6so19759485ad.2 for ; Mon, 24 Jul 2023 03:10:05 -0700 (PDT) Received: from libai.bytedance.net ([61.213.176.11]) by smtp.gmail.com with ESMTPSA id je2-20020a170903264200b001bb9d6b1baasm2419124plb.198.2023.07.24.03.10.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 03:10:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690193405; x=1690798205; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=48meBdD6mTHtH2x/RIoONhW/lCpA4vlss4RgaZN1ubw=; b=B8kA0s8if2dmDpb7M3s+UuaHlYU+LTioLR8arpqUgwrQpfu3A53CQ6ST6GfcKspzEJ rehzRWBoWzeHZUDPwnAKE3xtiminG9qSGgHehBlsBByZHg44wrHowoKQ//94OUqsO3Gi DW3SG6ar7GJwZYywp0KrZSyeYKQeXixDR5fuItMgwxHhpTPp4H6mtKk/xNp8FzU76S0i tX9O8XVHQSeOJZv9faYwKx/r0Ix1MLrmzhmLEqQWUUP8p0R+P8Hu4Olj+uuf24lJztMP VVTgfzLQCuboaqX2RdYmWZ/HKo0Pd41rV527Y0LM+os3VI21JxVI4evkZw/EWwi5CbBb TeRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690193405; x=1690798205; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=48meBdD6mTHtH2x/RIoONhW/lCpA4vlss4RgaZN1ubw=; b=KVwwfQA/b3VOti2kF6iMRgOnIv7op7anFU9nP36fA2DTBQfpL7KPp5MFcWKjRM/2/0 TqVdTVpN3Li+9f9ZI83fxEnYQfyJb2j8Bx1me55p1UzowUyBmgdCrKB+2pRVC8jSXHWT ifXvRKqFopQaxouolHq3B/lEyQYwkJNdleW8ApSGOUC4/3unORzb2Vg4Ckj7KHpo2S6w GgNzrd+OXhs1PNJ31l9kaCOrsP6X+M4wZsk+UevgDDMv6CRbASoU9B76nCocV0ykT5qj uwCXrWE4KsjbH7lYOe/YU9TeCNSY45iFvsEH9ZUcpNiVvdV53NUgnbfbM6BXgeuSQ+M5 VOQQ== X-Gm-Message-State: ABy/qLa6NF0yxCqMLFQmnq9ZWiihrvJjWXihodD3fQaXvOlSVIQQdkgE ZF2zvsOsEeNrkRXPDj7HvTOPeA== X-Google-Smtp-Source: APBJJlGPrW24zARdxGxhNApX2wQ10GYEuWdo7LsP1f3yqH+RCOqal33F5fvEM8b13VSQsEOln+ii2Q== X-Received: by 2002:a17:903:22c1:b0:1b9:c207:1802 with SMTP id y1-20020a17090322c100b001b9c2071802mr8475947plg.0.1690193405012; Mon, 24 Jul 2023 03:10:05 -0700 (PDT) From: zhenwei pi To: berto@igalia.com, kwolf@redhat.com, groug@kaod.org, qemu_oss@crudebyte.com, hreitz@redhat.com Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, berrange@redhat.com, zhenwei pi , Gonglei Subject: [PATCH v4 5/9] cryptodev: use NULL throttle timer cb for read direction Date: Mon, 24 Jul 2023 18:09:35 +0800 Message-Id: <20230724100939.1022984-6-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230724100939.1022984-1-pizhenwei@bytedance.com> References: <20230724100939.1022984-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x634.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1690193515712100003 Content-Type: text/plain; charset="utf-8" Operations on a cryptodev are considered as *write* only, the callback of read direction is never invoked. Use NULL instead of an unreachable path(cryptodev_backend_throttle_timer_cb on read direction). The dummy read timer(never invoked) is already removed here, it means that the 'FIXME' tag is no longer needed. Reviewed-by: Alberto Garcia Reviewed-by: Hanna Czenczek Cc: Gonglei Signed-off-by: zhenwei pi --- backends/cryptodev.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backends/cryptodev.c b/backends/cryptodev.c index 7d29517843..5cfa25c61c 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -331,8 +331,7 @@ static void cryptodev_backend_set_throttle(CryptoDevBac= kend *backend, int field, if (!enabled) { throttle_init(&backend->ts); throttle_timers_init(&backend->tt, qemu_get_aio_context(), - QEMU_CLOCK_REALTIME, - cryptodev_backend_throttle_timer_cb, /* FIXME= */ + QEMU_CLOCK_REALTIME, NULL, cryptodev_backend_throttle_timer_cb, backend); } =20 --=20 2.34.1 From nobody Fri May 17 05:54:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1690193519; cv=none; d=zohomail.com; s=zohoarc; b=gYgukYFonBGdEEe3ZLq8l5lHLKEJtdTPnHHUMYc13YB6+pienhKq5lb7i8vxcGunHTFtVu0k9ZAf0uR4wzM08lLz2te4m1wWkJ8ka9A8HwFCmW9H1DFqc6nvkJnnkemqOqlDZnCkHL4/iRPMd3ITLmEGQl1/TrtY8gQaCh5P/Vw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690193519; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qacRUi0hhH5FP4hhwD8aVp/ujoAgoDtm7ItlVZRYtG4=; b=Z5fe4sLWBkiJ5kNJ6zC1wa10xXrFf57MP9glGeSPuRFrIDWujkM5VvnYWsgQCH793WOxl2E2QEqdPDTaQOEQ+WER1IlQnauMddICrrnwzr0YERhwR0YUCL94tbRHbvmDGzY+TkLD53h2kaXnnp0fWK6ikZz26rD/AeSQS8JGqgQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1690193519805948.6527305534391; Mon, 24 Jul 2023 03:11:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qNsWN-0007w3-RQ; Mon, 24 Jul 2023 06:10:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qNsW5-0007kI-Kn for qemu-devel@nongnu.org; Mon, 24 Jul 2023 06:10:13 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qNsW3-0000ke-1q for qemu-devel@nongnu.org; Mon, 24 Jul 2023 06:10:12 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1bba48b0bd2so3793485ad.3 for ; Mon, 24 Jul 2023 03:10:09 -0700 (PDT) Received: from libai.bytedance.net ([61.213.176.11]) by smtp.gmail.com with ESMTPSA id je2-20020a170903264200b001bb9d6b1baasm2419124plb.198.2023.07.24.03.10.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 03:10:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690193408; x=1690798208; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qacRUi0hhH5FP4hhwD8aVp/ujoAgoDtm7ItlVZRYtG4=; b=GbWrs45horAl23Wz6vxjQV1okKfcZvjhDRxRqrwUv+iAWrgJOiijz3ehjd98utimio aRlFdARUkkbX3LDybQ1CAqF98GHrAMc/pCBRcruyOILIZeM/9mrjkfUtKjCYlPh9sS6l xlR92zU5umi8rrhm+PUF+Op3k3DiA6+FBiDzUd2HtgLmjkzqO+KKPecnXRpif6mJpJM3 GxGhh0SxXiz4tZGKsLQFrI47GQqbZzqF35wFHMAJ7siyykdvuJjaGz345s6fhaswH3zx XdAc/xRYtiNUPdopWqJQsLH9w8eP2G0CmZ4RijyPaoj0nGpon4KEbyYVnjtj7AqklDjX th0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690193408; x=1690798208; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qacRUi0hhH5FP4hhwD8aVp/ujoAgoDtm7ItlVZRYtG4=; b=gaIqvhBRf3T3Fasp4w0Da/VlCEZnth7V+usb0dX05wrD6W2MjgE5nzm8Xi5yJ1dcIb V2hUJUg3+27AuD4gGV3qyrfR3J2xVniieiUFBWFMKQb72h2lvOR4+AWWFLKUVjSksMLN bdiXXW9Fvwp31QvdawZfVM8kPBgMjMdT/EE4+HPQ14syB5u9GZjGx4qorD76qWLaCwDR 7mHklfjO/BTdtlwo+EXQZ/Q3+78moBfJ3t7ZivNFoYnEUFjLBq/9pOxxaREvFaAKfD/A b9INhaYv5YJK9Dyzdje/RW0yjE+eu3Ju+d/3s1MjaGj9N+1S3pbayGOX33X53fmyvY3E jG8w== X-Gm-Message-State: ABy/qLY3t0W2HIIBH1iQ7WjQ8efYlKjgLch/93TyLUKUOewr8GkjyiTj wkX1EuMOikuVMmp5CPt1Gp6MYg== X-Google-Smtp-Source: APBJJlHHmLPcy+J6/i0C9oFDwJ9NKQLhpuidmqjZbyRMEsQSbZjzjBmpGnaeurrluPDPt6krzsLwDA== X-Received: by 2002:a17:902:f543:b0:1b6:771a:3516 with SMTP id h3-20020a170902f54300b001b6771a3516mr10794101plf.22.1690193408368; Mon, 24 Jul 2023 03:10:08 -0700 (PDT) From: zhenwei pi To: berto@igalia.com, kwolf@redhat.com, groug@kaod.org, qemu_oss@crudebyte.com, hreitz@redhat.com Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, berrange@redhat.com, zhenwei pi Subject: [PATCH v4 6/9] throttle: use enum ThrottleDirection instead of bool is_write Date: Mon, 24 Jul 2023 18:09:36 +0800 Message-Id: <20230724100939.1022984-7-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230724100939.1022984-1-pizhenwei@bytedance.com> References: <20230724100939.1022984-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x62d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1690193521194100001 Content-Type: text/plain; charset="utf-8" enum ThrottleDirection is already there, use ThrottleDirection instead of 'bool is_write' for throttle API, also modify related codes from block, fsdev, cryptodev and tests. Signed-off-by: zhenwei pi Reviewed-by: Hanna Czenczek --- backends/cryptodev.c | 9 +++++---- block/throttle-groups.c | 6 ++++-- fsdev/qemu-fsdev-throttle.c | 8 +++++--- include/qemu/throttle.h | 5 +++-- tests/unit/test-throttle.c | 4 ++-- util/throttle.c | 31 +++++++++++++++++-------------- 6 files changed, 36 insertions(+), 27 deletions(-) diff --git a/backends/cryptodev.c b/backends/cryptodev.c index 5cfa25c61c..06142eae57 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -242,10 +242,11 @@ static void cryptodev_backend_throttle_timer_cb(void = *opaque) continue; } =20 - throttle_account(&backend->ts, true, ret); + throttle_account(&backend->ts, THROTTLE_WRITE, ret); cryptodev_backend_operation(backend, op_info); if (throttle_enabled(&backend->tc) && - throttle_schedule_timer(&backend->ts, &backend->tt, true)) { + throttle_schedule_timer(&backend->ts, &backend->tt, + THROTTLE_WRITE)) { break; } } @@ -261,7 +262,7 @@ int cryptodev_backend_crypto_operation( goto do_account; } =20 - if (throttle_schedule_timer(&backend->ts, &backend->tt, true) || + if (throttle_schedule_timer(&backend->ts, &backend->tt, THROTTLE_WRITE= ) || !QTAILQ_EMPTY(&backend->opinfos)) { QTAILQ_INSERT_TAIL(&backend->opinfos, op_info, next); return 0; @@ -273,7 +274,7 @@ do_account: return ret; } =20 - throttle_account(&backend->ts, true, ret); + throttle_account(&backend->ts, THROTTLE_WRITE, ret); =20 return cryptodev_backend_operation(backend, op_info); } diff --git a/block/throttle-groups.c b/block/throttle-groups.c index fb203c3ced..3847d27801 100644 --- a/block/throttle-groups.c +++ b/block/throttle-groups.c @@ -270,6 +270,7 @@ static bool throttle_group_schedule_timer(ThrottleGroup= Member *tgm, ThrottleState *ts =3D tgm->throttle_state; ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); ThrottleTimers *tt =3D &tgm->throttle_timers; + ThrottleDirection direction =3D is_write ? THROTTLE_WRITE : THROTTLE_R= EAD; bool must_wait; =20 if (qatomic_read(&tgm->io_limits_disabled)) { @@ -281,7 +282,7 @@ static bool throttle_group_schedule_timer(ThrottleGroup= Member *tgm, return true; } =20 - must_wait =3D throttle_schedule_timer(ts, tt, is_write); + must_wait =3D throttle_schedule_timer(ts, tt, direction); =20 /* If a timer just got armed, set tgm as the current token */ if (must_wait) { @@ -364,6 +365,7 @@ void coroutine_fn throttle_group_co_io_limits_intercept= (ThrottleGroupMember *tgm bool must_wait; ThrottleGroupMember *token; ThrottleGroup *tg =3D container_of(tgm->throttle_state, ThrottleGroup,= ts); + ThrottleDirection direction =3D is_write ? THROTTLE_WRITE : THROTTLE_R= EAD; =20 assert(bytes >=3D 0); =20 @@ -386,7 +388,7 @@ void coroutine_fn throttle_group_co_io_limits_intercept= (ThrottleGroupMember *tgm } =20 /* The I/O will be executed, so do the accounting */ - throttle_account(tgm->throttle_state, is_write, bytes); + throttle_account(tgm->throttle_state, direction, bytes); =20 /* Schedule the next request */ schedule_next_request(tgm, is_write); diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index 5c83a1cc09..1c137d6f0f 100644 --- a/fsdev/qemu-fsdev-throttle.c +++ b/fsdev/qemu-fsdev-throttle.c @@ -97,16 +97,18 @@ void fsdev_throttle_init(FsThrottle *fst) void coroutine_fn fsdev_co_throttle_request(FsThrottle *fst, bool is_write, struct iovec *iov, int iovcnt) { + ThrottleDirection direction =3D is_write ? THROTTLE_WRITE : THROTTLE_R= EAD; + if (throttle_enabled(&fst->cfg)) { - if (throttle_schedule_timer(&fst->ts, &fst->tt, is_write) || + if (throttle_schedule_timer(&fst->ts, &fst->tt, direction) || !qemu_co_queue_empty(&fst->throttled_reqs[is_write])) { qemu_co_queue_wait(&fst->throttled_reqs[is_write], NULL); } =20 - throttle_account(&fst->ts, is_write, iov_size(iov, iovcnt)); + throttle_account(&fst->ts, direction, iov_size(iov, iovcnt)); =20 if (!qemu_co_queue_empty(&fst->throttled_reqs[is_write]) && - !throttle_schedule_timer(&fst->ts, &fst->tt, is_write)) { + !throttle_schedule_timer(&fst->ts, &fst->tt, direction)) { qemu_co_queue_next(&fst->throttled_reqs[is_write]); } } diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h index 9ca5ab8197..181245d29b 100644 --- a/include/qemu/throttle.h +++ b/include/qemu/throttle.h @@ -154,9 +154,10 @@ void throttle_config_init(ThrottleConfig *cfg); /* usage */ bool throttle_schedule_timer(ThrottleState *ts, ThrottleTimers *tt, - bool is_write); + ThrottleDirection direction); =20 -void throttle_account(ThrottleState *ts, bool is_write, uint64_t size); +void throttle_account(ThrottleState *ts, ThrottleDirection direction, + uint64_t size); void throttle_limits_to_config(ThrottleLimits *arg, ThrottleConfig *cfg, Error **errp); void throttle_config_to_limits(ThrottleConfig *cfg, ThrottleLimits *var); diff --git a/tests/unit/test-throttle.c b/tests/unit/test-throttle.c index 5547837a58..2c4754fb8a 100644 --- a/tests/unit/test-throttle.c +++ b/tests/unit/test-throttle.c @@ -637,9 +637,9 @@ static bool do_test_accounting(bool is_ops, /* are we t= esting bps or ops */ throttle_config(&ts, QEMU_CLOCK_VIRTUAL, &cfg); =20 /* account a read */ - throttle_account(&ts, false, size); + throttle_account(&ts, THROTTLE_READ, size); /* account a write */ - throttle_account(&ts, true, size); + throttle_account(&ts, THROTTLE_WRITE, size); =20 /* check total result */ index =3D to_test[is_ops][0]; diff --git a/util/throttle.c b/util/throttle.c index 0439028d21..9a37209bb8 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -136,11 +136,11 @@ int64_t throttle_compute_wait(LeakyBucket *bkt) =20 /* This function compute the time that must be waited while this IO * - * @is_write: true if the current IO is a write, false if it's a read + * @throttle: throttle direction * @ret: time to wait */ static int64_t throttle_compute_wait_for(ThrottleState *ts, - bool is_write) + ThrottleDirection direction) { BucketType to_check[2][4] =3D { {THROTTLE_BPS_TOTAL, THROTTLE_OPS_TOTAL, @@ -154,7 +154,7 @@ static int64_t throttle_compute_wait_for(ThrottleState = *ts, int i; =20 for (i =3D 0; i < 4; i++) { - BucketType index =3D to_check[is_write][i]; + BucketType index =3D to_check[direction][i]; wait =3D throttle_compute_wait(&ts->cfg.buckets[index]); if (wait > max_wait) { max_wait =3D wait; @@ -166,13 +166,13 @@ static int64_t throttle_compute_wait_for(ThrottleStat= e *ts, =20 /* compute the timer for this type of operation * - * @is_write: the type of operation + * @throttle: throttle direction * @now: the current clock timestamp * @next_timestamp: the resulting timer * @ret: true if a timer must be set */ static bool throttle_compute_timer(ThrottleState *ts, - bool is_write, + ThrottleDirection direction, int64_t now, int64_t *next_timestamp) { @@ -182,7 +182,7 @@ static bool throttle_compute_timer(ThrottleState *ts, throttle_do_leak(ts, now); =20 /* compute the wait time if any */ - wait =3D throttle_compute_wait_for(ts, is_write); + wait =3D throttle_compute_wait_for(ts, direction); =20 /* if the code must wait compute when the next timer should fire */ if (wait) { @@ -425,23 +425,24 @@ void throttle_get_config(ThrottleState *ts, ThrottleC= onfig *cfg) * NOTE: this function is not unit tested due to it's usage of timer_mod * * @tt: the timers structure - * @is_write: the type of operation (read/write) + * @throttle: throttle direction * @ret: true if the timer has been scheduled else false */ bool throttle_schedule_timer(ThrottleState *ts, ThrottleTimers *tt, - bool is_write) + ThrottleDirection direction) { int64_t now =3D qemu_clock_get_ns(tt->clock_type); int64_t next_timestamp; QEMUTimer *timer; bool must_wait; =20 - timer =3D is_write ? tt->timers[THROTTLE_WRITE] : tt->timers[THROTTLE_= READ]; + assert(direction < THROTTLE_MAX); + timer =3D tt->timers[direction]; assert(timer); =20 must_wait =3D throttle_compute_timer(ts, - is_write, + direction, now, &next_timestamp); =20 @@ -462,10 +463,11 @@ bool throttle_schedule_timer(ThrottleState *ts, =20 /* do the accounting for this operation * - * @is_write: the type of operation (read/write) + * @throttle: throttle direction * @size: the size of the operation */ -void throttle_account(ThrottleState *ts, bool is_write, uint64_t size) +void throttle_account(ThrottleState *ts, ThrottleDirection direction, + uint64_t size) { const BucketType bucket_types_size[2][2] =3D { { THROTTLE_BPS_TOTAL, THROTTLE_BPS_READ }, @@ -478,6 +480,7 @@ void throttle_account(ThrottleState *ts, bool is_write,= uint64_t size) double units =3D 1.0; unsigned i; =20 + assert(direction < THROTTLE_MAX); /* if cfg.op_size is defined and smaller than size we compute unit cou= nt */ if (ts->cfg.op_size && size > ts->cfg.op_size) { units =3D (double) size / ts->cfg.op_size; @@ -486,13 +489,13 @@ void throttle_account(ThrottleState *ts, bool is_writ= e, uint64_t size) for (i =3D 0; i < 2; i++) { LeakyBucket *bkt; =20 - bkt =3D &ts->cfg.buckets[bucket_types_size[is_write][i]]; + bkt =3D &ts->cfg.buckets[bucket_types_size[direction][i]]; bkt->level +=3D size; if (bkt->burst_length > 1) { bkt->burst_level +=3D size; } =20 - bkt =3D &ts->cfg.buckets[bucket_types_units[is_write][i]]; + bkt =3D &ts->cfg.buckets[bucket_types_units[direction][i]]; bkt->level +=3D units; if (bkt->burst_length > 1) { bkt->burst_level +=3D units; --=20 2.34.1 From nobody Fri May 17 05:54:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1690193532; cv=none; d=zohomail.com; s=zohoarc; b=CaisWXtwMBNNHryaUp1+ECQ/lxiX0vqwIKQW0JWy7x1FDjrMi/5ZRlOZXxAm42j/QrCMHtCVrwDWUHeSCQJrQr/QlzcnUbZSE45dQxmy7KLtwfszw13kQIvIDLWb9NNRQFq7hPR7aH1Xj4d1C4zpSL4PT/PtMeHRz6xjQNC/77Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690193532; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=l5hGyy9C4bW1jMhiyeNJHvEUqyBP6dGee4Td3XP+VNQ=; b=GALH/ewdegz/UpcMQbU4jKysYILovNrWWuXAeK5nVc0FM5E8Zt+NAUj4wHiA9bbPa6DTQKuk/nKJX90QW0ul/3+YZ0AdDyZQqREa8vN5QJX5e8xi7DufG6azJX7iRBGj/q30uQbXFCu1LnNKGMj2HhCXS4FdmhLm2KrPAKmdY1I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1690193532364972.3174687636291; Mon, 24 Jul 2023 03:12:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qNsWQ-0007zV-5u; Mon, 24 Jul 2023 06:10:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qNsW7-0007kv-M0 for qemu-devel@nongnu.org; Mon, 24 Jul 2023 06:10:16 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qNsW5-0000n1-CZ for qemu-devel@nongnu.org; Mon, 24 Jul 2023 06:10:14 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1bb81809ca8so16028805ad.3 for ; Mon, 24 Jul 2023 03:10:12 -0700 (PDT) Received: from libai.bytedance.net ([61.213.176.11]) by smtp.gmail.com with ESMTPSA id je2-20020a170903264200b001bb9d6b1baasm2419124plb.198.2023.07.24.03.10.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 03:10:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690193412; x=1690798212; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=l5hGyy9C4bW1jMhiyeNJHvEUqyBP6dGee4Td3XP+VNQ=; b=dGKWeGwOnxRRUqSUQ3C27211hBZeX74jiz7Exybgc5wMjyPmCqs7psd8D6BxdmBQWV i8LfRI5SOk9PGQYkDYcs+v++zVDyX4qWQxscroA+16K5FoTopeqrydePPFlInWZzt8Wx xdNoMgg07YNifICgt+XXBpk46xea3S1WOcoLXwYIkbMGwLbWQRsv1IJfG/5ssbHlZrpG vQ8XLgAMv6EHbQ47Kx62XomabQtbgo9AMSvCu2n9JyfT5039PKUmpOKixj6tQhr1JOE7 +0W7+PUVhk20X5GvyxyftNzntxH9iiP4ROcBXl4v5QNPKjkcMEY6r31HCAEm6ziLdQjx eGUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690193412; x=1690798212; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=l5hGyy9C4bW1jMhiyeNJHvEUqyBP6dGee4Td3XP+VNQ=; b=d+h0sR72eNtL2OCFWkZZwiXqUoPu1LHACrBosFTAM+ZzQDdUTB7GQSL10eFrS+pD10 ljac6tSccnhfFzsU6RhTSoLNQvT2aZQmWFpIaG01ncdj1ReEQKuEJ0wPcmLY9LMR6Mvd yA8WPw6csXVY2SJMlz5M3RHL7cWmY5xD93DtwARk3YTlQgDXvjEJ3AihCG/UkQFmgJ7N dxslWoAx6cNCCwIXE3DZC4GOMrOP+ZYJt0b6yJxnf1mtmBuwRjOfHDptM9YvV8Ek9LRX Llv09LlA3fTfmEyFf6MXeNXW1KPD+XRLxsax2maMAYr2QTrxBwfJAsS1buHJtM8mgbbb N1OA== X-Gm-Message-State: ABy/qLb32PXgZth1ginM7Mf2+JGGMtHkCs874J2/Z+sc6bYHWPnA+DUH LRWxsFUZZuAwLxCcybXaUXSh/A== X-Google-Smtp-Source: APBJJlETGz88s/ouJ1JfVycBqrVeBHYUuimnWkJsbX8daQAbQfZRg78XTREFvlRfhvDjz7YtlVBfsQ== X-Received: by 2002:a17:903:2286:b0:1b9:be2e:2b40 with SMTP id b6-20020a170903228600b001b9be2e2b40mr11536946plh.50.1690193411881; Mon, 24 Jul 2023 03:10:11 -0700 (PDT) From: zhenwei pi To: berto@igalia.com, kwolf@redhat.com, groug@kaod.org, qemu_oss@crudebyte.com, hreitz@redhat.com Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, berrange@redhat.com, zhenwei pi Subject: [PATCH v4 7/9] throttle: use THROTTLE_MAX/ARRAY_SIZE for hard code Date: Mon, 24 Jul 2023 18:09:37 +0800 Message-Id: <20230724100939.1022984-8-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230724100939.1022984-1-pizhenwei@bytedance.com> References: <20230724100939.1022984-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x636.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1690193533337100001 Content-Type: text/plain; charset="utf-8" The first dimension of both to_check and bucket_types_size/bucket_types_units is used as throttle direction, use THROTTLE_MAX instead of hard coded number. Also use ARRAY_SIZE() to avoid hard coded number for the second dimension. Hanna noticed that the two array should be static. Yes, turn them into static variables. Signed-off-by: zhenwei pi Reviewed-by: Hanna Czenczek --- util/throttle.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/util/throttle.c b/util/throttle.c index 9a37209bb8..9baa6b8a3a 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -142,7 +142,8 @@ int64_t throttle_compute_wait(LeakyBucket *bkt) static int64_t throttle_compute_wait_for(ThrottleState *ts, ThrottleDirection direction) { - BucketType to_check[2][4] =3D { {THROTTLE_BPS_TOTAL, + static const BucketType to_check[THROTTLE_MAX][4] =3D { + {THROTTLE_BPS_TOTAL, THROTTLE_OPS_TOTAL, THROTTLE_BPS_READ, THROTTLE_OPS_READ}, @@ -153,7 +154,7 @@ static int64_t throttle_compute_wait_for(ThrottleState = *ts, int64_t wait, max_wait =3D 0; int i; =20 - for (i =3D 0; i < 4; i++) { + for (i =3D 0; i < ARRAY_SIZE(to_check[THROTTLE_READ]); i++) { BucketType index =3D to_check[direction][i]; wait =3D throttle_compute_wait(&ts->cfg.buckets[index]); if (wait > max_wait) { @@ -469,11 +470,11 @@ bool throttle_schedule_timer(ThrottleState *ts, void throttle_account(ThrottleState *ts, ThrottleDirection direction, uint64_t size) { - const BucketType bucket_types_size[2][2] =3D { + static const BucketType bucket_types_size[THROTTLE_MAX][2] =3D { { THROTTLE_BPS_TOTAL, THROTTLE_BPS_READ }, { THROTTLE_BPS_TOTAL, THROTTLE_BPS_WRITE } }; - const BucketType bucket_types_units[2][2] =3D { + static const BucketType bucket_types_units[THROTTLE_MAX][2] =3D { { THROTTLE_OPS_TOTAL, THROTTLE_OPS_READ }, { THROTTLE_OPS_TOTAL, THROTTLE_OPS_WRITE } }; @@ -486,7 +487,7 @@ void throttle_account(ThrottleState *ts, ThrottleDirect= ion direction, units =3D (double) size / ts->cfg.op_size; } =20 - for (i =3D 0; i < 2; i++) { + for (i =3D 0; i < ARRAY_SIZE(bucket_types_size[THROTTLE_READ]); i++) { LeakyBucket *bkt; =20 bkt =3D &ts->cfg.buckets[bucket_types_size[direction][i]]; --=20 2.34.1 From nobody Fri May 17 05:54:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1690193538; cv=none; d=zohomail.com; s=zohoarc; b=NYOdN+roza2Gok9nY/ONzvikGJJwhqJQx2NlEotAeHCI3MHLop5D9gwJoHtE+Mx1K/I1rELCprwIEH0Ym4MM3Q1Fvb62lhwp+vj0fG18HtcbTw5Ey4yytnzAquXo/GSPJZ0pa814bqGLiFPNwZB2G5rRogBHxPYCsmsyKCxCHeA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690193538; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cYjCaoiHAm8swBEnNC+m57LDdWlBhajl9tKWF/1FxQ4=; b=SJCXYaguH7JDBL8AySP/Hk37/CmonBSraY4VffAj+CqKNKq2UhQFOy6WfbceIpnRjq7JDRGS7SaPWMSX52NI/J4C1djLoyaZz7llskEuJ675iqmFmOZLNmcV0eFVBwNS/yWmXbf3mDejaVPiXSJHjzgc282lL6LV/Otu0DujlK0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1690193538747342.01158159651266; Mon, 24 Jul 2023 03:12:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qNsWR-00084c-EF; Mon, 24 Jul 2023 06:10:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qNsWB-0007nM-GM for qemu-devel@nongnu.org; Mon, 24 Jul 2023 06:10:19 -0400 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qNsW8-0000np-Gi for qemu-devel@nongnu.org; Mon, 24 Jul 2023 06:10:17 -0400 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-5638180156aso2389946a12.0 for ; Mon, 24 Jul 2023 03:10:16 -0700 (PDT) Received: from libai.bytedance.net ([61.213.176.11]) by smtp.gmail.com with ESMTPSA id je2-20020a170903264200b001bb9d6b1baasm2419124plb.198.2023.07.24.03.10.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 03:10:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690193415; x=1690798215; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cYjCaoiHAm8swBEnNC+m57LDdWlBhajl9tKWF/1FxQ4=; b=J/sSz1SD1fxwBoi4iHmAhjN41U5OUoZUlGVvNSJsvSG/FN/W7QDTO+BsypUX4EFrRO rEE9bvXLbm5xR1G8NcA315oQ3EHvy3F/yMZWA+PF3tcmqq8h5vCbkWIYAL/RaMzgpIb2 v55bEqKuNbC6JrUoyAnWMbH1lcl/Zj8+veRhS995f6MehYusvaa8n+zjVXGXWKKw3RNg 1e1dCRo7SfHgY6ZkBlTEDnXKxrEZy5DHvogXCDv9KpSlYN+OONNbScaGN19MDMKBYRYu IJYOicT9vkgFWjsEMU4qhMUwuzlcE04g3BwM6dg4kW5TrGgCgfy5Bt04UYfpoWSOSs7q FOTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690193415; x=1690798215; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cYjCaoiHAm8swBEnNC+m57LDdWlBhajl9tKWF/1FxQ4=; b=kTD2kticMaDU8AQISEBHcSe2MxLexw/jUWVkKfNm3KSojd4C7N0IAu20Z0JXXBq8iS Z+KrYAMDPu6u0YH03gE1AhGLop3MLpEX6eLzwNC8ozJsXFnDOUeX2JUAI/qN5gP0ehyY 1y5CN88RrU1AZEEH1kL0k/xaUR5YYUUQ5VH1+HRfQ/vOcHaip0LpVScYoTTO1NVG+YYy qqUP2PNrusLQuHozKTxaJ6XZJ1YNPy3AmvUWm0K/qZKTLv3Jqy2ntmSBHO/+eGhMz1LK rIaX9jsYTJ6zcbddiiwWWaXMvywdPfL6QG6adl7++WvAqYuCeHoBfFCpdlIcohjDOqYd wv1Q== X-Gm-Message-State: ABy/qLbdHujYoRcRwOrESdbXEawvroMkgBLJFs4btJurO1BENRvKg8x/ 3yaJ50yAARIjTsWZWmkIyJzDxg== X-Google-Smtp-Source: APBJJlH8YGpBtweUOIoFi3Zx2zpIMFRPVZMxUE+L9ka+RL0CiIrtDkRwvh76oxuE7MqX2q8Lb9c3cg== X-Received: by 2002:a17:903:230a:b0:1bb:a85c:23cc with SMTP id d10-20020a170903230a00b001bba85c23ccmr2111947plh.15.1690193415312; Mon, 24 Jul 2023 03:10:15 -0700 (PDT) From: zhenwei pi To: berto@igalia.com, kwolf@redhat.com, groug@kaod.org, qemu_oss@crudebyte.com, hreitz@redhat.com Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, berrange@redhat.com, zhenwei pi Subject: [PATCH v4 8/9] fsdev: Use ThrottleDirection instread of bool is_write Date: Mon, 24 Jul 2023 18:09:38 +0800 Message-Id: <20230724100939.1022984-9-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230724100939.1022984-1-pizhenwei@bytedance.com> References: <20230724100939.1022984-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::531; envelope-from=pizhenwei@bytedance.com; helo=mail-pg1-x531.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1690193539995100001 Content-Type: text/plain; charset="utf-8" 'bool is_write' style is obsolete from throttle framework, adapt fsdev to the new style. Cc: Greg Kurz Signed-off-by: zhenwei pi Reviewed-by: Hanna Czenczek --- fsdev/qemu-fsdev-throttle.c | 14 +++++++------- fsdev/qemu-fsdev-throttle.h | 4 ++-- hw/9pfs/cofile.c | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index 1c137d6f0f..d912da906d 100644 --- a/fsdev/qemu-fsdev-throttle.c +++ b/fsdev/qemu-fsdev-throttle.c @@ -94,22 +94,22 @@ void fsdev_throttle_init(FsThrottle *fst) } } =20 -void coroutine_fn fsdev_co_throttle_request(FsThrottle *fst, bool is_write, +void coroutine_fn fsdev_co_throttle_request(FsThrottle *fst, + ThrottleDirection direction, struct iovec *iov, int iovcnt) { - ThrottleDirection direction =3D is_write ? THROTTLE_WRITE : THROTTLE_R= EAD; - + assert(direction < THROTTLE_MAX); if (throttle_enabled(&fst->cfg)) { if (throttle_schedule_timer(&fst->ts, &fst->tt, direction) || - !qemu_co_queue_empty(&fst->throttled_reqs[is_write])) { - qemu_co_queue_wait(&fst->throttled_reqs[is_write], NULL); + !qemu_co_queue_empty(&fst->throttled_reqs[direction])) { + qemu_co_queue_wait(&fst->throttled_reqs[direction], NULL); } =20 throttle_account(&fst->ts, direction, iov_size(iov, iovcnt)); =20 - if (!qemu_co_queue_empty(&fst->throttled_reqs[is_write]) && + if (!qemu_co_queue_empty(&fst->throttled_reqs[direction]) && !throttle_schedule_timer(&fst->ts, &fst->tt, direction)) { - qemu_co_queue_next(&fst->throttled_reqs[is_write]); + qemu_co_queue_next(&fst->throttled_reqs[direction]); } } } diff --git a/fsdev/qemu-fsdev-throttle.h b/fsdev/qemu-fsdev-throttle.h index a21aecddc7..daa8ca2494 100644 --- a/fsdev/qemu-fsdev-throttle.h +++ b/fsdev/qemu-fsdev-throttle.h @@ -23,14 +23,14 @@ typedef struct FsThrottle { ThrottleState ts; ThrottleTimers tt; ThrottleConfig cfg; - CoQueue throttled_reqs[2]; + CoQueue throttled_reqs[THROTTLE_MAX]; } FsThrottle; =20 int fsdev_throttle_parse_opts(QemuOpts *, FsThrottle *, Error **); =20 void fsdev_throttle_init(FsThrottle *); =20 -void coroutine_fn fsdev_co_throttle_request(FsThrottle *, bool , +void coroutine_fn fsdev_co_throttle_request(FsThrottle *, ThrottleDirectio= n , struct iovec *, int); =20 void fsdev_throttle_cleanup(FsThrottle *); diff --git a/hw/9pfs/cofile.c b/hw/9pfs/cofile.c index 9c5344039e..71174c3e4a 100644 --- a/hw/9pfs/cofile.c +++ b/hw/9pfs/cofile.c @@ -252,7 +252,7 @@ int coroutine_fn v9fs_co_pwritev(V9fsPDU *pdu, V9fsFidS= tate *fidp, if (v9fs_request_cancelled(pdu)) { return -EINTR; } - fsdev_co_throttle_request(s->ctx.fst, true, iov, iovcnt); + fsdev_co_throttle_request(s->ctx.fst, THROTTLE_WRITE, iov, iovcnt); v9fs_co_run_in_worker( { err =3D s->ops->pwritev(&s->ctx, &fidp->fs, iov, iovcnt, offse= t); @@ -272,7 +272,7 @@ int coroutine_fn v9fs_co_preadv(V9fsPDU *pdu, V9fsFidSt= ate *fidp, if (v9fs_request_cancelled(pdu)) { return -EINTR; } - fsdev_co_throttle_request(s->ctx.fst, false, iov, iovcnt); + fsdev_co_throttle_request(s->ctx.fst, THROTTLE_READ, iov, iovcnt); v9fs_co_run_in_worker( { err =3D s->ops->preadv(&s->ctx, &fidp->fs, iov, iovcnt, offset= ); --=20 2.34.1 From nobody Fri May 17 05:54:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1690193527; cv=none; d=zohomail.com; s=zohoarc; b=Jfw7di2l1gKa74YrFNuAhG5XRqKU9pOhRpu/Tpclt5t2SPBI9V/byFZnR7Ob8onvzJi27EAX0Jvi+BzjRKr6dW5rlnzOioESNJQMGVUlxmGvNpjP7MRKQOFZffHKxbT6dEFf8UI6lUPnwc0AGtDZTCpkgJTL0tcjmzfNpzoQ7f4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690193527; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6VPEAG/rwGthrLq2mN5H5WqCPAGdQoLGAKzXLULMkIQ=; b=FtJXEiZMx/2V3OF/NZaH1L/DdcrictsPOaM0euS3W8ptUtXy2QIwcsL1CCSsU2gewdsuq6A9QY2tTdel/BhZiQYq9U9y4Ew3oYegrf3MnXUAYUGUfC83vjFt10PfcmlbX4NYGAZdIDLGfxlOTGi2yRROdqKVSHm+51uT90up+mc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1690193527770965.7531932390036; Mon, 24 Jul 2023 03:12:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qNsWR-00084H-4x; Mon, 24 Jul 2023 06:10:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qNsWO-0007vx-Kq for qemu-devel@nongnu.org; Mon, 24 Jul 2023 06:10:32 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qNsWC-0000pv-Rf for qemu-devel@nongnu.org; Mon, 24 Jul 2023 06:10:27 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1b8ad8383faso32046235ad.0 for ; Mon, 24 Jul 2023 03:10:19 -0700 (PDT) Received: from libai.bytedance.net ([61.213.176.11]) by smtp.gmail.com with ESMTPSA id je2-20020a170903264200b001bb9d6b1baasm2419124plb.198.2023.07.24.03.10.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 03:10:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690193419; x=1690798219; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6VPEAG/rwGthrLq2mN5H5WqCPAGdQoLGAKzXLULMkIQ=; b=Kr4++d2DubKl3dIili3qhgBXoC6rJR6NAo6rROwRKoXYxvoiLlC5owM/3YL0rx4ecJ nwQS6O99rVNpI/aldD1ix/qgwDSC+b4hjIj0tPgLcmkVhieYSku4/O1ODewvEuFtzr0R zl/vZQ7obX0yALMtgG/Pc0g7XYfTKqT3ECpABhYfAGMDuIq1sGKu7hlJMgcqgc98DlH3 3CUP3lgInmXvJXoVnECYMSJsk5qd/AoZAFuTDlUvIAWKZgQgywdN32XS+SsWdMtAnR3n waDxfQ0g3tFFwBqdYklYLljet7ebhywGysqLWIIzpWh3CyUwfkjb8zh7N/+t8o7JON8q c8gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690193419; x=1690798219; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6VPEAG/rwGthrLq2mN5H5WqCPAGdQoLGAKzXLULMkIQ=; b=Brrn7bN4Qez0b9UJG05oq6Nl2FVlzH1izHfTfIGAV4TqzJI0/3iU47BL+T4vMIouUA 8WIVnn7IkR82NkY77munveJf+y3G3iLdynOCBGiXJzVuLLWWThVkLaPB+ZhtKf2F6BTW 2cfiuNvcWqechubGFzEVUJ1ptQ2R3m+LLkyE+MUL2dh8OaM89jp7wa7yPrJPYl72tXYL o1zDo8fnx5ixUlQVM2uFVTs/CFHkrDe7J2Xt4royzbiSsMMcGWhpY2ebPvW/0pPUtOJW 8kTgh/+7XcAsFNmO/uzibGrZbQKuRSiLXKKXdVQclZJ0g9KQLHV6bD5Ke7u5y6/HiUuP 9j5w== X-Gm-Message-State: ABy/qLaamsgj7ki92HkTbSWwa4Bux9BOVmRaj6llChZuG9TRA8cRp2py 7+fdyB9uZSqKyPkaSXpbLwAkxg== X-Google-Smtp-Source: APBJJlHqLSry+sOvY+RnnOc8RHfoK+bRM44u8v78eKN0M6wXssbWhRA/gf3+jE9AQj9Ih+bqfyC85A== X-Received: by 2002:a17:902:c404:b0:1b8:abe7:5a80 with SMTP id k4-20020a170902c40400b001b8abe75a80mr15197611plk.40.1690193418753; Mon, 24 Jul 2023 03:10:18 -0700 (PDT) From: zhenwei pi To: berto@igalia.com, kwolf@redhat.com, groug@kaod.org, qemu_oss@crudebyte.com, hreitz@redhat.com Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, berrange@redhat.com, zhenwei pi Subject: [PATCH v4 9/9] block/throttle-groups: Use ThrottleDirection instread of bool is_write Date: Mon, 24 Jul 2023 18:09:39 +0800 Message-Id: <20230724100939.1022984-10-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230724100939.1022984-1-pizhenwei@bytedance.com> References: <20230724100939.1022984-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x62d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1690193529151100003 Content-Type: text/plain; charset="utf-8" 'bool is_write' style is obsolete from throttle framework, adapt block throttle groups to the new style. Use a simple python script to test the new style: #!/usr/bin/python3 import subprocess import random import time commands =3D ['virsh blkdeviotune jammy vda --write-bytes-sec ', \ 'virsh blkdeviotune jammy vda --write-iops-sec ', \ 'virsh blkdeviotune jammy vda --read-bytes-sec ', \ 'virsh blkdeviotune jammy vda --read-iops-sec '] for loop in range(1, 1000): time.sleep(random.randrange(3, 5)) command =3D commands[random.randrange(0, 3)] + str(random.randrange(0, = 1000000)) subprocess.run(command, shell=3DTrue, check=3DTrue) This works fine. Signed-off-by: zhenwei pi --- block/throttle-groups.c | 105 ++++++++++++++++---------------- block/throttle.c | 8 +-- include/block/throttle-groups.h | 6 +- 3 files changed, 60 insertions(+), 59 deletions(-) diff --git a/block/throttle-groups.c b/block/throttle-groups.c index 3847d27801..c7c700fdb6 100644 --- a/block/throttle-groups.c +++ b/block/throttle-groups.c @@ -37,7 +37,7 @@ =20 static void throttle_group_obj_init(Object *obj); static void throttle_group_obj_complete(UserCreatable *obj, Error **errp); -static void timer_cb(ThrottleGroupMember *tgm, bool is_write); +static void timer_cb(ThrottleGroupMember *tgm, ThrottleDirection direction= ); =20 /* The ThrottleGroup structure (with its ThrottleState) is shared * among different ThrottleGroupMembers and it's independent from @@ -73,8 +73,8 @@ struct ThrottleGroup { QemuMutex lock; /* This lock protects the following four fields */ ThrottleState ts; QLIST_HEAD(, ThrottleGroupMember) head; - ThrottleGroupMember *tokens[2]; - bool any_timer_armed[2]; + ThrottleGroupMember *tokens[THROTTLE_MAX]; + bool any_timer_armed[THROTTLE_MAX]; QEMUClockType clock_type; =20 /* This field is protected by the global QEMU mutex */ @@ -197,13 +197,13 @@ static ThrottleGroupMember *throttle_group_next_tgm(T= hrottleGroupMember *tgm) * This assumes that tg->lock is held. * * @tgm: the ThrottleGroupMember - * @is_write: the type of operation (read/write) + * @direction: the ThrottleDirection * @ret: whether the ThrottleGroupMember has pending requests. */ static inline bool tgm_has_pending_reqs(ThrottleGroupMember *tgm, - bool is_write) + ThrottleDirection direction) { - return tgm->pending_reqs[is_write]; + return tgm->pending_reqs[direction]; } =20 /* Return the next ThrottleGroupMember in the round-robin sequence with pe= nding @@ -212,12 +212,12 @@ static inline bool tgm_has_pending_reqs(ThrottleGroup= Member *tgm, * This assumes that tg->lock is held. * * @tgm: the current ThrottleGroupMember - * @is_write: the type of operation (read/write) + * @direction: the ThrottleDirection * @ret: the next ThrottleGroupMember with pending requests, or tgm = if * there is none. */ static ThrottleGroupMember *next_throttle_token(ThrottleGroupMember *tgm, - bool is_write) + ThrottleDirection directio= n) { ThrottleState *ts =3D tgm->throttle_state; ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); @@ -227,16 +227,16 @@ static ThrottleGroupMember *next_throttle_token(Throt= tleGroupMember *tgm, * it's being drained. Skip the round-robin search and return tgm * immediately if it has pending requests. Otherwise we could be * forcing it to wait for other member's throttled requests. */ - if (tgm_has_pending_reqs(tgm, is_write) && + if (tgm_has_pending_reqs(tgm, direction) && qatomic_read(&tgm->io_limits_disabled)) { return tgm; } =20 - start =3D token =3D tg->tokens[is_write]; + start =3D token =3D tg->tokens[direction]; =20 /* get next bs round in round robin style */ token =3D throttle_group_next_tgm(token); - while (token !=3D start && !tgm_has_pending_reqs(token, is_write)) { + while (token !=3D start && !tgm_has_pending_reqs(token, direction)) { token =3D throttle_group_next_tgm(token); } =20 @@ -244,12 +244,12 @@ static ThrottleGroupMember *next_throttle_token(Throt= tleGroupMember *tgm, * then decide the token is the current tgm because chances are * the current tgm got the current request queued. */ - if (token =3D=3D start && !tgm_has_pending_reqs(token, is_write)) { + if (token =3D=3D start && !tgm_has_pending_reqs(token, direction)) { token =3D tgm; } =20 /* Either we return the original TGM, or one with pending requests */ - assert(token =3D=3D tgm || tgm_has_pending_reqs(token, is_write)); + assert(token =3D=3D tgm || tgm_has_pending_reqs(token, direction)); =20 return token; } @@ -261,16 +261,15 @@ static ThrottleGroupMember *next_throttle_token(Throt= tleGroupMember *tgm, * This assumes that tg->lock is held. * * @tgm: the current ThrottleGroupMember - * @is_write: the type of operation (read/write) + * @direction: the ThrottleDirection * @ret: whether the I/O request needs to be throttled or not */ static bool throttle_group_schedule_timer(ThrottleGroupMember *tgm, - bool is_write) + ThrottleDirection direction) { ThrottleState *ts =3D tgm->throttle_state; ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); ThrottleTimers *tt =3D &tgm->throttle_timers; - ThrottleDirection direction =3D is_write ? THROTTLE_WRITE : THROTTLE_R= EAD; bool must_wait; =20 if (qatomic_read(&tgm->io_limits_disabled)) { @@ -278,7 +277,7 @@ static bool throttle_group_schedule_timer(ThrottleGroup= Member *tgm, } =20 /* Check if any of the timers in this group is already armed */ - if (tg->any_timer_armed[is_write]) { + if (tg->any_timer_armed[direction]) { return true; } =20 @@ -286,8 +285,8 @@ static bool throttle_group_schedule_timer(ThrottleGroup= Member *tgm, =20 /* If a timer just got armed, set tgm as the current token */ if (must_wait) { - tg->tokens[is_write] =3D tgm; - tg->any_timer_armed[is_write] =3D true; + tg->tokens[direction] =3D tgm; + tg->any_timer_armed[direction] =3D true; } =20 return must_wait; @@ -297,15 +296,15 @@ static bool throttle_group_schedule_timer(ThrottleGro= upMember *tgm, * any request was actually pending. * * @tgm: the current ThrottleGroupMember - * @is_write: the type of operation (read/write) + * @direction: the ThrottleDirection */ static bool coroutine_fn throttle_group_co_restart_queue(ThrottleGroupMemb= er *tgm, - bool is_write) + ThrottleDirection= direction) { bool ret; =20 qemu_co_mutex_lock(&tgm->throttled_reqs_lock); - ret =3D qemu_co_queue_next(&tgm->throttled_reqs[is_write]); + ret =3D qemu_co_queue_next(&tgm->throttled_reqs[direction]); qemu_co_mutex_unlock(&tgm->throttled_reqs_lock); =20 return ret; @@ -316,9 +315,10 @@ static bool coroutine_fn throttle_group_co_restart_que= ue(ThrottleGroupMember *tg * This assumes that tg->lock is held. * * @tgm: the current ThrottleGroupMember - * @is_write: the type of operation (read/write) + * @direction: the ThrottleDirection */ -static void schedule_next_request(ThrottleGroupMember *tgm, bool is_write) +static void schedule_next_request(ThrottleGroupMember *tgm, + ThrottleDirection direction) { ThrottleState *ts =3D tgm->throttle_state; ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); @@ -326,27 +326,27 @@ static void schedule_next_request(ThrottleGroupMember= *tgm, bool is_write) ThrottleGroupMember *token; =20 /* Check if there's any pending request to schedule next */ - token =3D next_throttle_token(tgm, is_write); - if (!tgm_has_pending_reqs(token, is_write)) { + token =3D next_throttle_token(tgm, direction); + if (!tgm_has_pending_reqs(token, direction)) { return; } =20 /* Set a timer for the request if it needs to be throttled */ - must_wait =3D throttle_group_schedule_timer(token, is_write); + must_wait =3D throttle_group_schedule_timer(token, direction); =20 /* If it doesn't have to wait, queue it for immediate execution */ if (!must_wait) { /* Give preference to requests from the current tgm */ if (qemu_in_coroutine() && - throttle_group_co_restart_queue(tgm, is_write)) { + throttle_group_co_restart_queue(tgm, direction)) { token =3D tgm; } else { ThrottleTimers *tt =3D &token->throttle_timers; int64_t now =3D qemu_clock_get_ns(tg->clock_type); - timer_mod(tt->timers[is_write], now); - tg->any_timer_armed[is_write] =3D true; + timer_mod(tt->timers[direction], now); + tg->any_timer_armed[direction] =3D true; } - tg->tokens[is_write] =3D token; + tg->tokens[direction] =3D token; } } =20 @@ -356,49 +356,49 @@ static void schedule_next_request(ThrottleGroupMember= *tgm, bool is_write) * * @tgm: the current ThrottleGroupMember * @bytes: the number of bytes for this I/O - * @is_write: the type of operation (read/write) + * @direction: the ThrottleDirection */ void coroutine_fn throttle_group_co_io_limits_intercept(ThrottleGroupMembe= r *tgm, int64_t bytes, - bool is_write) + ThrottleDirection = direction) { bool must_wait; ThrottleGroupMember *token; ThrottleGroup *tg =3D container_of(tgm->throttle_state, ThrottleGroup,= ts); - ThrottleDirection direction =3D is_write ? THROTTLE_WRITE : THROTTLE_R= EAD; =20 assert(bytes >=3D 0); + assert(direction < THROTTLE_MAX); =20 qemu_mutex_lock(&tg->lock); =20 /* First we check if this I/O has to be throttled. */ - token =3D next_throttle_token(tgm, is_write); - must_wait =3D throttle_group_schedule_timer(token, is_write); + token =3D next_throttle_token(tgm, direction); + must_wait =3D throttle_group_schedule_timer(token, direction); =20 /* Wait if there's a timer set or queued requests of this type */ - if (must_wait || tgm->pending_reqs[is_write]) { - tgm->pending_reqs[is_write]++; + if (must_wait || tgm->pending_reqs[direction]) { + tgm->pending_reqs[direction]++; qemu_mutex_unlock(&tg->lock); qemu_co_mutex_lock(&tgm->throttled_reqs_lock); - qemu_co_queue_wait(&tgm->throttled_reqs[is_write], + qemu_co_queue_wait(&tgm->throttled_reqs[direction], &tgm->throttled_reqs_lock); qemu_co_mutex_unlock(&tgm->throttled_reqs_lock); qemu_mutex_lock(&tg->lock); - tgm->pending_reqs[is_write]--; + tgm->pending_reqs[direction]--; } =20 /* The I/O will be executed, so do the accounting */ throttle_account(tgm->throttle_state, direction, bytes); =20 /* Schedule the next request */ - schedule_next_request(tgm, is_write); + schedule_next_request(tgm, direction); =20 qemu_mutex_unlock(&tg->lock); } =20 typedef struct { ThrottleGroupMember *tgm; - bool is_write; + ThrottleDirection direction; } RestartData; =20 static void coroutine_fn throttle_group_restart_queue_entry(void *opaque) @@ -407,16 +407,16 @@ static void coroutine_fn throttle_group_restart_queue= _entry(void *opaque) ThrottleGroupMember *tgm =3D data->tgm; ThrottleState *ts =3D tgm->throttle_state; ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); - bool is_write =3D data->is_write; + ThrottleDirection direction =3D data->direction; bool empty_queue; =20 - empty_queue =3D !throttle_group_co_restart_queue(tgm, is_write); + empty_queue =3D !throttle_group_co_restart_queue(tgm, direction); =20 /* If the request queue was empty then we have to take care of * scheduling the next one */ if (empty_queue) { qemu_mutex_lock(&tg->lock); - schedule_next_request(tgm, is_write); + schedule_next_request(tgm, direction); qemu_mutex_unlock(&tg->lock); } =20 @@ -426,18 +426,19 @@ static void coroutine_fn throttle_group_restart_queue= _entry(void *opaque) aio_wait_kick(); } =20 -static void throttle_group_restart_queue(ThrottleGroupMember *tgm, bool is= _write) +static void throttle_group_restart_queue(ThrottleGroupMember *tgm, + ThrottleDirection direction) { Coroutine *co; RestartData *rd =3D g_new0(RestartData, 1); =20 rd->tgm =3D tgm; - rd->is_write =3D is_write; + rd->direction =3D direction; =20 /* This function is called when a timer is fired or when * throttle_group_restart_tgm() is called. Either way, there can * be no timer pending on this tgm at this point */ - assert(!timer_pending(tgm->throttle_timers.timers[is_write])); + assert(!timer_pending(tgm->throttle_timers.timers[direction])); =20 qatomic_inc(&tgm->restart_pending); =20 @@ -502,20 +503,20 @@ void throttle_group_get_config(ThrottleGroupMember *t= gm, ThrottleConfig *cfg) * because it had been throttled. * * @tgm: the ThrottleGroupMember whose request had been throttled - * @is_write: the type of operation (read/write) + * @direction: the ThrottleDirection */ -static void timer_cb(ThrottleGroupMember *tgm, bool is_write) +static void timer_cb(ThrottleGroupMember *tgm, ThrottleDirection direction) { ThrottleState *ts =3D tgm->throttle_state; ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); =20 /* The timer has just been fired, so we can update the flag */ qemu_mutex_lock(&tg->lock); - tg->any_timer_armed[is_write] =3D false; + tg->any_timer_armed[direction] =3D false; qemu_mutex_unlock(&tg->lock); =20 /* Run the request that was waiting for this timer */ - throttle_group_restart_queue(tgm, is_write); + throttle_group_restart_queue(tgm, direction); } =20 static void read_timer_cb(void *opaque) diff --git a/block/throttle.c b/block/throttle.c index 3aaef18d4e..1098a4ae9a 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -118,7 +118,7 @@ throttle_co_preadv(BlockDriverState *bs, int64_t offset= , int64_t bytes, { =20 ThrottleGroupMember *tgm =3D bs->opaque; - throttle_group_co_io_limits_intercept(tgm, bytes, false); + throttle_group_co_io_limits_intercept(tgm, bytes, THROTTLE_READ); =20 return bdrv_co_preadv(bs->file, offset, bytes, qiov, flags); } @@ -128,7 +128,7 @@ throttle_co_pwritev(BlockDriverState *bs, int64_t offse= t, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { ThrottleGroupMember *tgm =3D bs->opaque; - throttle_group_co_io_limits_intercept(tgm, bytes, true); + throttle_group_co_io_limits_intercept(tgm, bytes, THROTTLE_WRITE); =20 return bdrv_co_pwritev(bs->file, offset, bytes, qiov, flags); } @@ -138,7 +138,7 @@ throttle_co_pwrite_zeroes(BlockDriverState *bs, int64_t= offset, int64_t bytes, BdrvRequestFlags flags) { ThrottleGroupMember *tgm =3D bs->opaque; - throttle_group_co_io_limits_intercept(tgm, bytes, true); + throttle_group_co_io_limits_intercept(tgm, bytes, THROTTLE_WRITE); =20 return bdrv_co_pwrite_zeroes(bs->file, offset, bytes, flags); } @@ -147,7 +147,7 @@ static int coroutine_fn GRAPH_RDLOCK throttle_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes) { ThrottleGroupMember *tgm =3D bs->opaque; - throttle_group_co_io_limits_intercept(tgm, bytes, true); + throttle_group_co_io_limits_intercept(tgm, bytes, THROTTLE_WRITE); =20 return bdrv_co_pdiscard(bs->file, offset, bytes); } diff --git a/include/block/throttle-groups.h b/include/block/throttle-group= s.h index ff282fc0f8..2355e8d9de 100644 --- a/include/block/throttle-groups.h +++ b/include/block/throttle-groups.h @@ -37,7 +37,7 @@ typedef struct ThrottleGroupMember { AioContext *aio_context; /* throttled_reqs_lock protects the CoQueues for throttled requests. = */ CoMutex throttled_reqs_lock; - CoQueue throttled_reqs[2]; + CoQueue throttled_reqs[THROTTLE_MAX]; =20 /* Nonzero if the I/O limits are currently being ignored; generally * it is zero. Accessed with atomic operations. @@ -54,7 +54,7 @@ typedef struct ThrottleGroupMember { * throttle_state tells us if I/O limits are configured. */ ThrottleState *throttle_state; ThrottleTimers throttle_timers; - unsigned pending_reqs[2]; + unsigned pending_reqs[THROTTLE_MAX]; QLIST_ENTRY(ThrottleGroupMember) round_robin; =20 } ThrottleGroupMember; @@ -78,7 +78,7 @@ void throttle_group_restart_tgm(ThrottleGroupMember *tgm); =20 void coroutine_fn throttle_group_co_io_limits_intercept(ThrottleGroupMembe= r *tgm, int64_t bytes, - bool is_write); + ThrottleDirection = direction); void throttle_group_attach_aio_context(ThrottleGroupMember *tgm, AioContext *new_context); void throttle_group_detach_aio_context(ThrottleGroupMember *tgm); --=20 2.34.1