From nobody Mon Feb 9 23:19:12 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=1623008897; cv=none; d=zohomail.com; s=zohoarc; b=eceiXQVoHpKHO0YKsGM6C3NjTuBLOBAT3wclkpG9hieBAVN+uDAO2/luIoLQzmq987wyNVQ1P3gcsPsVOTXB1Qg+aITt7X7CCx0VD6jdQJC4cPkGySZwVF4zG8GCntP66ZDK2OEhSB2IqmIL749NTHhSMy6TMj5d1gCQHYQggtM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623008897; 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=Kpn+7/w1jq/joSEbdWBoa9JKiOLx7bNNf6ckE3CnT2M=; b=bE2pA7OR/81Oaw+SSoAfXs4xtPFeVAKwlUaj9Q0c5v5+HIG6tCfBcB/7lmS0y9RCKPLuX8SQWpiANxPOsWCIITMUclf/IvUeL+4HHer/fCccGWy+bgEIExnR5TkrVN1ioP2yBSODOZE/8a9D/uTX4fCCVgiaxub8zXk3/Rk3WwE= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1623008896804715.9367182487543; Sun, 6 Jun 2021 12:48:16 -0700 (PDT) Received: from localhost ([::1]:37460 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lpykp-0006B7-OC for importer@patchew.org; Sun, 06 Jun 2021 15:48:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39080) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lpyiQ-00031D-Sl for qemu-devel@nongnu.org; Sun, 06 Jun 2021 15:45:46 -0400 Received: from prt-mail.chinatelecom.cn ([42.123.76.228]:58665 helo=chinatelecom.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lpyiP-0000es-43 for qemu-devel@nongnu.org; Sun, 06 Jun 2021 15:45:46 -0400 Received: from clientip-182.138.181.182?logid-6a63b4a58d5044dca93b5e0cdce340a5 (unknown [172.18.0.218]) by chinatelecom.cn (HERMES) with SMTP id 7DB282800EC; Mon, 7 Jun 2021 03:45:42 +0800 (CST) Received: from ([172.18.0.218]) by app0025 with ESMTP id 6a63b4a58d5044dca93b5e0cdce340a5 for qemu-devel@nongnu.org; Mon Jun 7 03:45:42 2021 HMM_SOURCE_IP: 172.18.0.218:49746.1671325402 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +huangy81@chinatelecom.cn X-Transaction-ID: 6a63b4a58d5044dca93b5e0cdce340a5 X-filter-score: filter<0> X-Real-From: huangy81@chinatelecom.cn X-Receive-IP: 172.18.0.218 X-MEDUSA-Status: 0 From: huangy81@chinatelecom.cn To: qemu-devel@nongnu.org Subject: [PATCH v2 2/6] KVM: introduce dirty_pages and kvm_dirty_ring_enabled Date: Mon, 7 Jun 2021 03:45:30 +0800 Message-Id: <5fd7f4b444d14447649982ed44c5ddc5ebde635c.1623007591.git.huangy81@chinatelecom.cn> X-Mailer: git-send-email 1.8.3.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: pass client-ip=42.123.76.228; envelope-from=huangy81@chinatelecom.cn; helo=chinatelecom.cn 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, SPF_HELO_PASS=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Juan Quintela , Hyman , "Dr. David Alan Gilbert" , Peter Xu , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" From: Hyman Huang(=E9=BB=84=E5=8B=87) dirty_pages is used to calculate dirtyrate via dirty ring, when enabled, kvm-reaper will increase the dirty pages after gfns being dirtied. kvm_dirty_ring_enabled shows if kvm-reaper is working. dirtyrate thread could use it to check if measurement can base on dirty ring feature. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) --- accel/kvm/kvm-all.c | 7 +++++++ include/hw/core/cpu.h | 1 + include/sysemu/kvm.h | 1 + 3 files changed, 9 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index c7ec538850..bc012f0bee 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -469,6 +469,7 @@ int kvm_init_vcpu(CPUState *cpu, Error **errp) cpu->kvm_fd =3D ret; cpu->kvm_state =3D s; cpu->vcpu_dirty =3D true; + cpu->dirty_pages =3D 0; =20 mmap_size =3D kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0); if (mmap_size < 0) { @@ -743,6 +744,7 @@ static uint32_t kvm_dirty_ring_reap_one(KVMState *s, CP= UState *cpu) count++; } cpu->kvm_fetch_index =3D fetch; + cpu->dirty_pages +=3D count; =20 return count; } @@ -2293,6 +2295,11 @@ bool kvm_vcpu_id_is_valid(int vcpu_id) return vcpu_id >=3D 0 && vcpu_id < kvm_max_vcpu_id(s); } =20 +bool kvm_dirty_ring_enabled(void) +{ + return kvm_state->kvm_dirty_ring_size ? true : false; +} + static int kvm_init(MachineState *ms) { MachineClass *mc =3D MACHINE_GET_CLASS(ms); diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 4e0ea68efc..80fcb1d563 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -374,6 +374,7 @@ struct CPUState { struct kvm_run *kvm_run; struct kvm_dirty_gfn *kvm_dirty_gfns; uint32_t kvm_fetch_index; + uint64_t dirty_pages; =20 /* Used for events with 'vcpu' and *without* the 'disabled' properties= */ DECLARE_BITMAP(trace_dstate_delayed, CPU_TRACE_DSTATE_MAX_EVENTS); diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index a1ab1ee12d..7b22aeb6ae 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -547,4 +547,5 @@ bool kvm_cpu_check_are_resettable(void); =20 bool kvm_arch_cpu_check_are_resettable(void); =20 +bool kvm_dirty_ring_enabled(void); #endif --=20 2.18.2