From patchwork Thu May 30 19:42:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 1941796 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=qyqnuRw7; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VqxWp4Kvcz20WX for ; Fri, 31 May 2024 05:43:49 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sClfx-0005cq-RG; Thu, 30 May 2024 15:43:01 -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 1sClfw-0005bp-0k for qemu-devel@nongnu.org; Thu, 30 May 2024 15:43:00 -0400 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sClft-0006HI-0q for qemu-devel@nongnu.org; Thu, 30 May 2024 15:42:59 -0400 Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-a6267778b3aso104624566b.3 for ; Thu, 30 May 2024 12:42:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717098172; x=1717702972; 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=uF3iE8sM7cMEjCs0SvCbRt/oMMRILi0hvudECvvT8YU=; b=qyqnuRw7c9bVN8zdLBqsDWexKpOqpQDHUBq13VWQC5/mBjqMLXTQCl8r/eMW6tZPz7 AIEy3MPSaqNaEImXCv1E4LqwBQvzS+6qrFUiOE8NFyoC3G/WTTHMCIU4Ne4Rn9LhHNnO XgXhdQh40IqxMs5A6TP6A7C03N9njojNxWnNFW1IQdY0//teAv0ZujUjhhUOw7lq0PcJ spAskfD2MCQ7cmnetjhDOAjN2h7NREBUDE58qg7kUUS3STkANlMaRhl32AAaevOvmBid lFlR1rvMHgD6ichbgygacVFh5cxIqb0AbMxtx6TT6IZvSxF3J28kR/4YkwE/PO/jNeyL sHHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717098172; x=1717702972; 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=uF3iE8sM7cMEjCs0SvCbRt/oMMRILi0hvudECvvT8YU=; b=LacK8uiUPGax5/XEKUcnVaDKSCTJSjKfyBvlrsz+uLc+GkWS6ZFLxbcaz2M3XWq5sL VuLZq1h8QnSFO044Pz6EJ72Tt4PbB9cz5B6KjQmioLdLtURjWhBVrFigPllVgo5YJcqT 6tsP7AecLeeMuZqjKKGmRsVjAEjOcRwcfAdrlcd631KaAlo9eOelPWh2NvCvSLJWHd3j WPdl7P+YxYQf7yPnfhub1wKAigOx6ONURfri3v7CEBEwzHKlYMf0wVdGF1hEGJ5T/4RT KQ91Ta5+35a49pM72pZz1wB20h0MfJzoqPVSz5kCgmMa38bBw/KvYBLHuGoiTzhs5fwt GbTg== X-Gm-Message-State: AOJu0YyeJERyLOX/n3VTjIUyv1rntjYWotfYMZznRgAobwgEqBJhS09D 3sZgxMZqLK1cf1k2Xv3veon6Y01DR63qjEk7E+IniUrqRe2bwmLSpi6wpu8Lb4E= X-Google-Smtp-Source: AGHT+IGq5go7pjxVXZoiDIctGP4OrpbOzSdrxavQVhZcrfZhYA5v6u0JB+p8JidVC79uF/koqWAkCw== X-Received: by 2002:a17:906:ae8f:b0:a66:ebc8:ad2c with SMTP id a640c23a62f3a-a66ebd812e1mr100669966b.42.1717098171713; Thu, 30 May 2024 12:42:51 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a67e73faa76sm8314766b.75.2024.05.30.12.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 12:42:51 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id A25505F8D5; Thu, 30 May 2024 20:42:50 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , Cameron Esfahani , Alexandre Iooss , Yanan Wang , Paolo Bonzini , Eduardo Habkost , Sunil Muthuswamy , Richard Henderson , Pierrick Bouvier , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?Daud=C3=A9?= , Mahmoud Mandour , Reinoud Zandijk , =?utf-8?q?Alex_Benn=C3=A9e?= , kvm@vger.kernel.org, Roman Bolshakov Subject: [PATCH 1/5] hw/core: expand on the alignment of CPUState Date: Thu, 30 May 2024 20:42:46 +0100 Message-Id: <20240530194250.1801701-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240530194250.1801701-1-alex.bennee@linaro.org> References: <20240530194250.1801701-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::635; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x635.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, T_SCC_BODY_TEXT_LINE=-0.01 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Make the relationship between CPUState, ArchCPU and cpu_env a bit clearer in the kdoc comments. Signed-off-by: Alex Bennée Reviewed-by: Pierrick Bouvier Reviewed-by: Philippe Mathieu-Daudé --- include/hw/core/cpu.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index bb398e8237..35d345371b 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -391,7 +391,8 @@ struct qemu_work_item; #define CPU_UNSET_NUMA_NODE_ID -1 /** - * CPUState: + * struct CPUState - common state of one CPU core or thread. + * * @cpu_index: CPU index (informative). * @cluster_index: Identifies which cluster this CPU is in. * For boards which don't define clusters or for "loose" CPUs not assigned @@ -439,10 +440,15 @@ struct qemu_work_item; * @kvm_fetch_index: Keeps the index that we last fetched from the per-vCPU * dirty ring structure. * - * State of one CPU core or thread. + * @neg_align: The CPUState is the common part of a concrete ArchCPU + * which is allocated when an individual CPU instance is created. As + * such care is taken is ensure there is no gap between between + * CPUState and CPUArchState within ArchCPU. * - * Align, in order to match possible alignment required by CPUArchState, - * and eliminate a hole between CPUState and CPUArchState within ArchCPU. + * @neg: The architectural register state ("cpu_env") immediately follows CPUState + * in ArchCPU and is passed to TCG code. The @neg structure holds some + * common TCG CPU variables which are accessed with a negative offset + * from cpu_env. */ struct CPUState { /*< private >*/ From patchwork Thu May 30 19:42:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 1941798 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=TPGsivEk; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VqxWp4Zndz23vC for ; Fri, 31 May 2024 05:43:49 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sClfy-0005dO-Fy; Thu, 30 May 2024 15:43:02 -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 1sClfw-0005cB-BP for qemu-devel@nongnu.org; Thu, 30 May 2024 15:43:00 -0400 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sClft-0006HT-0G for qemu-devel@nongnu.org; Thu, 30 May 2024 15:43:00 -0400 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-a667e104375so92875566b.1 for ; Thu, 30 May 2024 12:42:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717098173; x=1717702973; 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=Cnc+k2fYpUESVUzqiNhwI1EEtv65T/mceqpj8jrBceI=; b=TPGsivEkah+YWZfFOWdgKXB/8asyeaKesCUHcB7OcvcQ1Yb6WnI//SMBdvamuK+k0R ryYMti2/NsEMavvSu2N5T4yarHy9b8YwEep3mAsDOlC2RlaNuPktzXjEa1Ib6SNQPESK /ULFBjb6lE3zT/nsiwYBwmGCHxAwB82Q56P9vC/Nceu5OSOapCiRDGKA8KHWdfZz88qh nJshlUTHHWjllyNo+HiX9umJnoOqW2FEMmWGYDnpS2rJKYU6XzfmJMM5EhSxCQiEDm5e hNLrK7A19MKy5fviIUVI04evcuiOt8p84jh60++Syq1HZhtRpOXcf2i4XkcJ6Az++8wg jBLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717098173; x=1717702973; 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=Cnc+k2fYpUESVUzqiNhwI1EEtv65T/mceqpj8jrBceI=; b=MqghTdIEWicNxlJvTOfQyu0J5qJpBmPnN077S1m6fp4PNMAS4fAhyt7evUQd10rTlU 4/Im7P2XBSNCGzYmWXL8FwePmJBdhMneX1xeTfyyCMT55csgUJUVx/j1+7nyUDjMU+Mu j8N9IGTKHMN+zWNsdNmAB1zE89P+99jFPW/ZdBGQz4+09Rvo1Zzc+SDkz9UdMw0f33w0 GBb5udPzdvx+6a0RqHzJXI2I9fwui18sCy4ey9Pw6vzu+ruvIn2XRqDae0qtk7F0NemH d29Qce3vizvqawzxUOxvqr/AOzTYrci5XqL2BsBywF9ctjpAqXKXsUtZonZcs8cV8BX1 WnpQ== X-Gm-Message-State: AOJu0YwJZ3Vvc3j7wcNxUr1yIdPE0x7YB1HdzlolKGPuuQbS2FHtuxBM 9pzFzKHB3pX1NkB11d3szNvCporOHaBMIM4l+X+tGlINF0PGabuonbZlB4kcuWw= X-Google-Smtp-Source: AGHT+IFVOq8MKMEfrXxp4J5Y6CJd2GA9ZM++5hdN2jPC99fsqqvcLrmD9aX73RbTWxQdJn18BZeDlg== X-Received: by 2002:a17:906:d1c9:b0:a67:aa2b:1032 with SMTP id a640c23a62f3a-a67aa2b10f1mr32855366b.28.1717098173261; Thu, 30 May 2024 12:42:53 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a67ea67b4f8sm7831766b.102.2024.05.30.12.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 12:42:51 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id C35165F8E3; Thu, 30 May 2024 20:42:50 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , Cameron Esfahani , Alexandre Iooss , Yanan Wang , Paolo Bonzini , Eduardo Habkost , Sunil Muthuswamy , Richard Henderson , Pierrick Bouvier , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?Daud=C3=A9?= , Mahmoud Mandour , Reinoud Zandijk , =?utf-8?q?Alex_Benn=C3=A9e?= , kvm@vger.kernel.org, Roman Bolshakov Subject: [PATCH 2/5] cpu: move Qemu[Thread|Cond] setup into common code Date: Thu, 30 May 2024 20:42:47 +0100 Message-Id: <20240530194250.1801701-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240530194250.1801701-1-alex.bennee@linaro.org> References: <20240530194250.1801701-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62a; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x62a.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, T_SCC_BODY_TEXT_LINE=-0.01 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Aside from the round robin threads this is all common code. By moving the halt_cond setup we also no longer need hacks to work around the race between QOM object creation and thread creation. It is a little ugly to free stuff up for the round robin thread but better it deal with its own specialises than making the other accelerators jump through hoops. Signed-off-by: Alex Bennée Reviewed-by: Pierrick Bouvier Reviewed-by: Philippe Mathieu-Daudé --- include/hw/core/cpu.h | 4 ++++ accel/dummy-cpus.c | 3 --- accel/hvf/hvf-accel-ops.c | 4 ---- accel/kvm/kvm-accel-ops.c | 3 --- accel/tcg/tcg-accel-ops-mttcg.c | 4 ---- accel/tcg/tcg-accel-ops-rr.c | 14 +++++++------- hw/core/cpu-common.c | 5 +++++ target/i386/nvmm/nvmm-accel-ops.c | 3 --- target/i386/whpx/whpx-accel-ops.c | 3 --- 9 files changed, 16 insertions(+), 27 deletions(-) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 35d345371b..a405119eda 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -404,10 +404,14 @@ struct qemu_work_item; * @tcg_cflags: Pre-computed cflags for this cpu. * @nr_cores: Number of cores within this CPU package. * @nr_threads: Number of threads within this CPU core. + * @thread: Host thread details, only live once @created is #true + * @sem: WIN32 only semaphore used only for qtest + * @thread_id: native thread id of vCPU, only live once @created is #true * @running: #true if CPU is currently running (lockless). * @has_waiter: #true if a CPU is currently waiting for the cpu_exec_end; * valid under cpu_list_lock. * @created: Indicates whether the CPU thread has been successfully created. + * @halt_cond: condition variable sleeping threads can wait on. * @interrupt_request: Indicates a pending interrupt request. * @halted: Nonzero if the CPU is in suspended state. * @stop: Indicates a pending stop request. diff --git a/accel/dummy-cpus.c b/accel/dummy-cpus.c index 20519f1ea4..f32d8c8dc3 100644 --- a/accel/dummy-cpus.c +++ b/accel/dummy-cpus.c @@ -68,9 +68,6 @@ void dummy_start_vcpu_thread(CPUState *cpu) { char thread_name[VCPU_THREAD_NAME_SIZE]; - cpu->thread = g_malloc0(sizeof(QemuThread)); - cpu->halt_cond = g_malloc0(sizeof(QemuCond)); - qemu_cond_init(cpu->halt_cond); snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/DUMMY", cpu->cpu_index); qemu_thread_create(cpu->thread, thread_name, dummy_cpu_thread_fn, cpu, diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c index 40d4187d9d..6f1e27ef46 100644 --- a/accel/hvf/hvf-accel-ops.c +++ b/accel/hvf/hvf-accel-ops.c @@ -463,10 +463,6 @@ static void hvf_start_vcpu_thread(CPUState *cpu) */ assert(hvf_enabled()); - cpu->thread = g_malloc0(sizeof(QemuThread)); - cpu->halt_cond = g_malloc0(sizeof(QemuCond)); - qemu_cond_init(cpu->halt_cond); - snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/HVF", cpu->cpu_index); qemu_thread_create(cpu->thread, thread_name, hvf_cpu_thread_fn, diff --git a/accel/kvm/kvm-accel-ops.c b/accel/kvm/kvm-accel-ops.c index 94c828ac8d..c239dfc87a 100644 --- a/accel/kvm/kvm-accel-ops.c +++ b/accel/kvm/kvm-accel-ops.c @@ -66,9 +66,6 @@ static void kvm_start_vcpu_thread(CPUState *cpu) { char thread_name[VCPU_THREAD_NAME_SIZE]; - cpu->thread = g_malloc0(sizeof(QemuThread)); - cpu->halt_cond = g_malloc0(sizeof(QemuCond)); - qemu_cond_init(cpu->halt_cond); snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/KVM", cpu->cpu_index); qemu_thread_create(cpu->thread, thread_name, kvm_vcpu_thread_fn, diff --git a/accel/tcg/tcg-accel-ops-mttcg.c b/accel/tcg/tcg-accel-ops-mttcg.c index c552b45b8e..49814ec4af 100644 --- a/accel/tcg/tcg-accel-ops-mttcg.c +++ b/accel/tcg/tcg-accel-ops-mttcg.c @@ -137,10 +137,6 @@ void mttcg_start_vcpu_thread(CPUState *cpu) g_assert(tcg_enabled()); tcg_cpu_init_cflags(cpu, current_machine->smp.max_cpus > 1); - cpu->thread = g_new0(QemuThread, 1); - cpu->halt_cond = g_malloc0(sizeof(QemuCond)); - qemu_cond_init(cpu->halt_cond); - /* create a thread per vCPU with TCG (MTTCG) */ snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/TCG", cpu->cpu_index); diff --git a/accel/tcg/tcg-accel-ops-rr.c b/accel/tcg/tcg-accel-ops-rr.c index 894e73e52c..84c36c1450 100644 --- a/accel/tcg/tcg-accel-ops-rr.c +++ b/accel/tcg/tcg-accel-ops-rr.c @@ -317,22 +317,22 @@ void rr_start_vcpu_thread(CPUState *cpu) tcg_cpu_init_cflags(cpu, false); if (!single_tcg_cpu_thread) { - cpu->thread = g_new0(QemuThread, 1); - cpu->halt_cond = g_new0(QemuCond, 1); - qemu_cond_init(cpu->halt_cond); + single_tcg_halt_cond = cpu->halt_cond; + single_tcg_cpu_thread = cpu->thread; /* share a single thread for all cpus with TCG */ snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "ALL CPUs/TCG"); qemu_thread_create(cpu->thread, thread_name, rr_cpu_thread_fn, cpu, QEMU_THREAD_JOINABLE); - - single_tcg_halt_cond = cpu->halt_cond; - single_tcg_cpu_thread = cpu->thread; } else { - /* we share the thread */ + /* we share the thread, dump spare data */ + g_free(cpu->thread); + qemu_cond_destroy(cpu->halt_cond); cpu->thread = single_tcg_cpu_thread; cpu->halt_cond = single_tcg_halt_cond; + + /* copy the stuff done at start of rr_cpu_thread_fn */ cpu->thread_id = first_cpu->thread_id; cpu->neg.can_do_io = 1; cpu->created = true; diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c index 0f0a247f56..6cfc01593a 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -261,6 +261,11 @@ static void cpu_common_initfn(Object *obj) cpu->nr_threads = 1; cpu->cflags_next_tb = -1; + /* allocate storage for thread info, initialise condition variables */ + cpu->thread = g_new0(QemuThread, 1); + cpu->halt_cond = g_new0(QemuCond, 1); + qemu_cond_init(cpu->halt_cond); + qemu_mutex_init(&cpu->work_mutex); qemu_lockcnt_init(&cpu->in_ioctl_lock); QSIMPLEQ_INIT(&cpu->work_list); diff --git a/target/i386/nvmm/nvmm-accel-ops.c b/target/i386/nvmm/nvmm-accel-ops.c index 6b2bfd9b9c..0ba31201e2 100644 --- a/target/i386/nvmm/nvmm-accel-ops.c +++ b/target/i386/nvmm/nvmm-accel-ops.c @@ -64,9 +64,6 @@ static void nvmm_start_vcpu_thread(CPUState *cpu) { char thread_name[VCPU_THREAD_NAME_SIZE]; - cpu->thread = g_new0(QemuThread, 1); - cpu->halt_cond = g_new0(QemuCond, 1); - qemu_cond_init(cpu->halt_cond); snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/NVMM", cpu->cpu_index); qemu_thread_create(cpu->thread, thread_name, qemu_nvmm_cpu_thread_fn, diff --git a/target/i386/whpx/whpx-accel-ops.c b/target/i386/whpx/whpx-accel-ops.c index 189ae0f140..1a2b4e1c43 100644 --- a/target/i386/whpx/whpx-accel-ops.c +++ b/target/i386/whpx/whpx-accel-ops.c @@ -64,9 +64,6 @@ static void whpx_start_vcpu_thread(CPUState *cpu) { char thread_name[VCPU_THREAD_NAME_SIZE]; - cpu->thread = g_new0(QemuThread, 1); - cpu->halt_cond = g_new0(QemuCond, 1); - qemu_cond_init(cpu->halt_cond); snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/WHPX", cpu->cpu_index); qemu_thread_create(cpu->thread, thread_name, whpx_cpu_thread_fn, From patchwork Thu May 30 19:42:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 1941795 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=WvH2LWEQ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VqxWp43K5z20Pc for ; Fri, 31 May 2024 05:43:49 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sClfw-0005cO-Td; Thu, 30 May 2024 15:43:00 -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 1sClfv-0005be-5d for qemu-devel@nongnu.org; Thu, 30 May 2024 15:42:59 -0400 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sClft-0006HL-02 for qemu-devel@nongnu.org; Thu, 30 May 2024 15:42:58 -0400 Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-a626777f74eso125709766b.3 for ; Thu, 30 May 2024 12:42:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717098172; x=1717702972; 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=32yQbNKYA/0QpYwGyLEbfW3tqRcvc30vIF3lo+QmN14=; b=WvH2LWEQpYp8Q5bSeGBHdDeAgwfgbgSh9s94/RIvygnDz6krOZRgc7hlod6t6GRarT ouf/fYcPnbiK6mOuex1lzb1FlB8e45rDhtsUVmlIN2kMwl8xvaUHXpcmrmP8N95aLx1t 7c2vilNx65mBHxm1McXKWoRjeRDi2IITcqxhvRJchwoLHWzfdD+shhqwu+EYUH6p8sps DGsOiL71Sx6qeskWsFPiW8b2HVkC04ebccCNsHc8pPaWxji9hSylrTSM8SkwkonCi8Mc GLEPuA6pYgdUKcIgMwgMJaxBlHrgHrnn18uMSDfduZ/0TqvsvfxpgVGK9hsWOBH5EiRn cOiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717098172; x=1717702972; 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=32yQbNKYA/0QpYwGyLEbfW3tqRcvc30vIF3lo+QmN14=; b=u42D9S0YXCKzhTtC5q5W0hkX9Gwa9BKY3x989wQPLKtjApiWMB7BF1F4cGOtcHMM/U +SfaJgiPGaEqNQDC5CXymj/tFptV7IZX65HMkNyrjEWLQthOHoY/dfT1i8sJulXgygh9 a1o5MB3G1RKS/UpCL62Ib5886DgC3pS7EXgKNPF4oLiRbBGFQ/5PZDQ/sI4yZYsAlW28 H9rD1wNYjW/tStl/JfjxzKOr9Dr9+kVYUqWL8/Jzw654QhltmhtkFAHFhsu1y9/dnwSr 9o/NbbABK8XPMyDkZoqXH6eUANHAVcsropntNhvxol93EGsAi7/0NrrE8gafbP17ELOY FJDQ== X-Gm-Message-State: AOJu0YxkraqBGYKfTtiG4h9Fk8o1GbcRJvgPuCHxeIEcyXVCs40ad1s7 2nrOEdrZzcFCvI1OhlKqhNlnQ/vcJ2YBIve1YjJ+eqQ7xju2/klCHHTjvXeai2o= X-Google-Smtp-Source: AGHT+IFTafnXNuDoHGvLjw9aFZh+7U9j0vtTJAyWKnYBLNX81Afkye3DJvtDOKRgz1AGcECBR87nFQ== X-Received: by 2002:a17:906:f2d9:b0:a61:42ce:bbe4 with SMTP id a640c23a62f3a-a65e8e507f0mr301550166b.27.1717098171970; Thu, 30 May 2024 12:42:51 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a67eb34204dsm7560266b.191.2024.05.30.12.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 12:42:51 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id DA9075F8E5; Thu, 30 May 2024 20:42:50 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , Cameron Esfahani , Alexandre Iooss , Yanan Wang , Paolo Bonzini , Eduardo Habkost , Sunil Muthuswamy , Richard Henderson , Pierrick Bouvier , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?Daud=C3=A9?= , Mahmoud Mandour , Reinoud Zandijk , =?utf-8?q?Alex_Benn=C3=A9e?= , kvm@vger.kernel.org, Roman Bolshakov Subject: [PATCH 3/5] cpu-target: don't set cpu->thread_id to bogus value Date: Thu, 30 May 2024 20:42:48 +0100 Message-Id: <20240530194250.1801701-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240530194250.1801701-1-alex.bennee@linaro.org> References: <20240530194250.1801701-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::636; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x636.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, T_SCC_BODY_TEXT_LINE=-0.01 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The thread_id isn't valid until the threads are created. There is no point setting it here. The only thing that cares about the thread_id is qmp_query_cpus_fast. Signed-off-by: Alex Bennée Reviewed-by: Pierrick Bouvier Reviewed-by: Philippe Mathieu-Daudé --- cpu-target.c | 1 - 1 file changed, 1 deletion(-) diff --git a/cpu-target.c b/cpu-target.c index 5af120e8aa..499facf774 100644 --- a/cpu-target.c +++ b/cpu-target.c @@ -241,7 +241,6 @@ void cpu_exec_initfn(CPUState *cpu) cpu->num_ases = 0; #ifndef CONFIG_USER_ONLY - cpu->thread_id = qemu_get_thread_id(); cpu->memory = get_system_memory(); object_ref(OBJECT(cpu->memory)); #endif From patchwork Thu May 30 19:42:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 1941799 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=kWm70oz+; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VqxWv6wn7z20Pc for ; Fri, 31 May 2024 05:43:55 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sClg1-0005eR-1n; Thu, 30 May 2024 15:43:05 -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 1sClfy-0005dR-Sj for qemu-devel@nongnu.org; Thu, 30 May 2024 15:43:02 -0400 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sClft-0006HV-05 for qemu-devel@nongnu.org; Thu, 30 May 2024 15:43:02 -0400 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a621cb07d8fso134150066b.2 for ; Thu, 30 May 2024 12:42:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717098174; x=1717702974; 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=uSiuGXiCgmtxSxVezOHytC/a0n/fTNdw2YFzo1KJ2YY=; b=kWm70oz+mNRpjlcqKQl0qYPZ750I7cW5ssBh14uVBcA422l9x+6ilKeP+yiv1lCbBI N0o9BgporXvCFTBw3XRlzEqUYGd40fzMPoy3ohEHfABaNoE2Q8+EKkqrmejriksZICQo pofVzAGXV3rLRLwyJFiVqS/Y5mOc1amzpnGbHFXXF/AoMLnnofbj/FoUPbgYlAnVihrl Z0u0bGSIhzz0b8wCAzaKgHEUoQyQ90omkMKa/VJpE/cgOrGAVX25WNQ2E/HdEaaJSB9Y A174yqrjc1K7TtomQVyENjCswjQtkjre8wkcmVcvSxVCLPVCGxx1oDaT/mk5GwWZMVlA UHcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717098174; x=1717702974; 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=uSiuGXiCgmtxSxVezOHytC/a0n/fTNdw2YFzo1KJ2YY=; b=loUqKIXFGSGJOkkYW4v8uoR8JA4nY5s9iezbVebOWygMrG9KfdmQKrwbcOc+t4oNnD i1RI2WvKUhy4Yiqsric6whKUJenAT1cpTiE3cQzQSiZwoFjNAuEDGBV85MwjwqyANm1v o48um6qwOHiYpxlXDH4A9NHvyUw6OA14u/vv1EtTsi52gjrh7N1aGvgg6ykfKF83Etia 8Tep2rXvZm7XvZSevVwZGVHBSKOixHdxjSqOP+IX7n1s91gDOKAWi3h86CSI+6sQabST Ud78pMzC+9Q9yJzxYVUpVac53HSgDgPkEHFdmhKvDs6VY5noS6kir3POE1bqnuWgp9Q5 fUGg== X-Gm-Message-State: AOJu0YxhguhVPgbhLtC6ejMvcWDz6k7Jxa/8Xx+C39Twd++Csol/j1e8 NtLArRNtKc58261tUTp4r8dy/c24jDHNoFnISK2Ks7t7kQsa3MvnJcj5EXqWU18= X-Google-Smtp-Source: AGHT+IGCaRuVtIWhRyQ8FoN38Rt6/VkrlKQU/oJb9EQPlJPnpazA4r4xUC8i+X5fKyvCMARa5tUTRQ== X-Received: by 2002:a17:907:1dd3:b0:a59:ad15:6142 with SMTP id a640c23a62f3a-a65e92304eemr189379466b.77.1717098173472; Thu, 30 May 2024 12:42:53 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a67eab85f32sm7774166b.180.2024.05.30.12.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 12:42:51 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id F38205F8E7; Thu, 30 May 2024 20:42:50 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , Cameron Esfahani , Alexandre Iooss , Yanan Wang , Paolo Bonzini , Eduardo Habkost , Sunil Muthuswamy , Richard Henderson , Pierrick Bouvier , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?Daud=C3=A9?= , Mahmoud Mandour , Reinoud Zandijk , =?utf-8?q?Alex_Benn=C3=A9e?= , kvm@vger.kernel.org, Roman Bolshakov Subject: [PATCH 4/5] plugins: remove special casing for cpu->realized Date: Thu, 30 May 2024 20:42:49 +0100 Message-Id: <20240530194250.1801701-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240530194250.1801701-1-alex.bennee@linaro.org> References: <20240530194250.1801701-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62c; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x62c.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, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Now the condition variable is initialised early on we don't need to go through hoops to avoid calling async_run_on_cpu. Signed-off-by: Alex Bennée Reviewed-by: Pierrick Bouvier Reviewed-by: Philippe Mathieu-Daudé --- plugins/core.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/plugins/core.c b/plugins/core.c index 0726bc7f25..badede28cf 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -65,11 +65,7 @@ static void plugin_cpu_update__locked(gpointer k, gpointer v, gpointer udata) CPUState *cpu = container_of(k, CPUState, cpu_index); run_on_cpu_data mask = RUN_ON_CPU_HOST_ULONG(*plugin.mask); - if (DEVICE(cpu)->realized) { - async_run_on_cpu(cpu, plugin_cpu_update__async, mask); - } else { - plugin_cpu_update__async(cpu, mask); - } + async_run_on_cpu(cpu, plugin_cpu_update__async, mask); } void plugin_unregister_cb__locked(struct qemu_plugin_ctx *ctx, From patchwork Thu May 30 19:42:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 1941797 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Cpr15LOX; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VqxWp4Trpz20fB for ; Fri, 31 May 2024 05:43:49 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sClfz-0005da-90; Thu, 30 May 2024 15:43:03 -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 1sClfw-0005bo-0J for qemu-devel@nongnu.org; Thu, 30 May 2024 15:43:00 -0400 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sClft-0006HX-1a for qemu-devel@nongnu.org; Thu, 30 May 2024 15:42:59 -0400 Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-57a1fe6392eso1177179a12.0 for ; Thu, 30 May 2024 12:42:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717098174; x=1717702974; 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=fPCSTF6BhpGl/BOGWj8t6sMDRxBkBVgL05/HycPv784=; b=Cpr15LOX3D6CRbGYnptBxBZx07KYsY8FhPeQXNXTvuJAedeA5iL8KqBe/gYmn9P0Ra GywApjV6hl5szGirleSwljmgAdf/PUm6aO1wN8HQaP8+yZqTCB8Hnyfus/H5vS5OxSAT KHRJVywwd13mq0H8endRpFu8Xs9gc0QhBXi/N8SgSmgNKwLtzJhZRVueDoZaBdLSEzrS /cCgj8Al4Wp5AvcMtSwtQXiV+VUFOJrdZcwmQEILL7fGuxNRQvpWo5JGIlFf6QGf65lP IWiHpCt2rMZX34vRt+/rBDdyzRNAA18JRLQTLmtZqUZHYuH5hYbp/GX3OjUGvel0Ol1K mL+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717098174; x=1717702974; 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=fPCSTF6BhpGl/BOGWj8t6sMDRxBkBVgL05/HycPv784=; b=tAPftSMohLf0yFYMQSTOme59OKsu6hlGJxLGM0tNPGBwz3DqhmsUOr4baOOB3r8v62 Is1SIAO5oEkjaKcvcWmTeZKs9/lcA0gSu2hKUZ9kPsvCu/PystzogdMYG9h3/JQPHkat sGXHTNHAhWUqrm872E39nOLeysb2Yel7wEQgizqT1t7KjS1+YD5UcR6OPTwF318lQH7z cJ9oWkl2U2TRaTh0JyQcUFLJ1lM4GCGAA6Ab5IFv0pLGgsqAuDwS+gz6wjZZchZEFdip 4cniQrjsMMKFEo9RyE9AmtVpu6/6I5a485eORYh+RmjuhrwD94kCavDMNXs4AluqiKs0 2rWA== X-Gm-Message-State: AOJu0Yz/5YF6/pBvDuZkmjZbA8WaN5FLsXizzTqMbQZhiWKVx7Pn9nrR w9S7/DD+FNeS9uMYrqSSKZaxG8qjhtLTREGW3AyY6suZPhJwoqXwsIl1p4ixwKQ= X-Google-Smtp-Source: AGHT+IE6R76QAmiPveib3Be1Nxuw357LnoAEk7dKHLZ8AdvRVSDfuYn+KOWdz8CdSrBFOQdmXMpLAA== X-Received: by 2002:a17:906:7714:b0:a67:da88:149a with SMTP id a640c23a62f3a-a67da881f76mr21672966b.55.1717098173884; Thu, 30 May 2024 12:42:53 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a67eab85c8fsm7754766b.183.2024.05.30.12.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 12:42:53 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 16D015F8E9; Thu, 30 May 2024 20:42:51 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , Cameron Esfahani , Alexandre Iooss , Yanan Wang , Paolo Bonzini , Eduardo Habkost , Sunil Muthuswamy , Richard Henderson , Pierrick Bouvier , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?Daud=C3=A9?= , Mahmoud Mandour , Reinoud Zandijk , =?utf-8?q?Alex_Benn=C3=A9e?= , kvm@vger.kernel.org, Roman Bolshakov Subject: [PATCH 5/5] core/cpu-common: initialise plugin state before thread creation Date: Thu, 30 May 2024 20:42:50 +0100 Message-Id: <20240530194250.1801701-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240530194250.1801701-1-alex.bennee@linaro.org> References: <20240530194250.1801701-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52c; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x52c.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, T_SCC_BODY_TEXT_LINE=-0.01 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Originally I tried to move where vCPU thread initialisation to later in realize. However pulling that thread (sic) got gnarly really quickly. It turns out some steps of CPU realization need values that can only be determined from the running vCPU thread. However having moved enough out of the thread creation we can now queue work before the thread starts (at least for TCG guests) and avoid the race between vcpu_init and other vcpu states a plugin might subscribe to. Signed-off-by: Alex Bennée Reviewed-by: Pierrick Bouvier Reviewed-by: Philippe Mathieu-Daudé --- hw/core/cpu-common.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c index 6cfc01593a..bf1a7b8892 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -222,14 +222,6 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp) cpu_resume(cpu); } - /* Plugin initialization must wait until the cpu start executing code */ -#ifdef CONFIG_PLUGIN - if (tcg_enabled()) { - cpu->plugin_state = qemu_plugin_create_vcpu_state(); - async_run_on_cpu(cpu, qemu_plugin_vcpu_init__async, RUN_ON_CPU_NULL); - } -#endif - /* NOTE: latest generic point where the cpu is fully realized */ } @@ -273,6 +265,18 @@ static void cpu_common_initfn(Object *obj) QTAILQ_INIT(&cpu->watchpoints); cpu_exec_initfn(cpu); + + /* + * Plugin initialization must wait until the cpu start executing + * code, but we must queue this work before the threads are + * created to ensure we don't race. + */ +#ifdef CONFIG_PLUGIN + if (tcg_enabled()) { + cpu->plugin_state = qemu_plugin_create_vcpu_state(); + async_run_on_cpu(cpu, qemu_plugin_vcpu_init__async, RUN_ON_CPU_NULL); + } +#endif } static void cpu_common_finalize(Object *obj)