From nobody Wed May 15 18:24:53 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=1690512872; cv=none; d=zohomail.com; s=zohoarc; b=aj7oz1bTPlQaJzdhnnol54wWLyspXXhYC8U2ki0F7nnatB7Alnt1HgKHAhSwM1m/YkuC57pyorVz5GxTE5nOa0rzz+k3tzYt25Cxh4OgMzf1+Qf4px2Afk3VeXIbUFWqmz8iVdUGgtWSw5Ai2ejEq5tMuVIQnT3zU5Y5xMeFzuA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690512872; 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=eDJQrRqixWsuDdFvrk2LRaf/hG2LAFSsJjDNc5+h2HTOTWk3hn71NHuccYIZ2dh1uMRWH5KEo6RYekkAQcY14LNBd4LsSJOHnKcNMs1LxP4BeshR9Ume4/nOIZnQ0OtmqemAttx32FfZbbVgFA3BiYeWeJydqNaW2wZHXFlHVzM= 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 1690512872162705.9481979586687; Thu, 27 Jul 2023 19:54:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qPD5c-0007tr-Ge; Thu, 27 Jul 2023 22:20:24 -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 1qPD5a-0007su-It for qemu-devel@nongnu.org; Thu, 27 Jul 2023 22:20:22 -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 1qPD5Y-0006u1-Ne for qemu-devel@nongnu.org; Thu, 27 Jul 2023 22:20:22 -0400 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1bba2318546so13323815ad.1 for ; Thu, 27 Jul 2023 19:20:16 -0700 (PDT) Received: from libai.bytedance.net ([61.213.176.11]) by smtp.gmail.com with ESMTPSA id b21-20020a170902d31500b001bb9f104328sm2312947plc.146.2023.07.27.19.20.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 19:20:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690510816; x=1691115616; 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=MU+3C2/mKJj+HSXsyJcSKa3ZeZ3U+3FvFiGVh5VJlIsB9Y/b2d47wlW5GITa+gTrlx +qyEBwra7SJmQ2Q8/c0y4JmXK7FbQCVULmluGfrwwjNm3VizHO8Mn1isL/iMvOf17avw RN72ap2VPzrYxKHuG1PSSk56xdYAGaIZaCdBOCZyRuwOqyRFU1V+S14NiwgUdulnFVD/ s87uclcXjbD97snU/GboJJUgMMvyJdrtXmLks+m/aJ5f2/Brphw+qNjIsm3kwhGyz+9+ nOd6JUIrw2n6NL+70OYjnIMnPIbKnIJaeDSvXqrWpa6SRcjGIaLKJXE3Ek4ncV/A3ALQ Lw3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690510816; x=1691115616; 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=MqLZ3uGhgDgxHj7d+XsZcORDEzmecLQtjVS9sXycVI7yClyDZjQD3sqwpbFqtio6TG nyKlDIt0e1Y4O8vYb+RYhVtlnWrIgPlQYeaNeYAP5hl6+f5CeAaljgwJQAbrWlEI5Xze r1UXk8l8OcAg9nMiwkT+N9eTqHYEAMEw4lgFK3fpQeErGjI+BxJvNvSaxr0txbTaZfjn y6yR92MurqIafOqrIUOkRFxXLWm0pwHCmWlbnlAdoMEk4FotpSh4BGShH+hbiWcjG6oA vd4IJlMxFJDJA8I723WraLUlWjwOn2jLgp3se0xCUdjazeLjDFkRhSMs/VDoElobIVPW /yww== X-Gm-Message-State: ABy/qLZZtDZPzSCQfYwlxYkzOe0SgFGvdPeH91HNLR8ooOLvzmx0Sp+i VJC582dpsbLnXVBn3zN4Gf+2cA== X-Google-Smtp-Source: APBJJlEmdkOyYJX1Hb1GYkIJhyHtll2BbB+dB0ZWWURkGwYX/YR1m1taIJeJ/GkWsGnD1O0pQUhfAA== X-Received: by 2002:a17:902:8542:b0:1b7:ecbb:aa06 with SMTP id d2-20020a170902854200b001b7ecbbaa06mr385124plo.55.1690510815953; Thu, 27 Jul 2023 19:20:15 -0700 (PDT) From: zhenwei pi To: berto@igalia.com, kwolf@redhat.com, hreitz@redhat.com Cc: qemu_oss@crudebyte.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, zhenwei pi Subject: [PATCH v5 1/9] throttle: introduce enum ThrottleDirection Date: Fri, 28 Jul 2023 10:19:58 +0800 Message-Id: <20230728022006.1098509-2-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230728022006.1098509-1-pizhenwei@bytedance.com> References: <20230728022006.1098509-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, 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: 1690512875208100003 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 Wed May 15 18:24:53 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=1690512036; cv=none; d=zohomail.com; s=zohoarc; b=ZfI6YdSUSa4g4JRSfFeGezlHblV7RkNvI8ReNo6H/x7dspyCTpaRCcaIeIMeM8hOvcVbz2pn19ogUHzO7inqh5bCTm2VCZmHfdp/81mwdivR2CydJphOkcs99HsCSLtNrNUs9EgS/zA6sx6tOs3qlRa1Swhufikt02auxLte17U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690512036; 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=cVbPDOpDDOPCpaoI83xwqe5c0EwHKJFaeDsXMGpwCcSOq3gfzq8Gd+Ksw7x0o7MxFDjuKlgBHrLkdQKEEQmEJFa6bfayV2D7zRyZfMP8vdteRn2QT37ODMj++vllAf9MeVhfXEQnrXRHigO56c5EEGclnPibvP4C7X4sNUv6XuA= 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 1690512035799712.0943797165758; Thu, 27 Jul 2023 19:40:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qPD5g-0007vP-Nx; Thu, 27 Jul 2023 22:20:28 -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 1qPD5a-0007sr-DW for qemu-devel@nongnu.org; Thu, 27 Jul 2023 22:20:22 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qPD5Y-0006vY-49 for qemu-devel@nongnu.org; Thu, 27 Jul 2023 22:20:22 -0400 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1bb775625e2so10429955ad.1 for ; Thu, 27 Jul 2023 19:20:19 -0700 (PDT) Received: from libai.bytedance.net ([61.213.176.11]) by smtp.gmail.com with ESMTPSA id b21-20020a170902d31500b001bb9f104328sm2312947plc.146.2023.07.27.19.20.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 19:20:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690510819; x=1691115619; 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=MreQ7FUhcIKjf+CqukObOMxWJSsc+na7SHQiDn7W7RyCwr3iXzegqx1IY2bu3U1/yp sNkiR6vX3oyMTO+vxWDIECnWzaDNTjX3uaKMuaODV0PPACjnje9QISOcqHbVEWdbgxLe hb0JDZvYHioat15hUWNA5ZKl+BqxWcdJwmgmTGU3MhojTkdgnS3s6OdqAamrdHM3pRHx GhZD+FYkZGN7WirHWhweSJE1r+qlzNCa3f67pbpTbQu213853YktpztkeiIfmk0EXufL nkfN4BFpUYz9N+NG0x76CxlEAo6tP3w1qqKVqDqYx3S4YrAIytJsx8kHJW0Ep3Y4JC3b JSKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690510819; x=1691115619; 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=PCMkbLlQ0DoPMb5a6gaLZyKjN5i/UONCkvtQLDHB6CcB642xgZdIJLYmb2Vq1Pr5wZ SNd5bFUmZeoPZ6cIFrDheX0KxrPBxlbmF2T0c4Uc//crGyRRxrjx+sUCkK73o+8dkexZ 0cysRLGVEQaHjGoPpZKj9de8B2xl3PxcpkgNzKaTDM5WBnEVP7tOt5YFmSBwtC4xFb2w X0OXDLgsLfslaFnyZowNWsqk2YIgXUZd1wowjL3bsGN+Yg7pynKVcaHDPnGoewRhP6Fm Z+6xIi5JPXISGBXX3SEJDqKl1snvmUYKZXQmrv+n2rihYaiVjm4aGUu7x6X4AhWwcd2L j6Hg== X-Gm-Message-State: ABy/qLbg0sbaF59Zyy1Pb6WIljo07C9K/7/xMAwxXrmcAc1mXsgBRhqf NTKI+f+mh8uYr8SYg+q/069cJw== X-Google-Smtp-Source: APBJJlHgr1Vn/vL1KLbCeWbW/yumSwzG1RU1lnzBdjTJ7cnS382yLcR17lMWliVB3LLZXRGeypDp3A== X-Received: by 2002:a17:902:d506:b0:1b8:c8bc:c81b with SMTP id b6-20020a170902d50600b001b8c8bcc81bmr627535plg.21.1690510818893; Thu, 27 Jul 2023 19:20:18 -0700 (PDT) From: zhenwei pi To: berto@igalia.com, kwolf@redhat.com, hreitz@redhat.com Cc: qemu_oss@crudebyte.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, zhenwei pi Subject: [PATCH v5 2/9] test-throttle: use enum ThrottleDirection Date: Fri, 28 Jul 2023 10:19:59 +0800 Message-Id: <20230728022006.1098509-3-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230728022006.1098509-1-pizhenwei@bytedance.com> References: <20230728022006.1098509-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::62e; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x62e.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: 1690512039356100003 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 Wed May 15 18:24:53 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=1690515894; cv=none; d=zohomail.com; s=zohoarc; b=DwZxxWxLyJ8Kw3z4Z4X2PGvNuHvQTHmITS91owTrvlyO0LiQO3mqJyeJ/ZFGcICAPhapPnQXuF+pY9azkLELxV/xXP+K93fnmeXK0xmt9uCHd4STWHRbAckJrgbiZWsskBNhH99RHG0PWA0o/7uhOBYI4HD2TjjY4D53qzprYaA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690515894; 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=R3z34g4mGZulapFy+xIGwbE3qV90OuMqLsvXsx3TrdRnLbUIiPynMyEyNeX+QmtS8wzmUaEr+b5/FjZV2Z5okc2OHpKefJ4w265wT9gJbKcwRxhPekIiyHVS5jbsL76k06uNo4uzIOh+m3Ah9CF/EmF1oZVKRV0/n6X4iJAKG7o= 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 1690515894789172.69683509894003; Thu, 27 Jul 2023 20:44:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qPD5k-0007vg-Kk; Thu, 27 Jul 2023 22:20:32 -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 1qPD5d-0007uf-CI for qemu-devel@nongnu.org; Thu, 27 Jul 2023 22:20:25 -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 1qPD5b-0006y7-N7 for qemu-devel@nongnu.org; Thu, 27 Jul 2023 22:20:25 -0400 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1b8ad356f03so10029435ad.1 for ; Thu, 27 Jul 2023 19:20:22 -0700 (PDT) Received: from libai.bytedance.net ([61.213.176.11]) by smtp.gmail.com with ESMTPSA id b21-20020a170902d31500b001bb9f104328sm2312947plc.146.2023.07.27.19.20.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 19:20:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690510822; x=1691115622; 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=dKHX52/KdDVjUCR/V0MslzQvUF8/jl7FNTUo2jhmq0r3syWXDo0vvk8bFZfrJAtSdI W/+akKONT5OPPJWIEvv1v+vqdcMbA8AZ53tsn8Xyc0XxOrjr03hNNp+QgQBfgqCwkYyj pkvkvKdv8Z7I0dfJ1L2DXcbzYO6QtXclHRQIlOpccVzJM7DNgepq6YM/7CWB87HcGSzO 0AkJ/LPU4plVw8FO6NNBjZASy1x7ZTES6hc2W37s3+aPaNXMbNq6wOBktBsTpegAQSG6 oLCEslRMmToo7cWPr7+eui6YZpdtIPxF8mNbP+C86hYWGPkSig583a1U2p9rvwFiMofQ SeFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690510822; x=1691115622; 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=QT958vKchBsD9l4wEpcWVUz/9MqcoHX48q6vOz7QXOq4TwPgdKoQKFqlDxvatT934p uEWkN3Yv8Lkhbu9H8TxJh+gMKeGLStNNvWR3uaLdEqNSZO0Wvsjad1gXuRjfdWY/ZJDF eGQuJ6xii9Fv4gLGa+ikGJOLvchIfQw7rlYeb9WbeZLiNXoTlptXAf+HAnyj6UUMQHT/ 8ji8pDxCi4CyinhPZsUaa0FSZvoFyIQx6nrFED6/7ZUBR9j8RQWlbNZAlE1jbER091Ta 4yRKexNkG6xp/FpCXY+3dUBtNMdXALh7p3P/VuoB4zeq6DOojR/YgK//01lOnaZMtgz6 uyVg== X-Gm-Message-State: ABy/qLama8EvcxXs4glaC1eHacxjAVpL1efnPBFB4/ahyZTC6a5aik2P 0pvJBH1KdhRTj1GSKa/ozIndRg== X-Google-Smtp-Source: APBJJlFtsZom+Mx62/Un/xN3hg/6mUBhhHWC/+DT10L3GeN1mEL1OkFm3MxXTk+JvMKDHlKKa83R1w== X-Received: by 2002:a17:903:18c:b0:1b9:e481:ef3f with SMTP id z12-20020a170903018c00b001b9e481ef3fmr317061plg.9.1690510821932; Thu, 27 Jul 2023 19:20:21 -0700 (PDT) From: zhenwei pi To: berto@igalia.com, kwolf@redhat.com, hreitz@redhat.com Cc: qemu_oss@crudebyte.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, zhenwei pi Subject: [PATCH v5 3/9] throttle: support read-only and write-only Date: Fri, 28 Jul 2023 10:20:00 +0800 Message-Id: <20230728022006.1098509-4-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230728022006.1098509-1-pizhenwei@bytedance.com> References: <20230728022006.1098509-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, 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: 1690515896611100001 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 Wed May 15 18:24:53 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=1690515654; cv=none; d=zohomail.com; s=zohoarc; b=VKyyxmWbHVAqajntPNm83EN0V6vr0iSReebqNmeqR5Jv6VVaVbLF9YLdhxonXb4I4qg6FpS4WIGU73zKyRnXFbYmiDYD+Kq4UAFQ3r2dlUzux+NKDpAxQXaO2Y0qWnoRMustpJ7xEj79GfUOInDADwfVKdf2hQI4V6tRrZdPLSQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690515654; 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=Sb7wRhJwRsh4JeTdZfgop2AlRFRrgiwostDBJyUBGLamNjbMm3i91oOngkVdRlXyCKYIPyGSoBzK2+G8ploT/VtYnYj4iikrrOE9a47fa1MdskSYFyvD8QIA5T2aH4b3zZ4LFm10TL98PTd9gdil+zTotPU+g7wX0fUt7BiUqNg= 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 1690515654085155.17488272819776; Thu, 27 Jul 2023 20:40:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qPD5m-0007wF-UF; Thu, 27 Jul 2023 22:20: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 1qPD5f-0007vR-Kk for qemu-devel@nongnu.org; Thu, 27 Jul 2023 22:20:28 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qPD5e-0006yx-2T for qemu-devel@nongnu.org; Thu, 27 Jul 2023 22:20:27 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1b8ad907ba4so10723775ad.0 for ; Thu, 27 Jul 2023 19:20:25 -0700 (PDT) Received: from libai.bytedance.net ([61.213.176.11]) by smtp.gmail.com with ESMTPSA id b21-20020a170902d31500b001bb9f104328sm2312947plc.146.2023.07.27.19.20.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 19:20:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690510825; x=1691115625; 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=T8Og8lb22kMN7nQ4vVkGyoRUBjRifex91RdCuo99G1iGgBNppqYVUDFfG1mPB2Ygki cX/AOw6piPyq7OA5LflU+aIPFUR7etkKY4DU3W5wH+JgCf9TU2gapulOzZIpOYaHxBZA bxFa7r8NdyXMEAQXxCKti+QZqerXPv4rfZqj2PBT+ARUBQS7+kEq73vu2nNhm9JSnoMq mu0GGQHftMjONPjQ1DJot3qUxXYjbXRYU1nXRzvULLxgl3kQCbE28M61jOl6XbqZMXvH xB/f0DQq8Cpy+EtOtgEtUaqFdQGF3SNH2+XVC5pvCRnusb47zBRSBbumV5rFXVD9bR12 Je2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690510825; x=1691115625; 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=f7IyZfm4fLoezUR+dp0eOFmznmECC+AXsrX6mksXdhdiW8QK6KMvMYA4XpQnUR23Zl dig0DKF2gK2E2FU43JwMmzdHjdZaFLyxb0dSKbhEzIBB+h/l74tKzyoCPDYWA7R5hrSX 427nC86m016bC4m4J0Z9jsHx3MbwcUISdG+GQbkTr+7L9s66Vrcf8Y/UXF5NI9NbZQfO 1vuZ32ezShQQACJSWR4Ct6LslRJTZDojUsX7W8l5q5/smq2cYStQbRLMRd0DleQiOy9G EdRlGvs27F9XxCI1c3hmoDxXo0F95OIkjOab9vew2wqFJs4TB1HH64JqT/hptK5EJj0n d2/w== X-Gm-Message-State: ABy/qLYzTwS5DAV73V8/DefSGXBn1PLgo+U/GamQZJrJLIhOgdJ4bT4l vE0Onf6adMOBDLMjftX8oSVzWQ== X-Google-Smtp-Source: APBJJlFiA3NUxb9GBA+KDT7AP7hwiWJamewbEn9uoRfZGtTYj+8NapOyvPwtzuawCbqoMaY/Hrtetg== X-Received: by 2002:a17:902:a405:b0:1b8:7d0d:5ac5 with SMTP id p5-20020a170902a40500b001b87d0d5ac5mr245491plq.50.1690510824833; Thu, 27 Jul 2023 19:20:24 -0700 (PDT) From: zhenwei pi To: berto@igalia.com, kwolf@redhat.com, hreitz@redhat.com Cc: qemu_oss@crudebyte.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, zhenwei pi Subject: [PATCH v5 4/9] test-throttle: test read only and write only Date: Fri, 28 Jul 2023 10:20:01 +0800 Message-Id: <20230728022006.1098509-5-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230728022006.1098509-1-pizhenwei@bytedance.com> References: <20230728022006.1098509-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::630; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x630.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: 1690515655622100001 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 Wed May 15 18:24:53 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=1690514685; cv=none; d=zohomail.com; s=zohoarc; b=HbSxu0yuC5MAKQ4mspjIhnb4xsZcUwVPlXaq/n41+NbJzxWdEjTy0JNYYMO22rkxhxFvDFVK9gzPe0hbxoKOJwyVGnlDGHEtibA5fkxVVHuUUZRhfX1rXX0oMMSHQbIxgWhLyIjI7MVs05f1LfNzZOPUJRYJ0vW7fJixdejq2v4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690514685; 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=jsfS6gGno2BOtGoWmduTdiYdaH87lQQ6CJY7M9PeK50=; b=DWFVv+uTs2UvhaLlg6pBZAc5y9z9JmhxE0vJsRn6Z5HP9xvySqnj1LJIJ7ORUYGVMrDTfXs5l6NQknmrCJcsdwvpj4HXtEgGmKPKFh00yiGVSB9441om5hgv+GVIES0jW1RxWvfepsha+Zam+ThEJNIkqv92TYfRq9y2pYucxGQ= 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 1690514685258154.43653456003858; Thu, 27 Jul 2023 20:24:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qPD5r-0007wz-Gj; Thu, 27 Jul 2023 22:20:39 -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 1qPD5i-0007vl-Vz for qemu-devel@nongnu.org; Thu, 27 Jul 2023 22:20:32 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qPD5h-00070Q-LK for qemu-devel@nongnu.org; Thu, 27 Jul 2023 22:20:30 -0400 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-686fa3fc860so868939b3a.1 for ; Thu, 27 Jul 2023 19:20:29 -0700 (PDT) Received: from libai.bytedance.net ([61.213.176.11]) by smtp.gmail.com with ESMTPSA id b21-20020a170902d31500b001bb9f104328sm2312947plc.146.2023.07.27.19.20.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 19:20:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690510828; x=1691115628; 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=jsfS6gGno2BOtGoWmduTdiYdaH87lQQ6CJY7M9PeK50=; b=UqzFMGFVTj+tn0qR0mc9WITus+aDL5vJSaAKKqQVUopw9ZBhABMDyzvSiiUaIXjgFf 6VUtW4nPJiAhIOmrsqGd5nn+iY4vpHEAPc+Jgc4F1RzAh4aKdrtM5ksfElNiWExZf0uM G93eApVxkwExTilRoH8xCqAg+XGQZ2sFF6fxeaSrxGMSA7ondo9p03mnGMehWRKzAHbf lkxIQi2oNjSI81/Ewjq/9JP8N+y6V0TNwJw2lw6CxiDAYebA1r3z4FRXakggm15VLJ82 VgkJ3PLUxFhAQhbkMYpk70E3bS9m3ieWgRQUBxl/+Up5R2/b+SRRDWaO/VTVPE22TbWE 2tsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690510828; x=1691115628; 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=jsfS6gGno2BOtGoWmduTdiYdaH87lQQ6CJY7M9PeK50=; b=A/YbxG7l0EBxm84t/3Oj9eFSMcW0GE9UbUDk83occsg83SphPV9ZGnNuYABdHPTtkL GC/jvOIl138rPE4+OO4X1if7SVMC8FBxg7dlC+8koI7DeHCDiCMdhw8sHKe5vZHBOqkQ RFCAqAygcXs44Groaj3CDsdJaHEM31gggVn7JRJYBWc684GP4ZOUfhKVnTFXxAX27ElX Xhc+bDKzityq5VCbaQZkqHqJ8GsmcnSW116e9bHa6bVQ/nKGf441vHpQO/+9iLZIfBPS +qO/Wv+ax1t+JyLakS8bxmtK2ZBMOwrm9dDQY8hHhB6yf1gWrS7ZUw9622AzMzuP/Zu5 3DHg== X-Gm-Message-State: ABy/qLZQ2cw3lS1lZmStIHnL5220bh4/rsrvA4+H/apqfgsb3M04i71c 50ibFKEY5a6UzxsRvm/Nlw4VVw== X-Google-Smtp-Source: APBJJlG2cZx+NmOpnBUeKklGEgd9UTHsVLMI3xun/tXbH1zZ7KZvMtpGIPTIDH7jG6wwfYyL7E7Dtw== X-Received: by 2002:a05:6a21:7888:b0:121:ca90:df01 with SMTP id bf8-20020a056a21788800b00121ca90df01mr430252pzc.40.1690510827825; Thu, 27 Jul 2023 19:20:27 -0700 (PDT) From: zhenwei pi To: berto@igalia.com, kwolf@redhat.com, hreitz@redhat.com Cc: qemu_oss@crudebyte.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, zhenwei pi Subject: [PATCH v5 5/9] cryptodev: use NULL throttle timer cb for read direction Date: Fri, 28 Jul 2023 10:20:02 +0800 Message-Id: <20230728022006.1098509-6-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230728022006.1098509-1-pizhenwei@bytedance.com> References: <20230728022006.1098509-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::432; envelope-from=pizhenwei@bytedance.com; helo=mail-pf1-x432.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: 1690514687690100003 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 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 Wed May 15 18:24:53 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=1690513421; cv=none; d=zohomail.com; s=zohoarc; b=GHF+gWeYYa5aGJi8VyWUUHPfrkDIhk16bwhHMeTc0PIm0EtrnfpfuUOIemVFTdNnG5PzA8kMtM69onJ914WIl+ccWCT3x0nQQ2ri+g0IcypLYQA9Qv4t1ysbviZJ4pEkNsCK/aNfqMvMi2TEZ7tCYKqjzkxrvaxFRXbvCJy2C14= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690513421; 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=Xs6DWP1PeJYVSzfXuw2AADBvwb/gT3Getei4YfZq+/k=; b=McnRpmhvkQAINL4ekCUbWpvWKXjYfor2RwK8AdBhVa/F79PnT4Mj+8RXvSoP4YvuKj/jdHhlAFhWMceXqL/iZ64Rx+AK19cSYfymTa+kBx+ybAVrdn1c2yDmf9z/dr9KosDQcWSniqizlmxN3DNtXNJOEdyW8n2H1XEJr5gMNuU= 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 16905134215161011.6795604698814; Thu, 27 Jul 2023 20:03:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qPD5s-0007xt-4c; Thu, 27 Jul 2023 22:20:40 -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 1qPD5m-0007wN-JW for qemu-devel@nongnu.org; Thu, 27 Jul 2023 22:20:34 -0400 Received: from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qPD5k-00072N-Jc for qemu-devel@nongnu.org; Thu, 27 Jul 2023 22:20:34 -0400 Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-3a3e1152c23so1344797b6e.2 for ; Thu, 27 Jul 2023 19:20:32 -0700 (PDT) Received: from libai.bytedance.net ([61.213.176.11]) by smtp.gmail.com with ESMTPSA id b21-20020a170902d31500b001bb9f104328sm2312947plc.146.2023.07.27.19.20.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 19:20:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690510831; x=1691115631; 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=Xs6DWP1PeJYVSzfXuw2AADBvwb/gT3Getei4YfZq+/k=; b=lMnIhhQHJS4Q9MsmyXZgLxHzQlBJVfcgtoFDcOAMns5kWa7fzGjYGEkoLqdL48FTMl vgGiVbI4BcSYuMmmhOI7Hzui+qZZxJMJ2mY5/t0vxVrzVdUgr7tgsDRb25HrtqA2RjRl Bb3WOeweS7dqihRHuShQqE4FBopyrNVuJi/hIGcvcZMS+wUipbga2A9GziqqhzHjfz1R +YA5faVwPrEnCexYxYNE90jtiSltUE+Cf6RQvsDt2/T2krUMKFIjY0mDix1MxYFUGD67 oUt86AWu6JjuMfZR8arPNVWLb9Fn362PXIQv8PTsCJ4rdjatM3DWblEtSXMTQgRi+bUG GztA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690510831; x=1691115631; 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=Xs6DWP1PeJYVSzfXuw2AADBvwb/gT3Getei4YfZq+/k=; b=dGmn9XPVxLGO0BUCMXgaAxmqS9amSsd3xg5aK9M70fKGeenUrzRGl4sTAE4ywprJ4w 6r28AImBOrFH2Vy5L3X6zOL8ZdI1fEm06MnkrqFN3fh7AbJFksOrSCeNjQj7RLVFhk/o zjnqdB2XB/ACcvOYcggo/l9fq9mXD1AJ6oSIf3LSeSmXeEvHUynlDEPzA4sUvtW6Gp73 ErdLwGGHp4yQy8EHICKNfsTgugryFNoTqUEYmBelmK80J+jb27i9Mg12BVkZgShkp0f2 gft44e3j4gxY0Lv31aqDgv80HVy3tHzc7xRGssJ2566RqvMdxMD64AAgw9zbVnEJneZr utmA== X-Gm-Message-State: ABy/qLaBxh87vk0FpvsTzt9KlfpbDZ5U7fd6p7fRV54ApOiCWnFi1J7S gDtfLRgxV7c4omJT7G8+M3Toaw== X-Google-Smtp-Source: APBJJlG2/h4UY7Tx7HdtyIhinl3Q1oxtlScGwd2L82EeAh8tPO+5tK6UH8cHAt0hPC+2b2lfIvRa4Q== X-Received: by 2002:a05:6808:1387:b0:3a4:3192:1627 with SMTP id c7-20020a056808138700b003a431921627mr1446658oiw.42.1690510831332; Thu, 27 Jul 2023 19:20:31 -0700 (PDT) From: zhenwei pi To: berto@igalia.com, kwolf@redhat.com, hreitz@redhat.com Cc: qemu_oss@crudebyte.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, zhenwei pi Subject: [PATCH v5 6/9] throttle: use enum ThrottleDirection instead of bool is_write Date: Fri, 28 Jul 2023 10:20:03 +0800 Message-Id: <20230728022006.1098509-7-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230728022006.1098509-1-pizhenwei@bytedance.com> References: <20230728022006.1098509-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::22f; envelope-from=pizhenwei@bytedance.com; helo=mail-oi1-x22f.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: 1690513423081100001 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. Reviewed-by: Hanna Czenczek Signed-off-by: zhenwei pi --- 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..7d3eb6032f 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 + * @direction: 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 + * @direction: 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) + * @direction: 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) + * @direction: 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 Wed May 15 18:24:53 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=1690515846; cv=none; d=zohomail.com; s=zohoarc; b=iA6QEXWboONHk6o6A6ItsfmEgcODOgp/6dPZ0iXGKVsUc6pwsHnbMXLZH44s/AAGE5jUXKUJ9T0ceKNVk9Z4B2ivXw/Uzf4pk2Px6LdivVuaRiGhydDE6M/GlKAxHzQEwMF676R5iMlH3UWmKyid/dgcbOYXhi/cP6daYonS0XU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690515846; 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=tQs4Fsv0nvz66FedKG0+cIDiS7sJUOlO0kK/3h8TTRs=; b=L5DKrEOS1oezv8UPtRi3M1NWTaRIK2MQRtq+30b1PdcDDHIw8uRVH/a2oSit0d1zF2GmxtibKSZEpzKB0x7gS2X+yUgNnOgIhGy8tfLyHUy1Fkm6eDyQx/55qvgIUBoR6AhqqHE7Q2++cSAvOKCzIaMSHExI3MoTCqE138SgcXo= 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 1690515846508725.727445265303; Thu, 27 Jul 2023 20:44:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qPD5t-0007zA-0v; Thu, 27 Jul 2023 22:20:41 -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 1qPD5p-0007we-8u for qemu-devel@nongnu.org; Thu, 27 Jul 2023 22:20:38 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qPD5n-00073a-MY for qemu-devel@nongnu.org; Thu, 27 Jul 2023 22:20:36 -0400 Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-55ba895d457so942888a12.0 for ; Thu, 27 Jul 2023 19:20:35 -0700 (PDT) Received: from libai.bytedance.net ([61.213.176.11]) by smtp.gmail.com with ESMTPSA id b21-20020a170902d31500b001bb9f104328sm2312947plc.146.2023.07.27.19.20.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 19:20:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690510834; x=1691115634; 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=tQs4Fsv0nvz66FedKG0+cIDiS7sJUOlO0kK/3h8TTRs=; b=kyiw5jllxwHNwrbk3CVtgNjKAtFn+NqoHre5dXloqMy2O7iY6O3MLnYCoiEbc0mBD+ sHleeYbNdhyQ5ZgFJHiGzqlyvxC/Cou8oVJB4UPfXcKyKPdb8CM2ZKeLxAD20AamByy9 p1uv+Hfy+P7ut2kjIQKmrNJ3I0P2VOd7KegYOdpO5v2v4cN9QP1NzVbX5wMFl9KThFPy FbU8jpaiDobhmfBzjNDiTXO38lFNiKtYEIeTwkoFZtdDH4xKF9VXRGeH8HEZhZ5vaeeG mHaawhvtuRZNMU/f5SSYLcoEbTT7hmZCwdwcOYlx6Ke5JW3YDXV8YVLYkhVOFrWj0iiE k/Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690510834; x=1691115634; 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=tQs4Fsv0nvz66FedKG0+cIDiS7sJUOlO0kK/3h8TTRs=; b=LQNfpkdMk5LALZw5MrXUgtHZaGp8j0GtgP6z3BUOSZeV/vObJNbSN83R7NayCsKRdh hxtltcs4MR9Qw5bE0EcOcZk0dLdHnkeGG4T7b36IaDvhCJIH3/g+ImoB0Zud7M/RVgRv palpUdK+pGuENujpiJeLoKzmbqNXXRbWo0L7m4YUePWRKhI7IXTeRg+vc/HhzHskGjD/ f0Gb9V9tMsUVWIfMEZ1juu2rL5tsK+2gCdZNnRNCnt9uj4dx+CuNLL+0dL9iVruBOK/G L8hpOs4XI6jbRSfJR36b13ntYPUqkN4bzhlcPZJOB+tXscjbuTnQ7NgUdDwpcvyxEEBZ M/tw== X-Gm-Message-State: ABy/qLbEnx22TYLv42q9MnZdDF48hSl5fY/3NR5uTjaWOB+FNLrx3xw1 XEYATxRYSpIheFHq6bDdzxLD3sgxJ9L5JsyJp+I= X-Google-Smtp-Source: APBJJlE/DygaADj5u/W1WFcICNeiMm7VI/qeYk9wPlMZpq/6BfajQaxeV7HZDnNT/nTMgxapK0cw8Q== X-Received: by 2002:a05:6a20:1591:b0:132:84e4:4bea with SMTP id h17-20020a056a20159100b0013284e44beamr473910pzj.12.1690510834378; Thu, 27 Jul 2023 19:20:34 -0700 (PDT) From: zhenwei pi To: berto@igalia.com, kwolf@redhat.com, hreitz@redhat.com Cc: qemu_oss@crudebyte.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, zhenwei pi Subject: [PATCH v5 7/9] throttle: use THROTTLE_MAX/ARRAY_SIZE for hard code Date: Fri, 28 Jul 2023 10:20:04 +0800 Message-Id: <20230728022006.1098509-8-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230728022006.1098509-1-pizhenwei@bytedance.com> References: <20230728022006.1098509-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::536; envelope-from=pizhenwei@bytedance.com; helo=mail-pg1-x536.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: 1690515847097100001 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. Reviewed-by: Hanna Czenczek Signed-off-by: zhenwei pi --- util/throttle.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/util/throttle.c b/util/throttle.c index 7d3eb6032f..9582899da3 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 Wed May 15 18:24:53 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=1690515858; cv=none; d=zohomail.com; s=zohoarc; b=f+ptJHTpoTrJT+1ErieUcNKLGIq4E9A1qIhxj54Kq54Huhav35MnLFQruzvyz9tJA2lLI+lFVDUKGoYo2zfg9+4kFdDBwpfXl3Fa1zwqHMwRokblaQ3mPgTGVjnke0GpIqrBO6PqLn5LKkBigQnQcL0HVZRXojMcRx/KoVAqKQ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690515858; 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=B9iF4jVh41otFASCZmoc1VL/sJXGCh2dQxBqUQfIoLI=; b=cQsoqdzLVECP6NGXvNA3YnFJUv8KybGNKigc8BkNynrDhWfEAPjYIyMgcNqNEUpYzhOjYvSoQcaGCdycUyjLq62qMPpId7wpigXz52S40a2ABLOg5quuMXePyRUeVlFyDX8JCFd7CCtW9jJE4JqSPPj6KYyKCLSv0Tm7XOavNgE= 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 1690515858439103.80061353217502; Thu, 27 Jul 2023 20:44:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qPD5t-0007zE-W6; Thu, 27 Jul 2023 22:20:42 -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 1qPD5s-0007yR-Je for qemu-devel@nongnu.org; Thu, 27 Jul 2023 22:20:40 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qPD5q-000744-Tm for qemu-devel@nongnu.org; Thu, 27 Jul 2023 22:20:40 -0400 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1b9c368f4b5so18402725ad.0 for ; Thu, 27 Jul 2023 19:20:38 -0700 (PDT) Received: from libai.bytedance.net ([61.213.176.11]) by smtp.gmail.com with ESMTPSA id b21-20020a170902d31500b001bb9f104328sm2312947plc.146.2023.07.27.19.20.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 19:20:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690510837; x=1691115637; 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=B9iF4jVh41otFASCZmoc1VL/sJXGCh2dQxBqUQfIoLI=; b=JPPOCFtytHdtOJdV9PsjLqtyfPMh8e8yHGKgcvN9G+zKQ1ZGqV68HOtVmk51iQIez9 eACWwa/Gwa7pkmE/6rt5humiI7ZMRlCb1VN12/aWshtkZLuOut0qWltl2G9ropD1BLP0 Gn9nLH7lN6OskXDtQZgTe2XkemNl5TkHisFitO21FrmW2d9MznncQKsX6KDRo630KkVb c+Y4Z8i2tJr7W7qvXTsV/yNEBvs2ekhl+SOJqCtwM4pjV99hvJ4ueyguQ5Mf6b0ssZlf RySZeElR/ENP45XyP6PxZ3AFPBdKKg6cCXTvGtLXTUT0lp8jj739d2ZzLcl9MPHarSPc pFBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690510837; x=1691115637; 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=B9iF4jVh41otFASCZmoc1VL/sJXGCh2dQxBqUQfIoLI=; b=SswZ6g96pd9PbSjALcLa/ywRJ4NAfWtCc5ZQL9qbL6QFbo5tdr9FHDQUpT+Eb4bSUQ qXLsCpykDgNMe6CDIAoMgWNsLR3p1UOeNTPHtz8LxRlIHiCWhas0QmtojlTstH2BxHtV I42K1TI5DxjK/YNOeqnwHytZ21CT4+3dvS7wtfLCD3IuoS3n08LXNnYmka5Z/5VepcTx IIN4U8XYBe/W5OsDxXFPrH1aMn5W7fKSTqxrHqGVua13d3DT962EIU3TZxFisoAhfzA+ q7dUYJHjvO/x1kG0dYrSTVdAlEGkm/2jA2ke/5dRrCFkOms63dB+iXUh0WX8wQHKxr5s O1pw== X-Gm-Message-State: ABy/qLYk9MahU9MsuFNvl7+zSjYN1T7XESGay5vkX9OtXaSBscbDAa+2 08kH+0HVAb3tfhqZVZxmRoMRBQ== X-Google-Smtp-Source: APBJJlELzRp2vWAAJRLYJIclzHKdqKRyHOngGv6WeNtRexV9CKG2crjRp+rPHXTyF+hK2u+Cnm2HKA== X-Received: by 2002:a17:902:d481:b0:1b8:3936:7b64 with SMTP id c1-20020a170902d48100b001b839367b64mr599479plg.1.1690510837548; Thu, 27 Jul 2023 19:20:37 -0700 (PDT) From: zhenwei pi To: berto@igalia.com, kwolf@redhat.com, hreitz@redhat.com Cc: qemu_oss@crudebyte.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, zhenwei pi , Greg Kurz Subject: [PATCH v5 8/9] fsdev: Use ThrottleDirection instread of bool is_write Date: Fri, 28 Jul 2023 10:20:05 +0800 Message-Id: <20230728022006.1098509-9-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230728022006.1098509-1-pizhenwei@bytedance.com> References: <20230728022006.1098509-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::633; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x633.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: 1690515860242100001 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 Reviewed-by: Hanna Czenczek Signed-off-by: zhenwei pi Reviewed-by: Greg Kurz --- 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 Wed May 15 18:24:53 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=1690513536; cv=none; d=zohomail.com; s=zohoarc; b=XzBsPngqN8LWM4E9yzei47h934gZ8ptJ3GYLAPYcTrsFJyOIdz8DgoHRa9X5l+5AYdR9O8oOvcHGHu/NDCNeUU9KLs3ISHvOnQyWg283LNQMzy9JFk6psV0BwqJAlih72OwjryBwCC+3C8ohGbUA18zixMOpZFd1vJGzelh/YXc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690513536; 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=HcCs4b7e0ZsFuCKArukEgfiWdiQeBbMSgre2yImNmBY=; b=dqH0xiASe0sLLPbB/mJtanDS6A0nVYAPKCJwe4useqOZ8/bQ1AgUXfa4us4OG/u7r9DQtEfohnfjGEBZW+yCB12+p+/rubne9Z5TP5W+0PuKNJvBp/IXOnVKNfipH6X1zy+DBMIO7oW3AjHrygKfyFw9WxAk3OGSkGSJfygtIyI= 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 1690513536694656.3468941390479; Thu, 27 Jul 2023 20:05:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qPD5y-000812-Hi; Thu, 27 Jul 2023 22:20:46 -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 1qPD5w-00080I-EO for qemu-devel@nongnu.org; Thu, 27 Jul 2023 22:20:44 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qPD5t-00074U-Q6 for qemu-devel@nongnu.org; Thu, 27 Jul 2023 22:20:44 -0400 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1bb9e6c2a90so12758565ad.1 for ; Thu, 27 Jul 2023 19:20:41 -0700 (PDT) Received: from libai.bytedance.net ([61.213.176.11]) by smtp.gmail.com with ESMTPSA id b21-20020a170902d31500b001bb9f104328sm2312947plc.146.2023.07.27.19.20.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 19:20:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690510840; x=1691115640; 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=HcCs4b7e0ZsFuCKArukEgfiWdiQeBbMSgre2yImNmBY=; b=Dd8IeL2np9jbRNT5Hjjqb2Swldm3hAvI/ENW6Y8EtrKwibHX2cDNXOwlPyFy3uLlYV WM5KZ5cjnic7l23XV1dvS6W0ulA9elQeblY7YaTFud2akfm/gQ39IUAy6QYZjPajcCOC e2uIL/8Z3pFkUOYnx4EnUfHPVc+ZNFb4d7/rT83T7OC1xQupevQoHwNtmWuP5uQiwIhl twgk2fWbUIJsUvw6VjaweGQMwWeSKIqqNvOJIsENIj66q0NsHqKCYCajLIA1yvcVzko8 bEF+vW91HEDzU1JKUOVjETva+aUWYZYWFg1YoD/Ue40AWI9DCQWOeHw6cdN4YnI/VuBg HBpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690510840; x=1691115640; 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=HcCs4b7e0ZsFuCKArukEgfiWdiQeBbMSgre2yImNmBY=; b=l5b0dltfd39Eju2Qcj0WAdq8wzEFfPm+tUQYch4Md9v7NWenX7x8ekhjnh8xIZOV5g h68dUC+j61FfnWlkP7z9WK9KYPGN3Y4ZmJkwsIIMj9IkZ4HB8Ywzfz/N44ScEGOzjvaN KVbnhGTse11PJEo8o9pyT9SkpFX0V9MaK0vJtOuwT7h9nkqeQV56lhVBOu9Samy2wMTE DFdNAIQXyZvKZ51HrPeP1LPdfqgYEPOESMOD3Ok1Rd4NLFyEjxycqkULU3dWdF7U2C6E ChZhDDCvpiiLjh1HuUlhXnFbNcImXFGjaAmZc4dBeNQ1xUpzq+tIqCRiorys5RQN55RN +VXw== X-Gm-Message-State: ABy/qLZdaghoKMRMZRJ4+JinQs6DANyMFmDNLkPy2u5VgMYiux835DoY yTSiDvDjO5HbQNwnesrzavG5KA== X-Google-Smtp-Source: APBJJlH8sOFjS3OvjOXkcGkI+etQVyGuVTY8haxTbGWs1XsOritpaSWaJzC49MEpESE8nbNKaoa7Aw== X-Received: by 2002:a17:902:eccc:b0:1b8:1335:b775 with SMTP id a12-20020a170902eccc00b001b81335b775mr578454plh.0.1690510840622; Thu, 27 Jul 2023 19:20:40 -0700 (PDT) From: zhenwei pi To: berto@igalia.com, kwolf@redhat.com, hreitz@redhat.com Cc: qemu_oss@crudebyte.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, zhenwei pi Subject: [PATCH v5 9/9] block/throttle-groups: Use ThrottleDirection instread of bool is_write Date: Fri, 28 Jul 2023 10:20:06 +0800 Message-Id: <20230728022006.1098509-10-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230728022006.1098509-1-pizhenwei@bytedance.com> References: <20230728022006.1098509-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::633; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x633.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: 1690513537908100003 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 ThrottleDirection instead of 'bool is_write'. Ex, schedule_next_request(ThrottleGroupMember *tgm, bool is_write) -> schedule_next_request(ThrottleGroupMember *tgm, ThrottleDirection dire= ction) - use THROTTLE_MAX instead of hard code. Ex, ThrottleGroupMember *tokens[2] -> ThrottleGroupMember *tokens[THROTTLE_MAX] - use ThrottleDirection instead of hard code on iteration. Ex, (i =3D 0; i = < 2; i++) -> for (dir =3D THROTTLE_READ; dir < THROTTLE_MAX; dir++) 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/block-backend.c | 4 +- block/throttle-groups.c | 161 ++++++++++++++++---------------- block/throttle.c | 8 +- include/block/throttle-groups.h | 6 +- 4 files changed, 90 insertions(+), 89 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 4009ed5fed..47d360c97a 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1341,7 +1341,7 @@ blk_co_do_preadv_part(BlockBackend *blk, int64_t offs= et, int64_t bytes, /* throttling disk I/O */ if (blk->public.throttle_group_member.throttle_state) { throttle_group_co_io_limits_intercept(&blk->public.throttle_group_= member, - bytes, false); + bytes, THROTTLE_READ); } =20 ret =3D bdrv_co_preadv_part(blk->root, offset, bytes, qiov, qiov_offse= t, @@ -1415,7 +1415,7 @@ blk_co_do_pwritev_part(BlockBackend *blk, int64_t off= set, int64_t bytes, /* throttling disk I/O */ if (blk->public.throttle_group_member.throttle_state) { throttle_group_co_io_limits_intercept(&blk->public.throttle_group_= member, - bytes, true); + bytes, THROTTLE_WRITE); } =20 if (!blk->enable_write_cache) { diff --git a/block/throttle-groups.c b/block/throttle-groups.c index 3847d27801..3eda4c4e3d 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 @@ -447,18 +448,18 @@ static void throttle_group_restart_queue(ThrottleGrou= pMember *tgm, bool is_write =20 void throttle_group_restart_tgm(ThrottleGroupMember *tgm) { - int i; + ThrottleDirection dir; =20 if (tgm->throttle_state) { - for (i =3D 0; i < 2; i++) { - QEMUTimer *t =3D tgm->throttle_timers.timers[i]; + for (dir =3D THROTTLE_READ; dir < THROTTLE_MAX; dir++) { + QEMUTimer *t =3D tgm->throttle_timers.timers[dir]; if (timer_pending(t)) { /* If there's a pending timer on this tgm, fire it now */ timer_del(t); - timer_cb(tgm, i); + timer_cb(tgm, dir); } else { /* Else run the next request from the queue manually */ - throttle_group_restart_queue(tgm, i); + throttle_group_restart_queue(tgm, dir); } } } @@ -502,30 +503,30 @@ 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) { - timer_cb(opaque, false); + timer_cb(opaque, THROTTLE_READ); } =20 static void write_timer_cb(void *opaque) { - timer_cb(opaque, true); + timer_cb(opaque, THROTTLE_WRITE); } =20 /* Register a ThrottleGroupMember from the throttling group, also initiali= zing @@ -543,7 +544,7 @@ void throttle_group_register_tgm(ThrottleGroupMember *t= gm, const char *groupname, AioContext *ctx) { - int i; + ThrottleDirection dir; ThrottleState *ts =3D throttle_group_incref(groupname); ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); =20 @@ -553,10 +554,11 @@ void throttle_group_register_tgm(ThrottleGroupMember = *tgm, =20 QEMU_LOCK_GUARD(&tg->lock); /* If the ThrottleGroup is new set this ThrottleGroupMember as the tok= en */ - for (i =3D 0; i < 2; i++) { - if (!tg->tokens[i]) { - tg->tokens[i] =3D tgm; + for (dir =3D THROTTLE_READ; dir < THROTTLE_MAX; dir++) { + if (!tg->tokens[dir]) { + tg->tokens[dir] =3D tgm; } + qemu_co_queue_init(&tgm->throttled_reqs[dir]); } =20 QLIST_INSERT_HEAD(&tg->head, tgm, round_robin); @@ -568,8 +570,6 @@ void throttle_group_register_tgm(ThrottleGroupMember *t= gm, write_timer_cb, tgm); qemu_co_mutex_init(&tgm->throttled_reqs_lock); - qemu_co_queue_init(&tgm->throttled_reqs[0]); - qemu_co_queue_init(&tgm->throttled_reqs[1]); } =20 /* Unregister a ThrottleGroupMember from its group, removing it from the l= ist, @@ -587,7 +587,7 @@ void throttle_group_unregister_tgm(ThrottleGroupMember = *tgm) ThrottleState *ts =3D tgm->throttle_state; ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); ThrottleGroupMember *token; - int i; + ThrottleDirection dir; =20 if (!ts) { /* Discard already unregistered tgm */ @@ -598,17 +598,17 @@ void throttle_group_unregister_tgm(ThrottleGroupMembe= r *tgm) AIO_WAIT_WHILE(tgm->aio_context, qatomic_read(&tgm->restart_pending) >= 0); =20 WITH_QEMU_LOCK_GUARD(&tg->lock) { - for (i =3D 0; i < 2; i++) { - assert(tgm->pending_reqs[i] =3D=3D 0); - assert(qemu_co_queue_empty(&tgm->throttled_reqs[i])); - assert(!timer_pending(tgm->throttle_timers.timers[i])); - if (tg->tokens[i] =3D=3D tgm) { + for (dir =3D THROTTLE_READ; dir < THROTTLE_MAX; dir++) { + assert(tgm->pending_reqs[dir] =3D=3D 0); + assert(qemu_co_queue_empty(&tgm->throttled_reqs[dir])); + assert(!timer_pending(tgm->throttle_timers.timers[dir])); + if (tg->tokens[dir] =3D=3D tgm) { token =3D throttle_group_next_tgm(tgm); /* Take care of the case where this is the last tgm in the= group */ if (token =3D=3D tgm) { token =3D NULL; } - tg->tokens[i] =3D token; + tg->tokens[dir] =3D token; } } =20 @@ -633,19 +633,20 @@ void throttle_group_detach_aio_context(ThrottleGroupM= ember *tgm) { ThrottleGroup *tg =3D container_of(tgm->throttle_state, ThrottleGroup,= ts); ThrottleTimers *tt =3D &tgm->throttle_timers; - int i; + ThrottleDirection dir; =20 /* Requests must have been drained */ - assert(tgm->pending_reqs[0] =3D=3D 0 && tgm->pending_reqs[1] =3D=3D 0); - assert(qemu_co_queue_empty(&tgm->throttled_reqs[0])); - assert(qemu_co_queue_empty(&tgm->throttled_reqs[1])); + for (dir =3D THROTTLE_READ; dir < THROTTLE_MAX; dir++) { + assert(tgm->pending_reqs[dir] =3D=3D 0); + assert(qemu_co_queue_empty(&tgm->throttled_reqs[dir])); + } =20 /* Kick off next ThrottleGroupMember, if necessary */ WITH_QEMU_LOCK_GUARD(&tg->lock) { - for (i =3D 0; i < 2; i++) { - if (timer_pending(tt->timers[i])) { - tg->any_timer_armed[i] =3D false; - schedule_next_request(tgm, i); + for (dir =3D THROTTLE_READ; dir < THROTTLE_MAX; dir++) { + if (timer_pending(tt->timers[dir])) { + tg->any_timer_armed[dir] =3D false; + schedule_next_request(tgm, dir); } } } 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