From nobody Mon Feb 9 19:56:48 2026 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 ARC-Seal: i=1; a=rsa-sha256; t=1697542782; cv=none; d=zohomail.com; s=zohoarc; b=Ywr3ndvr1SAP7VuhMdSGDbMqfNb9MfVTV81Bw/xVI+9UnQ08SE0LmY0MNQxZsU0lIJNoua/AEo5cKac5zzqAu+jng+47eJObtcGWyDIbC2c4rzPhfsV94iVhbxrATapnCGk1QJJsQALONiAop5jI++jrf5H9y0wyUYE33e/+OV8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697542782; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NZN3PZcjXAZrKvaLzoF/mqQnoItoBs27sZrKsshwE4s=; b=F7yaRCsTbanruQlJezMxBRKlsLUiuWXIR4d2B+391fdN8u/WpZ7hX0a5xBZExMyHltgG9fYHtV0S++eaM4MbGThEEp6zhOl1wfzxiRfguawa5BDkI8fKp29Rw/YKjMMyXFJBQSzV6ViWcC3cWlixSA1sPY9hI346uIMMSh021Q8= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697542782623653.6321204497889; Tue, 17 Oct 2023 04:39:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qsiPj-00031k-KD; Tue, 17 Oct 2023 07:39:07 -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 1qsiPi-00031Y-Ca for qemu-devel@nongnu.org; Tue, 17 Oct 2023 07:39:06 -0400 Received: from mail-ot1-x332.google.com ([2607:f8b0:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qsiPg-000159-1T for qemu-devel@nongnu.org; Tue, 17 Oct 2023 07:39:06 -0400 Received: by mail-ot1-x332.google.com with SMTP id 46e09a7af769-6c67060fdfaso3857730a34.2 for ; Tue, 17 Oct 2023 04:37:03 -0700 (PDT) Received: from localhost.localdomain ([171.216.79.181]) by smtp.gmail.com with ESMTPSA id x28-20020aa79a5c000000b00692c5b1a731sm1198647pfj.186.2023.10.17.04.36.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:36:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1697542623; x=1698147423; darn=nongnu.org; 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=NZN3PZcjXAZrKvaLzoF/mqQnoItoBs27sZrKsshwE4s=; b=mvXCYDBi34BcNaQgLtzugUGKVcQfitn/1SKYKYouyePoCPdKgGes/ABY4oIHsjec32 fMaWtYkjI+eQ2ekuweWBylYSyr8x/7VaJpXNFpWfrvwTdNSHHaPzwrghHgm0dvRHts3f CTLK5/iOTqzUkeawLWmqUcKlzJaUeedbei6eiUOSPDnt1FitHJhfUjhykpeBdiBO4wjx 8geqCE9OVi0VH7e3EvCsKD348KNQ6cpjrbmnsJY1xydDWWSMlTxFGPmAT+pVtyuSrbu/ vwPivlqLE/MreXhp2hN3DaSIN9hVUcSJpkWp1qKkkEMdyzLEpw3DuZtiF3LDcIgET+Sf XHRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697542623; x=1698147423; 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=NZN3PZcjXAZrKvaLzoF/mqQnoItoBs27sZrKsshwE4s=; b=fxhBSdw5VusexHUT+r+2IQ6O/mjwdcJ4jOZqe/G62kvinIjugtF4vI3uMkZypZQegD iPy88BkPN3ZWDcskgLPEcEoL+DJLW9YCnyq6AoSHCq2S6YGINLkDsCQ98KevzY4C7RUO nO7PxFb7JfY1d8MZcW+V5oKzeNN0S9UQeUJP+mEST8/iB747DF08pEhjJsQsQYkZKsB5 rZxD8qLVU97xzzqCkabQRfzqL9Z8iclaKlqgD1A3Uabmsxj2GOKq9wYYV3D9hphjA4Df ZyhcNIUvr66hTtqby9oLSDA+OASrCpFf4Dap3dLwGOhTzL7eUSaQl2lDMp9zaOgxZdl0 s0pg== X-Gm-Message-State: AOJu0YwbNTWur8bQlNsCaJLQUBRrWKlswQhqwnBi4aNt6rfdJxL5qwqX IIAdAXwfm8UBy2NnhS/QJmWqY7KxltFqQSpisj9dwoK/ X-Google-Smtp-Source: AGHT+IHuANjDvuOmNZP89BifXKe3+8uw71sT0jIxoXk5To2bFdEJ3zD4XpDIBfyVlNV+EzZZ9qjsGw== X-Received: by 2002:a05:6830:18c3:b0:6c4:81d6:171b with SMTP id v3-20020a05683018c300b006c481d6171bmr2134957ote.21.1697542622742; Tue, 17 Oct 2023 04:37:02 -0700 (PDT) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Juan Quintela , Peter Xu , Fabiano Rosas , Leonardo Bras , Thomas Huth , Laurent Vivier , Paolo Bonzini , Hyman Huang Subject: [PATCH 1/6] system/dirtylimit: Fix a race situation Date: Tue, 17 Oct 2023 19:36:04 +0800 Message-Id: <69ad82c901244e55f05a157edd828914b057e084.1697502089.git.yong.huang@smartx.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: 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: none client-ip=2607:f8b0:4864:20::332; envelope-from=yong.huang@smartx.com; helo=mail-ot1-x332.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 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 @smartx-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1697542783026100001 Content-Type: text/plain; charset="utf-8" Fix a race situation for global variable dirtylimit_state. Also, replace usleep by g_usleep to increase platform accessibility to the sleep function. Signed-off-by: Hyman Huang Reviewed-by: Fabiano Rosas --- system/dirtylimit.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/system/dirtylimit.c b/system/dirtylimit.c index fa959d7743..3666c4cb7c 100644 --- a/system/dirtylimit.c +++ b/system/dirtylimit.c @@ -411,12 +411,20 @@ void dirtylimit_set_all(uint64_t quota, =20 void dirtylimit_vcpu_execute(CPUState *cpu) { - if (dirtylimit_in_service() && - dirtylimit_vcpu_get_state(cpu->cpu_index)->enabled && - cpu->throttle_us_per_full) { - trace_dirtylimit_vcpu_execute(cpu->cpu_index, - cpu->throttle_us_per_full); - usleep(cpu->throttle_us_per_full); + if (cpu->throttle_us_per_full) { + dirtylimit_state_lock(); + + if (dirtylimit_in_service() && + dirtylimit_vcpu_get_state(cpu->cpu_index)->enabled) { + dirtylimit_state_unlock(); + trace_dirtylimit_vcpu_execute(cpu->cpu_index, + cpu->throttle_us_per_full); + + g_usleep(cpu->throttle_us_per_full); + return; + } + + dirtylimit_state_unlock(); } } =20 --=20 2.39.1