From nobody Sun Feb 8 18:29:13 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.128.47 as permitted sender) client-ip=209.85.128.47; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-f47.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.47 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1646571658; cv=none; d=zohomail.com; s=zohoarc; b=mN+DzyAOye7vDU+N6nZyS67/lLm9ngC567tnIP8vWeZSUu+BYjrNTq8D6q1dT25u7DpZNaHstZUa8eXrIP0tpNzDc1H23/XS0V5e0mAKeOJ8G6Pcevq80VeEOTkf9UmnB4jpadanizHFBzyTMZtkShAuGFyk8u6kNYVoLJYvlBk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646571658; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=I1BibOgzE1kXRXSK7t3OOwFMjdn8Qs/Lnfs/VlDah2s=; b=Hz8OMbgxIw3C/lMU7Kv4mOq0X0wEvjjHif5cmxkwMkLVOmbVmNrJchNNz4o5vFgB7QiFz9IBd7jt661+I3F1hVc+KcoWIVfdpU9jEXSoLDoMdIeBQnbv50n1pbaUDiQ9gsPK1IQ2tUqMtOCzu0pdqGNREGq1T0+XFLdpiSAe7ic= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.47 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com; dmarc=pass header.from= (p=none dis=none) Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) by mx.zohomail.com with SMTPS id 1646571658907275.1919450009931; Sun, 6 Mar 2022 05:00:58 -0800 (PST) Received: by mail-wm1-f47.google.com with SMTP id 19so7379459wmy.3 for ; Sun, 06 Mar 2022 05:00:58 -0800 (PST) Return-Path: Return-Path: Received: from nuc.lan ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id g11-20020a5d554b000000b001f0326a23ddsm9113637wrw.70.2022.03.06.05.00.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 05:00:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=I1BibOgzE1kXRXSK7t3OOwFMjdn8Qs/Lnfs/VlDah2s=; b=Jwy3EcOq9Hx+V/KGcjbZpIhkoqVlpAviEoarslz3zwL7cegBEqq+1SphtL40tiH6OC 8vXwQ9MlqNFynu3yNws2n4hcVa3B4Zrnmv+q3WmQmyMUQGw+VtRFyUmA5cnNMzctZCv1 HAE+C1GTzSWDc0yo6DUC90Bt3ct7FgwBHufzTlz3aZN2pKVeJwJswlKIkZ9kX4U4gZz/ 0YvkFPGR+UDX0QvJlhd5H7Kim/81fOvaHkmIxvOl600mNsJOw792Fo/KN3e2guv+HZtG MLs6TlRTZVGGZ9GClYZyJExBUtxVdzbU3eEmhUP6XQyd4u8Z7jGwbE1cBmsUZQXVyICV Iu7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=I1BibOgzE1kXRXSK7t3OOwFMjdn8Qs/Lnfs/VlDah2s=; b=xCA/q4BraX1NxT9koUiD2sdqyYU21oEnggU9U2fJdKI0fdsz210cYBLjj7w7SGPODg sTnbgSbmwwVSoG2NeOAfiDabodIr7ARe/tVzuE9tOBWI+vdgC6TBwh0jE3fLBLjK0QX1 VurHBsh3lJNhfyclHp2++vDHOqfdfcPUY8/JBCccQ26xa3hmD4GD+JNjshdfiUwiT7+o B3dP8ck1rQFpkymazI0kiVeMPgBYMLOvCe1Ia6BVIwrAfnZjzgdgkX+GuxRhFt1D2N+g Kd5rCgQQkN77acn03yQsErBQH0rAonhq8dNDzV5j5bGnXse8mRYZN19YUQZnpofJ+opU SuXA== X-Gm-Message-State: AOAM530tB+IV7/i/It7xGeOe6PBksolESn3uGZXgsAGV0cld0tpMAsDn J7zGeyL8JhT3t71eKjnnYlU= X-Google-Smtp-Source: ABdhPJw3jfcgaqTg/zd8lhpqboKH6UurEddO7oAFnulIktUIkw5cDsEY8G1UmHJRylgzobhXiKfvdA== X-Received: by 2002:a1c:c911:0:b0:389:8f96:28f3 with SMTP id f17-20020a1cc911000000b003898f9628f3mr6050694wmb.49.1646571657023; Sun, 06 Mar 2022 05:00:57 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Thomas Huth , Eduardo Habkost , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 10/33] accel: Introduce AccelOpsClass::cpu_thread_is_idle() Date: Sun, 6 Mar 2022 13:59:37 +0100 Message-Id: <20220306130000.8104-11-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220306130000.8104-1-philippe.mathieu.daude@gmail.com> References: <20220306130000.8104-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1646571660016100003 From: Philippe Mathieu-Daud=C3=A9 Add cpu_thread_is_idle() to AccelOps, and implement it for the KVM / WHPX accelerators. Suggested-by: Richard Henderson Reviewed-by: Paolo Bonzini Reviewed-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20220207075426.81934-11-f4bug@amsat.org> --- include/sysemu/accel-ops.h | 1 + accel/kvm/kvm-accel-ops.c | 6 ++++++ softmmu/cpus.c | 6 ++++-- target/i386/whpx/whpx-accel-ops.c | 6 ++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/sysemu/accel-ops.h b/include/sysemu/accel-ops.h index 032f6979d76..50c72540c73 100644 --- a/include/sysemu/accel-ops.h +++ b/include/sysemu/accel-ops.h @@ -30,6 +30,7 @@ struct AccelOpsClass { =20 void (*create_vcpu_thread)(CPUState *cpu); /* MANDATORY NON-NULL */ void (*kick_vcpu_thread)(CPUState *cpu); + bool (*cpu_thread_is_idle)(CPUState *cpu); =20 void (*synchronize_post_reset)(CPUState *cpu); void (*synchronize_post_init)(CPUState *cpu); diff --git a/accel/kvm/kvm-accel-ops.c b/accel/kvm/kvm-accel-ops.c index 7516c67a3f5..95b7b080202 100644 --- a/accel/kvm/kvm-accel-ops.c +++ b/accel/kvm/kvm-accel-ops.c @@ -74,11 +74,17 @@ static void kvm_start_vcpu_thread(CPUState *cpu) cpu, QEMU_THREAD_JOINABLE); } =20 +static bool kvm_vcpu_thread_is_idle(CPUState *cpu) +{ + return !kvm_halt_in_kernel(); +} + static void kvm_accel_ops_class_init(ObjectClass *oc, void *data) { AccelOpsClass *ops =3D ACCEL_OPS_CLASS(oc); =20 ops->create_vcpu_thread =3D kvm_start_vcpu_thread; + ops->cpu_thread_is_idle =3D kvm_vcpu_thread_is_idle; ops->synchronize_post_reset =3D kvm_cpu_synchronize_post_reset; ops->synchronize_post_init =3D kvm_cpu_synchronize_post_init; ops->synchronize_state =3D kvm_cpu_synchronize_state; diff --git a/softmmu/cpus.c b/softmmu/cpus.c index ac6bec56038..b17033d3bce 100644 --- a/softmmu/cpus.c +++ b/softmmu/cpus.c @@ -90,10 +90,12 @@ bool cpu_thread_is_idle(CPUState *cpu) if (cpu_is_stopped(cpu)) { return true; } - if (!cpu->halted || cpu_has_work(cpu) || - kvm_halt_in_kernel() || whpx_apic_in_platform()) { + if (!cpu->halted || cpu_has_work(cpu)) { return false; } + if (cpus_accel->cpu_thread_is_idle) { + return cpus_accel->cpu_thread_is_idle(cpu); + } return true; } =20 diff --git a/target/i386/whpx/whpx-accel-ops.c b/target/i386/whpx/whpx-acce= l-ops.c index 6bc47c53098..1d30e4e2ed2 100644 --- a/target/i386/whpx/whpx-accel-ops.c +++ b/target/i386/whpx/whpx-accel-ops.c @@ -83,12 +83,18 @@ static void whpx_kick_vcpu_thread(CPUState *cpu) } } =20 +static bool whpx_vcpu_thread_is_idle(CPUState *cpu) +{ + return !whpx_apic_in_platform(); +} + static void whpx_accel_ops_class_init(ObjectClass *oc, void *data) { AccelOpsClass *ops =3D ACCEL_OPS_CLASS(oc); =20 ops->create_vcpu_thread =3D whpx_start_vcpu_thread; ops->kick_vcpu_thread =3D whpx_kick_vcpu_thread; + ops->cpu_thread_is_idle =3D whpx_vcpu_thread_is_idle; =20 ops->synchronize_post_reset =3D whpx_cpu_synchronize_post_reset; ops->synchronize_post_init =3D whpx_cpu_synchronize_post_init; --=20 2.35.1