From nobody Thu Nov 28 08:26:27 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 ARC-Seal: i=1; a=rsa-sha256; t=1693243327; cv=none; d=zohomail.com; s=zohoarc; b=VKlWcMUuEZXzKep8ckD8lMyf7DGZfIdy8YVbFSHyi8zq+x29740wNRBvFjEJ3NqqLA/oJfIw/Mv8DEWtpokvAv+yClgxzIQxG9XFCrH3pEw907HTtZCkg4wPX0dXgDsvXWjy/PnL5pn51uiAeQCuGLpRLHUz0UvfqW2OCGDENg0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693243327; 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=J+M1b4oBXMxVhhUnSSd4fdMxTnS6/iN50/aUGAiSJHs=; b=bAmdqAXz6DA2VcELcZivlICuP9jdC2ME8hi3dsOghnEJpFYs7VOahKZJRolz3X3mVciIJLFA1HQpue//gq2+2fO3zUjJwfbOSjpASmji6jWBKvsI1FT1ytG5PHQMe84HC2fJfJU6jqOgt1laQ/Br+mrdBmGwe5FL/YqNSMYktTw= 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 1693243326842679.2473907598915; Mon, 28 Aug 2023 10:22:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qafvy-000584-C7; Mon, 28 Aug 2023 13:21:50 -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 1qafvw-00056K-W5 for qemu-devel@nongnu.org; Mon, 28 Aug 2023 13:21:49 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qafvu-0006f8-Re for qemu-devel@nongnu.org; Mon, 28 Aug 2023 13:21:48 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-68bee12e842so2315029b3a.3 for ; Mon, 28 Aug 2023 10:19:46 -0700 (PDT) Received: from localhost.localdomain ([118.114.61.244]) by smtp.gmail.com with ESMTPSA id d23-20020a637357000000b0055c558ac4edsm7697985pgn.46.2023.08.28.10.19.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Aug 2023 10:19:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20221208.gappssmtp.com; s=20221208; t=1693243185; x=1693847985; 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=J+M1b4oBXMxVhhUnSSd4fdMxTnS6/iN50/aUGAiSJHs=; b=o5W8Ov5S+xXMkhtLjCWgo0Yhtt9pzQUVw5P1dARwQx8OAtLtlkUBjfggOtStrhhBVi ZkFiIAwYmMilOWEcvNlDaYFh7NntBUB2txgGunI6rhZvIj2544UXb2kTHm7sbd7z11mn G74A1GlbJwK8YLJ4vYP03ZCXvVObNYblFKTPFOE6LZsvxiQkE64i1VNssxpGuZ2msdsF omqUWWqj/M/66ullt4aViIN1NiryOOvKH+9KX9+qcLLeJS3ZhNAeszFmHcxPTwqmBbXn 1hm1rFaaXvUCnOiMg6mdAxpXQOh/o+/oCU59RdCNR5RDLBFPbo34N/gdZ+8agSf3Jrjd eltg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693243185; x=1693847985; 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=J+M1b4oBXMxVhhUnSSd4fdMxTnS6/iN50/aUGAiSJHs=; b=H3b+clJ+eo7UPyi0xmmHL/3j1ll/ePZj71dNnvLrmc6il6RVzY+aFPRXRa7pQZfG4s pbV7tn7nH38wpGf3qVFH6qQMJKH+8yOprKbfaYAnhwLFpuYaR963/sK/PhB1KpyGRLCO GY7DCgik/HY5lu55wUcPdl6SVAeXHxhRkE9dEJC6fhV4GZNKu3AnbqgT4pKZOk8SMrH5 ABSD2YZZtxl+qb7PDfaB1lhEnPTC/UxtNs27AYBXi0Zv89x7D5YPrL5LYFqx9ZdIfQZc ZL5HwhBP+Htt2YQOEZhei44kTgFvhOzTN61Dke3uHZOKStCC7YUMgD7XqmFk6wnHl8pU 0qhQ== X-Gm-Message-State: AOJu0YxYJmD3SkPfhNarJwslTolniQsOCVj49Xa+T3R3WiunCS122dNM LDf9eWRt2cCj6+hHhx1YsIalj7yjThSig5KNAoseJCrr X-Google-Smtp-Source: AGHT+IHZqQE825N6wQbFSNr4M9kjHPorihvkgjnfji7T66yKo+Y+utiYuDlgaYMAgraKDVJ3l6/w1w== X-Received: by 2002:a05:6a00:15d6:b0:68b:de2a:3798 with SMTP id o22-20020a056a0015d600b0068bde2a3798mr13708927pfu.18.1693243185268; Mon, 28 Aug 2023 10:19:45 -0700 (PDT) From: Hyman Huang To: qemu-devel@nongnu.org Cc: "alloc.young" , Hyman Huang Subject: [PULL 1/3] softmmu: Fix dirtylimit memory leak Date: Tue, 29 Aug 2023 01:19:20 +0800 Message-Id: <6d10290e8c25e8228657f6496aa0bb4342694fd4.1693241678.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::433; envelope-from=yong.huang@smartx.com; helo=mail-pf1-x433.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.20221208.gappssmtp.com) X-ZM-MESSAGEID: 1693243328701100001 Content-Type: text/plain; charset="utf-8" From: "alloc.young" Fix memory leak in hmp_info_vcpu_dirty_limit,use g_autoptr to handle memory deallocation. Signed-off-by: alloc.young Reviewed-by: Hyman Huang Message-Id: Signed-off-by: Hyman Huang --- softmmu/dirtylimit.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/softmmu/dirtylimit.c b/softmmu/dirtylimit.c index 3c275ee55b..e3ff53b8fc 100644 --- a/softmmu/dirtylimit.c +++ b/softmmu/dirtylimit.c @@ -653,7 +653,8 @@ struct DirtyLimitInfoList *qmp_query_vcpu_dirty_limit(E= rror **errp) =20 void hmp_info_vcpu_dirty_limit(Monitor *mon, const QDict *qdict) { - DirtyLimitInfoList *limit, *head, *info =3D NULL; + DirtyLimitInfoList *info; + g_autoptr(DirtyLimitInfoList) head =3D NULL; Error *err =3D NULL; =20 if (!dirtylimit_in_service()) { @@ -661,20 +662,17 @@ void hmp_info_vcpu_dirty_limit(Monitor *mon, const QD= ict *qdict) return; } =20 - info =3D qmp_query_vcpu_dirty_limit(&err); + head =3D qmp_query_vcpu_dirty_limit(&err); if (err) { hmp_handle_error(mon, err); return; } =20 - head =3D info; - for (limit =3D head; limit !=3D NULL; limit =3D limit->next) { + for (info =3D head; info !=3D NULL; info =3D info->next) { monitor_printf(mon, "vcpu[%"PRIi64"], limit rate %"PRIi64 " (MB/s)= ," " current rate %"PRIi64 " (MB/s)\n", - limit->value->cpu_index, - limit->value->limit_rate, - limit->value->current_rate); + info->value->cpu_index, + info->value->limit_rate, + info->value->current_rate); } - - g_free(info); } --=20 2.39.1 From nobody Thu Nov 28 08:26:27 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 ARC-Seal: i=1; a=rsa-sha256; t=1693243322; cv=none; d=zohomail.com; s=zohoarc; b=doPAzmt3GeftSVin/Q9mNWiO5ILsHYIY5njQRTJC6N7LlZyrZ0MOyQXRYxrcmbQbkG1+J+Z3LFmLQ/D1fS6/5rHaP2DiU0+KWkJ+AJPYHTWccSa+luXVoE+eLfZ9V1ER+reGOv3+wqFcOXHIk7iiH9qZZa2y9MVB7cliHmEPuFs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693243322; h=Content-Type: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=XppDKu9NZs7FVrVBX8oS7hGn8g76t1JDjeegSdQLlZc=; b=C48cm04+aJOHWD14uu5BW3mm6W0dsgmMAPqsnhWZ2MnaNDhjA0o351yJ12B8u6jCoOMcQD61yX3qBKC28s/Knj5RS57zq1So6jkdrl124tr9LevX/qwnOokR1ZpEhJ4Ev9Y8xk5i+f3eSsEUUFG8JnsJ2DATVmtCxXm9sDLB9Zo= 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 1693243322747989.6414974819517; Mon, 28 Aug 2023 10:22:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qafw3-0005IQ-3K; Mon, 28 Aug 2023 13:21: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 1qafw1-0005Eq-Pi for qemu-devel@nongnu.org; Mon, 28 Aug 2023 13:21:53 -0400 Received: from mail-oi1-x231.google.com ([2607:f8b0:4864:20::231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qafvz-0006fl-MH for qemu-devel@nongnu.org; Mon, 28 Aug 2023 13:21:53 -0400 Received: by mail-oi1-x231.google.com with SMTP id 5614622812f47-3a88c422e23so2007452b6e.0 for ; Mon, 28 Aug 2023 10:19:51 -0700 (PDT) Received: from localhost.localdomain ([118.114.61.244]) by smtp.gmail.com with ESMTPSA id d23-20020a637357000000b0055c558ac4edsm7697985pgn.46.2023.08.28.10.19.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Aug 2023 10:19:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20221208.gappssmtp.com; s=20221208; t=1693243190; x=1693847990; 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=XppDKu9NZs7FVrVBX8oS7hGn8g76t1JDjeegSdQLlZc=; b=EhRe+RAdl841lg7KsM1NFt02GCjwnPwcFYyhvctRxvgwZq/pr80z8eVbAViS8OxIZv 0FG1G2luXJ9r4HhvqtZmbd0eHVrjq3OZUeoYfolgv+fQUhD+38rI2b2nGYFRJunDVXBv Cm2XASZ3aozZQB0o9xw9ceAUYSjfUbWyymHJcdyEsLSkDi9mrx+mSMPLy4VGqkwYlEc2 2fyy4H8/whKSe+8sWGDv8uy+GFMqpkmLCSIOFS90uUxm/O4ZlKmsZTmxpKEU4SIyb0M0 qwQM4yqnPa7VVnYihrwVX2kJ4FBcJZ4L4repUkXJHTZT6Ak6xqU5QdohCU1cJ8hnHDea H+3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693243190; x=1693847990; 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=XppDKu9NZs7FVrVBX8oS7hGn8g76t1JDjeegSdQLlZc=; b=WyEacYh77XrJwTyJxtpEhnRTqZAevmYIbwygghaT6pTGBNk6U9XC2b9DnJQ6FJ37EM AioeJ3lNrMJQFTUxK8i7hgGvGzUOrF/Z3SI4nPFINoWt8FTv0fR119tk1rx5vhgEvBm+ 5ctmJlOlHKvu6YUKxOYDnf8vN45fYQYQwFR3/VkfoOt0BXlMEuxNMvgs50tsMyJXTxzg lngsTxbqeegZZmtv4eMasPFX7QejFqfebjahSY0yUtcEdxQMxCbSf7iH109ZsgjAOc21 fAYjnfuCyDCkHpcubYrPM/zi/LUNWbDO42p/m2KSPxOh/4aO3B6A0zIpyPODuQVmwoeZ HRQQ== X-Gm-Message-State: AOJu0YxblbnoLKltC661iT/hbdnQenf4Y0UrVFhpIeZpknnGgYCe0ZRZ Y2VDOFVuw7+lanuKRxUcjuYNavePlJ3FTtpp3TSQ8aRx X-Google-Smtp-Source: AGHT+IF3YawrKouDEsK0XGHqDgdZ7Tt9G0Ci43u7ZxjxQ0yEdSiE4rJnTdqaJyK7akIEN0u9Cc4TTw== X-Received: by 2002:a05:6808:1785:b0:3a9:6400:62cb with SMTP id bg5-20020a056808178500b003a9640062cbmr11474341oib.57.1693243190182; Mon, 28 Aug 2023 10:19:50 -0700 (PDT) From: Hyman Huang To: qemu-devel@nongnu.org Cc: "alloc.young" , Hyman Huang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 2/3] softmmu/dirtylimit: Convert free to g_free Date: Tue, 29 Aug 2023 01:19:21 +0800 Message-Id: <1b4e2e0a33674ccfd43e1b86fc3f882e4219c1c7.1693241678.git.yong.huang@smartx.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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::231; envelope-from=yong.huang@smartx.com; helo=mail-oi1-x231.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.20221208.gappssmtp.com) X-ZM-MESSAGEID: 1693243324428100001 From: "alloc.young" Convert free to g_free to match g_new and g_malloc functions. Fixes: cc2b33eab0 ("softmmu/dirtylimit: Implement vCPU dirtyrate calculatio= n periodically") Fixes: baa609832e ("softmmu/dirtylimit: Implement virtual CPU throttle") Signed-off-by: alloc.young Reviewed-by: Hyman Huang Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-Id: Signed-off-by: Hyman Huang --- softmmu/dirtylimit.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/softmmu/dirtylimit.c b/softmmu/dirtylimit.c index e3ff53b8fc..fa959d7743 100644 --- a/softmmu/dirtylimit.c +++ b/softmmu/dirtylimit.c @@ -100,7 +100,7 @@ static void vcpu_dirty_rate_stat_collect(void) stat.rates[i].dirty_rate; } =20 - free(stat.rates); + g_free(stat.rates); } =20 static void *vcpu_dirty_rate_stat_thread(void *opaque) @@ -171,10 +171,10 @@ void vcpu_dirty_rate_stat_initialize(void) =20 void vcpu_dirty_rate_stat_finalize(void) { - free(vcpu_dirty_rate_stat->stat.rates); + g_free(vcpu_dirty_rate_stat->stat.rates); vcpu_dirty_rate_stat->stat.rates =3D NULL; =20 - free(vcpu_dirty_rate_stat); + g_free(vcpu_dirty_rate_stat); vcpu_dirty_rate_stat =3D NULL; } =20 @@ -220,10 +220,10 @@ void dirtylimit_state_initialize(void) =20 void dirtylimit_state_finalize(void) { - free(dirtylimit_state->states); + g_free(dirtylimit_state->states); dirtylimit_state->states =3D NULL; =20 - free(dirtylimit_state); + g_free(dirtylimit_state); dirtylimit_state =3D NULL; =20 trace_dirtylimit_state_finalize(); --=20 2.39.1 From nobody Thu Nov 28 08:26:27 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 ARC-Seal: i=1; a=rsa-sha256; t=1693243332; cv=none; d=zohomail.com; s=zohoarc; b=FGw221+tBXQjv5wSpi8LV5re7l3vv+Vpd2O/eRbjJEOvOa9QzBlxKRCLTlOosxAu2pJz+j1IWZS7zRTyKOD0SZrEvx/NeMN9YHr02cxGUn5hGcQ3UUW9s59041gORpPpZPlQrnuqvlJ0tz5kif5MMHLNtGFr0dcfTYDq73a3hdg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693243332; 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=SDbikvrJURYSUdco/ZqIPH9U7npc2uzsUXfdoZeozoM=; b=Bn59dPSIbt4iwp2H+yzNnV2B2NeHC+z0scj/rSuKRGV+S2VDyvP4lxDy+X5I04e790yFY2PReYO9DicECDirCpGVAbJ6O+2yfktMIUgKY7bpNc/G2KYa6tqyb5a4H8UhPSF2FyjqqZfCPhu4GN78sUr6Jzs7qOy29GMKzorHAes= 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 1693243332632971.4955997462853; Mon, 28 Aug 2023 10:22:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qafw8-0005mY-Mq; Mon, 28 Aug 2023 13:22:00 -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 1qafw6-0005X7-1d for qemu-devel@nongnu.org; Mon, 28 Aug 2023 13:21:58 -0400 Received: from mail-oi1-x22c.google.com ([2607:f8b0:4864:20::22c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qafw3-0006gC-Rx for qemu-devel@nongnu.org; Mon, 28 Aug 2023 13:21:57 -0400 Received: by mail-oi1-x22c.google.com with SMTP id 5614622812f47-3a7781225b4so2461787b6e.3 for ; Mon, 28 Aug 2023 10:19:55 -0700 (PDT) Received: from localhost.localdomain ([118.114.61.244]) by smtp.gmail.com with ESMTPSA id d23-20020a637357000000b0055c558ac4edsm7697985pgn.46.2023.08.28.10.19.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Aug 2023 10:19:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20221208.gappssmtp.com; s=20221208; t=1693243194; x=1693847994; 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=SDbikvrJURYSUdco/ZqIPH9U7npc2uzsUXfdoZeozoM=; b=tOH4pBedfmXEJT5OyigJ+EHs5qTn5ziTuzRApkATx+0RGvJEsX22glkJs3v5ybaLWr 4fUpa1dg9D1OUujKoT/3O5qURHSgyGsapMigosABSDNLyPZ2AX61gmnhuRQpgttQV2kj 7DeGUBGJwmhn8yqwp3eccTmoUwIVBl9w49urDHNmkPDb8rEglBFvv0IGDEmtxzhRy1Jn rlpTIV1oZt0b9BlA0qU917L10qJPJlw47DTzg9HMNQYTQCKObuaPWOuhbydBQ3u2tP4o 39LEgTXbqFDUxdYUltSeZrQWaPmMqOTdIZ5w1zOh8ZF8n8co0WKo9NCPSFgQLKJGCFEo AqUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693243194; x=1693847994; 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=SDbikvrJURYSUdco/ZqIPH9U7npc2uzsUXfdoZeozoM=; b=Ns+fCAc+aDsnXeMpm0NMQ7nLvOL8VcR6KthHLloFPK7S4mzTosKNLr+kEPoePHb6dg Q91W/7zWPvpjq5OlltkUJcCR9T2a2SKOdfHgXdlFO2hut4f8xXQ0zjbuFaB5lTSVVYzB 0pq+3zmcHpZ8jjN3GRadqtT1nVutrdfJlScEO/Cs7LIFVNBqhV6wESKdgqzjQzuvgAtA UMit3WYBFnuhLLM/dgGp60MSMGGqzYhr4DvkfqhUjEhMaLEjDugd+LnY0XC6UwUfP+ZA N4WnAAU2EUNUtwcdcPz/FbkPo6i5bH4q972NXe+odpmIXYkLCpOEXJJe2UmodyWNzXUE BKdQ== X-Gm-Message-State: AOJu0YwSIB59mKScdqcrUnNbklZxfjhBjBMik1NubWCNm9IXOmMqo8wx s8yBjaM6IqogB7O/1qHO4ShFUAJPIbHu0vV3o7pP90n8 X-Google-Smtp-Source: AGHT+IG3Vou5fcQ3Zy0QHLCi5UPhiZhmb4gCvGA81YteOoKVO/CzQhEHcO7grfXCel0dIYsZiWlnlw== X-Received: by 2002:a05:6808:138c:b0:3a7:1cca:f99f with SMTP id c12-20020a056808138c00b003a71ccaf99fmr14948630oiw.34.1693243194692; Mon, 28 Aug 2023 10:19:54 -0700 (PDT) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Andrei Gudkov , Hyman Huang Subject: [PULL 3/3] migration/dirtyrate: Fix precision losses and g_usleep overshoot Date: Tue, 29 Aug 2023 01:19:22 +0800 Message-Id: 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::22c; envelope-from=yong.huang@smartx.com; helo=mail-oi1-x22c.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.20221208.gappssmtp.com) X-ZM-MESSAGEID: 1693243333893100001 Content-Type: text/plain; charset="utf-8" From: Andrei Gudkov Signed-off-by: Andrei Gudkov Reviewed-by: Hyman Huang Message-Id: <8ddb0d40d143f77aab8f602bd494e01e5fa01614.1691161009.git.gudkov= .andrei@huawei.com> Signed-off-by: Hyman Huang --- migration/dirtyrate.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 84f1b0fb20..bccb3515e3 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -57,6 +57,8 @@ static int64_t dirty_stat_wait(int64_t msec, int64_t init= ial_time) msec =3D current_time - initial_time; } else { g_usleep((msec + initial_time - current_time) * 1000); + /* g_usleep may overshoot */ + msec =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME) - initial_time; } =20 return msec; @@ -77,9 +79,13 @@ static int64_t do_calculate_dirtyrate(DirtyPageRecord di= rty_pages, { uint64_t increased_dirty_pages =3D dirty_pages.end_pages - dirty_pages.start_pages; - uint64_t memory_size_MiB =3D qemu_target_pages_to_MiB(increased_dirty_= pages); =20 - return memory_size_MiB * 1000 / calc_time_ms; + /* + * multiply by 1000ms/s _before_ converting down to megabytes + * to avoid losing precision + */ + return qemu_target_pages_to_MiB(increased_dirty_pages * 1000) / + calc_time_ms; } =20 void global_dirty_log_change(unsigned int flag, bool start) --=20 2.39.1