From patchwork Mon Jan 6 20:02:56 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: 855283 Delivered-To: patch@linaro.org Received: by 2002:a5d:4888:0:b0:385:e875:8a9e with SMTP id g8csp9620825wrq; Mon, 6 Jan 2025 12:04:28 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXy1iFIlSBkqfUXyIQ8z44jPd7NI4MZuFOiJGQM+oQlVHM3Yl9O0GbEZ60JcYO4PHMxJlO2xw==@linaro.org X-Google-Smtp-Source: AGHT+IHfW+pOF3LLKbIWLVCSAe4f4Xk6duYKFFKf1dksDjcSd7nSn9i7MG2MK2BrM+Hk5o+Xgkd3 X-Received: by 2002:a05:6102:d8a:b0:4af:c5c8:bb4c with SMTP id ada2fe7eead31-4b2cc3873f0mr47254153137.16.1736193868188; Mon, 06 Jan 2025 12:04:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1736193868; cv=none; d=google.com; s=arc-20240605; b=liBg8RnOG31STUt0q0KSnpFDuOLGe19FVoc+f9ZE0utxFBW2s2g23KwtTaq/Qx9w8R lsq2ZCIN91w6JswON7GUuT9jslZ4pX5iE7pHL8tAVEH+/XLAtCqrU+N4PeD1eguOYBP0 k2Ck0eVlutqe0vd3HfhgRrIhUqeWJDVzv9pRSbwS0kaFEQdOqqYTNztYNPuQVpaXJBQK t6IsMViIMB9aef8GsqLvMttIu4MY4eVRn1QcwY81VzM3Er00PNfZvLBkcnenXF+kMZLY qwmwAdYRC9THqxNY28JYBAAWC06fb08oUNOi1B9EmQwxhOdxOlTBY8oqXKSXH2WYwy/v NDgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zxJ3+xb03FIgQb6HyhO+0vTNSYN1GRLEa0EnbI36swA=; fh=YIGq2OjjvJJvfOLa9lPT9cLAg4GPwPsWWWag+t9HO1Y=; b=QR8Na7NVIMlXE98LWw4pBgWc4kv89hiJ326G0kzynssKH4h01tziov7JVBwrqNK1hw rF0uVk6Yu2DFCu5yk1yj6Qbp70EEt31xn6abiVfhLnGnTeI7mTtczBsxM7Y2xdA0xf7E h7yxJbRo2PyC1s9ebxBhZ3NDXnpVn007UT6rM7T8CHeEEk8ZKcr9cUCgFEvkIGwv3wKO K9+pz0R8mcyZHGdq6c5qi16sVOe2ug8TIQYL+N1p8tqRSRTUI/keTbtQ6hEtCOX5Wcsl tfZGk1f2qWU6NWhdP4oDT+LZ3GivTTJjDmnTOg78JL3N+VPuoshX+zh2p9JflL+DC0U0 W0VQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fi+mmOV6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id a1e0cc1a2514c-861d0da6e9dsi2638102241.72.2025.01.06.12.04.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 06 Jan 2025 12:04:28 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fi+mmOV6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tUtK9-0002ld-1r; Mon, 06 Jan 2025 15:03:41 -0500 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 1tUtK7-0002ja-2f for qemu-devel@nongnu.org; Mon, 06 Jan 2025 15:03:39 -0500 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tUtK3-0003FX-6M for qemu-devel@nongnu.org; Mon, 06 Jan 2025 15:03:38 -0500 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-385dece873cso5490594f8f.0 for ; Mon, 06 Jan 2025 12:03:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736193813; x=1736798613; darn=nongnu.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=zxJ3+xb03FIgQb6HyhO+0vTNSYN1GRLEa0EnbI36swA=; b=fi+mmOV6FpCWixDy/UGX6sSvUe51RRCle/PhRukH6wdUPnDYzo5O6GqGbFqrXsUgT4 ErIw1js0sFnfGpRJeY3CrpxElC0EG2i5NJPPN7Bw0KRTspIh8jQlk1cuzP+up25QF/Ou gpLWTpU/zTqDWmRnZSms5h+/81azirWJOt0sbfUUK1hjqxhsqrIPCY+XrvBXUltN3wWd mrwwOG2bk4GvHz9MOAbkAz8plix/jy7x6u67/96EtALeJeOEj0HYP5E2M5+6CcUa87a7 wCTRK/k4Zd6N2zA751tGOAq6WelbDkzSkmZE7Hlv1suwR9gEJbS+vKfQQ0P0IYPPHCkA tS6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736193813; x=1736798613; 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=zxJ3+xb03FIgQb6HyhO+0vTNSYN1GRLEa0EnbI36swA=; b=gHICRBblk2pnF6BL6l/qw8tzAmkloZLZWQgM6YkwuQ1i7qqhS9H99r7YffVezh6T8M gOEZAb6uOGAU0dkVyqzxTLOlUgQvkkFnRgQSnWLel2fwRpqdIYg0xkbjqIxbUFhbA+sX dAz1ruEmrgzKTkYWWRg4KUllGqwv1Aw/F2c1l5a+JMY1eBPsttvgv9IPggVeR9p7A9x5 jVrd1WHy7epMjialxyGJkXk0FJ3m+zATzeud+HGIMcU1oBJLZAY1uqz02JjR5o0uwl/M vpMZm7ygR9G14h8/in6udMWuS4yS0TTnGloobQ5QQgFlgEnDAzp/iUpgaNZE+DBIS3pu 5OqA== X-Gm-Message-State: AOJu0YzpWaayFW2nSnbUiuO44gMYHU5+6gTWoK5+e1UvLa+qrxUBCGfe gYa59Ya09HNtJQySxHA0Zi7fpo9j+uTTs+NvVlLq8wCECw4ZCf4sfPNbGgXvTmkQnYRMDPzYF80 wpaM= X-Gm-Gg: ASbGncsx5R5jKP8laHfykcMZrLfVnGJfy/NhAea1DWa15jXNFdBrCzEcJyWXWjJ9ymb aj+pBxsCo6TI8xHZeYD7Rm4Cv+tP4n3Jco1LMzDbymYk6w57dJFcZHD5om8cKvg6rSKoKEV40nj 9G5WBAPTQxnErkt119tAH0OREu6xgBa795oUdxzmGqM9bQWgfSYtv7QuWUMYdFyS7iTlTLiEp9I qOiPvVzyixh8aPzHKJsalX1RHHx8hYXDmzLNXk5W5mQbq+y+7pm2Mm5SSXmHjOYHaDNRdg3e3W6 nqTDo6wIaOAQEjSfhstyIY61gEOgplw= X-Received: by 2002:adf:a3d9:0:b0:38a:39ad:3e31 with SMTP id ffacd0b85a97d-38a39ad4128mr24752061f8f.57.1736193813254; Mon, 06 Jan 2025 12:03:33 -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-43656af6d02sm618987535e9.1.2025.01.06.12.03.31 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 06 Jan 2025 12:03:32 -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 5/7] accel/hw: Implement hw_accel_get_cpus_queue() Date: Mon, 6 Jan 2025 21:02:56 +0100 Message-ID: <20250106200258.37008-6-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 Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=philmd@linaro.org; helo=mail-wr1-x42d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org We can only run a single hardware accelerator at a time, so add a generic hw_accel_get_cpus_queue() helper in accel-system.c, a file common to all HW accelerators. Register AccelOpsClass::get_cpus_queue() for each HW accelerator. Add a generic CPU_FOREACH_HWACCEL() macro. Signed-off-by: Philippe Mathieu-Daudé --- include/system/hw_accel.h | 9 +++++++++ accel/accel-system.c | 8 ++++++++ accel/kvm/kvm-accel-ops.c | 1 + accel/xen/xen-all.c | 1 + target/i386/nvmm/nvmm-accel-ops.c | 1 + target/i386/whpx/whpx-accel-ops.c | 1 + 6 files changed, 21 insertions(+) diff --git a/include/system/hw_accel.h b/include/system/hw_accel.h index 380e9e640b6..12664cac6f9 100644 --- a/include/system/hw_accel.h +++ b/include/system/hw_accel.h @@ -2,6 +2,7 @@ * QEMU Hardware accelerators support * * Copyright 2016 Google, Inc. + * Copyright 2025 Linaro Ltd. * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory. @@ -17,6 +18,14 @@ #include "system/whpx.h" #include "system/nvmm.h" +/* Guard with qemu_cpu_list_lock */ +extern CPUTailQ hw_accel_cpus_queue; + +#define CPU_FOREACH_HWACCEL(cpu) \ + QTAILQ_FOREACH_RCU(cpu, &hw_accel_cpus_queue, node) + +CPUTailQ *hw_accel_get_cpus_queue(void); + void cpu_synchronize_state(CPUState *cpu); void cpu_synchronize_post_reset(CPUState *cpu); void cpu_synchronize_post_init(CPUState *cpu); diff --git a/accel/accel-system.c b/accel/accel-system.c index a7596aef59d..60877ea7a28 100644 --- a/accel/accel-system.c +++ b/accel/accel-system.c @@ -27,9 +27,17 @@ #include "qemu/accel.h" #include "hw/boards.h" #include "system/cpus.h" +#include "system/hw_accel.h" #include "qemu/error-report.h" #include "accel-system.h" +CPUTailQ hw_accel_cpus_queue = QTAILQ_HEAD_INITIALIZER(hw_accel_cpus_queue); + +CPUTailQ *hw_accel_get_cpus_queue(void) +{ + return &hw_accel_cpus_queue; +} + int accel_init_machine(AccelState *accel, MachineState *ms) { AccelClass *acc = ACCEL_GET_CLASS(accel); diff --git a/accel/kvm/kvm-accel-ops.c b/accel/kvm/kvm-accel-ops.c index a81e8f3b03b..5f4001860d5 100644 --- a/accel/kvm/kvm-accel-ops.c +++ b/accel/kvm/kvm-accel-ops.c @@ -93,6 +93,7 @@ static void kvm_accel_ops_class_init(ObjectClass *oc, void *data) { AccelOpsClass *ops = ACCEL_OPS_CLASS(oc); + ops->get_cpus_queue = hw_accel_get_cpus_queue; ops->create_vcpu_thread = kvm_start_vcpu_thread; ops->cpu_thread_is_idle = kvm_vcpu_thread_is_idle; ops->cpus_are_resettable = kvm_cpus_are_resettable; diff --git a/accel/xen/xen-all.c b/accel/xen/xen-all.c index 852e9fbe5fe..ac5ed2dfb80 100644 --- a/accel/xen/xen-all.c +++ b/accel/xen/xen-all.c @@ -150,6 +150,7 @@ static void xen_accel_ops_class_init(ObjectClass *oc, void *data) { AccelOpsClass *ops = ACCEL_OPS_CLASS(oc); + ops->get_cpus_queue = hw_accel_get_cpus_queue; ops->create_vcpu_thread = dummy_start_vcpu_thread; } diff --git a/target/i386/nvmm/nvmm-accel-ops.c b/target/i386/nvmm/nvmm-accel-ops.c index e7b56662fee..bb407c68e14 100644 --- a/target/i386/nvmm/nvmm-accel-ops.c +++ b/target/i386/nvmm/nvmm-accel-ops.c @@ -84,6 +84,7 @@ static void nvmm_accel_ops_class_init(ObjectClass *oc, void *data) { AccelOpsClass *ops = ACCEL_OPS_CLASS(oc); + ops->get_cpus_queue = hw_accel_get_cpus_queue; ops->create_vcpu_thread = nvmm_start_vcpu_thread; ops->kick_vcpu_thread = nvmm_kick_vcpu_thread; diff --git a/target/i386/whpx/whpx-accel-ops.c b/target/i386/whpx/whpx-accel-ops.c index ab2e014c9ea..191214ca81d 100644 --- a/target/i386/whpx/whpx-accel-ops.c +++ b/target/i386/whpx/whpx-accel-ops.c @@ -86,6 +86,7 @@ static void whpx_accel_ops_class_init(ObjectClass *oc, void *data) { AccelOpsClass *ops = ACCEL_OPS_CLASS(oc); + ops->get_cpus_queue = hw_accel_get_cpus_queue; ops->create_vcpu_thread = whpx_start_vcpu_thread; ops->kick_vcpu_thread = whpx_kick_vcpu_thread; ops->cpu_thread_is_idle = whpx_vcpu_thread_is_idle;