From nobody Wed May 15 02:21:38 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=1693323215; cv=none; d=zohomail.com; s=zohoarc; b=P4O3ex7KptsePldD5j3wb9cFbMWOUejshD/zEzQVdzPJsyR/dl+jXlEqmuH7+KD4w7uuG4bnWgA9IK6fS2Ai0knziSrGDQaKXxAw4Ofjjv+xPaYu7agO76VWQiqD0f+IRwGok4cKjcTkkxXYCJdHR3IXfnFKARAfgRcslzIsfd8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693323215; 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=N1Q5L9kGOY+80315qo8aqyIxFpiUtnLIXVMTOWbVbONV3VPpI+JSiHx/KNlArnufcHX7jyerPLTwXTZbp1HVHhVi8dtWWuyAhO5/fI4+JlnYBSFtlznG72+d3fD5RV1Mffntie+rjPqG37KvG4/idib59sY9hVIAWbX4i6yQFGs= 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 1693323215153831.3604728105814; Tue, 29 Aug 2023 08:33:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qb0i8-00083T-A4; Tue, 29 Aug 2023 11:32:56 -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 1qb0i3-00082x-7k for qemu-devel@nongnu.org; Tue, 29 Aug 2023 11:32:51 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb0i0-0006jy-D3 for qemu-devel@nongnu.org; Tue, 29 Aug 2023 11:32:50 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1c09673b006so23404405ad.1 for ; Tue, 29 Aug 2023 08:30:48 -0700 (PDT) Received: from localhost.localdomain ([118.114.61.244]) by smtp.gmail.com with ESMTPSA id c15-20020a170902d48f00b001bdc8a5e96csm9510282plg.169.2023.08.29.08.30.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 08:30:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20221208.gappssmtp.com; s=20221208; t=1693323047; x=1693927847; 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=Sn564WK6SbJVRkR6ZAjiYpv7mJgG/qAN5XOQck36SxqKwBdKJhn80ccc7/GRtqz8Uv NrhRZDEP8TwT5D+Oye2/8vXn+e6nHRSEc5vEbWpRROIy/CoxxdYzyXCcnVXww8RB0+1Y 4FZOI+Owo5PCvSoj0mzN0B/X+hmFm7TVG4KXTuTC4FzMmWEhVdwqIUX24ByiUQwwZxKm TPyc+kKE0WT+2V3gSIn8HGsnN4Q5cm/lBc2HM3szFEq2JWWphFD0p1864a/AdUT/eT+r 2eH1ZwDh4hgiIDOUYcM0HfODrNOLKhwQO07m2AFpZwQpt9l4xJoaVLSOWn/9IGCKZKf+ P8sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693323047; x=1693927847; 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=SbFztY19sE3JyCK6kocS/2B+SNb0Dj7TjeMSIfYbUebIIufFaEECkS7NKfAzkhKX0J zQU2Pz2L0XyjJBmk/B8X1n6kwWrGn5QYohcu3Vnv8vrg0Bi7W0wNQO8CKpDJfH2uzkg4 mkZZLZl+3dqRkS1okS/Te1zt5Lcv4OFtsZTCxfxchi7YnM8E7Ypc2LKyRtVkXOIWuHjg Mmsjr6yeObdDear0jhvZFU75POeIDajX0/1K1h69P0ccLN68PbyjH8ODcY5mw5cmMWQT J64rRtBFlHVnnWcLnhZz3slaN+e7hWbcGS6RLgvFVpsye+33x5YJHT8UR30xMUPfamdV ZAXQ== X-Gm-Message-State: AOJu0Yyx8mqTuVgVU6o4VHcdgo7WbtBjp1Hw/Uj2KJMR4+BrG6Flz2C3 VlOk7c+0bAVBRppoDhW9AH2LAc5O4awQscIBRJI2m7PO X-Google-Smtp-Source: AGHT+IGa5IzyHGugidMrEsV0khfbCqb/Rpxq0IfWg2At3tf8jP2qo4yZK67Wn+ODr8KkCunQZByCJw== X-Received: by 2002:a17:902:d4c3:b0:1bb:f82f:fb93 with SMTP id o3-20020a170902d4c300b001bbf82ffb93mr28094518plg.2.1693323046737; Tue, 29 Aug 2023 08:30:46 -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 23:29:48 +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::629; envelope-from=yong.huang@smartx.com; helo=mail-pl1-x629.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: 1693323215698100001 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 Wed May 15 02:21:38 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=1693323200; cv=none; d=zohomail.com; s=zohoarc; b=aVYfePhfQqVfKTFwEiXCXdGpkO2HUvfmaKud5L29HPnQZotfdxfGL8n6TRxcFuuH5qLG2ccujKhNZTD4INz1A26PT2HatS95BXwSXIEpSPASGuf91kNeDUGMbQB4m6BWk0Ksa3IiYMO3V4z83n8U7wJnsM/8HRv3N8jDhgmcSkY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693323200; 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=Zl+sVzhDGFjZ1QoetFjLatCBFpzA29n4jCgSIHmMNc4rDxyataByocI3nZDNeYmJAJcMfCxsf9C6WKQnAZEEQvDdkNiRdOZQ8f+w24fMWF2hGzqOBsUuLcgqM3pU4jeYJ3Uauf01PzKaTimtROyRoyQEAvgwVYarrqJVbqAIPhQ= 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 169332320031615.756568623573003; Tue, 29 Aug 2023 08:33:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qb0iD-00084C-Rj; Tue, 29 Aug 2023 11:33:01 -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 1qb0iB-00083p-Um for qemu-devel@nongnu.org; Tue, 29 Aug 2023 11:33:00 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb0i9-0006mr-6T for qemu-devel@nongnu.org; Tue, 29 Aug 2023 11:32:59 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1c1ff5b741cso6679845ad.2 for ; Tue, 29 Aug 2023 08:30:56 -0700 (PDT) Received: from localhost.localdomain ([118.114.61.244]) by smtp.gmail.com with ESMTPSA id c15-20020a170902d48f00b001bdc8a5e96csm9510282plg.169.2023.08.29.08.30.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 08:30:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20221208.gappssmtp.com; s=20221208; t=1693323056; x=1693927856; 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=Q3QDoA/jfnA+6kHtZvZaePahJwNJQaXxbo2c6Y6hfkRVdo3fOGfL/vls6TyU0soort WdIwqx0Kc1VM05AuEIYoftB9EnBpqNDVIrRCaqy5DNxisiOasXatLeqiuPSt0FRJchlt EmvoCDftW2a6B5tGe/5zsy4+gPCVWdBN0QyCKwi+VAIYUg2HZGmXhhF6PDMXiqgFzy34 oMKM0N4+wFVUVhqLlxAasE5HMwJ+GJI0FbMrfatpnjGGKHJ6laMcGGqQWSPjtNgCVrSe 0vpZZXyApAkWlVDN0ujGa88Vaxp9h9z+cmOjB/ECFIfxQ0wi1p0BBgOpMmCWLwk1CDuC zrCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693323056; x=1693927856; 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=H/vw7xJd6k2y8iu5Fij/mVMJ/L/9z357rbXunkAuP90QcU/Reifr6jjxMV+aij+6s2 lNQpnN1sS7ZyDncE4+YFMp226xiLT8rks7FRO0nc1LasMj0GphKMFscFyZxs+iASlQHB 8QbUQiEgjeSQBjp0BGHZ+6Isdr8PavFKatWFMgyHEHxb6+U87HOa5xkY+NLNK+b3hMuH zeGanQcL30eTxuEM2vInPox+Iljo3vSVNVgkbPDPGqcr8F1VvmaxXcz/GpmKZdX8qSZd KNH1wVTcsaSsJAOn3RMiBBjG0EGC5IRtaENsxyEgCnj5W3apgD9s+r1ziz4wuiVPYQqT HnFg== X-Gm-Message-State: AOJu0YzHfonZ47pfysxCe6sCRxnQGe2HBggHdXu7hiDuvc46D0nRlvE9 3zfM8d3FLBLwm2GNGWVolwB4zxZHnTyQjZPS+ykpE9eJ X-Google-Smtp-Source: AGHT+IEkhVgG0VABxKJQ+C1kpaa4afLdmcXC0lacb/kbT/qsoqWSXx3+bdyM8K2IhApfABrMlhuVmA== X-Received: by 2002:a17:902:e54f:b0:1bc:61d6:5fcc with SMTP id n15-20020a170902e54f00b001bc61d65fccmr37389267plf.51.1693323055810; Tue, 29 Aug 2023 08:30:55 -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 23:29:49 +0800 Message-Id: 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::62b; envelope-from=yong.huang@smartx.com; helo=mail-pl1-x62b.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: 1693323203934100001 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 Wed May 15 02:21:38 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=1693323240; cv=none; d=zohomail.com; s=zohoarc; b=JgYtgfhTNjVK8+vd6B9AvA1gVppwYHAJAZf3lYjLAz2IQpoSN4SaIc01rYY4EguFegwt/6mt7PMcAFU/xv5NH/q+MhAXYttEutuQYxAYSfz9i3OcpYHV0bAG681PGIBZLoB/cap2LU0uProwEGXN0m2J4rxgGAUP1Tf7GVfMgfI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693323240; 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=i+oNAqLSk//UDPHhaVTM4d84nh7q3JIqTk8s8/xfZbQzrEajxcbcj+6C8rz9hSXPEs78hjkF018E94LElMMZPZRln93rFCdhSjrp9Fibe6adL4w62mvEyukU9re6Ze6gla3WnKevHWj2v7NUF3ki8lA+PhzFnOL0ead2iaCbXSg= 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 1693323240156642.1454809570537; Tue, 29 Aug 2023 08:34:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qb0iK-00084w-Bo; Tue, 29 Aug 2023 11:33:08 -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 1qb0iI-00084h-7e for qemu-devel@nongnu.org; Tue, 29 Aug 2023 11:33:06 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb0iF-0006oc-Jr for qemu-devel@nongnu.org; Tue, 29 Aug 2023 11:33:05 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1bdc19b782aso28542705ad.0 for ; Tue, 29 Aug 2023 08:31:03 -0700 (PDT) Received: from localhost.localdomain ([118.114.61.244]) by smtp.gmail.com with ESMTPSA id c15-20020a170902d48f00b001bdc8a5e96csm9510282plg.169.2023.08.29.08.30.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 08:31:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20221208.gappssmtp.com; s=20221208; t=1693323062; x=1693927862; 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=hIcDyreBdh5KalomlxsGiS39drF7uTs5H/ThoL66/swHuLCTEyekXoquGaoZ+peerq JPihrwHqsrasDGFTjmnVZUxktgkIPJNYP3waM1mluj23owI6hPQKKK08U+BZXuEztiV8 HhGtumdt7ko/wou62jbnNO1svCJrC1oEind3DJdQdNocZH+n+cLmDFea/iaYMYfLV3oF tbex60UMENcpQ6JsEgPiJMVZWMlV47t3G8C8YZu/Gagn7SZBbN9wFrQD7uyJZ/kleqsL X7o3pX91DmXnb6CPxzCtNuMffAqLX59QEXgkk2sbJGUDu/NpOa1vyWTDKSWOroSsQSEr KncA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693323062; x=1693927862; 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=J2hYBTxdiIqo4SdKnOPYrIte/+Dsio2QU7zArEV5Axr/MfgPTlyto+aH4e1TAP+Eys zdmmQ/AuIa84MXwCCfSqncDJmDPLLvHdw7TuMlAjg5rhO8/dD65x/AeTIAiQDslvSvdN vdAbZ6JOiFNhENPgroy59oBt1wQicPB9ps7ZFcXAC+y6cjOiWVjZ3nDaYWJOqXfBCwF6 mCulJrS3LKUqLKc8+MC6y0roZf9X9O3w18KhTEa2oz1e1d0kgp8ptxRYZ+mB0YP0L47f rDGZ8Sm7Wjvz+YDAL44KqbK54XWjZo4OHezMHtcC7ujVYJcP7mJihPA0D/mvN80yFEvm sBUg== X-Gm-Message-State: AOJu0Yx5B4MXM+BhdZynT7+lLOFlt2ttJ+IDJS5Mx/nXDZM+eXS4o4bd wsbD/9o5jDuJLQjccnLkZCnoL08W/vz3qVU0OQu/QTXN X-Google-Smtp-Source: AGHT+IFCKB4y9SxFeV10FWPTH5kksVmONjZYzoHhoIEWKWdmN5QupRAObIgmodGuNflk5adm0jitkw== X-Received: by 2002:a17:902:ce90:b0:1bf:3378:6808 with SMTP id f16-20020a170902ce9000b001bf33786808mr28169075plg.56.1693323061827; Tue, 29 Aug 2023 08:31:01 -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 23:29:50 +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::634; envelope-from=yong.huang@smartx.com; helo=mail-pl1-x634.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: 1693323241401100003 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