From nobody Fri Dec 19 17:01:25 2025 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=1687850757; cv=none; d=zohomail.com; s=zohoarc; b=K+C6AyMsNf9o9FYPJiH/7nJTWjEywR8PgkOHsdWraKgr0/trXzrTqllHnwovxMdV6Mq/NGBLFUEN02JUFadNt2I/rE/yHiUPm17Xht7WLMtDl7bj54hRCgHQis7fjHzFD+qmDyAFMwJhBCK1+aYt01enpQWzsow0FvWAHovaSgs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687850757; 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=31NL63ixAGpk3LIat/cuu4mWxOeI4E9qGV2see5Ihc0=; b=OqcIhQPFOMlVt4vl1BLk49KIs8cI4RXPanOCxb8ATtUjCowqci3dGM1C4RcGHub7+Eaf8yNn3zZVqkkwW5Kh8bgraRZ2MmZifwq+dl3iFn87ce7YKGzrxQLA0Ks6c4xK3BpGN/D90PhWxJeObgtIdy5vWvInlHMf7Tl+CMK7Bh8= 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 1687850757276725.1805069701298; Tue, 27 Jun 2023 00:25:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qE34A-00080u-PL; Tue, 27 Jun 2023 03:24: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 1qE348-0007z7-Ek for qemu-devel@nongnu.org; Tue, 27 Jun 2023 03:24:44 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qE346-0005uI-Iw for qemu-devel@nongnu.org; Tue, 27 Jun 2023 03:24:44 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-666e3b15370so2540236b3a.0 for ; Tue, 27 Jun 2023 00:24:40 -0700 (PDT) Received: from libai.bytedance.net ([61.213.176.11]) by smtp.gmail.com with ESMTPSA id u22-20020aa78496000000b00640f1e4a811sm3210915pfn.22.2023.06.27.00.24.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 00:24:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1687850680; x=1690442680; 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=31NL63ixAGpk3LIat/cuu4mWxOeI4E9qGV2see5Ihc0=; b=idjFbBvXwKV7P6RPlI168so8sDZLzjGiIJQVCwDCMs7HZdB3zGeQa3OI8//8A6aAvj teqnhcbmoNiUafp28Ju26qIOYpcefUPoyin2SD7oVfWUs8DAWayZa4Y8jmMfDZSs0ECm yXCkdwNX+AP5nYzTyl+QODZmvb6yORbin2cqyug7N2wBfDdbD2CLDIGxdUXBiZi2VL4/ O6RIq4tqQS1DY10HtVMxlUKK1Qel4vCFTPZIUE+CQbet8168d7PZTEGU2oS4Y4IvroS8 PQ+ThzvBLKdT83hwbD9HAh/2oiuP+acHHA69WBe/9pddvhCTWKYCuEW3USAmE3jGfSM0 XVhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687850680; x=1690442680; 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=31NL63ixAGpk3LIat/cuu4mWxOeI4E9qGV2see5Ihc0=; b=FpGSHOArQ/lVrtypZaSUCg8IiNyNWkM0eTA8bVK0sSmXk23/HYuc6pt9epmWY+i0Z9 BOHdnh8keBHSh0hVJwXH99H6VRjuFrsbLb6OX2fdvnG9SX9zn/yJdPiSVnY2Ec9A9qZW vIZSBaPRNyq8pF5zvYoJz0NjxBaYcTVaxxmMmjH3BcvJOwMuCjnbyhdsz8pH4hiRFqWb +r3XJ1CYDAskDnIFdcvCHqJu+Uu2Wh+EzJrpnT+1CgGpmUpEvtnl2N1yEkhcv5Dzhh88 c5kwVdK5Eer6Mcyx/mpeC8FArjRIkPBs6ppbb0TRscYEv3NO2P8GSn61I0dbE98Pzmz5 l80g== X-Gm-Message-State: AC+VfDwCXlM788wvDszVFcdo9HIFVcojM3eN8x/kTygaytVo6dVApHFA 8WDpJSSehEF3yN1qZ4LiR10Zmg== X-Google-Smtp-Source: ACHHUZ73oV2d4QF9GQvVihiONVEGWuZJGAQbCcbiw0ot78pW1+uN7aAkL+PyTj9rcZhrwh2z/qXNSA== X-Received: by 2002:a05:6a00:1946:b0:658:cbf1:d05a with SMTP id s6-20020a056a00194600b00658cbf1d05amr29579960pfk.3.1687850679770; Tue, 27 Jun 2023 00:24:39 -0700 (PDT) From: zhenwei pi To: berto@igalia.com Cc: arei.gonglei@huawei.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, berrange@redhat.com, zhenwei pi Subject: [PATCH v2 1/5] throttle: introduce enum ThrottleType Date: Tue, 27 Jun 2023 15:24:27 +0800 Message-Id: <20230627072431.449171-2-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230627072431.449171-1-pizhenwei@bytedance.com> References: <20230627072431.449171-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::42f; envelope-from=pizhenwei@bytedance.com; helo=mail-pf1-x42f.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: 1687850759434100003 Content-Type: text/plain; charset="utf-8" Use enum ThrottleType instead of number index. Signed-off-by: zhenwei pi Reviewed-by: Alberto Garcia --- 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; =20 +typedef enum { + THROTTLE_READ =3D 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 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