From patchwork Thu Jul 13 06:41:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13311362 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5EFB1EB64DD for ; Thu, 13 Jul 2023 06:43:02 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qJq1K-0004g2-Ax; Thu, 13 Jul 2023 02:41: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 1qJq1I-0004fQ-GX for qemu-devel@nongnu.org; Thu, 13 Jul 2023 02:41:44 -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 1qJq1B-0007ob-Ct for qemu-devel@nongnu.org; Thu, 13 Jul 2023 02:41:44 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1b9c368f4b5so11128905ad.0 for ; Wed, 12 Jul 2023 23:41:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1689230491; x=1691822491; 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=+nzZLdnHvv22BtX0bis4ofXWb7eL4AjLZDSnk3l5cPM=; b=jokGQ+A86gyDGZwNwZgNNUBG21K/mfzFQ3YR0zjhoZBX3gP1wfJlDw1qtfnhTgh0Wm YTEOm+oQAwRAfBPcUZrtdwvBR1RhkYKQRv8/ASUO1u2gokIo/L8PhU7eo4pMyq836/sh liki/RrHRL+2CtaKzTn1zS1960FF3wX2BMics68245tRG2IuUi9If6xFLt7vetxZUu1/ Wbx/Fgv9RjVBRxH12I6rSQj90ZIbWOILsSQLrSaVWLKzLGMoibail5AiVAHQyArF974C ofTBopLKOwBXEUCM+LAI8XJJAUnehPrdGWVnrs/SnwsbRxs8qHvJ1npgk+eu3aJsFeGA FHbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689230491; x=1691822491; 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=+nzZLdnHvv22BtX0bis4ofXWb7eL4AjLZDSnk3l5cPM=; b=Kas5GXZElRWE0WSt0Dvzidjhb5X0nrvbu1RLig0KBfwerbv0ebR4iKRWCsdgDATos7 Esx3sTSOFaK4umQt+0V8C0jGn2H5c+8ZscQgln6B+ANqfzf6Ve57ZzrIPh61uKFvbvrV beIietiZN8wu6NwKbXX/0swHG8TotRL6IdoZmYnK2cptYz55AFuFCS80EMuPQSwqJhgc uzk61LEnryAdxE0oVhQ9fSPlBM/hTImdMFUFqxNdwLCV1TUpY05hElfRLR0+4JnPtLsW 5z6GhplWQW0MArfeGhq4qr4599/QkHpHrnFX/JkLMTGDQk9Qx9+mhmAt7VdNzJuvdYFw eg4g== X-Gm-Message-State: ABy/qLbrXnS7UewbYLCQHh8oMHjHSj2b6On5hildNfIw2/biqnzhe1Cg QqyJGMmOq606c/ll49JN/HMT5w== X-Google-Smtp-Source: APBJJlHIyIhGAK+ueDlqgCLNLAnFdjeXGO3SMa7rxVlKkTfGzx36VFuOfFtfJ7sW58ocvMJaAT1+kQ== X-Received: by 2002:a17:902:c401:b0:1b1:99c9:8ce5 with SMTP id k1-20020a170902c40100b001b199c98ce5mr6614486plk.16.1689230491337; Wed, 12 Jul 2023 23:41:31 -0700 (PDT) Received: from libai.bytedance.net ([61.213.176.11]) by smtp.gmail.com with ESMTPSA id h13-20020a170902680d00b001ac2be26340sm5144966plk.222.2023.07.12.23.41.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 23:41:30 -0700 (PDT) From: zhenwei pi To: berto@igalia.com, kwolf@redhat.com, groug@kaod.org, qemu_oss@crudebyte.com, hreitz@redhat.com Cc: arei.gonglei@huawei.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, berrange@redhat.com, zhenwei pi Subject: [PATCH v3 1/6] throttle: introduce enum ThrottleType Date: Thu, 13 Jul 2023 14:41:06 +0800 Message-Id: <20230713064111.558652-2-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230713064111.558652-1-pizhenwei@bytedance.com> References: <20230713064111.558652-1-pizhenwei@bytedance.com> MIME-Version: 1.0 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, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Use enum ThrottleType instead of number index. Reviewed-by: Alberto Garcia Signed-off-by: zhenwei pi Reviewed-by: Hanna Czenczek --- 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..ba6293eeef 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; +typedef enum { + THROTTLE_READ = 0, + THROTTLE_WRITE, + THROTTLE_MAX +} ThrottleType; + typedef struct ThrottleTimers { - QEMUTimer *timers[2]; /* timers used to do the throttling */ + QEMUTimer *timers[THROTTLE_MAX]; /* timers used to do the throttling */ QEMUClockType clock_type; /* the clock used */ /* Callbacks */ - QEMUTimerCB *read_timer_cb; - QEMUTimerCB *write_timer_cb; + QEMUTimerCB *timer_cb[THROTTLE_MAX]; void *timer_opaque; } ThrottleTimers; 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] = aio_timer_new(new_context, tt->clock_type, SCALE_NS, - tt->read_timer_cb, tt->timer_opaque); - tt->timers[1] = aio_timer_new(new_context, tt->clock_type, SCALE_NS, - tt->write_timer_cb, tt->timer_opaque); + tt->timers[THROTTLE_READ] = + aio_timer_new(new_context, tt->clock_type, SCALE_NS, + tt->timer_cb[THROTTLE_READ], tt->timer_opaque); + tt->timers[THROTTLE_WRITE] = + aio_timer_new(new_context, tt->clock_type, SCALE_NS, + tt->timer_cb[THROTTLE_WRITE], tt->timer_opaque); } /* @@ -236,8 +238,8 @@ void throttle_timers_init(ThrottleTimers *tt, memset(tt, 0, sizeof(ThrottleTimers)); tt->clock_type = clock_type; - tt->read_timer_cb = read_timer_cb; - tt->write_timer_cb = write_timer_cb; + tt->timer_cb[THROTTLE_READ] = read_timer_cb; + tt->timer_cb[THROTTLE_WRITE] = write_timer_cb; tt->timer_opaque = timer_opaque; throttle_timers_attach_aio_context(tt, aio_context); } @@ -256,7 +258,7 @@ void throttle_timers_detach_aio_context(ThrottleTimers *tt) { int i; - for (i = 0; i < 2; i++) { + for (i = 0; i < THROTTLE_MAX; i++) { throttle_timer_destroy(&tt->timers[i]); } } From patchwork Thu Jul 13 06:41:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13311363 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0D16CEB64DD for ; Thu, 13 Jul 2023 06:43:06 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qJq1G-0004e4-1E; Thu, 13 Jul 2023 02:41: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 1qJq1D-0004cm-Mx for qemu-devel@nongnu.org; Thu, 13 Jul 2023 02:41:39 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qJq1A-0007pT-GX for qemu-devel@nongnu.org; Thu, 13 Jul 2023 02:41:39 -0400 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-66c729f5618so410576b3a.1 for ; Wed, 12 Jul 2023 23:41:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1689230495; x=1691822495; 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=S33JWaL5Ut8IU49sA03uYQs6qNZeMPjhvpHxuQfR6ds=; b=LiTUc2oK+SnNsFV75V0tMvWg1MBL+YIAH7m3LZD5+jz4FX52Qp6paxsIAe7beMdi0n 56pC6oS5rF96GqCAgTJ9f4CYAxXSxjT7u+tt4Z714b8r57oA6ImCOIBSO6gOdDGNSjGu DpiUhAiyEQ7QXIOO2mvdUTGdy7xhKmiLj5Uy2B8cebhmIZT7HiDM+5/uYEVj8J1oaJqt hxomR2jlXyAJrJi4XrHsD0jjBoOTpd/b84IyTE3wltxQJO650O+QEcMbwN45b4Epj0M8 hD369LdKkJb+SXzovI7bH+ZEthAqEkMbuX0kfGZHXddnd0FSFRkw8nJpm/JdSUB8Yw44 YfRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689230495; x=1691822495; 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=S33JWaL5Ut8IU49sA03uYQs6qNZeMPjhvpHxuQfR6ds=; b=EYgdIlRPFFG/aly/cEoYV2bHsKS3DeYImOh2lrz1JWvrnnOy2CV0md6502sYW+5xwG 2Y9zNR3rSDm7nlPR/p34HrZ1wenT98Pc7/UKTfTzS5aBJ18yENKaUDZaUW8KP0JOzd9A FdGnOo0vY5vnczcl+o354gtdk1LpD22PBaBJtsf3k0Qwi56I2NfE43v3ApKookNQ+Je3 8OB4zE6wuCaPMnA9+r/ZkfMt4p7OM6YikdJPqb4gK8qrLTZYHgJyaOVWaHgqZIKQN5E0 SrE8sKG32JQxVciO6czDlkQqVR3SBDJj9DfEshCPx1yGq4axQGHLJrXF3aLpMp7CtFcz uOvw== X-Gm-Message-State: ABy/qLaUHBtkUOh2DtGQhPbKrNPCQlP8lA0iri1fFO3qApToZ+t/f/2Q R930JsDzKLi7ZbOCUiG9XbjtE7EkLxGlabaaXWk= X-Google-Smtp-Source: APBJJlGyH6GksLmcWRKgpDl7wNqo3KrflzIF1PRoUVUSH+Osajejj0pKl2TTm69wlSArUtpT+JSACw== X-Received: by 2002:a05:6a20:9482:b0:131:5b6f:ccb6 with SMTP id hs2-20020a056a20948200b001315b6fccb6mr646802pzb.19.1689230495139; Wed, 12 Jul 2023 23:41:35 -0700 (PDT) Received: from libai.bytedance.net ([61.213.176.11]) by smtp.gmail.com with ESMTPSA id h13-20020a170902680d00b001ac2be26340sm5144966plk.222.2023.07.12.23.41.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 23:41:34 -0700 (PDT) From: zhenwei pi To: berto@igalia.com, kwolf@redhat.com, groug@kaod.org, qemu_oss@crudebyte.com, hreitz@redhat.com Cc: arei.gonglei@huawei.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, berrange@redhat.com, zhenwei pi Subject: [PATCH v3 2/6] test-throttle: use enum ThrottleType Date: Thu, 13 Jul 2023 14:41:07 +0800 Message-Id: <20230713064111.558652-3-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230713064111.558652-1-pizhenwei@bytedance.com> References: <20230713064111.558652-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=pizhenwei@bytedance.com; helo=mail-pf1-x435.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Use enum ThrottleType instead in the throttle test codes. Reviewed-by: Alberto Garcia Signed-off-by: zhenwei pi Reviewed-by: Hanna Czenczek --- 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) /* check initialized fields */ g_assert(tt->clock_type == 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]); /* 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 = 0; i < 2; i++) { + for (i = 0; i < THROTTLE_MAX; i++) { g_assert(!tt->timers[i]); } } From patchwork Thu Jul 13 06:41:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13311361 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 34124C001DF for ; Thu, 13 Jul 2023 06:42:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qJq1H-0004em-J7; Thu, 13 Jul 2023 02:41:43 -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 1qJq1F-0004da-IX for qemu-devel@nongnu.org; Thu, 13 Jul 2023 02:41:41 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qJq1D-0007q6-UN for qemu-devel@nongnu.org; Thu, 13 Jul 2023 02:41:41 -0400 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1b9cd6a0051so1797325ad.1 for ; Wed, 12 Jul 2023 23:41:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1689230498; x=1691822498; 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=jaWAmvEQQZcMF23gcTLnet2HrHi+tP++yrg1bE9ujnc=; b=UWakUxXuVNFrM1q1TMfK76nlA25n4YK4HA76yXHCCVHiup8RGQnDXcqfC+GxEW6LBb ssDBm/VMxemqh6upZCr/TNPZr36TaVnuH+CX8HwzqhkLXjBE3ukBRGgJ22Man+OyIs2x Im0BBrC/Pxatms7TRQiFf4PwPoyvh+byXNUr6KsxRTlFV2Jl86G0c4PCgeWfu4m5CFEC TkNuj2McZohZ7aNvwvVzo8oJtQLRAhIW00zjh69xsaLlRsuVi4g3v1VQlMLQPwIQZH8S LajjIG4FPiZoESPaiUcA3XCuvwi8vLP99zF87tkD23zgj/lo80dEBdv2Zh424JmU4O5I e9hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689230498; x=1691822498; 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=jaWAmvEQQZcMF23gcTLnet2HrHi+tP++yrg1bE9ujnc=; b=OPLuuaf6n+YSJgvMSWqptEdZ/lgn01Y74y0YNl9i1C9Sn51O8qzijBVDPCVeCvBGJ6 8JbA/pbLT6X6eDWlX2UYGbavac5gbrjTtZRWEj/vzPrnqHUf4Pl1ruJUkci/63Ji0Aba VRarm5kmOrMuo2Vk5/m1RNYdV4vGlAWnWCmGVmcjeszQyndoqAc4fY+c15SD+KQ94N/k PqV/YEbFeD4PIBardMvRhztuOUVia/5okKa0QEOSjnVeuvpwpIY61JDwPdS39UBHGZgl CJh2/RVkRoerygwxBSjGUaEI3oQ5JEbze2q3ouq61OOpfUZPHG0Dx0SC4nXaylSOmdL5 i0iA== X-Gm-Message-State: ABy/qLZvMuvwvY6c5Rx7Vb0TO1CoI6v9ep1USvjNKa6mjpXcV70HR2KT +hx7TaV6YAiMEgbZ7/yOBEmJbA== X-Google-Smtp-Source: APBJJlETg8IjpPehpeqozZeAhZ8TY9fYheTUHpZw5g9jeKULSzjkNUNr2AWDeiars7HXFZ8kW1qQ2w== X-Received: by 2002:a17:902:bd94:b0:1b8:1e05:ed09 with SMTP id q20-20020a170902bd9400b001b81e05ed09mr350496pls.36.1689230498560; Wed, 12 Jul 2023 23:41:38 -0700 (PDT) Received: from libai.bytedance.net ([61.213.176.11]) by smtp.gmail.com with ESMTPSA id h13-20020a170902680d00b001ac2be26340sm5144966plk.222.2023.07.12.23.41.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 23:41:38 -0700 (PDT) From: zhenwei pi To: berto@igalia.com, kwolf@redhat.com, groug@kaod.org, qemu_oss@crudebyte.com, hreitz@redhat.com Cc: arei.gonglei@huawei.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, berrange@redhat.com, zhenwei pi Subject: [PATCH v3 3/6] throttle: support read-only and write-only Date: Thu, 13 Jul 2023 14:41:08 +0800 Message-Id: <20230713064111.558652-4-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230713064111.558652-1-pizhenwei@bytedance.com> References: <20230713064111.558652-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x631.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 Signed-off-by: zhenwei pi Reviewed-by: Hanna Czenczek --- util/throttle.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/util/throttle.c b/util/throttle.c index 5642e61763..c0bd0c26c3 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -199,12 +199,17 @@ static bool throttle_compute_timer(ThrottleState *ts, void throttle_timers_attach_aio_context(ThrottleTimers *tt, AioContext *new_context) { - tt->timers[THROTTLE_READ] = - aio_timer_new(new_context, tt->clock_type, SCALE_NS, - tt->timer_cb[THROTTLE_READ], tt->timer_opaque); - tt->timers[THROTTLE_WRITE] = - aio_timer_new(new_context, tt->clock_type, SCALE_NS, - tt->timer_cb[THROTTLE_WRITE], tt->timer_opaque); + if (tt->timer_cb[THROTTLE_READ]) { + tt->timers[THROTTLE_READ] = + aio_timer_new(new_context, tt->clock_type, SCALE_NS, + tt->timer_cb[THROTTLE_READ], tt->timer_opaque); + } + + if (tt->timer_cb[THROTTLE_WRITE]) { + tt->timers[THROTTLE_WRITE] = + aio_timer_new(new_context, tt->clock_type, SCALE_NS, + tt->timer_cb[THROTTLE_WRITE], tt->timer_opaque); + } } /* @@ -235,6 +240,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)); tt->clock_type = clock_type; @@ -247,7 +253,9 @@ void throttle_timers_init(ThrottleTimers *tt, /* destroy a timer */ static void throttle_timer_destroy(QEMUTimer **timer) { - assert(*timer != NULL); + if (*timer == NULL) { + return; + } timer_free(*timer); *timer = NULL; @@ -272,7 +280,7 @@ void throttle_timers_destroy(ThrottleTimers *tt) /* is any throttling timer configured */ bool throttle_timers_are_initialized(ThrottleTimers *tt) { - if (tt->timers[0]) { + if (tt->timers[THROTTLE_READ] || tt->timers[THROTTLE_WRITE]) { return true; } @@ -424,8 +432,12 @@ bool throttle_schedule_timer(ThrottleState *ts, { int64_t now = qemu_clock_get_ns(tt->clock_type); int64_t next_timestamp; + QEMUTimer *timer; bool must_wait; + timer = is_write ? tt->timers[THROTTLE_WRITE] : tt->timers[THROTTLE_READ]; + assert(timer); + must_wait = throttle_compute_timer(ts, is_write, now, @@ -437,12 +449,12 @@ bool throttle_schedule_timer(ThrottleState *ts, } /* request throttled and timer pending -> do nothing */ - if (timer_pending(tt->timers[is_write])) { + if (timer_pending(timer)) { return true; } /* request throttled and timer not pending -> arm timer */ - timer_mod(tt->timers[is_write], next_timestamp); + timer_mod(timer, next_timestamp); return true; } From patchwork Thu Jul 13 06:41:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13311365 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 05D03C0015E for ; Thu, 13 Jul 2023 06:43:36 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qJq1L-0004g8-Bp; Thu, 13 Jul 2023 02:41:47 -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 1qJq1J-0004fc-77 for qemu-devel@nongnu.org; Thu, 13 Jul 2023 02:41:45 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qJq1H-0007qy-Hj for qemu-devel@nongnu.org; Thu, 13 Jul 2023 02:41:44 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6686ef86110so176982b3a.2 for ; Wed, 12 Jul 2023 23:41:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1689230502; x=1691822502; 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=n3sbCJaOmDfH1zIN/DRXdbhJFNPKJy9ruOuNCb7n1h4=; b=hK5cZs3QTH+j/ruUO+lYBc14Z3sQTZu+7FbMqkOQNmAS0Q3C7CWOlyd42q3Zq0ZMPt oD/n21UTN+zpbbj6GJfPiir2EI2YfcPqQBB5nAIvCpSBDRl2LMstnCbzB0DlR33q56k5 hswrwQdNYwc9X6FXYnhwyKn+AMFUB4GGqcxvR5DrXISrAK0384/XHit21+Lsg32SzS3L 97VLFsPRSXtDiDQ7aegRKSnasox7VW+2CfzJW7uNBpwZJa901uYzQPaPr8E0fORIfN1K 4CcWKBLddDmpd9ilycB3TNhXXC1DlzTOQaF73b6SlbSXhv3YFAsN9HLxlwQtUYimVLj9 F32w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689230502; x=1691822502; 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=n3sbCJaOmDfH1zIN/DRXdbhJFNPKJy9ruOuNCb7n1h4=; b=W3bQUG1IzEnNcLtlq/AFw+jjb6FLkwLVvwKFvaCC/khpC6qXKDwg/xMGSfC8ZOvbRk TgiAEbL1pMxTa7y7SHwZlhnuwau8BJBmHpmZNM19qYATiSdBOPrdGUQGqCgPM6OifUbe Itr1j1R08tcXf2tLi1sH3c9qUAvzUC56N2+UNCWt7hSIhne52B7PSVnWs44ef02I2rG/ XNyi2c/xBmLVCZBm6EI+hrd4ubKa3/RbHrpEtB9WHhA8nYhzU9zsu/SA8BBqj1dP5KzE sZobZ2X8eeVCSPpveIYEx2nVCrusvA8n5wJLmc2cbcHpTDxC2W7RHNs/3BNItZDH0EVd rA/A== X-Gm-Message-State: ABy/qLbDx1a4V2YoSLrCO9Dxu0y8hzH+6rxspsSSoWrv69moJ3rrd1A3 nja5gYgrrZSO7gwB7y0G195IaA== X-Google-Smtp-Source: APBJJlEbG7MFZPSEuGed7BpIpBwFmVr0HIAGUiTKfbYn0EqSvSzxHNjQZasXu5GcMSZ16EHjhkVwag== X-Received: by 2002:a05:6a20:4403:b0:12b:c8ee:c457 with SMTP id ce3-20020a056a20440300b0012bc8eec457mr209690pzb.39.1689230502139; Wed, 12 Jul 2023 23:41:42 -0700 (PDT) Received: from libai.bytedance.net ([61.213.176.11]) by smtp.gmail.com with ESMTPSA id h13-20020a170902680d00b001ac2be26340sm5144966plk.222.2023.07.12.23.41.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 23:41:41 -0700 (PDT) From: zhenwei pi To: berto@igalia.com, kwolf@redhat.com, groug@kaod.org, qemu_oss@crudebyte.com, hreitz@redhat.com Cc: arei.gonglei@huawei.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, berrange@redhat.com, zhenwei pi Subject: [PATCH v3 4/6] test-throttle: test read only and write only Date: Thu, 13 Jul 2023 14:41:09 +0800 Message-Id: <20230713064111.558652-5-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230713064111.558652-1-pizhenwei@bytedance.com> References: <20230713064111.558652-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=pizhenwei@bytedance.com; helo=mail-pf1-x42e.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Reviewed-by: Alberto Garcia Signed-off-by: zhenwei pi Reviewed-by: Hanna Czenczek --- 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); } +static void test_init_readonly(void) +{ + int i; + + tt = &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 == 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 = 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 = &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 == 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 = 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); From patchwork Thu Jul 13 06:41:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13311364 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ADB93EB64DD for ; Thu, 13 Jul 2023 06:43:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qJq1b-0004kX-Mu; Thu, 13 Jul 2023 02:42:03 -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 1qJq1a-0004kN-Ae for qemu-devel@nongnu.org; Thu, 13 Jul 2023 02:42:02 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qJq1L-0007rn-3E for qemu-devel@nongnu.org; Thu, 13 Jul 2023 02:42:02 -0400 Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-55c85b5321dso230240a12.3 for ; Wed, 12 Jul 2023 23:41:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1689230505; x=1691822505; 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=pEK1Z9Npjmo8oz7JUu1mUOmCLwI5rnb6nd13N6AuRpE=; b=UhxeoZcg0nga5d1YeUg8mFh9H+dxw0Bx3JYpl1vVaC4OqMtHm8f3hRxhwoNyOYjJMw a1YqNosm2CVY6bRtcrWLxj2d5txc75kzDcdiGJn8VLBZDUFrbnBuV1yHT3jRrXmxKJZo TkPVkTD3cI5i+3SClB6zEYrBcdF0tYYPQ6Jev8AHwVFUFe8eUT4wbW/Rz0SP00ZcNaqf 14jzSI3KYVRNecMNty9eNkcyosGtwCGxz1njrGuPgWfFRnYfKdlUM67myAuEd4w3hKrk ZlO1RPklHEOh91bucvqYKGFGiqxm2SBTwNHlRP/qvLEns6+zbgDt9wsy+DqcnOYAVNAf SBlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689230505; x=1691822505; 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=pEK1Z9Npjmo8oz7JUu1mUOmCLwI5rnb6nd13N6AuRpE=; b=RbfGUFdLTUvnxHcpFsr8wn9H8J0cG6C5v6gOOA6Qq097F4zsEQKJB0PrrZv6jHdIIp 9VHTK8Jy4hxm5gghJJ+eJsloxbfGMSSLGRFSiLqZha5YxLnVt6eqNRbcSJnrUuaM9Rxi mecNeh6zuJkBwMzm6PavkYz5LHGXkNOHh3CVBE2IJ9aKLAP3CZ8c52CreDJzkB952rXl B5xEmrVRjHOUj+1YkRcncGNVpMNRDZjxwBhdPptZDzdPMaNE+QL2n3BD61mRAGGj7gQX uv1gKPex1B84IILLhRYlIg5EQjhKBvCubFCcLX196ndyAcmGLVf/y9vFFveAkRGH45ZV UfGA== X-Gm-Message-State: ABy/qLaKT1v/K3s/v0wVSdxu3hICdiRtWyMo+YpXRr5d3kYgq6m6RJpL eLplI0LA4xlSC+mhSN4x4Le9kg== X-Google-Smtp-Source: APBJJlGhNwZ7CzgDPr0tJD9cT608Iaod1zn/D4QTLC56uIIFGaG6Uae9qTOQIHORWa2S3pcIP/xFzA== X-Received: by 2002:a05:6a20:2594:b0:12b:1686:3012 with SMTP id k20-20020a056a20259400b0012b16863012mr256290pzd.3.1689230505581; Wed, 12 Jul 2023 23:41:45 -0700 (PDT) Received: from libai.bytedance.net ([61.213.176.11]) by smtp.gmail.com with ESMTPSA id h13-20020a170902680d00b001ac2be26340sm5144966plk.222.2023.07.12.23.41.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 23:41:45 -0700 (PDT) From: zhenwei pi To: berto@igalia.com, kwolf@redhat.com, groug@kaod.org, qemu_oss@crudebyte.com, hreitz@redhat.com Cc: arei.gonglei@huawei.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, berrange@redhat.com, zhenwei pi Subject: [PATCH v3 5/6] cryptodev: use NULL throttle timer cb for read direction Date: Thu, 13 Jul 2023 14:41:10 +0800 Message-Id: <20230713064111.558652-6-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230713064111.558652-1-pizhenwei@bytedance.com> References: <20230713064111.558652-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=pizhenwei@bytedance.com; helo=mail-pg1-x535.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Operations on a crytpodev 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). Reviewed-by: Alberto Garcia Signed-off-by: zhenwei pi Reviewed-by: Hanna Czenczek --- 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(CryptoDevBackend *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); } From patchwork Thu Jul 13 06:41:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13311360 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1F11DC001DE for ; Thu, 13 Jul 2023 06:42:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qJq1T-0004jt-TX; Thu, 13 Jul 2023 02:41:55 -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 1qJq1R-0004j0-GQ for qemu-devel@nongnu.org; Thu, 13 Jul 2023 02:41:53 -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 1qJq1O-0007sW-Bt for qemu-devel@nongnu.org; Thu, 13 Jul 2023 02:41:53 -0400 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1b9c368f4b5so11130035ad.0 for ; Wed, 12 Jul 2023 23:41:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1689230509; x=1691822509; 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=mWAgTNnK/+O89w8pPWdsdxQaPBi4WLZtbT7kA5oIS2g=; b=Jx+t/n/1l2MX13ySP+PmGuE0t2gkk9bbgmTDzJraj/wltunXq6EiOIctBnkNRuhlRc 1Bv14T+thc9A4U59LqQRypaj1fwYlxOwXtbI9Y5TsZuSDGECdUi2TOrt8NO/kfSYI2Xf WhhR0Q5TBWYN+LC2LERHAkGObGB2h4Xe9zEG96rBZ6Co86QwCZ8t//HshQQsVdRjepb8 pKQC6rwgoRQyqFEDEncotIKxty8amBHI0kOzTgCtxvciMtm0IsBSOtE115iC80mcta+q B0ubfNSp3AHr+MUIVDMYnUC+ZCLEM62SYhpSrBKcMyHlWcoWp2VPZbxQBx718WkodEIb 5oIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689230509; x=1691822509; 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=mWAgTNnK/+O89w8pPWdsdxQaPBi4WLZtbT7kA5oIS2g=; b=L9JQ8JZT9y/Gl94CvtqglvoRf58ZNHCELQD5yQa0udLl4d5Tdx3vev7Z93v6hOUOrk 5PIsMfEKqDV2aRmfsQLTWKEZV8fr959UPETBsKpGPajdzSwiQw70rNzNE1C1QRUxK9uV v9acM6VF6sxEYhEemrTmgmxf/B6NGz1csMyr+CK1Iqq/J7NXS+qP1IscZ8bhJizPy1SH P1Grg74Wqc3sItNmvlV7LY+DcJyh9VVCvDm6MzMcfF2kvjdE5iwcSQwbEmYa8vYFvola w10otOvSSBiEBRMJoGeBpsjZ9RdK600MQucGXU+fyTDy7gGSCeQhqjsvf2E499rXcOWD By8w== X-Gm-Message-State: ABy/qLZafLQlLmpaTcYqcFEUu+pdOC8onheXSBLDjswn5InX8RWNTf50 e44ZS+PIYrchzxe2KpsYjMNURw== X-Google-Smtp-Source: APBJJlHsf5ocEyxKUIjZ4CqWF4LLVAFIY+kFSoJYBaSeS1AsqOZnHsbjYAUjpjU5K7WTpxo+/U4Q4g== X-Received: by 2002:a17:903:2309:b0:1b8:af5e:853c with SMTP id d9-20020a170903230900b001b8af5e853cmr1410357plh.26.1689230509075; Wed, 12 Jul 2023 23:41:49 -0700 (PDT) Received: from libai.bytedance.net ([61.213.176.11]) by smtp.gmail.com with ESMTPSA id h13-20020a170902680d00b001ac2be26340sm5144966plk.222.2023.07.12.23.41.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 23:41:48 -0700 (PDT) From: zhenwei pi To: berto@igalia.com, kwolf@redhat.com, groug@kaod.org, qemu_oss@crudebyte.com, hreitz@redhat.com Cc: arei.gonglei@huawei.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, berrange@redhat.com, zhenwei pi Subject: [PATCH v3 6/6] throttle: use enum ThrottleType instead of bool is_write Date: Thu, 13 Jul 2023 14:41:11 +0800 Message-Id: <20230713064111.558652-7-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230713064111.558652-1-pizhenwei@bytedance.com> References: <20230713064111.558652-1-pizhenwei@bytedance.com> MIME-Version: 1.0 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=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org enum ThrottleType is already there, use ThrottleType instead of 'bool is_write' for throttle API, also modify related codes from block, fsdev, cryptodev and tests. Signed-off-by: zhenwei pi --- backends/cryptodev.c | 9 +++++---- block/throttle-groups.c | 6 ++++-- fsdev/qemu-fsdev-throttle.c | 8 +++++--- include/qemu/throttle.h | 4 ++-- tests/unit/test-throttle.c | 4 ++-- util/throttle.c | 30 ++++++++++++++++-------------- 6 files changed, 34 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; } - 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; } - 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; } - throttle_account(&backend->ts, true, ret); + throttle_account(&backend->ts, THROTTLE_WRITE, ret); return cryptodev_backend_operation(backend, op_info); } diff --git a/block/throttle-groups.c b/block/throttle-groups.c index fb203c3ced..429b9d1dae 100644 --- a/block/throttle-groups.c +++ b/block/throttle-groups.c @@ -270,6 +270,7 @@ static bool throttle_group_schedule_timer(ThrottleGroupMember *tgm, ThrottleState *ts = tgm->throttle_state; ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts); ThrottleTimers *tt = &tgm->throttle_timers; + ThrottleType throttle = is_write ? THROTTLE_WRITE : THROTTLE_READ; bool must_wait; if (qatomic_read(&tgm->io_limits_disabled)) { @@ -281,7 +282,7 @@ static bool throttle_group_schedule_timer(ThrottleGroupMember *tgm, return true; } - must_wait = throttle_schedule_timer(ts, tt, is_write); + must_wait = throttle_schedule_timer(ts, tt, throttle); /* 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 = container_of(tgm->throttle_state, ThrottleGroup, ts); + ThrottleType throttle = is_write ? THROTTLE_WRITE : THROTTLE_READ; assert(bytes >= 0); @@ -386,7 +388,7 @@ void coroutine_fn throttle_group_co_io_limits_intercept(ThrottleGroupMember *tgm } /* The I/O will be executed, so do the accounting */ - throttle_account(tgm->throttle_state, is_write, bytes); + throttle_account(tgm->throttle_state, throttle, bytes); /* 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..4aa5bc0196 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) { + ThrottleType throttle = is_write ? THROTTLE_WRITE : THROTTLE_READ; + if (throttle_enabled(&fst->cfg)) { - if (throttle_schedule_timer(&fst->ts, &fst->tt, is_write) || + if (throttle_schedule_timer(&fst->ts, &fst->tt, throttle) || !qemu_co_queue_empty(&fst->throttled_reqs[is_write])) { qemu_co_queue_wait(&fst->throttled_reqs[is_write], NULL); } - throttle_account(&fst->ts, is_write, iov_size(iov, iovcnt)); + throttle_account(&fst->ts, throttle, iov_size(iov, iovcnt)); 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, throttle)) { qemu_co_queue_next(&fst->throttled_reqs[is_write]); } } diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h index ba6293eeef..1cd6b0c397 100644 --- a/include/qemu/throttle.h +++ b/include/qemu/throttle.h @@ -154,9 +154,9 @@ void throttle_config_init(ThrottleConfig *cfg); /* usage */ bool throttle_schedule_timer(ThrottleState *ts, ThrottleTimers *tt, - bool is_write); + ThrottleType throttle); -void throttle_account(ThrottleState *ts, bool is_write, uint64_t size); +void throttle_account(ThrottleState *ts, ThrottleType throttle, 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 testing bps or ops */ throttle_config(&ts, QEMU_CLOCK_VIRTUAL, &cfg); /* 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); /* check total result */ index = to_test[is_ops][0]; diff --git a/util/throttle.c b/util/throttle.c index c0bd0c26c3..5e4dc0bfdd 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -136,11 +136,11 @@ int64_t throttle_compute_wait(LeakyBucket *bkt) /* This function compute the time that must be waited while this IO * - * @is_write: true if the current IO is a write, false if it's a read + * @throttle: throttle type * @ret: time to wait */ static int64_t throttle_compute_wait_for(ThrottleState *ts, - bool is_write) + ThrottleType throttle) { BucketType to_check[2][4] = { {THROTTLE_BPS_TOTAL, THROTTLE_OPS_TOTAL, @@ -154,7 +154,7 @@ static int64_t throttle_compute_wait_for(ThrottleState *ts, int i; for (i = 0; i < 4; i++) { - BucketType index = to_check[is_write][i]; + BucketType index = to_check[throttle][i]; wait = throttle_compute_wait(&ts->cfg.buckets[index]); if (wait > max_wait) { max_wait = wait; @@ -166,13 +166,13 @@ static int64_t throttle_compute_wait_for(ThrottleState *ts, /* compute the timer for this type of operation * - * @is_write: the type of operation + * @throttle: throttle type * @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, + ThrottleType throttle, int64_t now, int64_t *next_timestamp) { @@ -182,7 +182,7 @@ static bool throttle_compute_timer(ThrottleState *ts, throttle_do_leak(ts, now); /* compute the wait time if any */ - wait = throttle_compute_wait_for(ts, is_write); + wait = throttle_compute_wait_for(ts, throttle); /* if the code must wait compute when the next timer should fire */ if (wait) { @@ -423,23 +423,24 @@ void throttle_get_config(ThrottleState *ts, ThrottleConfig *cfg) * NOTE: this function is not unit tested due to it's usage of timer_mod * * @tt: the timers structure - * @is_write: the type of operation (read/write) + * @throttle: throttle type * @ret: true if the timer has been scheduled else false */ bool throttle_schedule_timer(ThrottleState *ts, ThrottleTimers *tt, - bool is_write) + ThrottleType throttle) { int64_t now = qemu_clock_get_ns(tt->clock_type); int64_t next_timestamp; QEMUTimer *timer; bool must_wait; - timer = is_write ? tt->timers[THROTTLE_WRITE] : tt->timers[THROTTLE_READ]; + assert(throttle < THROTTLE_MAX); + timer = tt->timers[throttle]; assert(timer); must_wait = throttle_compute_timer(ts, - is_write, + throttle, now, &next_timestamp); @@ -460,10 +461,10 @@ bool throttle_schedule_timer(ThrottleState *ts, /* do the accounting for this operation * - * @is_write: the type of operation (read/write) + * @throttle: throttle type * @size: the size of the operation */ -void throttle_account(ThrottleState *ts, bool is_write, uint64_t size) +void throttle_account(ThrottleState *ts, ThrottleType throttle, uint64_t size) { const BucketType bucket_types_size[2][2] = { { THROTTLE_BPS_TOTAL, THROTTLE_BPS_READ }, @@ -476,6 +477,7 @@ void throttle_account(ThrottleState *ts, bool is_write, uint64_t size) double units = 1.0; unsigned i; + assert(throttle < THROTTLE_MAX); /* if cfg.op_size is defined and smaller than size we compute unit count */ if (ts->cfg.op_size && size > ts->cfg.op_size) { units = (double) size / ts->cfg.op_size; @@ -484,13 +486,13 @@ void throttle_account(ThrottleState *ts, bool is_write, uint64_t size) for (i = 0; i < 2; i++) { LeakyBucket *bkt; - bkt = &ts->cfg.buckets[bucket_types_size[is_write][i]]; + bkt = &ts->cfg.buckets[bucket_types_size[throttle][i]]; bkt->level += size; if (bkt->burst_length > 1) { bkt->burst_level += size; } - bkt = &ts->cfg.buckets[bucket_types_units[is_write][i]]; + bkt = &ts->cfg.buckets[bucket_types_units[throttle][i]]; bkt->level += units; if (bkt->burst_length > 1) { bkt->burst_level += units;