From patchwork Mon Jan 6 20:02:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13927802 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8DC75E77199 for ; Mon, 6 Jan 2025 20:03:30 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.865902.1277203 (Exim 4.92) (envelope-from ) id 1tUtJn-0003Bq-Ke; Mon, 06 Jan 2025 20:03:19 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 865902.1277203; Mon, 06 Jan 2025 20:03:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tUtJn-0003Bd-HJ; Mon, 06 Jan 2025 20:03:19 +0000 Received: by outflank-mailman (input) for mailman id 865902; Mon, 06 Jan 2025 20:03:17 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tUtJl-0002e6-QF for xen-devel@lists.xenproject.org; Mon, 06 Jan 2025 20:03:17 +0000 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [2a00:1450:4864:20::329]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 443e5027-cc69-11ef-99a4-01e77a169b0f; Mon, 06 Jan 2025 21:03:16 +0100 (CET) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-43635796b48so89318005e9.0 for ; Mon, 06 Jan 2025 12:03:16 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4366128a353sm577748615e9.42.2025.01.06.12.03.12 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 06 Jan 2025 12:03:15 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 443e5027-cc69-11ef-99a4-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736193795; x=1736798595; darn=lists.xenproject.org; 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=xubr80DdDK1TQnuEw657hT2ILmCSL1Bi/K/I0ME5hpI=; b=Z4/zdLcV/crESVhVabhQYBni+lmsiCCndmM88y5yJ7hPu4aaG2wSoyGhbEMxbpk7bv zEE2kpVpJ86cOf+1uUEaKotVnwcu2M7+GlgzUbj9JU1D9h9me+Waw+rMona96fEcvFL/ EtSyKviN0YTJ+CIwKQqEmaIC8xQFCEVFEZxVQ2FgRBTXFYwzhKRtG1VMh5ySR0ThV8J2 6Ap2ZJEDXsx3LetuLd5o5PfmQow3lusntyt3ku55vRWFI47XibE1Mt4ukwp8lSGpKXH8 c8MaK875hig5itxqrhB3Av4tZC8D0QRAVk6BPYdEmkXuMu+tU4dbaJr3P0y4Bbc6QjUr hHOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736193795; x=1736798595; 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=xubr80DdDK1TQnuEw657hT2ILmCSL1Bi/K/I0ME5hpI=; b=n0jfWCwazboGTCtrEOQkNjZGVPu1bKEYy9ISmsiIFZxS6DIsmRWjN/PPW7FuZU8uTh LTGqdWyDu+/ykwrr1k9wiJIAsDfb0FVCI+bzxNV+BuLhY7VnkbjqViJl/OAe+9KhUBNF WeuKsi+EN2eybn7mmQEVOgDpEuqUZLY44h5n+WirB2fm3GLUpjb76bock1+emLL+RZoO 2B4vche5B/IgRB1UEBT1ywGoDLWA4RvXzjPYZouBZ1sCroIR8XtPZOfie7MXzOku/ntK mjg2ppRuuKPUnZ6jJge522e0i5L5EarrGRP/Azn84Fp4pAUx0raEvETIZ2PmI+I68bdp LPtg== X-Forwarded-Encrypted: i=1; AJvYcCX/UModMtUrRF/D/9YkghwB/k2PaaE9aP0GAqrHaT5BcHh482B85TI4DKs4W1m4Fhq5MfgSz3Edp+U=@lists.xenproject.org X-Gm-Message-State: AOJu0Yze56e0eCoxQNwGXUKVDXSRqcEWj0CvDUCSlqCaY9v9zzk5THq7 GCyLG4u5T85aeJl8r0RoDR9NdjJhJK5+UKBzWR5Ab1Xy8SSQBmAfybluUNjq/MA= X-Gm-Gg: ASbGncvvXgWxcVVDcPuPAjGDsWx3z2hGM/G2NLBbqhDKAPcwUR3FrJBTpljIuY4cHkk pmfNqR52f4Jp765SFXmEqznHUFQXq6iHoxpV1M716BYY8lTWbOAOBKH1kL77SdN/p2a6Rv87fgc J9fKEo6utw+XnqtDAa8TY4TZaRqBcP7KnVWRB6afWXONMUSsZTabVVX3Wo/lgLZ0c1Fd0qrimWw efYH1lnt3NrJvQzFTs8MvrRLOsN1B8ixlwursEHjJ84ccjpjAR8E+bcKoyPLlY7xxG8k0bJ/Blh sUyNbPlogzB07G7NYXAHNAv924CCAfs= X-Google-Smtp-Source: AGHT+IG6hn6gQ1rEDpo0RUo5rK6HsOddWfOpcS85mXtVNMxlfkCCUdnnKaA6rQB2Q6OTZ5JLDkEevw== X-Received: by 2002:a05:600c:1d12:b0:436:1b86:f05 with SMTP id 5b1f17b1804b1-436dc20b0c1mr4405765e9.11.1736193795597; Mon, 06 Jan 2025 12:03:15 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Daniel Henrique Barboza , =?utf-8?b?RnLDqWQ=?= =?utf-8?b?w6lyaWMgQmFycmF0?= , Stefano Stabellini , Ilya Leoshkevich , Cameron Esfahani , Paolo Bonzini , kvm@vger.kernel.org, Alexander Graf , Paul Durrant , David Hildenbrand , Halil Pasic , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Marcel Apfelbaum , xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Yanan Wang , Reinoud Zandijk , Peter Maydell , qemu-s390x@nongnu.org, Riku Voipio , Anthony PERARD , Alistair Francis , Sunil Muthuswamy , Christian Borntraeger , Nicholas Piggin , Richard Henderson , Marcelo Tosatti , Thomas Huth , Roman Bolshakov , "Edgar E . Iglesias" , Zhao Liu , Phil Dennis-Jordan , David Woodhouse , Harsh Prateek Bora , Nina Schoetterl-Glausch , "Edgar E. Iglesias" , Eduardo Habkost , qemu-ppc@nongnu.org, Daniel Henrique Barboza , "Michael S. Tsirkin" , Anton Johansson Subject: [RFC PATCH 2/7] cpus: Introduce AccelOpsClass::get_cpus_queue() Date: Mon, 6 Jan 2025 21:02:53 +0100 Message-ID: <20250106200258.37008-3-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106200258.37008-1-philmd@linaro.org> References: <20250106200258.37008-1-philmd@linaro.org> MIME-Version: 1.0 We want the ability to iterate over vCPUs of a specific accelerator. Introduce cpus_get_accel_cpus_queue() to be used by accelerator common code, and expose the get_cpus_queue() in AccelOpsClass, so each accelerator can register its own queue of vCPUs. Signed-off-by: Philippe Mathieu-Daudé --- include/hw/core/cpu.h | 8 ++++++++ include/system/accel-ops.h | 6 ++++++ accel/tcg/user-exec-stub.c | 5 +++++ cpu-common.c | 10 ++++++++++ system/cpus.c | 5 +++++ 5 files changed, 34 insertions(+) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 48d90f50a71..5ae9bb64d6e 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -591,6 +591,14 @@ static inline CPUArchState *cpu_env(CPUState *cpu) typedef QTAILQ_HEAD(CPUTailQ, CPUState) CPUTailQ; extern CPUTailQ cpus_queue; +/** + * cpus_get_accel_cpus_queue: + * @cpu: The vCPU to get the accelerator #CPUTailQ. + * + * Returns the #CPUTailQ associated with the accelerator of the vCPU. + */ +CPUTailQ *cpus_get_accel_cpus_queue(CPUState *cpu); + #define first_cpu QTAILQ_FIRST_RCU(&cpus_queue) #define CPU_NEXT(cpu) QTAILQ_NEXT_RCU(cpu, node) #define CPU_FOREACH(cpu) QTAILQ_FOREACH_RCU(cpu, &cpus_queue, node) diff --git a/include/system/accel-ops.h b/include/system/accel-ops.h index 137fb96d444..fe59f728bfc 100644 --- a/include/system/accel-ops.h +++ b/include/system/accel-ops.h @@ -12,6 +12,7 @@ #include "exec/vaddr.h" #include "qom/object.h" +#include "hw/core/cpu.h" #define ACCEL_OPS_SUFFIX "-ops" #define TYPE_ACCEL_OPS "accel" ACCEL_OPS_SUFFIX @@ -37,6 +38,11 @@ struct AccelOpsClass { bool (*cpus_are_resettable)(void); void (*cpu_reset_hold)(CPUState *cpu); + /** + * get_cpus_queue: + * Returns the #CPUTailQ maintained by this accelerator. + */ + CPUTailQ *(*get_cpus_queue)(void); void (*create_vcpu_thread)(CPUState *cpu); /* MANDATORY NON-NULL */ void (*kick_vcpu_thread)(CPUState *cpu); bool (*cpu_thread_is_idle)(CPUState *cpu); diff --git a/accel/tcg/user-exec-stub.c b/accel/tcg/user-exec-stub.c index 4fbe2dbdc88..cb76cec76be 100644 --- a/accel/tcg/user-exec-stub.c +++ b/accel/tcg/user-exec-stub.c @@ -18,6 +18,11 @@ void cpu_exec_reset_hold(CPUState *cpu) { } +CPUTailQ *cpus_get_accel_cpus_queue(CPUState *cpu) +{ + return NULL; +} + /* User mode emulation does not support record/replay yet. */ bool replay_exception(void) diff --git a/cpu-common.c b/cpu-common.c index 4248b2d727e..ff8db9c7f9d 100644 --- a/cpu-common.c +++ b/cpu-common.c @@ -82,6 +82,7 @@ unsigned int cpu_list_generation_id_get(void) void cpu_list_add(CPUState *cpu) { static bool cpu_index_auto_assigned; + CPUTailQ *accel_cpus_queue = cpus_get_accel_cpus_queue(cpu); QEMU_LOCK_GUARD(&qemu_cpu_list_lock); if (cpu->cpu_index == UNASSIGNED_CPU_INDEX) { @@ -92,17 +93,26 @@ void cpu_list_add(CPUState *cpu) assert(!cpu_index_auto_assigned); } QTAILQ_INSERT_TAIL_RCU(&cpus_queue, cpu, node); + if (accel_cpus_queue) { + QTAILQ_INSERT_TAIL_RCU(accel_cpus_queue, cpu, node); + } + cpu_list_generation_id++; } void cpu_list_remove(CPUState *cpu) { + CPUTailQ *accel_cpus_queue = cpus_get_accel_cpus_queue(cpu); + QEMU_LOCK_GUARD(&qemu_cpu_list_lock); if (!QTAILQ_IN_USE(cpu, node)) { /* there is nothing to undo since cpu_exec_init() hasn't been called */ return; } + if (accel_cpus_queue) { + QTAILQ_REMOVE_RCU(accel_cpus_queue, cpu, node); + } QTAILQ_REMOVE_RCU(&cpus_queue, cpu, node); cpu->cpu_index = UNASSIGNED_CPU_INDEX; cpu_list_generation_id++; diff --git a/system/cpus.c b/system/cpus.c index 99f83806c16..972df6ab061 100644 --- a/system/cpus.c +++ b/system/cpus.c @@ -209,6 +209,11 @@ void cpu_exec_reset_hold(CPUState *cpu) } } +CPUTailQ *cpus_get_accel_cpus_queue(CPUState *cpu) +{ + return cpus_accel ? cpus_accel->get_cpus_queue() : NULL; +} + int64_t cpus_get_virtual_clock(void) { /*