From nobody Tue Dec 16 16:38:07 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1748387650; cv=none; d=zohomail.com; s=zohoarc; b=WZtTA/ZTuzMWpH2YeHKsbqzyc7VXHHFYsVtfCdm3W+oHgASPrWuXgel06cBryoS76VtESYKiA/ZiX4Abr34Jnd9/kfsutxEa/JS6BtNJDQiibuKHERxyJCFcfk/+UmtQnTR1l2Yhx18HxKAV0nMu9f5R4fk+l9PlW+QaRWZLiZk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748387650; 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=0FVFBOHDyRMLEfjUsQ8+u7RDvtWgplGxeHp+3xgYqh8=; b=ZAjXMffbmQ36LLCC5M8X/iunj3XjLDl3AagxlNjTSaOQBOS3a/K3UyqIkFSIt4ptO0nLrauH8t7zqnpTlhtxf2LR2fez4pjheo52BlkxdHDU03F0PBR4adu4zjH15CxcGVyOZ+C9IYDkSS0CuxIq93o+xhiZGWt0H3P8RUgoM1A= 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 1748387650337847.5334656583742; Tue, 27 May 2025 16:14:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uK3Tp-0003I3-Qs; Tue, 27 May 2025 19:13:09 -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 1uK3To-0003HT-4H for qemu-devel@nongnu.org; Tue, 27 May 2025 19:13:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uK3Tm-0001Cq-ED for qemu-devel@nongnu.org; Tue, 27 May 2025 19:13:07 -0400 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-91-5xrCPdwzPimLhucV3kSV-w-1; Tue, 27 May 2025 19:13:04 -0400 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-4853364ad97so33691991cf.0 for ; Tue, 27 May 2025 16:13:04 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a2f939cad3sm1984441cf.79.2025.05.27.16.13.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 May 2025 16:13:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748387585; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0FVFBOHDyRMLEfjUsQ8+u7RDvtWgplGxeHp+3xgYqh8=; b=ASUFeaXpkEluFXUw5/IOp3Tz3Y0z7cwylyZKjgLTVoiJzT0TxQz8rQTMWwIQl7XiWkAKeS lLDtl4VZOBc63d6Tdql/0q+HvwnP4laYQlwqh3tZHlKOkjPXcO7t64Wf7g+GYoWb+xkuPZ nMIgMK1lXoK3lKjTu2n12hDKL5O9T6Y= X-MC-Unique: 5xrCPdwzPimLhucV3kSV-w-1 X-Mimecast-MFC-AGG-ID: 5xrCPdwzPimLhucV3kSV-w_1748387584 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748387583; x=1748992383; 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=0FVFBOHDyRMLEfjUsQ8+u7RDvtWgplGxeHp+3xgYqh8=; b=fAVjHFhZYsXS5O5BPFORGkZ8DAq1XnvjDudd49lvpwCjJz6LTm3pAqixeTqOyhJhp5 /emr47y+PmkyUyoGgHcwyZpzgjez0gNni2CGM0lZJ+I1lEvJvN1k+IK8pZZA3vjfOnxn UkedtNUm3WQ8cj1ncykcH+ev56S9pfnGVIbaO0cj0XGFSayosb5ECCcxVqd2p5Pp+1HN dARfxWGmDwPypxAq0H40UBrofJwHSf2k2M8GXorgr+IDz+7W8PNnWzPiZFwRn1DUGwad qn1rMJjfE3UbodRgsCKMt03IDHzdqwFuJjFEM9/SJHDbmZsW0QXZTuj6yYRUj5siJipb w6gg== X-Gm-Message-State: AOJu0YwmIPNRgkZKTEo2YYNi55GBkMsLRHhnUzrO1iO6fCkaPQ0i0p6K e8ksW+j/SPmb9JsqrOXZloJ/4kz9hr3iCwoD9F92lyVB7S8t7ifDpiZuwBdmBCoUJiJXf20bOxr S33PEJEIgxYrrdQA4X246fa6GrNQBxoYfrKt3MSsNRHWsIoUpaLbVBC5tRtaSfGfxTTaE1kCVDy XY4E/e1xqyBa+keKywphtl8iqgxKQGj2ZwINatfA== X-Gm-Gg: ASbGncsP+99DqDJFxzSsDQmJdj90BBjnVtbEUbu8pfnDtPMjj6lBeMEACdo9CLtgmOl MSzqT7bY5H3yKtmq6yryozeid8Idzfmo4XuOQ119eHc5IKtI6tIgbhFl57VbH0QN3ubKFTJpdxO oZMXf537ET6mPZ1dsnbJvmEBMCgCS/TYYiJYMRBVZBc3XLHHA4qzt6Or5dj+cfCEOU5rNynW6em Bo8ghtTZGJXbAZVh239KWfZnrT21qzt6TiW/uLEh4rGKkZycnp7hmFT9pvYTwXdze5O4R/soE6N X-Received: by 2002:a05:622a:6992:b0:494:b3eb:a4cc with SMTP id d75a77b69052e-49f480c8fb9mr191276031cf.47.1748387583404; Tue, 27 May 2025 16:13:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHcszs9WQN3XMO00PhJlsqDs0Xu5sp8AY4+mIIMVWYKYOFs1zcjsRrU9G0xxdlQnXMUPkBxag== X-Received: by 2002:a05:622a:6992:b0:494:b3eb:a4cc with SMTP id d75a77b69052e-49f480c8fb9mr191275671cf.47.1748387582916; Tue, 27 May 2025 16:13:02 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Dr . David Alan Gilbert" , peterx@redhat.com, Alexey Perevalov , Fabiano Rosas , Juraj Marcin Subject: [PATCH 06/13] migration/postcopy: Bring blocktime layer to us level Date: Tue, 27 May 2025 19:12:41 -0400 Message-ID: <20250527231248.1279174-7-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250527231248.1279174-1-peterx@redhat.com> References: <20250527231248.1279174-1-peterx@redhat.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=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.907, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-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 @redhat.com) X-ZM-MESSAGEID: 1748387651696116600 Content-Type: text/plain; charset="utf-8" With 64-bit fields, it is trivial. The caution is when exposing any values in QMP, it was still declared with milliseconds (ms). Hence it's needed to do the convertion when exporting the values to existing QMP queries. Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- migration/postcopy-ram.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index c6ae4b650c..5cbc7aa77e 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -110,6 +110,7 @@ void postcopy_thread_create(MigrationIncomingState *mis, #include #include =20 +/* All the time records are in unit of microseconds (us) */ typedef struct PostcopyBlocktimeContext { /* time when page fault initiated per vCPU */ uint64_t *vcpu_blocktime_start; @@ -168,7 +169,8 @@ static uint32List *get_vcpu_blocktime_list(PostcopyBloc= ktimeContext *ctx) int i; =20 for (i =3D ms->smp.cpus - 1; i >=3D 0; i--) { - QAPI_LIST_PREPEND(list, (uint32_t)ctx->vcpu_blocktime_total[i]); + QAPI_LIST_PREPEND( + list, (uint32_t)(ctx->vcpu_blocktime_total[i] / 1000)); } =20 return list; @@ -191,7 +193,7 @@ void fill_destination_postcopy_migration_info(Migration= Info *info) } =20 info->has_postcopy_blocktime =3D true; - info->postcopy_blocktime =3D (uint32_t)bc->total_blocktime; + info->postcopy_blocktime =3D (uint32_t)(bc->total_blocktime / 1000); info->has_postcopy_vcpu_blocktime =3D true; info->postcopy_vcpu_blocktime =3D get_vcpu_blocktime_list(bc); } @@ -816,9 +818,9 @@ static int get_mem_fault_cpu_index(uint32_t pid) return -1; } =20 -static uint64_t get_low_time_offset(void) +static uint64_t get_current_us(void) { - return (uint64_t)qemu_clock_get_ms(QEMU_CLOCK_REALTIME); + return (uint64_t)qemu_clock_get_us(QEMU_CLOCK_REALTIME); } =20 /* @@ -835,7 +837,7 @@ void mark_postcopy_blocktime_begin(uintptr_t addr, uint= 32_t ptid, int cpu; MigrationIncomingState *mis =3D migration_incoming_get_current(); PostcopyBlocktimeContext *dc =3D mis->blocktime_ctx; - uint64_t low_time_offset; + uint64_t current_us; =20 if (!dc || ptid =3D=3D 0) { return; @@ -845,13 +847,13 @@ void mark_postcopy_blocktime_begin(uintptr_t addr, ui= nt32_t ptid, return; } =20 - low_time_offset =3D get_low_time_offset(); + current_us =3D get_current_us(); if (dc->vcpu_addr[cpu] =3D=3D 0) { dc->smp_cpus_down++; } =20 - dc->last_begin =3D low_time_offset; - dc->vcpu_blocktime_start[cpu] =3D low_time_offset; + dc->last_begin =3D current_us; + dc->vcpu_blocktime_start[cpu] =3D current_us; dc->vcpu_addr[cpu] =3D addr; =20 /* @@ -899,13 +901,13 @@ static void mark_postcopy_blocktime_end(uintptr_t add= r) unsigned int smp_cpus =3D ms->smp.cpus; int i, affected_cpu =3D 0; bool vcpu_total_blocktime =3D false; - uint64_t read_vcpu_time, low_time_offset; + uint64_t read_vcpu_time, current_us; =20 if (!dc) { return; } =20 - low_time_offset =3D get_low_time_offset(); + current_us =3D get_current_us(); /* lookup cpu, to clear it, * that algorithm looks straightforward, but it's not * optimal, more optimal algorithm is keeping tree or hash @@ -918,7 +920,7 @@ static void mark_postcopy_blocktime_end(uintptr_t addr) continue; } dc->vcpu_addr[i] =3D 0; - vcpu_blocktime =3D low_time_offset - read_vcpu_time; + vcpu_blocktime =3D current_us - read_vcpu_time; affected_cpu +=3D 1; /* we need to know is that mark_postcopy_end was due to * faulted page, another possible case it's prefetched @@ -932,7 +934,7 @@ static void mark_postcopy_blocktime_end(uintptr_t addr) =20 dc->smp_cpus_down -=3D affected_cpu; if (vcpu_total_blocktime) { - dc->total_blocktime +=3D low_time_offset - dc->last_begin; + dc->total_blocktime +=3D current_us - dc->last_begin; } trace_mark_postcopy_blocktime_end(addr, dc->total_blocktime, affected_cpu); --=20 2.49.0